##// END OF EJS Templates
Add API to specify plot area background....
Miikka Heikkinen -
r2498:e824058bc192
parent child
Show More
@@ -112,6 +112,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
112 */
112 */
113
113
114 /*!
114 /*!
115 \qmlproperty color ChartView::plotAreaColor
116 The color of the background of the chart's plot area. By default plot area background uses chart's
117 background color.
118 \sa ChartView::backgroundColor
119 */
120
121 /*!
115 \qmlproperty bool ChartView::dropShadowEnabled
122 \qmlproperty bool ChartView::dropShadowEnabled
116 The chart's border drop shadow. Set to true to enable drop shadow.
123 The chart's border drop shadow. Set to true to enable drop shadow.
117 */
124 */
@@ -596,6 +603,23 QColor DeclarativeChart::backgroundColor()
596 return m_chart->backgroundBrush().color();
603 return m_chart->backgroundBrush().color();
597 }
604 }
598
605
606 void QtCommercialChart::DeclarativeChart::setPlotAreaColor(QColor color)
607 {
608 QBrush b = m_chart->plotAreaBackgroundBrush();
609 if (b.style() != Qt::SolidPattern || color != b.color()) {
610 b.setStyle(Qt::SolidPattern);
611 b.setColor(color);
612 m_chart->setPlotAreaBackgroundBrush(b);
613 m_chart->setPlotAreaBackgroundVisible(true);
614 emit plotAreaColorChanged();
615 }
616 }
617
618 QColor QtCommercialChart::DeclarativeChart::plotAreaColor()
619 {
620 return m_chart->plotAreaBackgroundBrush().color();
621 }
622
599 int DeclarativeChart::count()
623 int DeclarativeChart::count()
600 {
624 {
601 return m_chart->series().count();
625 return m_chart->series().count();
@@ -59,6 +59,7 class DeclarativeChart : public QDECLARATIVE_PAINTED_ITEM
59 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
59 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
60 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
60 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
61 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
61 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
62 Q_PROPERTY(QColor plotAreaColor READ plotAreaColor WRITE setPlotAreaColor NOTIFY plotAreaColorChanged REVISION 3)
62 #ifdef CHARTS_FOR_QUICK2
63 #ifdef CHARTS_FOR_QUICK2
63 Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2)
64 Q_PROPERTY(QQmlListProperty<QAbstractAxis> axes READ axes REVISION 2)
64 #else
65 #else
@@ -133,6 +134,8 public:
133 QColor titleColor();
134 QColor titleColor();
134 void setBackgroundColor(QColor color);
135 void setBackgroundColor(QColor color);
135 QColor backgroundColor();
136 QColor backgroundColor();
137 Q_REVISION(3) void setPlotAreaColor(QColor color);
138 Q_REVISION(3) QColor plotAreaColor();
136 int count();
139 int count();
137 void setDropShadowEnabled(bool enabled);
140 void setDropShadowEnabled(bool enabled);
138 bool dropShadowEnabled();
141 bool dropShadowEnabled();
@@ -183,6 +186,7 Q_SIGNALS:
183 void plotAreaChanged(QRectF plotArea);
186 void plotAreaChanged(QRectF plotArea);
184 void seriesAdded(QAbstractSeries *series);
187 void seriesAdded(QAbstractSeries *series);
185 void seriesRemoved(QAbstractSeries *series);
188 void seriesRemoved(QAbstractSeries *series);
189 Q_REVISION(3) void plotAreaColorChanged();
186
190
187 private Q_SLOTS:
191 private Q_SLOTS:
188 void changeMinimumMargins(int top, int bottom, int left, int right);
192 void changeMinimumMargins(int top, int bottom, int left, int right);
@@ -229,6 +229,7 public:
229 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
229 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
230
230
231 // QtCommercial.Chart 1.3
231 // QtCommercial.Chart 1.3
232 qmlRegisterType<DeclarativeChart, 3>(uri, 1, 3, "ChartView");
232 qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView");
233 qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView");
233 qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries");
234 qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries");
234 qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries");
235 qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries");
@@ -42,6 +42,7 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
42 m_options(QChart::NoAnimation),
42 m_options(QChart::NoAnimation),
43 m_state(ShowState),
43 m_state(ShowState),
44 m_background(0),
44 m_background(0),
45 m_plotAreaBackground(0),
45 m_title(0)
46 m_title(0)
46 {
47 {
47 if (type == QChart::ChartTypeCartesian)
48 if (type == QChart::ChartTypeCartesian)
@@ -156,6 +157,22 void ChartPresenter::createBackgroundItem()
156 }
157 }
157 }
158 }
158
159
160 void ChartPresenter::createPlotAreaBackgroundItem()
161 {
162 if (!m_plotAreaBackground) {
163 if (m_chart->chartType() == QChart::ChartTypeCartesian)
164 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
165 else
166 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
167 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
168 // antialising artifacts with axis lines for some reason.
169 m_plotAreaBackground->setPen(QPen(Qt::transparent));
170 m_plotAreaBackground->setBrush(Qt::NoBrush);
171 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
172 m_plotAreaBackground->setVisible(false);
173 }
174 }
175
159 void ChartPresenter::createTitleItem()
176 void ChartPresenter::createTitleItem()
160 {
177 {
161 if (!m_title) {
178 if (!m_title) {
@@ -209,6 +226,34 QPen ChartPresenter::backgroundPen() const
209 return m_background->pen();
226 return m_background->pen();
210 }
227 }
211
228
229 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
230 {
231 createPlotAreaBackgroundItem();
232 m_plotAreaBackground->setBrush(brush);
233 m_layout->invalidate();
234 }
235
236 QBrush ChartPresenter::plotAreaBackgroundBrush() const
237 {
238 if (!m_plotAreaBackground)
239 return QBrush();
240 return m_plotAreaBackground->brush();
241 }
242
243 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
244 {
245 createPlotAreaBackgroundItem();
246 m_plotAreaBackground->setPen(pen);
247 m_layout->invalidate();
248 }
249
250 QPen ChartPresenter::plotAreaBackgroundPen() const
251 {
252 if (!m_plotAreaBackground)
253 return QPen();
254 return m_plotAreaBackground->pen();
255 }
256
212 void ChartPresenter::setTitle(const QString &title)
257 void ChartPresenter::setTitle(const QString &title)
213 {
258 {
214 createTitleItem();
259 createTitleItem();
@@ -265,6 +310,19 bool ChartPresenter::isBackgroundVisible() const
265 return m_background->isVisible();
310 return m_background->isVisible();
266 }
311 }
267
312
313 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
314 {
315 createPlotAreaBackgroundItem();
316 m_plotAreaBackground->setVisible(visible);
317 }
318
319 bool ChartPresenter::isPlotAreaBackgroundVisible() const
320 {
321 if (!m_plotAreaBackground)
322 return false;
323 return m_plotAreaBackground->isVisible();
324 }
325
268 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
326 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
269 {
327 {
270 createBackgroundItem();
328 createBackgroundItem();
@@ -299,6 +357,11 ChartBackground *ChartPresenter::backgroundElement()
299 return m_background;
357 return m_background;
300 }
358 }
301
359
360 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
361 {
362 return m_plotAreaBackground;
363 }
364
302 QList<ChartAxisElement *> ChartPresenter::axisItems() const
365 QList<ChartAxisElement *> ChartPresenter::axisItems() const
303 {
366 {
304 return m_axisItems;
367 return m_axisItems;
@@ -55,7 +55,8 class ChartPresenter: public QObject
55 public:
55 public:
56 enum ZValues {
56 enum ZValues {
57 BackgroundZValue = -1,
57 BackgroundZValue = -1,
58 ShadesZValue ,
58 PlotAreaZValue,
59 ShadesZValue,
59 GridZValue,
60 GridZValue,
60 AxisZValue,
61 AxisZValue,
61 SeriesZValue,
62 SeriesZValue,
@@ -87,6 +88,7 public:
87
88
88 QGraphicsItem *rootItem(){ return m_chart; }
89 QGraphicsItem *rootItem(){ return m_chart; }
89 ChartBackground *backgroundElement();
90 ChartBackground *backgroundElement();
91 QAbstractGraphicsShapeItem *plotAreaElement();
90 ChartTitle *titleElement();
92 ChartTitle *titleElement();
91 QList<ChartAxisElement *> axisItems() const;
93 QList<ChartAxisElement *> axisItems() const;
92 QList<ChartItem *> chartItems() const;
94 QList<ChartItem *> chartItems() const;
@@ -99,6 +101,12 public:
99 void setBackgroundPen(const QPen &pen);
101 void setBackgroundPen(const QPen &pen);
100 QPen backgroundPen() const;
102 QPen backgroundPen() const;
101
103
104 void setPlotAreaBackgroundBrush(const QBrush &brush);
105 QBrush plotAreaBackgroundBrush() const;
106
107 void setPlotAreaBackgroundPen(const QPen &pen);
108 QPen plotAreaBackgroundPen() const;
109
102 void setTitle(const QString &title);
110 void setTitle(const QString &title);
103 QString title() const;
111 QString title() const;
104
112
@@ -111,6 +119,9 public:
111 void setBackgroundVisible(bool visible);
119 void setBackgroundVisible(bool visible);
112 bool isBackgroundVisible() const;
120 bool isBackgroundVisible() const;
113
121
122 void setPlotAreaBackgroundVisible(bool visible);
123 bool isPlotAreaBackgroundVisible() const;
124
114 void setBackgroundDropShadowEnabled(bool enabled);
125 void setBackgroundDropShadowEnabled(bool enabled);
115 bool isBackgroundDropShadowEnabled() const;
126 bool isBackgroundDropShadowEnabled() const;
116
127
@@ -128,9 +139,11 public:
128 AbstractChartLayout *layout();
139 AbstractChartLayout *layout();
129
140
130 QChart::ChartType chartType() const { return m_chart->chartType(); }
141 QChart::ChartType chartType() const { return m_chart->chartType(); }
142 QChart *chart() { return m_chart; }
131
143
132 private:
144 private:
133 void createBackgroundItem();
145 void createBackgroundItem();
146 void createPlotAreaBackgroundItem();
134 void createTitleItem();
147 void createTitleItem();
135
148
136 public Q_SLOTS:
149 public Q_SLOTS:
@@ -157,6 +170,7 private:
157 QList<ChartAnimation *> m_animations;
170 QList<ChartAnimation *> m_animations;
158 AbstractChartLayout *m_layout;
171 AbstractChartLayout *m_layout;
159 ChartBackground *m_background;
172 ChartBackground *m_background;
173 QAbstractGraphicsShapeItem *m_plotAreaBackground;
160 ChartTitle *m_title;
174 ChartTitle *m_title;
161 QRectF m_rect;
175 QRectF m_rect;
162 };
176 };
@@ -92,6 +92,14 void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force
92 if (force || brush == chart->backgroundBrush())
92 if (force || brush == chart->backgroundBrush())
93 chart->setBackgroundBrush(theme->chartBackgroundGradient());
93 chart->setBackgroundBrush(theme->chartBackgroundGradient());
94
94
95 if (force) {
96 // Always clear plotArea brush when forced update, do not touch otherwise
97 QPen pen(Qt::transparent);
98 chart->setPlotAreaBackgroundBrush(brush);
99 chart->setPlotAreaBackgroundPen(pen);
100 chart->setPlotAreaBackgroundVisible(false);
101 }
102
95 chart->setTitleFont(theme->masterFont());
103 chart->setTitleFont(theme->masterFont());
96 chart->setTitleBrush(theme->labelBrush());
104 chart->setTitleBrush(theme->labelBrush());
97 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
105 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
@@ -64,6 +64,10 void AbstractChartLayout::setGeometry(const QRectF &rect)
64 contentGeometry = calculateAxisGeometry(contentGeometry, axes);
64 contentGeometry = calculateAxisGeometry(contentGeometry, axes);
65
65
66 m_presenter->setGeometry(contentGeometry);
66 m_presenter->setGeometry(contentGeometry);
67 if (m_presenter->chart()->chartType() == QChart::ChartTypeCartesian)
68 static_cast<QGraphicsRectItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
69 else
70 static_cast<QGraphicsEllipseItem *>(m_presenter->plotAreaElement())->setRect(contentGeometry);
67
71
68 QGraphicsLayout::setGeometry(rect);
72 QGraphicsLayout::setGeometry(rect);
69 }
73 }
@@ -87,7 +87,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
87 /*!
87 /*!
88 \property QChart::backgroundVisible
88 \property QChart::backgroundVisible
89 Specifies whether the chart background is visible or not.
89 Specifies whether the chart background is visible or not.
90 \sa setBackgroundBrush(), setBackgroundPen()
90 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
91 */
91 */
92
92
93 /*!
93 /*!
@@ -130,6 +130,14 QTCOMMERCIALCHART_BEGIN_NAMESPACE
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QChart::plotAreaBackgroundVisible
134 Specifies whether the chart plot area background is visible or not.
135 \note By default the plot area background is not visible and the plot area uses
136 the general chart background.
137 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
138 */
139
140 /*!
133 \internal
141 \internal
134 Constructs a chart object of \a type which is a child of a \a parent.
142 Constructs a chart object of \a type which is a child of a \a parent.
135 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
143 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
@@ -476,6 +484,56 QRectF QChart::plotArea() const
476 return d_ptr->m_presenter->geometry();
484 return d_ptr->m_presenter->geometry();
477 }
485 }
478
486
487 /*!
488 Sets the \a brush for the background of the plot area of the chart.
489
490 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
491 */
492 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
493 {
494 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
495 }
496
497 /*!
498 Returns the brush for the background of the plot area of the chart.
499
500 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
501 */
502 QBrush QChart::plotAreaBackgroundBrush() const
503 {
504 return d_ptr->m_presenter->plotAreaBackgroundBrush();
505 }
506
507 /*!
508 Sets the \a pen for the background of the plot area of the chart.
509
510 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
511 */
512 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
513 {
514 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
515 }
516
517 /*!
518 Returns the \a pen for the background of the plot area of the chart.
519
520 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
521 */
522 QPen QChart::plotAreaBackgroundPen() const
523 {
524 return d_ptr->m_presenter->plotAreaBackgroundPen();
525 }
526
527 void QChart::setPlotAreaBackgroundVisible(bool visible)
528 {
529 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
530 }
531
532 bool QChart::isPlotAreaBackgroundVisible() const
533 {
534 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
535 }
536
479 void QChart::setAnimationOptions(AnimationOptions options)
537 void QChart::setAnimationOptions(AnimationOptions options)
480 {
538 {
481 d_ptr->m_presenter->setAnimationOptions(options);
539 d_ptr->m_presenter->setAnimationOptions(options);
@@ -46,6 +46,7 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
46 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
46 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
47 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
47 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
48 Q_PROPERTY(QChart::ChartType chartType READ chartType)
48 Q_PROPERTY(QChart::ChartType chartType READ chartType)
49 Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
49 Q_ENUMS(ChartTheme)
50 Q_ENUMS(ChartTheme)
50 Q_ENUMS(AnimationOption)
51 Q_ENUMS(AnimationOption)
51 Q_ENUMS(ChartType)
52 Q_ENUMS(ChartType)
@@ -137,6 +138,12 public:
137 QMargins margins() const;
138 QMargins margins() const;
138
139
139 QRectF plotArea() const;
140 QRectF plotArea() const;
141 void setPlotAreaBackgroundBrush(const QBrush &brush);
142 QBrush plotAreaBackgroundBrush() const;
143 void setPlotAreaBackgroundPen(const QPen &pen);
144 QPen plotAreaBackgroundPen() const;
145 void setPlotAreaBackgroundVisible(bool visible = true);
146 bool isPlotAreaBackgroundVisible() const;
140
147
141 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
148 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
142 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
149 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
@@ -71,6 +71,12 private slots:
71 void backgroundPen();
71 void backgroundPen();
72 void isBackgroundVisible_data();
72 void isBackgroundVisible_data();
73 void isBackgroundVisible();
73 void isBackgroundVisible();
74 void plotAreaBackgroundBrush_data();
75 void plotAreaBackgroundBrush();
76 void plotAreaBackgroundPen_data();
77 void plotAreaBackgroundPen();
78 void isPlotAreaBackgroundVisible_data();
79 void isPlotAreaBackgroundVisible();
74 void legend_data();
80 void legend_data();
75 void legend();
81 void legend();
76 void plotArea_data();
82 void plotArea_data();
@@ -357,6 +363,52 void tst_QChart::isBackgroundVisible()
357 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
363 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
358 }
364 }
359
365
366 void tst_QChart::plotAreaBackgroundBrush_data()
367 {
368 QTest::addColumn<QBrush>("plotAreaBackgroundBrush");
369 QTest::newRow("null") << QBrush();
370 QTest::newRow("blue") << QBrush(Qt::blue);
371 QTest::newRow("white") << QBrush(Qt::white);
372 QTest::newRow("black") << QBrush(Qt::black);
373 }
374
375 void tst_QChart::plotAreaBackgroundBrush()
376 {
377 QFETCH(QBrush, plotAreaBackgroundBrush);
378 m_chart->setPlotAreaBackgroundBrush(plotAreaBackgroundBrush);
379 QCOMPARE(m_chart->plotAreaBackgroundBrush(), plotAreaBackgroundBrush);
380 }
381
382 void tst_QChart::plotAreaBackgroundPen_data()
383 {
384 QTest::addColumn<QPen>("plotAreaBackgroundPen");
385 QTest::newRow("null") << QPen();
386 QTest::newRow("blue") << QPen(Qt::blue);
387 QTest::newRow("white") << QPen(Qt::white);
388 QTest::newRow("black") << QPen(Qt::black);
389 }
390
391
392 void tst_QChart::plotAreaBackgroundPen()
393 {
394 QFETCH(QPen, plotAreaBackgroundPen);
395 m_chart->setPlotAreaBackgroundPen(plotAreaBackgroundPen);
396 QCOMPARE(m_chart->plotAreaBackgroundPen(), plotAreaBackgroundPen);
397 }
398
399 void tst_QChart::isPlotAreaBackgroundVisible_data()
400 {
401 QTest::addColumn<bool>("isPlotAreaBackgroundVisible");
402 QTest::newRow("true") << true;
403 QTest::newRow("false") << false;
404 }
405
406 void tst_QChart::isPlotAreaBackgroundVisible()
407 {
408 QFETCH(bool, isPlotAreaBackgroundVisible);
409 m_chart->setPlotAreaBackgroundVisible(isPlotAreaBackgroundVisible);
410 QCOMPARE(m_chart->isPlotAreaBackgroundVisible(), isPlotAreaBackgroundVisible);
411 }
360 void tst_QChart::legend_data()
412 void tst_QChart::legend_data()
361 {
413 {
362
414
@@ -58,12 +58,16 MainWindow::MainWindow(QWidget *parent) :
58 m_radialShadesBrush(new QBrush(Qt::NoBrush)),
58 m_radialShadesBrush(new QBrush(Qt::NoBrush)),
59 m_labelBrush(new QBrush(Qt::black)),
59 m_labelBrush(new QBrush(Qt::black)),
60 m_titleBrush(new QBrush(Qt::black)),
60 m_titleBrush(new QBrush(Qt::black)),
61 m_backgroundBrush(new QBrush(Qt::white)),
62 m_plotAreaBackgroundBrush(new QBrush(Qt::NoBrush)),
61 m_angularShadesPen(new QPen(Qt::NoPen)),
63 m_angularShadesPen(new QPen(Qt::NoPen)),
62 m_radialShadesPen(new QPen(Qt::NoPen)),
64 m_radialShadesPen(new QPen(Qt::NoPen)),
63 m_labelPen(new QPen(Qt::NoPen)),
65 m_labelPen(new QPen(Qt::NoPen)),
64 m_titlePen(new QPen(Qt::NoPen)),
66 m_titlePen(new QPen(Qt::NoPen)),
65 m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by
67 m_gridPen(new QPen(QRgb(0x010101))), // Note: Pure black is default color, so it gets overridden by
66 m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround.
68 m_arrowPen(new QPen(QRgb(0x010101))), // default theme if set to that initially. This is an example of workaround.
69 m_backgroundPen(new QPen(Qt::NoPen)),
70 m_plotAreaBackgroundPen(new QPen(Qt::NoPen)),
67 m_labelFormat(QString("%.2f")),
71 m_labelFormat(QString("%.2f")),
68 m_animationOptions(QChart::NoAnimation),
72 m_animationOptions(QChart::NoAnimation),
69 m_angularTitle(QString("Angular Title")),
73 m_angularTitle(QString("Angular Title")),
@@ -157,6 +161,8 MainWindow::MainWindow(QWidget *parent) :
157 connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked()));
161 connect(ui->series6checkBox, SIGNAL(clicked()), this, SLOT(series6CheckBoxChecked()));
158 connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked()));
162 connect(ui->series7checkBox, SIGNAL(clicked()), this, SLOT(series7CheckBoxChecked()));
159 connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int)));
163 connect(ui->themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeIndexChanged(int)));
164 connect(ui->backgroundComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(backgroundIndexChanged(int)));
165 connect(ui->plotAreaComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(plotAreaIndexChanged(int)));
160
166
161 ui->chartView->setChart(m_chart);
167 ui->chartView->setChart(m_chart);
162 ui->chartView->setRenderHint(QPainter::Antialiasing);
168 ui->chartView->setRenderHint(QPainter::Antialiasing);
@@ -379,6 +385,10 void MainWindow::initXYValueChart()
379 m_chart->setAnimationOptions(m_animationOptions);
385 m_chart->setAnimationOptions(m_animationOptions);
380 //m_chart->legend()->setVisible(false);
386 //m_chart->legend()->setVisible(false);
381 m_chart->setAcceptHoverEvents(true);
387 m_chart->setAcceptHoverEvents(true);
388 m_chart->setBackgroundBrush(*m_backgroundBrush);
389 m_chart->setBackgroundPen(*m_backgroundPen);
390 m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush);
391 m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen);
382 }
392 }
383
393
384 void MainWindow::setAngularAxis(MainWindow::AxisMode mode)
394 void MainWindow::setAngularAxis(MainWindow::AxisMode mode)
@@ -1081,6 +1091,59 void MainWindow::seriesClicked(const QPointF &point)
1081 }
1091 }
1082 }
1092 }
1083
1093
1094 void MainWindow::backgroundIndexChanged(int index)
1095 {
1096 delete m_backgroundBrush;
1097 delete m_backgroundPen;
1098
1099 switch (index) {
1100 case 0:
1101 m_backgroundBrush = new QBrush(Qt::white);
1102 m_backgroundPen = new QPen(Qt::NoPen);
1103 break;
1104 case 1:
1105 m_backgroundBrush = new QBrush(Qt::blue);
1106 m_backgroundPen = new QPen(Qt::NoPen);
1107 break;
1108 case 2:
1109 m_backgroundBrush = new QBrush(Qt::yellow);
1110 m_backgroundPen = new QPen(Qt::black, 2);
1111 break;
1112 default:
1113 break;
1114 }
1115 m_chart->setBackgroundBrush(*m_backgroundBrush);
1116 m_chart->setBackgroundPen(*m_backgroundPen);
1117 }
1118
1119 void MainWindow::plotAreaIndexChanged(int index)
1120 {
1121 delete m_plotAreaBackgroundBrush;
1122 delete m_plotAreaBackgroundPen;
1123
1124 switch (index) {
1125 case 0:
1126 m_plotAreaBackgroundBrush = new QBrush(Qt::green);
1127 m_plotAreaBackgroundPen = new QPen(Qt::green);
1128 m_chart->setPlotAreaBackgroundVisible(false);
1129 break;
1130 case 1:
1131 m_plotAreaBackgroundBrush = new QBrush(Qt::magenta);
1132 m_plotAreaBackgroundPen = new QPen(Qt::NoPen);
1133 m_chart->setPlotAreaBackgroundVisible(true);
1134 break;
1135 case 2:
1136 m_plotAreaBackgroundBrush = new QBrush(Qt::lightGray);
1137 m_plotAreaBackgroundPen = new QPen(Qt::red, 6);
1138 m_chart->setPlotAreaBackgroundVisible(true);
1139 break;
1140 default:
1141 break;
1142 }
1143 m_chart->setPlotAreaBackgroundBrush(*m_plotAreaBackgroundBrush);
1144 m_chart->setPlotAreaBackgroundPen(*m_plotAreaBackgroundPen);
1145 }
1146
1084 void MainWindow::applyCategories()
1147 void MainWindow::applyCategories()
1085 {
1148 {
1086 // Basic layout is three categories, extended has five
1149 // Basic layout is three categories, extended has five
@@ -85,6 +85,8 public slots:
85 void themeIndexChanged(int index);
85 void themeIndexChanged(int index);
86 void seriesHovered(QPointF point, bool state);
86 void seriesHovered(QPointF point, bool state);
87 void seriesClicked(const QPointF &point);
87 void seriesClicked(const QPointF &point);
88 void backgroundIndexChanged(int index);
89 void plotAreaIndexChanged(int index);
88
90
89 private:
91 private:
90 enum AxisMode {
92 enum AxisMode {
@@ -121,12 +123,16 private:
121 QBrush *m_radialShadesBrush;
123 QBrush *m_radialShadesBrush;
122 QBrush *m_labelBrush;
124 QBrush *m_labelBrush;
123 QBrush *m_titleBrush;
125 QBrush *m_titleBrush;
126 QBrush *m_backgroundBrush;
127 QBrush *m_plotAreaBackgroundBrush;
124 QPen *m_angularShadesPen;
128 QPen *m_angularShadesPen;
125 QPen *m_radialShadesPen;
129 QPen *m_radialShadesPen;
126 QPen *m_labelPen;
130 QPen *m_labelPen;
127 QPen *m_titlePen;
131 QPen *m_titlePen;
128 QPen *m_gridPen;
132 QPen *m_gridPen;
129 QPen *m_arrowPen;
133 QPen *m_arrowPen;
134 QPen *m_backgroundPen;
135 QPen *m_plotAreaBackgroundPen;
130 QString m_labelFormat;
136 QString m_labelFormat;
131 QFont m_currentLabelFont;
137 QFont m_currentLabelFont;
132 QFont m_currentTitleFont;
138 QFont m_currentTitleFont;
@@ -6,8 +6,8
6 <rect>
6 <rect>
7 <x>0</x>
7 <x>0</x>
8 <y>0</y>
8 <y>0</y>
9 <width>1207</width>
9 <width>1193</width>
10 <height>905</height>
10 <height>956</height>
11 </rect>
11 </rect>
12 </property>
12 </property>
13 <property name="windowTitle">
13 <property name="windowTitle">
@@ -892,6 +892,74
892 <string>Hover coordinates here!</string>
892 <string>Hover coordinates here!</string>
893 </property>
893 </property>
894 </widget>
894 </widget>
895 <widget class="QComboBox" name="backgroundComboBox">
896 <property name="geometry">
897 <rect>
898 <x>10</x>
899 <y>820</y>
900 <width>171</width>
901 <height>22</height>
902 </rect>
903 </property>
904 <property name="sizePolicy">
905 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
906 <horstretch>0</horstretch>
907 <verstretch>0</verstretch>
908 </sizepolicy>
909 </property>
910 <property name="currentIndex">
911 <number>0</number>
912 </property>
913 <item>
914 <property name="text">
915 <string>Background: White</string>
916 </property>
917 </item>
918 <item>
919 <property name="text">
920 <string>Background: Blue</string>
921 </property>
922 </item>
923 <item>
924 <property name="text">
925 <string>Background: Yellow + Black Border</string>
926 </property>
927 </item>
928 </widget>
929 <widget class="QComboBox" name="plotAreaComboBox">
930 <property name="geometry">
931 <rect>
932 <x>10</x>
933 <y>850</y>
934 <width>171</width>
935 <height>22</height>
936 </rect>
937 </property>
938 <property name="sizePolicy">
939 <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
940 <horstretch>0</horstretch>
941 <verstretch>0</verstretch>
942 </sizepolicy>
943 </property>
944 <property name="currentIndex">
945 <number>0</number>
946 </property>
947 <item>
948 <property name="text">
949 <string>PlotArea: Transparent</string>
950 </property>
951 </item>
952 <item>
953 <property name="text">
954 <string>PlotArea: Magenta</string>
955 </property>
956 </item>
957 <item>
958 <property name="text">
959 <string>PlotArea: Gray + Red Border</string>
960 </property>
961 </item>
962 </widget>
895 </widget>
963 </widget>
896 </item>
964 </item>
897 </layout>
965 </layout>
@@ -901,7 +969,7
901 <rect>
969 <rect>
902 <x>0</x>
970 <x>0</x>
903 <y>0</y>
971 <y>0</y>
904 <width>1207</width>
972 <width>1193</width>
905 <height>21</height>
973 <height>21</height>
906 </rect>
974 </rect>
907 </property>
975 </property>
@@ -19,7 +19,7
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.2
22 import QtCommercial.Chart 1.3
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
@@ -44,6 +44,7 ChartView {
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
45 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
46 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
46 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
47 onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor);
47
48
48 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible);
49 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible);
49 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
50 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
@@ -50,6 +50,10 Flow {
50 onClicked: chart.backgroundColor = main.nextColor();
50 onClicked: chart.backgroundColor = main.nextColor();
51 }
51 }
52 Button {
52 Button {
53 text: "plot area color"
54 onClicked: chart.plotAreaColor = main.nextColor();
55 }
56 Button {
53 text: "drop shadow enabled"
57 text: "drop shadow enabled"
54 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
58 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
55 }
59 }
@@ -19,7 +19,7
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 2.0
21 import QtQuick 2.0
22 import QtCommercial.Chart 1.2
22 import QtCommercial.Chart 1.3
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
@@ -44,6 +44,7 ChartView {
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
45 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
46 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
46 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
47 onPlotAreaColorChanged: console.log("chart.plotAreaColorChanged: " + chart.plotAreaColor);
47
48
48 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible);
49 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible);
49 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
50 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
@@ -50,6 +50,10 Flow {
50 onClicked: chart.backgroundColor = main.nextColor();
50 onClicked: chart.backgroundColor = main.nextColor();
51 }
51 }
52 Button {
52 Button {
53 text: "plot area color"
54 onClicked: chart.plotAreaColor = main.nextColor();
55 }
56 Button {
53 text: "drop shadow enabled"
57 text: "drop shadow enabled"
54 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
58 onClicked: chart.dropShadowEnabled = !chart.dropShadowEnabled;
55 }
59 }
General Comments 0
You need to be logged in to leave comments. Login now