@@ -15,37 +15,28 class DrilldownBarSeries : public QStackedBarSeries | |||
|
15 | 15 | { |
|
16 | 16 | Q_OBJECT |
|
17 | 17 | public: |
|
18 |
DrilldownBarSeries(QStringList categories, QObject* |
|
|
18 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {} | |
|
19 | 19 | |
|
20 | ||
|
21 | public Q_SLOTS: | |
|
22 | void handleRightClick(QBarSet *barset, QString category) | |
|
20 | void addDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) | |
|
23 | 21 | { |
|
24 | qDebug() << "DrilldownBarSeries::handleRightClick" << barset->name() << category; | |
|
25 | // mChart->changeSeries(this); | |
|
22 | mDrilldownSeries[category] = drilldownSeries; | |
|
26 | 23 | } |
|
27 | 24 | |
|
28 | }; | |
|
29 | //! [1] | |
|
30 | ||
|
31 | //! [2] | |
|
32 | class DrilldownBarSet : public QBarSet | |
|
33 | { | |
|
34 | Q_OBJECT | |
|
35 | public: | |
|
36 | DrilldownBarSet(QString name, DrilldownBarSeries* drilldownSeries) : QBarSet(name) , mSeries(drilldownSeries) {} | |
|
37 | ||
|
38 | 25 | DrilldownBarSeries* drilldownSeries(QString category) |
|
39 |
|
|
|
40 | return mSeries; | |
|
41 | } | |
|
26 | { | |
|
27 | // qDebug() << "DrilldownBarSeries::drilldownSeries" << category << mDrilldownSeries[category]; | |
|
28 | return mDrilldownSeries[category]; | |
|
29 | } | |
|
30 | ||
|
31 | public Q_SLOTS: | |
|
42 | 32 | |
|
43 | 33 | private: |
|
44 | DrilldownBarSeries* mSeries; | |
|
34 | ||
|
35 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; | |
|
45 | 36 | }; |
|
46 |
//! [ |
|
|
37 | //! [1] | |
|
47 | 38 | |
|
48 |
//! [ |
|
|
39 | //! [2] | |
|
49 | 40 | class DrilldownChart : public QChartView |
|
50 | 41 | { |
|
51 | 42 | Q_OBJECT |
@@ -66,14 +57,14 public Q_SLOTS: | |||
|
66 | 57 | { |
|
67 | 58 | qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category; |
|
68 | 59 | // TODO: continue from here |
|
69 |
DrilldownBarSe |
|
|
70 |
changeSeries( |
|
|
60 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
|
61 | changeSeries(series->drilldownSeries(category)); | |
|
71 | 62 | } |
|
72 | 63 | |
|
73 | 64 | private: |
|
74 | 65 | QSeries* m_currentSeries; |
|
75 | 66 | }; |
|
76 |
//! [ |
|
|
67 | //! [2] | |
|
77 | 68 | |
|
78 | 69 | int main(int argc, char *argv[]) |
|
79 | 70 | { |
@@ -83,7 +74,7 int main(int argc, char *argv[]) | |||
|
83 | 74 | DrilldownChart* drilldownChart = new DrilldownChart(&window); |
|
84 | 75 | drilldownChart->setChartTheme(QChart::ChartThemeIcy); |
|
85 | 76 | |
|
86 |
//! [ |
|
|
77 | //! [3] | |
|
87 | 78 | // Define categories |
|
88 | 79 | QStringList months; |
|
89 | 80 | months << "Jun" << "Jul" << "Aug" << "Sep"; |
@@ -91,61 +82,62 int main(int argc, char *argv[]) | |||
|
91 | 82 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
92 | 83 | QStringList plants; |
|
93 | 84 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
85 | //! [3] | |
|
86 | ||
|
94 | 87 | //! [4] |
|
88 | // Create drilldown structure | |
|
89 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
|
90 | seasonSeries->setTitle("Crop by month - Season"); | |
|
95 | 91 | |
|
96 | DrilldownBarSeries* monthlySeries = new DrilldownBarSeries(months, drilldownChart); | |
|
97 | monthlySeries->setTitle("Crop by month - Season"); | |
|
92 | // Each month in season series has drilldown series for weekly data | |
|
93 | foreach (QString month, months) { | |
|
98 | 94 | |
|
99 | foreach (QString plant, plants) { | |
|
95 | // Create drilldown series for every week | |
|
100 | 96 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
101 | DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries); | |
|
102 | weeklySeries->setTitle("Crop by week - Month"); | |
|
103 | ||
|
104 | foreach(QString month, months) { | |
|
105 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); | |
|
106 | ||
|
107 | foreach (QString week, weeks ) { | |
|
108 | *weeklyCrop << (qrand() % 20); | |
|
109 | } | |
|
97 | seasonSeries->addDrilldownSeries(month, weeklySeries); | |
|
110 | 98 | |
|
111 | weeklySeries->addBarSet(weeklyCrop); | |
|
112 | weeklySeries->setToolTipEnabled(true); | |
|
113 | *monthlyCrop << weeklyCrop->total(); | |
|
114 | ||
|
115 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
|
116 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
99 | // Drilling down from weekly data brings us back to season data. | |
|
100 | foreach (QString week, weeks) { | |
|
101 | weeklySeries->addDrilldownSeries(week, seasonSeries); | |
|
102 | weeklySeries->setTitle(QString("Crop by week - " + month)); | |
|
117 | 103 | } |
|
118 | 104 | |
|
119 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
|
120 | monthlySeries->addBarSet(monthlyCrop); | |
|
105 | // Use right click signal to implement drilldown | |
|
106 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
121 | 107 | } |
|
108 | //! [4] | |
|
122 | 109 | |
|
123 | /* | |
|
110 | //! [5] | |
|
111 | // Fill monthly and weekly series with data | |
|
124 | 112 | foreach (QString plant, plants) { |
|
125 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
|
126 | DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries); | |
|
127 | weeklySeries->setTitle("Crop by week - Month"); | |
|
128 | foreach(QString month, months) { | |
|
129 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); | |
|
113 | QBarSet* monthlyCrop = new QBarSet(plant); | |
|
114 | foreach (QString month, months) { | |
|
115 | QBarSet* weeklyCrop = new QBarSet(plant); | |
|
130 | 116 | foreach (QString week, weeks ) { |
|
131 | 117 | *weeklyCrop << (qrand() % 20); |
|
132 | 118 | } |
|
133 | weeklySeries->addBarSet(weeklyCrop); | |
|
134 | weeklySeries->setToolTipEnabled(true); | |
|
119 | // Get the drilldown series from upper level series and add crop to it. | |
|
120 | seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop); | |
|
121 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); | |
|
135 | 122 | *monthlyCrop << weeklyCrop->total(); |
|
123 | ||
|
136 | 124 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); |
|
137 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
138 | 125 | } |
|
126 | seasonSeries->addBarSet(monthlyCrop); | |
|
139 | 127 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); |
|
140 | monthlySeries->addBarSet(monthlyCrop); | |
|
141 | 128 | } |
|
142 | */ | |
|
143 | QObject::connect(monthlySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
129 | //! [5] | |
|
130 | ||
|
131 | seasonSeries->setToolTipEnabled(true); | |
|
132 | ||
|
133 | // Enable drilldown from season series using right click. | |
|
134 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
144 | 135 | |
|
145 | monthlySeries->setToolTipEnabled(true); | |
|
146 |
drilldownChart->changeSeries( |
|
|
147 |
drilldownChart->setChartTitle( |
|
|
136 | // Show season series in initial view | |
|
137 | drilldownChart->changeSeries(seasonSeries); | |
|
138 | drilldownChart->setChartTitle(seasonSeries->title()); | |
|
148 | 139 | |
|
140 | // Disable axis, since they don't really apply to bar chart | |
|
149 | 141 | drilldownChart->axisX()->setAxisVisible(false); |
|
150 | 142 | drilldownChart->axisX()->setGridVisible(false); |
|
151 | 143 | drilldownChart->axisX()->setLabelsVisible(false); |
@@ -15,7 +15,6 StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QGraphicsItem *pare | |||
|
15 | 15 | |
|
16 | 16 | StackedBarPresenter::~StackedBarPresenter() |
|
17 | 17 | { |
|
18 | qDebug() << "StackedBarPresenter deleted"; | |
|
19 | 18 | } |
|
20 | 19 | |
|
21 | 20 |
@@ -213,12 +213,20 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const | |||
|
213 | 213 | case QSeries::SeriesTypeScatter: { |
|
214 | 214 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
215 | 215 | Q_ASSERT(scatterSeries); |
|
216 | qreal minX(domain->minX()); | |
|
217 | qreal minY(domain->minY()); | |
|
218 | qreal maxX(domain->maxX()); | |
|
219 | qreal maxY(domain->maxY()); | |
|
216 | 220 | foreach (QPointF point, scatterSeries->data()) { |
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 | minX = qMin(minX, point.x()); | |
|
222 | minY = qMin(minY, point.y()); | |
|
223 | maxX = qMax(maxX, point.x()); | |
|
224 | maxY = qMax(maxY, point.y()); | |
|
221 | 225 | } |
|
226 | domain->setMinX(minX); | |
|
227 | domain->setMinY(minY); | |
|
228 | domain->setMaxX(maxX); | |
|
229 | domain->setMaxY(maxY); | |
|
222 | 230 | break; |
|
223 | 231 | } |
|
224 | 232 |
@@ -219,9 +219,13 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |||
|
219 | 219 | scatterSeries, SIGNAL(clicked(QPointF))); |
|
220 | 220 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
221 | 221 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
222 | QObject::connect(domain, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)), | |
|
223 | scatterPresenter, SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
|
222 | 224 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
223 | 225 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
224 | if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect); | |
|
226 | if (m_rect.isValid()) | |
|
227 | scatterPresenter->handleGeometryChanged(m_rect); | |
|
228 | scatterPresenter->handleDomainChanged(domain->minX(), domain->maxX(), domain->minY(), domain->maxY()); | |
|
225 | 229 | break; |
|
226 | 230 | } |
|
227 | 231 | case QSeries::SeriesTypePie: { |
@@ -4,7 +4,7 | |||
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | class QChartAxisCategories : public QObject | |
|
7 | class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject | |
|
8 | 8 | { |
|
9 | 9 | Q_OBJECT |
|
10 | 10 | private: |
@@ -18,10 +18,10 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare | |||
|
18 | 18 | m_minY(0), |
|
19 | 19 | m_maxY(0), |
|
20 | 20 | m_series(series), |
|
21 |
m_ |
|
|
21 | m_clippingRect() | |
|
22 | 22 | { |
|
23 | 23 | if (parent) |
|
24 |
m_ |
|
|
24 | m_clippingRect = parent->boundingRect(); | |
|
25 | 25 | |
|
26 | 26 | if (series) { |
|
27 | 27 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
@@ -38,16 +38,16 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare | |||
|
38 | 38 | |
|
39 | 39 | void ScatterPresenter::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
40 | 40 | { |
|
41 | m_minX=minX; | |
|
42 | m_maxX=maxX; | |
|
43 | m_minY=minY; | |
|
44 | m_maxY=maxY; | |
|
41 | m_minX = minX; | |
|
42 | m_maxX = maxX; | |
|
43 | m_minY = minY; | |
|
44 | m_maxY = maxY; | |
|
45 | 45 | changeGeometry(); |
|
46 | 46 | } |
|
47 | 47 | |
|
48 | 48 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
49 | 49 | { |
|
50 |
m_ |
|
|
50 | m_clippingRect = rect.translated(-rect.topLeft()); | |
|
51 | 51 | changeGeometry(); |
|
52 | 52 | setPos(rect.topLeft()); |
|
53 | 53 | } |
@@ -61,7 +61,7 void ScatterPresenter::handleModelChanged() | |||
|
61 | 61 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
62 | 62 | { |
|
63 | 63 | painter->save(); |
|
64 |
painter->setClipRect(m_ |
|
|
64 | painter->setClipRect(m_clippingRect); | |
|
65 | 65 | |
|
66 | 66 | // TODO: how to draw a drop shadow? |
|
67 | 67 | // Now using a custom implementation for drop shadow instead of QGraphicsDropShadowEffect. |
@@ -104,17 +104,17 void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
104 | 104 | void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
105 | 105 | { |
|
106 | 106 | QPointF clickedPoint( |
|
107 |
m_minX + (event->lastPos().x() / m_ |
|
|
108 |
m_maxY - (event->lastPos().y() / m_ |
|
|
107 | m_minX + (event->lastPos().x() / m_clippingRect.width()) * (m_maxX-m_minX), | |
|
108 | m_maxY - (event->lastPos().y() / m_clippingRect.height()) * (m_maxY-m_minY)); | |
|
109 | 109 | emit clicked(clickedPoint); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | void ScatterPresenter::changeGeometry() |
|
113 | 113 | { |
|
114 |
if (m_ |
|
|
114 | if (m_clippingRect.isValid()) { | |
|
115 | 115 | prepareGeometryChange(); |
|
116 |
qreal scalex = m_ |
|
|
117 |
qreal scaley = m_ |
|
|
116 | qreal scalex = m_clippingRect.width() / (m_maxX - m_minX); | |
|
117 | qreal scaley = m_clippingRect.height() / (m_maxY - m_minY); | |
|
118 | 118 | |
|
119 | 119 | int shape = m_series->shape(); |
|
120 | 120 | m_path = QPainterPath(); |
@@ -124,7 +124,7 void ScatterPresenter::changeGeometry() | |||
|
124 | 124 | foreach (QPointF point, m_series->data()) { |
|
125 | 125 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
126 | 126 | qreal x = point.x() * scalex - m_minX * scalex - size / 2; |
|
127 |
qreal y = m_ |
|
|
127 | qreal y = m_clippingRect.height() - point.y() * scaley + m_minY * scaley - size / 2; | |
|
128 | 128 | |
|
129 | 129 | if (x < scene()->width() && y < scene()->height()) { |
|
130 | 130 | switch (shape) { |
@@ -39,7 +39,7 public: | |||
|
39 | 39 | qreal m_minY; |
|
40 | 40 | qreal m_maxY; |
|
41 | 41 | QScatterSeries *m_series; |
|
42 |
QRectF m_ |
|
|
42 | QRectF m_clippingRect; | |
|
43 | 43 | QPen m_markerPen; |
|
44 | 44 | QBrush m_markerBrush; |
|
45 | 45 | QPainterPath m_path; |
@@ -49,15 +49,6 MainWidget::MainWidget(QWidget *parent) : | |||
|
49 | 49 | QGridLayout *mainLayout = new QGridLayout(); |
|
50 | 50 | mainLayout->addLayout(grid, 0, 0); |
|
51 | 51 | |
|
52 | // Init series type specific controls | |
|
53 | initPieControls(); | |
|
54 | mainLayout->addLayout(m_pieLayout, 2, 0); | |
|
55 | // Scatter series specific settings | |
|
56 | // m_scatterLayout = new QGridLayout(); | |
|
57 | // m_scatterLayout->addWidget(new QLabel("scatter"), 0, 0); | |
|
58 | // m_scatterLayout->setEnabled(false); | |
|
59 | // mainLayout->addLayout(m_scatterLayout, 1, 0); | |
|
60 | ||
|
61 | 52 | // Add layouts and the chart widget to the main layout |
|
62 | 53 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
63 | 54 | setLayout(mainLayout); |
@@ -153,33 +144,6 void MainWidget::antiAliasToggled(bool enabled) | |||
|
153 | 144 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
154 | 145 | } |
|
155 | 146 | |
|
156 | void MainWidget::initPieControls() | |
|
157 | { | |
|
158 | // Pie series specific settings | |
|
159 | // Pie size factory | |
|
160 | QDoubleSpinBox *pieSizeSpin = new QDoubleSpinBox(); | |
|
161 | pieSizeSpin->setMinimum(LONG_MIN); | |
|
162 | pieSizeSpin->setMaximum(LONG_MAX); | |
|
163 | pieSizeSpin->setValue(1.0); | |
|
164 | pieSizeSpin->setSingleStep(0.1); | |
|
165 | connect(pieSizeSpin, SIGNAL(valueChanged(double)), this, SLOT(setPieSizeFactor(double))); | |
|
166 | // Pie position | |
|
167 | QComboBox *piePosCombo = new QComboBox(this); | |
|
168 | piePosCombo->addItem("Maximized"); | |
|
169 | piePosCombo->addItem("Top left"); | |
|
170 | piePosCombo->addItem("Top right"); | |
|
171 | piePosCombo->addItem("Bottom left"); | |
|
172 | piePosCombo->addItem("Bottom right"); | |
|
173 | connect(piePosCombo, SIGNAL(currentIndexChanged(int)), | |
|
174 | this, SLOT(setPiePosition(int))); | |
|
175 | m_pieLayout = new QGridLayout(); | |
|
176 | m_pieLayout->setEnabled(false); | |
|
177 | m_pieLayout->addWidget(new QLabel("Pie size factor"), 0, 0); | |
|
178 | m_pieLayout->addWidget(pieSizeSpin, 0, 1); | |
|
179 | m_pieLayout->addWidget(new QLabel("Pie position"), 1, 0); | |
|
180 | m_pieLayout->addWidget(piePosCombo, 1, 1); | |
|
181 | } | |
|
182 | ||
|
183 | 147 | void MainWidget::addSeries() |
|
184 | 148 | { |
|
185 | 149 | if (!m_addSerieDialog) { |
@@ -376,17 +340,3 void MainWidget::changeChartTheme(int themeIndex) | |||
|
376 | 340 | s.setWidth(s.width()+1); |
|
377 | 341 | resize(s); |
|
378 | 342 | } |
|
379 | ||
|
380 | void MainWidget::setPieSizeFactor(double size) | |
|
381 | { | |
|
382 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
|
383 | if (pie) | |
|
384 | pie->setSizeFactor(qreal(size)); | |
|
385 | } | |
|
386 | ||
|
387 | void MainWidget::setPiePosition(int position) | |
|
388 | { | |
|
389 | QPieSeries *pie = qobject_cast<QPieSeries *>(m_currentSeries); | |
|
390 | if (pie) | |
|
391 | pie->setPosition((QPieSeries::PiePosition) position); | |
|
392 | } |
@@ -27,7 +27,6 private: | |||
|
27 | 27 | void initScaleControls(QGridLayout *grid); |
|
28 | 28 | void initThemeCombo(QGridLayout *grid); |
|
29 | 29 | void initCheckboxes(QGridLayout *grid); |
|
30 | void initPieControls(); | |
|
31 | 30 | |
|
32 | 31 | private slots: |
|
33 | 32 | void addSeries(); |
@@ -41,8 +40,6 private slots: | |||
|
41 | 40 | void antiAliasToggled(bool enabled); |
|
42 | 41 | void setCurrentSeries(QSeries *series); |
|
43 | 42 | void changeChartTheme(int themeIndex); |
|
44 | void setPieSizeFactor(double margin); | |
|
45 | void setPiePosition(int position); | |
|
46 | 43 | QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics); |
|
47 | 44 | QStringList generateLabels(int count); |
|
48 | 45 | |
@@ -57,7 +54,6 private: | |||
|
57 | 54 | QString m_defaultSeriesName; |
|
58 | 55 | QSeries *m_currentSeries; |
|
59 | 56 | QGridLayout *m_scatterLayout; |
|
60 | QGridLayout *m_pieLayout; | |
|
61 | 57 | }; |
|
62 | 58 | |
|
63 | 59 | #endif // MAINWIDGET_H |
General Comments 0
You need to be logged in to leave comments.
Login now