@@ -0,0 +1,37 | |||||
|
1 | #include "qseriespointgraphicsitem.h" | |||
|
2 | #include <QPainter> | |||
|
3 | #include <QPicture> | |||
|
4 | #include <QPixmap> | |||
|
5 | #include <QDebug> | |||
|
6 | ||||
|
7 | QSeriesPointGraphicsItem::QSeriesPointGraphicsItem(qreal dx, qreal dy, QGraphicsItem *parent) | |||
|
8 | : QGraphicsItem(parent), | |||
|
9 | m_dx(dx), | |||
|
10 | m_dy(dy) | |||
|
11 | { | |||
|
12 | } | |||
|
13 | ||||
|
14 | QRectF QSeriesPointGraphicsItem::boundingRect() const | |||
|
15 | { | |||
|
16 | // return parentItem()->boundingRect(); | |||
|
17 | return QRectF(0, 0, 10, 10); | |||
|
18 | } | |||
|
19 | ||||
|
20 | void QSeriesPointGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
21 | { | |||
|
22 | QTransform transform = painter->transform(); | |||
|
23 | transform.translate(m_dx, m_dy); | |||
|
24 | painter->setTransform(transform); | |||
|
25 | ||||
|
26 | QPen pen = painter->pen(); | |||
|
27 | QBrush brush = pen.brush(); | |||
|
28 | brush.setColor(Qt::darkRed); | |||
|
29 | pen.setBrush(brush); | |||
|
30 | painter->setPen(pen); | |||
|
31 | ||||
|
32 | QPixmap pixmap; | |||
|
33 | pixmap.load("scatter.png"); | |||
|
34 | painter->drawPixmap(boundingRect().toRect(), pixmap); | |||
|
35 | ||||
|
36 | // painter->drawRect(boundingRect()); | |||
|
37 | } |
@@ -0,0 +1,18 | |||||
|
1 | #ifndef QSERIESPOINTGRAPHICSITEM_H | |||
|
2 | #define QSERIESPOINTGRAPHICSITEM_H | |||
|
3 | ||||
|
4 | #include <QGraphicsItem> | |||
|
5 | ||||
|
6 | class QSeriesPointGraphicsItem : public QGraphicsItem | |||
|
7 | { | |||
|
8 | public: | |||
|
9 | QSeriesPointGraphicsItem(qreal dx, qreal dy, QGraphicsItem *parent = 0); | |||
|
10 | ||||
|
11 | private: | |||
|
12 | QRectF boundingRect() const; | |||
|
13 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
14 | qreal m_dx; | |||
|
15 | qreal m_dy; | |||
|
16 | }; | |||
|
17 | ||||
|
18 | #endif // QSERIESPOINTGRAPHICSITEM_H |
@@ -1,28 +1,32 | |||||
1 | TARGET = chartwidgettest |
|
1 | TARGET = chartwidgettest | |
2 | TEMPLATE = app |
|
2 | TEMPLATE = app | |
3 |
|
3 | |||
4 | QT += core gui |
|
4 | QT += core gui | |
5 | contains(QT_MAJOR_VERSION, 5) { |
|
5 | contains(QT_MAJOR_VERSION, 5) { | |
6 | QT += widgets |
|
6 | QT += widgets | |
7 | } |
|
7 | } | |
8 |
|
8 | |||
9 | CONFIG += charts |
|
9 | CONFIG += charts | |
10 | CHARTS += widget |
|
10 | CHARTS += widget | |
11 |
|
11 | |||
12 | OBJECTS_DIR = tmp |
|
12 | OBJECTS_DIR = tmp | |
13 | MOC_DIR = tmp |
|
13 | MOC_DIR = tmp | |
14 |
|
14 | |||
15 | SOURCES += main.cpp \ |
|
15 | SOURCES += main.cpp \ | |
16 | mainwidget.cpp \ |
|
16 | mainwidget.cpp \ | |
17 | qscatterseries.cpp \ |
|
17 | qscatterseries.cpp \ | |
18 | qchartwidget.cpp |
|
18 | qchartwidget.cpp \ | |
|
19 | qseriespointgraphicsitem.cpp | |||
19 |
|
20 | |||
20 | HEADERS += \ |
|
21 | HEADERS += \ | |
21 | mainwidget.h \ |
|
22 | mainwidget.h \ | |
22 | qscatterseries.h \ |
|
23 | qscatterseries.h \ | |
23 | qchartwidget.h |
|
24 | qchartwidget.h \ | |
|
25 | qseriespointgraphicsitem.h | |||
|
26 | ||||
|
27 | ||||
24 |
|
28 | |||
25 |
|
29 | |||
26 |
|
30 | |||
27 |
|
31 | |||
28 |
|
32 |
@@ -1,157 +1,171 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "qchartwidget.h" |
|
2 | #include "qchartwidget.h" | |
3 | //#include <chartwidget.h> |
|
3 | //#include <chartwidget.h> | |
4 | #include <QPushButton> |
|
4 | #include <QPushButton> | |
5 | #include <QComboBox> |
|
5 | #include <QComboBox> | |
6 | #include <QSpinBox> |
|
6 | #include <QSpinBox> | |
7 | #include <QCheckBox> |
|
7 | #include <QCheckBox> | |
8 | #include <QGridLayout> |
|
8 | #include <QGridLayout> | |
9 | #include <QHBoxLayout> |
|
9 | #include <QHBoxLayout> | |
10 | #include <QLabel> |
|
10 | #include <QLabel> | |
11 | #include <QSpacerItem> |
|
11 | #include <QSpacerItem> | |
12 | #include <QMessageBox> |
|
12 | #include <QMessageBox> | |
|
13 | #include <cmath> | |||
13 | #include <QDebug> |
|
14 | #include <QDebug> | |
14 |
|
15 | |||
15 | MainWidget::MainWidget(QWidget *parent) : |
|
16 | MainWidget::MainWidget(QWidget *parent) : | |
16 | QWidget(parent) |
|
17 | QWidget(parent) | |
17 | { |
|
18 | { | |
18 | m_chartWidget = new QChartWidget(this); |
|
19 | m_chartWidget = new QChartWidget(this); | |
19 | // m_chartWidget->resize(QSize(200,200)); |
|
20 | // m_chartWidget->resize(QSize(200,200)); | |
20 | // m_chartWidget->setColor(Qt::red); |
|
21 | // m_chartWidget->setColor(Qt::red); | |
21 | // Chart type |
|
22 | // Chart type | |
22 | // TODO: How about multiple types? |
|
23 | // TODO: How about multiple types? | |
23 | // Should the type be a property of a graph instead of the chart? |
|
24 | // Should the type be a property of a graph instead of the chart? | |
24 | QComboBox *chartTypeCombo = new QComboBox(this); |
|
25 | QComboBox *chartTypeCombo = new QComboBox(this); | |
25 | chartTypeCombo->addItem("Line"); |
|
26 | chartTypeCombo->addItem("Line"); | |
26 | chartTypeCombo->addItem("Area"); |
|
27 | chartTypeCombo->addItem("Area"); | |
27 | chartTypeCombo->addItem("Bar"); |
|
28 | chartTypeCombo->addItem("Bar"); | |
28 | chartTypeCombo->addItem("Pie"); |
|
29 | chartTypeCombo->addItem("Pie"); | |
29 | chartTypeCombo->addItem("Scatter"); |
|
30 | chartTypeCombo->addItem("Scatter"); | |
30 | chartTypeCombo->addItem("Spline"); |
|
31 | chartTypeCombo->addItem("Spline"); | |
31 | connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), |
|
32 | connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), | |
32 | this, SLOT(chartTypeChanged(int))); |
|
33 | this, SLOT(chartTypeChanged(int))); | |
33 |
|
34 | |||
34 | // Test data selector |
|
35 | // Test data selector | |
35 | QPushButton *fileButton = new QPushButton("From file"); |
|
36 | QPushButton *fileButton = new QPushButton("From file"); | |
36 | QPushButton *urlButton = new QPushButton("From URL"); |
|
37 | QPushButton *urlButton = new QPushButton("From URL"); | |
37 |
|
38 | |||
38 | // Chart background |
|
39 | // Chart background | |
39 | QComboBox *backgroundCombo = new QComboBox(this); |
|
40 | QComboBox *backgroundCombo = new QComboBox(this); | |
40 | backgroundCombo->addItem("todo: add background types"); |
|
41 | backgroundCombo->addItem("todo: add background types"); | |
41 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
42 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
42 | this, SLOT(backgroundChanged(int))); |
|
43 | this, SLOT(backgroundChanged(int))); | |
43 |
|
44 | |||
44 | // Axis |
|
45 | // Axis | |
45 | // TODO: multiple axes? |
|
46 | // TODO: multiple axes? | |
46 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
47 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
47 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
48 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
48 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
49 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
49 | m_xMinSpin = new QSpinBox(); |
|
50 | m_xMinSpin = new QSpinBox(); | |
50 | m_xMinSpin->setMinimum(INT_MIN); |
|
51 | m_xMinSpin->setMinimum(INT_MIN); | |
51 | m_xMinSpin->setMaximum(INT_MAX); |
|
52 | m_xMinSpin->setMaximum(INT_MAX); | |
52 | m_xMinSpin->setValue(0); |
|
53 | m_xMinSpin->setValue(0); | |
53 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
54 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
54 | m_xMaxSpin = new QSpinBox(); |
|
55 | m_xMaxSpin = new QSpinBox(); | |
55 | m_xMaxSpin->setMinimum(INT_MIN); |
|
56 | m_xMaxSpin->setMinimum(INT_MIN); | |
56 | m_xMaxSpin->setMaximum(INT_MAX); |
|
57 | m_xMaxSpin->setMaximum(INT_MAX); | |
57 | m_xMaxSpin->setValue(10); |
|
58 | m_xMaxSpin->setValue(10); | |
58 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
59 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
59 | m_yMinSpin = new QSpinBox(); |
|
60 | m_yMinSpin = new QSpinBox(); | |
60 | m_yMinSpin->setMinimum(INT_MIN); |
|
61 | m_yMinSpin->setMinimum(INT_MIN); | |
61 | m_yMinSpin->setMaximum(INT_MAX); |
|
62 | m_yMinSpin->setMaximum(INT_MAX); | |
62 | m_yMinSpin->setValue(0); |
|
63 | m_yMinSpin->setValue(0); | |
63 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
64 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
64 | m_yMaxSpin = new QSpinBox(); |
|
65 | m_yMaxSpin = new QSpinBox(); | |
65 | m_yMaxSpin->setMinimum(INT_MIN); |
|
66 | m_yMaxSpin->setMinimum(INT_MIN); | |
66 | m_yMaxSpin->setMaximum(INT_MAX); |
|
67 | m_yMaxSpin->setMaximum(INT_MAX); | |
67 | m_yMaxSpin->setValue(10); |
|
68 | m_yMaxSpin->setValue(10); | |
68 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
69 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
69 |
|
70 | |||
70 | QGridLayout *grid = new QGridLayout(); |
|
71 | QGridLayout *grid = new QGridLayout(); | |
71 | QHBoxLayout *hbox = new QHBoxLayout(); |
|
72 | QHBoxLayout *hbox = new QHBoxLayout(); | |
72 | grid->addWidget(new QLabel("Chart type:"), 0, 0); |
|
73 | grid->addWidget(new QLabel("Chart type:"), 0, 0); | |
73 | grid->addWidget(chartTypeCombo, 0, 1, 1, 2); |
|
74 | grid->addWidget(chartTypeCombo, 0, 1, 1, 2); | |
74 | grid->addWidget(new QLabel("Data:"), 1, 0); |
|
75 | grid->addWidget(new QLabel("Data:"), 1, 0); | |
75 | grid->addWidget(fileButton, 1, 1); |
|
76 | grid->addWidget(fileButton, 1, 1); | |
76 | grid->addWidget(urlButton, 1, 2); |
|
77 | grid->addWidget(urlButton, 1, 2); | |
77 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
78 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
78 | grid->addWidget(backgroundCombo, 2, 1, 1, 2); |
|
79 | grid->addWidget(backgroundCombo, 2, 1, 1, 2); | |
79 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
80 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
80 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
81 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
81 | grid->addWidget(m_xMinSpin, 4, 1, 1, 2); |
|
82 | grid->addWidget(m_xMinSpin, 4, 1, 1, 2); | |
82 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
83 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
83 | grid->addWidget(m_xMaxSpin, 5, 1, 1, 2); |
|
84 | grid->addWidget(m_xMaxSpin, 5, 1, 1, 2); | |
84 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
85 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
85 | grid->addWidget(m_yMinSpin, 6, 1, 1, 2); |
|
86 | grid->addWidget(m_yMinSpin, 6, 1, 1, 2); | |
86 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
87 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
87 | grid->addWidget(m_yMaxSpin, 7, 1, 1, 2); |
|
88 | grid->addWidget(m_yMaxSpin, 7, 1, 1, 2); | |
88 | // add row with empty label to make all the other rows static |
|
89 | // add row with empty label to make all the other rows static | |
89 | grid->addWidget(new QLabel(""), 8, 0); |
|
90 | grid->addWidget(new QLabel(""), 8, 0); | |
90 | grid->setRowStretch(8, 1); |
|
91 | grid->setRowStretch(8, 1); | |
91 |
|
92 | |||
92 | hbox->addLayout(grid); |
|
93 | hbox->addLayout(grid); | |
93 | hbox->addWidget(m_chartWidget); |
|
94 | hbox->addWidget(m_chartWidget); | |
94 | hbox->setStretch(1, 1); |
|
95 | hbox->setStretch(1, 1); | |
95 |
|
96 | |||
96 | setLayout(hbox); |
|
97 | setLayout(hbox); | |
97 |
|
98 | |||
98 | m_autoScaleCheck->setChecked(true); |
|
99 | m_autoScaleCheck->setChecked(true); | |
|
100 | chartTypeChanged(4); | |||
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 | void MainWidget::chartTypeChanged(int itemIndex) |
|
103 | void MainWidget::chartTypeChanged(int itemIndex) | |
102 | { |
|
104 | { | |
103 | // TODO: change chart type |
|
105 | // TODO: change chart type | |
104 | switch (itemIndex) { |
|
106 | switch (itemIndex) { | |
105 | case 4: { |
|
107 | case 4: { | |
|
108 | QList<QChartDataPoint> data; | |||
|
109 | for (int x = 0; x < 1000; ++x) { | |||
|
110 | data.append(QChartDataPoint() << x -200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); | |||
|
111 | } | |||
|
112 | // data.append(QChartDataPoint() << 0 << 0); | |||
|
113 | // data.append(QChartDataPoint() << 2 << 2); | |||
|
114 | // data.append(QChartDataPoint() << 4 << 5); | |||
|
115 | // data.append(QChartDataPoint() << 5 << 9); | |||
|
116 | // data.append(QChartDataPoint() << 20 << 20); | |||
|
117 | // QList<int> data; | |||
106 |
|
|
118 | m_chartWidget->setType(4); | |
|
119 | m_chartWidget->setData(data); | |||
107 |
|
|
120 | break; | |
108 |
|
|
121 | } | |
109 | default: |
|
122 | default: { | |
110 | m_chartWidget->setType(0); |
|
123 | m_chartWidget->setType(0); | |
111 | break; |
|
124 | break; | |
112 | } |
|
125 | } | |
113 | } |
|
126 | } | |
|
127 | } | |||
114 |
|
128 | |||
115 | void MainWidget::dataChanged(QString itemText) |
|
129 | void MainWidget::dataChanged(QString itemText) | |
116 | { |
|
130 | { | |
117 | qDebug() << "dataChanged: " << itemText; |
|
131 | qDebug() << "dataChanged: " << itemText; | |
118 | } |
|
132 | } | |
119 |
|
133 | |||
120 | void MainWidget::backgroundChanged(int itemIndex) |
|
134 | void MainWidget::backgroundChanged(int itemIndex) | |
121 | { |
|
135 | { | |
122 | qDebug() << "backgroundChanged: " << itemIndex; |
|
136 | qDebug() << "backgroundChanged: " << itemIndex; | |
123 | } |
|
137 | } | |
124 |
|
138 | |||
125 | void MainWidget::autoScaleChanged(int value) |
|
139 | void MainWidget::autoScaleChanged(int value) | |
126 | { |
|
140 | { | |
127 | if (value) { |
|
141 | if (value) { | |
128 | // TODO: enable auto scaling |
|
142 | // TODO: enable auto scaling | |
129 | } else { |
|
143 | } else { | |
130 | // TODO: set scaling manually (and disable auto scaling) |
|
144 | // TODO: set scaling manually (and disable auto scaling) | |
131 | } |
|
145 | } | |
132 |
|
146 | |||
133 | m_xMinSpin->setEnabled(!value); |
|
147 | m_xMinSpin->setEnabled(!value); | |
134 | m_xMaxSpin->setEnabled(!value); |
|
148 | m_xMaxSpin->setEnabled(!value); | |
135 | m_yMinSpin->setEnabled(!value); |
|
149 | m_yMinSpin->setEnabled(!value); | |
136 | m_yMaxSpin->setEnabled(!value); |
|
150 | m_yMaxSpin->setEnabled(!value); | |
137 | } |
|
151 | } | |
138 |
|
152 | |||
139 | void MainWidget::xMinChanged(int value) |
|
153 | void MainWidget::xMinChanged(int value) | |
140 | { |
|
154 | { | |
141 | qDebug() << "xMinChanged: " << value; |
|
155 | qDebug() << "xMinChanged: " << value; | |
142 | } |
|
156 | } | |
143 |
|
157 | |||
144 | void MainWidget::xMaxChanged(int value) |
|
158 | void MainWidget::xMaxChanged(int value) | |
145 | { |
|
159 | { | |
146 | qDebug() << "xMaxChanged: " << value; |
|
160 | qDebug() << "xMaxChanged: " << value; | |
147 | } |
|
161 | } | |
148 |
|
162 | |||
149 | void MainWidget::yMinChanged(int value) |
|
163 | void MainWidget::yMinChanged(int value) | |
150 | { |
|
164 | { | |
151 | qDebug() << "yMinChanged: " << value; |
|
165 | qDebug() << "yMinChanged: " << value; | |
152 | } |
|
166 | } | |
153 |
|
167 | |||
154 | void MainWidget::yMaxChanged(int value) |
|
168 | void MainWidget::yMaxChanged(int value) | |
155 | { |
|
169 | { | |
156 | qDebug() << "yMaxChanged: " << value; |
|
170 | qDebug() << "yMaxChanged: " << value; | |
157 | } |
|
171 | } |
@@ -1,41 +1,44 | |||||
1 | #include "qchartwidget.h" |
|
1 | #include "qchartwidget.h" | |
2 | #include "qscatterseries.h" |
|
2 | #include "qscatterseries.h" | |
3 | #include <QGraphicsView> |
|
3 | #include <QGraphicsView> | |
4 | #include <QGraphicsScene> |
|
4 | #include <QGraphicsScene> | |
5 |
|
5 | |||
6 | QChartWidget::QChartWidget(QWidget *parent) : |
|
6 | QChartWidget::QChartWidget(QWidget *parent) : | |
7 | QWidget(parent) |
|
7 | QWidget(parent), | |
|
8 | m_scatter(0) | |||
8 | { |
|
9 | { | |
9 | // scatter |
|
|||
10 | m_scene = new QGraphicsScene(); |
|
10 | m_scene = new QGraphicsScene(); | |
11 | m_view = new QGraphicsView(m_scene, this); |
|
11 | m_view = new QGraphicsView(m_scene, this); | |
12 |
m_view->resize( |
|
12 | m_view->resize(490, 300); | |
13 |
|
||||
14 | // TODO: implement graphics item for axis |
|
|||
15 | m_scene->addLine(0, 0, 0, 100); |
|
|||
16 | m_scene->addLine(0, 100, 100, 100); |
|
|||
17 |
|
||||
18 | m_view->show(); |
|
13 | m_view->show(); | |
19 | } |
|
14 | } | |
20 |
|
15 | |||
21 | QChartWidget::~QChartWidget() |
|
16 | QChartWidget::~QChartWidget() | |
22 | { |
|
17 | { | |
23 | delete m_view; |
|
18 | delete m_view; | |
24 | delete m_scene; |
|
19 | delete m_scene; | |
25 | } |
|
20 | } | |
26 |
|
21 | |||
27 | void QChartWidget::setType(/*TODO QChart::Type*/ int type) |
|
22 | void QChartWidget::setType(/*TODO QChart::Type*/ int type) | |
28 | { |
|
23 | { | |
29 | if (type == 4) { |
|
24 | if (type == 4) { | |
30 | if (!m_scatter) { |
|
25 | if (!m_scatter) { | |
31 | m_scatter = new QScatterSeries(); |
|
26 | m_scatter = new QScatterSeries(); | |
32 | m_scene->addItem(m_scatter); |
|
27 | m_scene->addItem(m_scatter); | |
33 | } |
|
28 | } | |
34 | } else { |
|
29 | } else { | |
35 | if (m_scatter) { |
|
30 | if (m_scatter) { | |
36 | m_scene->removeItem(m_scatter); |
|
31 | m_scene->removeItem(m_scatter); | |
37 | delete m_scatter; |
|
32 | delete m_scatter; | |
38 | m_scatter = 0; |
|
33 | m_scatter = 0; | |
39 | } |
|
34 | } | |
40 | } |
|
35 | } | |
41 | } |
|
36 | } | |
|
37 | ||||
|
38 | void QChartWidget::setData(QList<QChartDataPoint> data) | |||
|
39 | //void QChartWidget::setData(QList<int> data) | |||
|
40 | { | |||
|
41 | // TODO: other chart types... this looks ugly | |||
|
42 | if (m_scatter) | |||
|
43 | m_scatter->setData(data); | |||
|
44 | } |
@@ -1,28 +1,33 | |||||
1 | #ifndef QCHARTWIDGET_H |
|
1 | #ifndef QCHARTWIDGET_H | |
2 | #define QCHARTWIDGET_H |
|
2 | #define QCHARTWIDGET_H | |
3 |
|
3 | |||
4 | #include <QWidget> |
|
4 | #include <QWidget> | |
5 |
|
5 | |||
6 | class QGraphicsView; |
|
6 | class QGraphicsView; | |
7 | class QGraphicsScene; |
|
7 | class QGraphicsScene; | |
8 | class QScatterSeries; |
|
8 | class QScatterSeries; | |
9 |
|
9 | |||
|
10 | // TODO: | |||
|
11 | #define QChartDataPoint QList<QVariant> | |||
|
12 | ||||
10 | class QChartWidget : public QWidget |
|
13 | class QChartWidget : public QWidget | |
11 | { |
|
14 | { | |
12 | Q_OBJECT |
|
15 | Q_OBJECT | |
13 | public: |
|
16 | public: | |
14 | explicit QChartWidget(QWidget *parent = 0); |
|
17 | explicit QChartWidget(QWidget *parent = 0); | |
15 | ~QChartWidget(); |
|
18 | ~QChartWidget(); | |
16 | void setType(/*TODO QChart::Type*/ int type); |
|
19 | void setType(/*TODO QChart::Type*/ int type); | |
|
20 | void setData(QList<QChartDataPoint> data); | |||
|
21 | // void setData(QList<int> data); | |||
17 |
|
22 | |||
18 | signals: |
|
23 | signals: | |
19 |
|
24 | |||
20 | public slots: |
|
25 | public slots: | |
21 |
|
26 | |||
22 | private: |
|
27 | private: | |
23 | QGraphicsView *m_view; |
|
28 | QGraphicsView *m_view; | |
24 | QGraphicsScene *m_scene; |
|
29 | QGraphicsScene *m_scene; | |
25 | QScatterSeries *m_scatter; |
|
30 | QScatterSeries *m_scatter; | |
26 | }; |
|
31 | }; | |
27 |
|
32 | |||
28 | #endif // QCHARTWIDGET_H |
|
33 | #endif // QCHARTWIDGET_H |
@@ -1,29 +1,30 | |||||
1 | #include "qscatterseries.h" |
|
1 | #include "qscatterseries.h" | |
|
2 | #include "qseriespointgraphicsitem.h" | |||
2 | #include <QPainter> |
|
3 | #include <QPainter> | |
|
4 | #include <QGraphicsScene> | |||
3 |
|
5 | |||
4 | QScatterSeries::QScatterSeries(QGraphicsItem *parent) : |
|
6 | QScatterSeries::QScatterSeries(QGraphicsItem *parent) : | |
5 | QGraphicsItem(parent) |
|
7 | QGraphicsItem(parent) | |
6 | { |
|
8 | { | |
7 | } |
|
9 | } | |
8 |
|
10 | |||
9 | QRectF QScatterSeries::boundingRect() const |
|
11 | QRectF QScatterSeries::boundingRect() const | |
10 | { |
|
12 | { | |
11 | // qreal penWidth = 1; |
|
13 | return QRectF(0, 50, 100, 100); | |
12 | // return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, |
|
|||
13 | // 20 + penWidth, 20 + penWidth); |
|
|||
14 | return QRectF(0, 0, 100, 100); |
|
|||
15 | } |
|
14 | } | |
16 |
|
15 | |||
17 | void QScatterSeries::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
16 | void QScatterSeries::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
18 | { |
|
17 | { | |
19 | QPen pen = painter->pen(); |
|
18 | // painter->drawRect(boundingRect()); | |
20 | QBrush brush = pen.brush(); |
|
19 | } | |
21 | brush.setColor(Qt::darkRed); |
|
20 | ||
22 | pen.setBrush(brush); |
|
21 | void QScatterSeries::setData(QList<QChartDataPoint> data) | |
23 | painter->setPen(pen); |
|
22 | //void QScatterSeries::setData(QList<int> data) | |
24 | painter->drawRoundedRect(0, 0, 10, 10, 5, 5); |
|
23 | { | |
25 | painter->drawRoundedRect(5, 5, 10, 10, 5, 5); |
|
24 | foreach(QChartDataPoint point, data) { | |
26 | painter->drawRoundedRect(54, 25, 10, 10, 5, 5); |
|
25 | // TODO: ownership? | |
27 | painter->drawRoundedRect(34, 35, 10, 10, 5, 5); |
|
26 | // TODO: position | |
28 | //painter->drawEllipse(QPoint(10, 10), 100, 100); |
|
27 | QSeriesPointGraphicsItem *item = new QSeriesPointGraphicsItem( | |
|
28 | point[0].toReal(), 100-point[1].toReal(), this); | |||
|
29 | } | |||
29 | } |
|
30 | } |
@@ -1,20 +1,27 | |||||
1 | #ifndef QSCATTERSERIES_H |
|
1 | #ifndef QSCATTERSERIES_H | |
2 | #define QSCATTERSERIES_H |
|
2 | #define QSCATTERSERIES_H | |
3 |
|
3 | |||
4 | #include <QGraphicsItem> |
|
4 | #include <QGraphicsItem> | |
5 |
|
5 | |||
|
6 | // TODO: | |||
|
7 | #define QChartDataPoint QList<QVariant> | |||
|
8 | ||||
|
9 | class QSeriesPointGraphicsItem; | |||
|
10 | ||||
6 | class QScatterSeries : public QGraphicsItem |
|
11 | class QScatterSeries : public QGraphicsItem | |
7 | { |
|
12 | { | |
8 | public: |
|
13 | public: | |
9 |
|
|
14 | QScatterSeries(QGraphicsItem *parent = 0); | |
|
15 | void setData(QList<QChartDataPoint> data); | |||
|
16 | // void setData(QList<int> data); | |||
10 |
|
17 | |||
11 | signals: |
|
18 | signals: | |
12 |
|
19 | |||
13 | public slots: |
|
20 | public slots: | |
14 |
|
21 | |||
15 | private: |
|
22 | public: | |
16 | QRectF boundingRect() const; |
|
23 | QRectF boundingRect() const; | |
17 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
24 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
18 | }; |
|
25 | }; | |
19 |
|
26 | |||
20 | #endif // QSCATTERSERIES_H |
|
27 | #endif // QSCATTERSERIES_H |
General Comments 0
You need to be logged in to leave comments.
Login now