@@ -1,171 +1,167 | |||||
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 <cmath> | |
14 | #include <QDebug> |
|
14 | #include <QDebug> | |
15 |
|
15 | |||
16 | MainWidget::MainWidget(QWidget *parent) : |
|
16 | MainWidget::MainWidget(QWidget *parent) : | |
17 | QWidget(parent) |
|
17 | QWidget(parent) | |
18 | { |
|
18 | { | |
19 | m_chartWidget = new QChartWidget(this); |
|
19 | m_chartWidget = new QChartWidget(this); | |
20 | // m_chartWidget->resize(QSize(200,200)); |
|
20 | // m_chartWidget->resize(QSize(200,200)); | |
21 | // m_chartWidget->setColor(Qt::red); |
|
21 | // m_chartWidget->setColor(Qt::red); | |
22 | // Chart type |
|
22 | // Chart type | |
23 | // TODO: How about multiple types? |
|
23 | // TODO: How about multiple types? | |
24 | // 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? | |
25 | QComboBox *chartTypeCombo = new QComboBox(this); |
|
25 | QComboBox *chartTypeCombo = new QComboBox(this); | |
26 | chartTypeCombo->addItem("Line"); |
|
26 | chartTypeCombo->addItem("Line"); | |
27 | chartTypeCombo->addItem("Area"); |
|
27 | chartTypeCombo->addItem("Area"); | |
28 | chartTypeCombo->addItem("Bar"); |
|
28 | chartTypeCombo->addItem("Bar"); | |
29 | chartTypeCombo->addItem("Pie"); |
|
29 | chartTypeCombo->addItem("Pie"); | |
30 | chartTypeCombo->addItem("Scatter"); |
|
30 | chartTypeCombo->addItem("Scatter"); | |
31 | chartTypeCombo->addItem("Spline"); |
|
31 | chartTypeCombo->addItem("Spline"); | |
32 | connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), |
|
32 | connect(chartTypeCombo, SIGNAL(currentIndexChanged(int)), | |
33 | this, SLOT(chartTypeChanged(int))); |
|
33 | this, SLOT(chartTypeChanged(int))); | |
34 |
|
34 | |||
35 | // Test data selector |
|
35 | // Test data selector | |
36 | QPushButton *fileButton = new QPushButton("From file"); |
|
36 | QPushButton *fileButton = new QPushButton("From file"); | |
37 | QPushButton *urlButton = new QPushButton("From URL"); |
|
37 | QPushButton *urlButton = new QPushButton("From URL"); | |
38 |
|
38 | |||
39 | // Chart background |
|
39 | // Chart background | |
40 | QComboBox *backgroundCombo = new QComboBox(this); |
|
40 | QComboBox *backgroundCombo = new QComboBox(this); | |
41 | backgroundCombo->addItem("todo: add background types"); |
|
41 | backgroundCombo->addItem("todo: add background types"); | |
42 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
42 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
43 | this, SLOT(backgroundChanged(int))); |
|
43 | this, SLOT(backgroundChanged(int))); | |
44 |
|
44 | |||
45 | // Axis |
|
45 | // Axis | |
46 | // TODO: multiple axes? |
|
46 | // TODO: multiple axes? | |
47 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
47 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
48 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
48 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
49 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
49 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
50 | m_xMinSpin = new QSpinBox(); |
|
50 | m_xMinSpin = new QSpinBox(); | |
51 | m_xMinSpin->setMinimum(INT_MIN); |
|
51 | m_xMinSpin->setMinimum(INT_MIN); | |
52 | m_xMinSpin->setMaximum(INT_MAX); |
|
52 | m_xMinSpin->setMaximum(INT_MAX); | |
53 | m_xMinSpin->setValue(0); |
|
53 | m_xMinSpin->setValue(0); | |
54 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
54 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
55 | m_xMaxSpin = new QSpinBox(); |
|
55 | m_xMaxSpin = new QSpinBox(); | |
56 | m_xMaxSpin->setMinimum(INT_MIN); |
|
56 | m_xMaxSpin->setMinimum(INT_MIN); | |
57 | m_xMaxSpin->setMaximum(INT_MAX); |
|
57 | m_xMaxSpin->setMaximum(INT_MAX); | |
58 | m_xMaxSpin->setValue(10); |
|
58 | m_xMaxSpin->setValue(10); | |
59 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
59 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
60 | m_yMinSpin = new QSpinBox(); |
|
60 | m_yMinSpin = new QSpinBox(); | |
61 | m_yMinSpin->setMinimum(INT_MIN); |
|
61 | m_yMinSpin->setMinimum(INT_MIN); | |
62 | m_yMinSpin->setMaximum(INT_MAX); |
|
62 | m_yMinSpin->setMaximum(INT_MAX); | |
63 | m_yMinSpin->setValue(0); |
|
63 | m_yMinSpin->setValue(0); | |
64 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
64 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
65 | m_yMaxSpin = new QSpinBox(); |
|
65 | m_yMaxSpin = new QSpinBox(); | |
66 | m_yMaxSpin->setMinimum(INT_MIN); |
|
66 | m_yMaxSpin->setMinimum(INT_MIN); | |
67 | m_yMaxSpin->setMaximum(INT_MAX); |
|
67 | m_yMaxSpin->setMaximum(INT_MAX); | |
68 | m_yMaxSpin->setValue(10); |
|
68 | m_yMaxSpin->setValue(10); | |
69 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
69 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
70 |
|
70 | |||
71 | QGridLayout *grid = new QGridLayout(); |
|
71 | QGridLayout *grid = new QGridLayout(); | |
72 | QHBoxLayout *hbox = new QHBoxLayout(); |
|
72 | QHBoxLayout *hbox = new QHBoxLayout(); | |
73 | grid->addWidget(new QLabel("Chart type:"), 0, 0); |
|
73 | grid->addWidget(new QLabel("Chart type:"), 0, 0); | |
74 | grid->addWidget(chartTypeCombo, 0, 1, 1, 2); |
|
74 | grid->addWidget(chartTypeCombo, 0, 1, 1, 2); | |
75 | grid->addWidget(new QLabel("Data:"), 1, 0); |
|
75 | grid->addWidget(new QLabel("Data:"), 1, 0); | |
76 | grid->addWidget(fileButton, 1, 1); |
|
76 | grid->addWidget(fileButton, 1, 1); | |
77 | grid->addWidget(urlButton, 1, 2); |
|
77 | grid->addWidget(urlButton, 1, 2); | |
78 | grid->addWidget(new QLabel("Background:"), 2, 0); |
|
78 | grid->addWidget(new QLabel("Background:"), 2, 0); | |
79 | grid->addWidget(backgroundCombo, 2, 1, 1, 2); |
|
79 | grid->addWidget(backgroundCombo, 2, 1, 1, 2); | |
80 | grid->addWidget(m_autoScaleCheck, 3, 0); |
|
80 | grid->addWidget(m_autoScaleCheck, 3, 0); | |
81 | grid->addWidget(new QLabel("x min:"), 4, 0); |
|
81 | grid->addWidget(new QLabel("x min:"), 4, 0); | |
82 | grid->addWidget(m_xMinSpin, 4, 1, 1, 2); |
|
82 | grid->addWidget(m_xMinSpin, 4, 1, 1, 2); | |
83 | grid->addWidget(new QLabel("x max:"), 5, 0); |
|
83 | grid->addWidget(new QLabel("x max:"), 5, 0); | |
84 | grid->addWidget(m_xMaxSpin, 5, 1, 1, 2); |
|
84 | grid->addWidget(m_xMaxSpin, 5, 1, 1, 2); | |
85 | grid->addWidget(new QLabel("y min:"), 6, 0); |
|
85 | grid->addWidget(new QLabel("y min:"), 6, 0); | |
86 | grid->addWidget(m_yMinSpin, 6, 1, 1, 2); |
|
86 | grid->addWidget(m_yMinSpin, 6, 1, 1, 2); | |
87 | grid->addWidget(new QLabel("y max:"), 7, 0); |
|
87 | grid->addWidget(new QLabel("y max:"), 7, 0); | |
88 | grid->addWidget(m_yMaxSpin, 7, 1, 1, 2); |
|
88 | grid->addWidget(m_yMaxSpin, 7, 1, 1, 2); | |
89 | // 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 | |
90 | grid->addWidget(new QLabel(""), 8, 0); |
|
90 | grid->addWidget(new QLabel(""), 8, 0); | |
91 | grid->setRowStretch(8, 1); |
|
91 | grid->setRowStretch(8, 1); | |
92 |
|
92 | |||
93 | hbox->addLayout(grid); |
|
93 | hbox->addLayout(grid); | |
94 | hbox->addWidget(m_chartWidget); |
|
94 | hbox->addWidget(m_chartWidget); | |
95 | hbox->setStretch(1, 1); |
|
95 | hbox->setStretch(1, 1); | |
96 |
|
96 | |||
97 | setLayout(hbox); |
|
97 | setLayout(hbox); | |
98 |
|
98 | |||
99 | m_autoScaleCheck->setChecked(true); |
|
99 | m_autoScaleCheck->setChecked(true); | |
100 | chartTypeChanged(4); |
|
100 | chartTypeChanged(4); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void MainWidget::chartTypeChanged(int itemIndex) |
|
103 | void MainWidget::chartTypeChanged(int itemIndex) | |
104 | { |
|
104 | { | |
105 | // TODO: change chart type |
|
105 | // TODO: change chart type | |
106 | switch (itemIndex) { |
|
106 | switch (itemIndex) { | |
107 | case 4: { |
|
107 | case 4: { | |
108 | QList<QChartDataPoint> data; |
|
108 | QList<QChartDataPoint> data; | |
109 | for (int x = 0; x < 1000; ++x) { |
|
109 | for (int x = 0; x < 1000; ++x) { | |
110 | data.append(QChartDataPoint() << x -200 << 2 * (uint(sin(3.14159/50*x)*80) % 100)); |
|
110 | data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |
|
111 | data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |||
|
112 | data.append(QChartDataPoint() << x - 200 << 2 * (uint(sin(3.14159/50*x)*80) % 100) + (rand() % 100 * 0.2)); | |||
111 | } |
|
113 | } | |
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; |
|
|||
118 | m_chartWidget->setType(4); |
|
114 | m_chartWidget->setType(4); | |
119 | m_chartWidget->setData(data); |
|
115 | m_chartWidget->setData(data); | |
120 | break; |
|
116 | break; | |
121 | } |
|
117 | } | |
122 | default: { |
|
118 | default: { | |
123 | m_chartWidget->setType(0); |
|
119 | m_chartWidget->setType(0); | |
124 | break; |
|
120 | break; | |
125 | } |
|
121 | } | |
126 | } |
|
122 | } | |
127 | } |
|
123 | } | |
128 |
|
124 | |||
129 | void MainWidget::dataChanged(QString itemText) |
|
125 | void MainWidget::dataChanged(QString itemText) | |
130 | { |
|
126 | { | |
131 | qDebug() << "dataChanged: " << itemText; |
|
127 | qDebug() << "dataChanged: " << itemText; | |
132 | } |
|
128 | } | |
133 |
|
129 | |||
134 | void MainWidget::backgroundChanged(int itemIndex) |
|
130 | void MainWidget::backgroundChanged(int itemIndex) | |
135 | { |
|
131 | { | |
136 | qDebug() << "backgroundChanged: " << itemIndex; |
|
132 | qDebug() << "backgroundChanged: " << itemIndex; | |
137 | } |
|
133 | } | |
138 |
|
134 | |||
139 | void MainWidget::autoScaleChanged(int value) |
|
135 | void MainWidget::autoScaleChanged(int value) | |
140 | { |
|
136 | { | |
141 | if (value) { |
|
137 | if (value) { | |
142 | // TODO: enable auto scaling |
|
138 | // TODO: enable auto scaling | |
143 | } else { |
|
139 | } else { | |
144 | // TODO: set scaling manually (and disable auto scaling) |
|
140 | // TODO: set scaling manually (and disable auto scaling) | |
145 | } |
|
141 | } | |
146 |
|
142 | |||
147 | m_xMinSpin->setEnabled(!value); |
|
143 | m_xMinSpin->setEnabled(!value); | |
148 | m_xMaxSpin->setEnabled(!value); |
|
144 | m_xMaxSpin->setEnabled(!value); | |
149 | m_yMinSpin->setEnabled(!value); |
|
145 | m_yMinSpin->setEnabled(!value); | |
150 | m_yMaxSpin->setEnabled(!value); |
|
146 | m_yMaxSpin->setEnabled(!value); | |
151 | } |
|
147 | } | |
152 |
|
148 | |||
153 | void MainWidget::xMinChanged(int value) |
|
149 | void MainWidget::xMinChanged(int value) | |
154 | { |
|
150 | { | |
155 | qDebug() << "xMinChanged: " << value; |
|
151 | qDebug() << "xMinChanged: " << value; | |
156 | } |
|
152 | } | |
157 |
|
153 | |||
158 | void MainWidget::xMaxChanged(int value) |
|
154 | void MainWidget::xMaxChanged(int value) | |
159 | { |
|
155 | { | |
160 | qDebug() << "xMaxChanged: " << value; |
|
156 | qDebug() << "xMaxChanged: " << value; | |
161 | } |
|
157 | } | |
162 |
|
158 | |||
163 | void MainWidget::yMinChanged(int value) |
|
159 | void MainWidget::yMinChanged(int value) | |
164 | { |
|
160 | { | |
165 | qDebug() << "yMinChanged: " << value; |
|
161 | qDebug() << "yMinChanged: " << value; | |
166 | } |
|
162 | } | |
167 |
|
163 | |||
168 | void MainWidget::yMaxChanged(int value) |
|
164 | void MainWidget::yMaxChanged(int value) | |
169 | { |
|
165 | { | |
170 | qDebug() << "yMaxChanged: " << value; |
|
166 | qDebug() << "yMaxChanged: " << value; | |
171 | } |
|
167 | } |
@@ -1,37 +1,41 | |||||
1 | #include "qseriespointgraphicsitem.h" |
|
1 | #include "qseriespointgraphicsitem.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 | #include <QPicture> |
|
3 | #include <QPicture> | |
4 | #include <QPixmap> |
|
4 | #include <QPixmap> | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QSeriesPointGraphicsItem::QSeriesPointGraphicsItem(qreal dx, qreal dy, QGraphicsItem *parent) |
|
7 | QSeriesPointGraphicsItem::QSeriesPointGraphicsItem(qreal dx, qreal dy, QGraphicsItem *parent) | |
8 | : QGraphicsItem(parent), |
|
8 | : QGraphicsItem(parent), | |
9 | m_dx(dx), |
|
9 | m_dx(dx), | |
10 | m_dy(dy) |
|
10 | m_dy(dy) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | QRectF QSeriesPointGraphicsItem::boundingRect() const |
|
14 | QRectF QSeriesPointGraphicsItem::boundingRect() const | |
15 | { |
|
15 | { | |
16 | // return parentItem()->boundingRect(); |
|
16 | // return parentItem()->boundingRect(); | |
17 | return QRectF(0, 0, 10, 10); |
|
17 | return QRectF(0, 0, 10, 10); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | void QSeriesPointGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
20 | void QSeriesPointGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
21 | { |
|
21 | { | |
22 | QTransform transform = painter->transform(); |
|
22 | QTransform transform = painter->transform(); | |
23 | transform.translate(m_dx, m_dy); |
|
23 | transform.translate(m_dx, m_dy); | |
24 | painter->setTransform(transform); |
|
24 | painter->setTransform(transform); | |
25 |
|
25 | |||
26 | QPen pen = painter->pen(); |
|
26 | QPen pen = painter->pen(); | |
27 | QBrush brush = pen.brush(); |
|
27 | QBrush brush = pen.brush(); | |
28 | brush.setColor(Qt::darkRed); |
|
28 | // TODO: The opacity should be user definable... | |
|
29 | brush.setColor(QColor(255, 82, 0, 50)); | |||
29 | pen.setBrush(brush); |
|
30 | pen.setBrush(brush); | |
|
31 | pen.setWidth(4); | |||
30 | painter->setPen(pen); |
|
32 | painter->setPen(pen); | |
|
33 | painter->drawArc(0, 0, 4, 4, 0, 5760); | |||
31 |
|
34 | |||
32 | QPixmap pixmap; |
|
35 | // TODO: how about using a bitmap? | |
33 | pixmap.load("scatter.png"); |
|
36 | // QPixmap pixmap; | |
34 | painter->drawPixmap(boundingRect().toRect(), pixmap); |
|
37 | // pixmap.load("scatter.png"); | |
|
38 | // painter->drawPixmap(boundingRect().toRect(), pixmap); | |||
35 |
|
39 | |||
36 | // painter->drawRect(boundingRect()); |
|
40 | // painter->drawRect(boundingRect()); | |
37 | } |
|
41 | } |
General Comments 0
You need to be logged in to leave comments.
Login now