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