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