##// END OF EJS Templates
Adds area chart...
Michal Klocek -
r421:fe0a0dc06876
parent child
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,30
1 /*!
2 \example example/areachart
3 \title AreaChart Example
4 \subtitle
5
6 The example shows how to create simple area chart.
7
8 \image areachart.png
9
10 To create area charts, we need two QLineSeries instances. They are going to define upper and lower boundary of the area.
11
12 \snippet ../example/areachart/main.cpp 1
13
14 We add data to both series, we use stream operator.
15
16 \snippet ../example/areachart/main.cpp 2
17
18 Now we create QAreaSeries instance using two line series objects. We set the custom gradient fill and width of the outline.
19
20 \snippet ../example/areachart/main.cpp 3
21
22 In the end we create QChartView instance, set title, set anti-aliasing and add area series. We also set the specific range for axes.
23
24 \snippet ../example/areachart/main.cpp 4
25
26 Chart is ready to be shown.
27
28 \snippet ../example/areachart/main.cpp 5
29
30 */ No newline at end of file
@@ -0,0 +1,8
1 !include( ../example.pri ) {
2 error( "Couldn't find the example.pri file!" )
3 }
4 TARGET = areachart
5 SOURCES += main.cpp
6
7
8
@@ -0,0 +1,59
1 #include <QApplication>
2 #include <QMainWindow>
3 #include <qchartview.h>
4 #include <qlineseries.h>
5 #include <qareaseries.h>
6 #include <qchart.h>
7 #include <qchartaxis.h>
8 #include <cmath>
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
12 int main(int argc, char *argv[])
13 {
14 QApplication a(argc, argv);
15
16 //![1]
17
18 QLineSeries* series0 = new QLineSeries();
19 QLineSeries* series1 = new QLineSeries();
20
21 //![1]
22
23 //![2]
24 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12,6)<<QPointF(16,7)<<QPointF(18,5);
25 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12,3)<<QPointF(16,4)<<QPointF(18,3);
26 //![2]
27 //![3]
28
29 QAreaSeries* series = new QAreaSeries(series0,series1);
30 QPen pen(0x059605);
31 pen.setWidth(3);
32 series->setPen(pen);
33
34 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
35 gradient.setColorAt(0.0,0x3cc63c);
36 gradient.setColorAt(1.0, 0x26f626);
37 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
38 series->setBrush(gradient);
39
40 //![3]
41 //![4]
42 QMainWindow window;
43 QChartView* chartView = new QChartView(&window);
44
45 chartView->setChartTitle("Basic area chart example");
46 chartView->setRenderHint(QPainter::Antialiasing);
47
48 chartView->addSeries(series);
49 chartView->axisX()->setRange(0,20);
50 chartView->axisY()->setRange(0,10);
51 //![4]
52 //![5]
53 window.setCentralWidget(chartView);
54 window.resize(400, 300);
55 window.show();
56 //![5]
57
58 return a.exec();
59 }
@@ -0,0 +1,14
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
3
4 SOURCES += \
5 #$$PWD/areachartanimationitem.cpp \
6 $$PWD/areachartitem.cpp \
7 $$PWD/qareaseries.cpp
8
9 PRIVATE_HEADERS += \
10 $$PWD/areachartitem_p.h \
11 # $$PWD/linechartanimationitem_p.h
12
13 PUBLIC_HEADERS += \
14 $$PWD/qareaseries.h No newline at end of file
@@ -0,0 +1,63
1 #include "linechartanimationitem_p.h"
2 #include "linechartitem_p.h"
3 #include <QPropertyAnimation>
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
7 const static int duration = 500;
8
9
10 LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):
11 LineChartItem(presenter,series,parent)
12 {
13
14 }
15
16 LineChartAnimationItem::~LineChartAnimationItem()
17 {
18 }
19
20 void LineChartAnimationItem::addPoints(const QVector<QPointF>& points)
21 {
22 m_data=points;
23 clearView();
24 QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent());
25 animation->setDuration(duration);
26 //animation->setEasingCurve(QEasingCurve::InOutBack);
27 animation->setKeyValueAt(0.0, 0);
28 animation->setKeyValueAt(1.0, m_data.size());
29 animation->start(QAbstractAnimation::DeleteWhenStopped);
30 }
31
32 void LineChartAnimationItem::setPoint(int index,const QPointF& point)
33 {
34 AnimationHelper* helper = new AnimationHelper(this,index);
35 QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent());
36 animation->setDuration(duration);
37 //animation->setEasingCurve(QEasingCurve::InOutBack);
38 animation->setKeyValueAt(0.0, points().value(index));
39 animation->setKeyValueAt(1.0, point);
40 animation->start(QAbstractAnimation::DeleteWhenStopped);
41 }
42
43 void LineChartAnimationItem::aw_addPoints(int points)
44 {
45 int index = count();
46 for(int i = index;i< points ;i++){
47 LineChartItem::addPoint(m_data.at(i));
48 }
49 updateGeometry();
50 update();
51 }
52
53 void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point)
54 {
55 LineChartItem::setPoint(index,point);
56 updateGeometry();
57 update();
58 }
59
60
61 #include "moc_linechartanimationitem_p.cpp"
62
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,55
1 #ifndef LINECHARTANIMATIONITEM_P_H_
2 #define LINECHARTANIMATIONITEM_P_H_
3
4 #include "qchartglobal.h"
5 #include "linechartitem_p.h"
6 #include "domain_p.h"
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class LineChartItem;
11
12 class LineChartAnimationItem : public LineChartItem {
13 Q_OBJECT
14 Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints);
15 // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint);
16 public:
17 LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0);
18 virtual ~LineChartAnimationItem();
19
20 void addPoints(const QVector<QPointF>& points);
21 void setPoint(int index,const QPointF& point);
22 //void removePoint(const QPointF& point){};
23 //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){};
24
25 int ar_addPoints() const { return m_addPoints;}
26 void aw_addPoints(int points);
27 const QPointF& ar_setPoint() const { return m_setPoint;}
28 void aw_setPoint(int index,const QPointF& point);
29
30 private:
31 QVector<QPointF> m_data;
32 Domain m_domain;
33 int m_addPoints;
34 QPointF m_setPoint;
35 int m_setPoint_index;
36 };
37
38 class AnimationHelper: public QObject
39 {
40 Q_OBJECT
41 Q_PROPERTY(QPointF point READ point WRITE setPoint);
42 public:
43 AnimationHelper(LineChartAnimationItem* item,int index):m_item(item),m_index(index){};
44 void setPoint(const QPointF& point){
45 m_item->aw_setPoint(m_index,point);
46 }
47 QPointF point(){return m_point;}
48 QPointF m_point;
49 LineChartAnimationItem* m_item;
50 int m_index;
51 };
52
53 QTCOMMERCIALCHART_END_NAMESPACE
54
55 #endif
@@ -0,0 +1,116
1 #include "areachartitem_p.h"
2 #include "qareaseries.h"
3 #include "qlineseries.h"
4 #include "chartpresenter_p.h"
5 #include <QPainter>
6
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 //TODO: optimize : remove points which are not visible
11
12 AreaChartItem::AreaChartItem(ChartPresenter* presenter, QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent),
13 m_presenter(presenter),
14 m_series(areaSeries),
15 m_upper(0),
16 m_lower(0)
17 {
18 //m_items.setZValue(ChartPresenter::LineChartZValue);
19 m_upper = new AreaBoundItem(this,presenter,m_series->upperSeries());
20 if(m_series->lowerSeries()){
21 m_lower = new AreaBoundItem(this,presenter,m_series->lowerSeries());
22 }
23 setZValue(ChartPresenter::LineChartZValue);
24
25 QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&)));
26 QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated()));
27
28 handleUpdated();
29 }
30
31 AreaChartItem::~AreaChartItem()
32 {
33 delete m_upper;
34 delete m_lower;
35 };
36
37 QRectF AreaChartItem::boundingRect() const
38 {
39 return m_rect;
40 }
41
42 QPainterPath AreaChartItem::shape() const
43 {
44 return m_path;
45 }
46
47 void AreaChartItem::setPen(const QPen& pen)
48 {
49 m_pen = pen;
50 }
51
52 void AreaChartItem::setBrush(const QBrush& brush)
53 {
54 m_brush = brush;
55 }
56
57 void AreaChartItem::updatePath()
58 {
59 QPainterPath path;
60
61 path.connectPath(m_upper->shape());
62 if(m_lower){
63 path.connectPath(m_lower->shape().toReversed());
64 }
65 else{
66 QPointF first = path.pointAtPercent(0);
67 QPointF last = path.pointAtPercent(1);
68 path.lineTo(last.x(),m_clipRect.bottom());
69 path.lineTo(first.x(),m_clipRect.bottom());
70 }
71 path.closeSubpath();
72 prepareGeometryChange();
73 m_path=path;
74 m_rect=path.boundingRect();
75 update();
76 }
77
78 void AreaChartItem::handleUpdated()
79 {
80 setPen(m_series->pen());
81 setBrush(m_series->brush());
82 update();
83 }
84
85 void AreaChartItem::handleDomainChanged(const Domain& domain)
86 {
87 m_upper->handleDomainChanged(domain);
88 if(m_lower)
89 m_lower->handleDomainChanged(domain);
90 }
91
92 void AreaChartItem::handleGeometryChanged(const QRectF& rect)
93 {
94 m_clipRect=rect.translated(-rect.topLeft());
95 setPos(rect.topLeft());
96 m_upper->handleGeometryChanged(rect);
97 if(m_lower)
98 m_lower->handleGeometryChanged(rect);
99 }
100 //painter
101
102 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
103 {
104 Q_UNUSED(widget);
105 Q_UNUSED(option);
106 painter->save();
107 painter->setPen(m_pen);
108 painter->setBrush(m_brush);
109 painter->setClipRect(m_clipRect);
110 painter->drawPath(m_path);
111 painter->restore();
112 }
113
114 #include "moc_areachartitem_p.cpp"
115
116 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,67
1 #ifndef AREACHARTITEM_H
2 #define AREACHARTITEM_H
3
4 #include "qchartglobal.h"
5 #include "linechartitem_p.h"
6 #include <QPen>
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
10 class ChartPresenter;
11 class QAreaSeries;
12 class AreaChartItem;
13
14 class AreaChartItem : public QObject ,public ChartItem
15 {
16 Q_OBJECT
17 public:
18 AreaChartItem(ChartPresenter* presenter, QAreaSeries* areaSeries, QGraphicsItem *parent = 0);
19 ~ AreaChartItem();
20
21 //from QGraphicsItem
22 QRectF boundingRect() const;
23 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
24 QPainterPath shape() const;
25
26 void setPen(const QPen& pen);
27 void setBrush(const QBrush& brush);
28 void setPointsVisible(bool visible);
29 void updatePath();
30 public slots:
31 void handleUpdated();
32 void handleDomainChanged(const Domain& domain);
33 void handleGeometryChanged(const QRectF& size);
34
35 private:
36 ChartPresenter* m_presenter;
37 QPainterPath m_path;
38 QAreaSeries* m_series;
39 LineChartItem* m_upper;
40 LineChartItem* m_lower;
41 QRectF m_rect;
42 QRectF m_clipRect;
43 QPen m_pen;
44 QBrush m_brush;
45 };
46
47 class AreaBoundItem : public LineChartItem
48 {
49 public:
50 AreaBoundItem(AreaChartItem* item,ChartPresenter* presenter, QLineSeries* lineSeries):LineChartItem(presenter,lineSeries),
51 m_item(item){};
52
53 ~AreaBoundItem(){};
54
55 void applyGeometry(QVector<QPointF>& points){
56 LineChartItem::applyGeometry(points);
57 m_item->updatePath();
58 }
59
60 private:
61 AreaChartItem* m_item;
62
63 };
64
65 QTCOMMERCIALCHART_END_NAMESPACE
66
67 #endif
@@ -0,0 +1,115
1 #include "qareaseries.h"
2 #include "qlineseries.h"
3
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
6 /*!
7 \class QAreaSeries
8 \brief The QAreaSeries class is used for making area charts.
9
10 \mainclass
11
12 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
13 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
14 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X (y=0). Instead of axis X "lower" boundary can be also specified also by other line.
15 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
16 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary will be filled.
17
18 \image areachart.png
19
20 Creating basic area chart is simple:
21 \code
22 QLineSeries* lineSeries = new QLineSeries();
23 series->add(0, 6);
24 series->add(2, 4);
25 QAreaSeries* areaSeries = new QAreaSeries(lineSeries);
26 ...
27 chartView->addSeries(areaSeries);
28 \endcode
29 */
30
31 /*!
32 \fn virtual QSeriesType QAreaSeries::type() const
33 \brief Returns type of series.
34 \sa QSeries, QSeriesType
35 */
36
37 /*!
38 \fn QLineSeries* QAreaSeries::upperSeries() const
39 \brief Returns upperSeries used to define one of area boundaries.
40 */
41
42 /*!
43 \fn QLineSeries* QAreaSeries::lowerSeries() const
44 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
45 this function return Null pointer.
46 */
47
48 /*!
49 \fn QPen QAreaSeries::pen() const
50 \brief Returns the pen used to draw line for this series.
51 \sa setPen()
52 */
53
54 /*!
55 \fn QPen QAreaSeries::brush() const
56 \brief Returns the brush used to draw line for this series.
57 \sa setBrush()
58 */
59
60 /*!
61 \fn bool QAreaSeries::pointsVisible() const
62 \brief Returns if the points are drawn for this series.
63 \sa setPointsVisible()
64 */
65
66 /*!
67 \fn void QAreaSeries::updated()
68 \brief \internal
69 */
70
71 /*!
72 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
73 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
74 When series object is added to QChartView or QChart instance ownerships is transfered.
75 */
76 QAreaSeries::QAreaSeries(QLineSeries* upperSeries,QLineSeries* lowerSeries):QSeries(upperSeries),
77 m_upperSeries(upperSeries),
78 m_lowerSeries(lowerSeries),
79 m_pointsVisible(false)
80 {
81 }
82 /*!
83 Destroys the object. Series added to QChartView or QChart instances are owned by those,
84 and are deleted when mentioned object are destroyed.
85 */
86 QAreaSeries::~QAreaSeries()
87 {
88 }
89
90 /*!
91 Sets \a pen used for drawing area outline.
92 */
93 void QAreaSeries::setPen(const QPen& pen)
94 {
95 m_pen=pen;
96 }
97
98 /*!
99 Sets \a brush used for filling the area.
100 */
101 void QAreaSeries::setBrush(const QBrush& brush)
102 {
103 m_brush=brush;
104 }
105 /*!
106 Sets if data points are \a visible and should be drawn on line.
107 */
108 void QAreaSeries::setPointsVisible(bool visible)
109 {
110 m_pointsVisible=visible;
111 }
112
113 #include "moc_qareaseries.cpp"
114
115 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,48
1 #ifndef QAREASERIES_H_
2 #define QAREASERIES_H_
3
4 #include "qchartglobal.h"
5 #include "qseries.h"
6 #include <QDebug>
7 #include <QPen>
8 #include <QBrush>
9
10 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 class QLineSeries;
12
13 class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries
14 {
15 Q_OBJECT
16 public:
17 QAreaSeries(QLineSeries* upperSeries,QLineSeries* lowerSeries=0);
18 virtual ~QAreaSeries();
19
20 public: // from QChartSeries
21 virtual QSeriesType type() const { return QSeries::SeriesTypeArea;}
22
23 QLineSeries* upperSeries() const { return m_upperSeries;}
24 QLineSeries* lowerSeries() const { return m_lowerSeries;}
25
26 void setPen(const QPen& pen);
27 QPen pen() const { return m_pen;}
28
29 void setBrush(const QBrush& brush);
30 QBrush brush() const { return m_brush;}
31
32 void setPointsVisible(bool visible);
33 bool pointsVisible() const {return m_pointsVisible;}
34
35 signals:
36 void updated();
37
38 private:
39 QBrush m_brush;
40 QPen m_pen;
41 QLineSeries* m_upperSeries;
42 QLineSeries* m_lowerSeries;
43 bool m_pointsVisible;
44 };
45
46 QTCOMMERCIALCHART_END_NAMESPACE
47
48 #endif
@@ -1,50 +1,51
1 /*!
1 /*!
2 \page classes.html
2 \page classes.html
3 \title QtCommercial Charts API
3 \title QtCommercial Charts API
4 \keyword All Classes
4 \keyword All Classes
5
5
6 \raw HTML
6 \raw HTML
7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
8 <tr>
8 <tr>
9 <th class="titleheader" width="33%">
9 <th class="titleheader" width="33%">
10 List of classes
10 List of classes
11 </th>
11 </th>
12 </tr>
12 </tr>
13 <tr>
13 <tr>
14 <td valign="top">
14 <td valign="top">
15 <ul>
15 <ul>
16 <li><a href="qareaseries.html">QAreaSeries</a></li>
16 <li><a href="qbarseries.html">QBarSeries</a></li>
17 <li><a href="qbarseries.html">QBarSeries</a></li>
17 <li><a href="qbarset.html">QBarSet</a></li>
18 <li><a href="qbarset.html">QBarSet</a></li>
18 <li><a href="qchart.html">QChart</a></li>
19 <li><a href="qchart.html">QChart</a></li>
19 <li><a href="qchartaxis.html">QChartAxis</a></li>
20 <li><a href="qchartaxis.html">QChartAxis</a></li>
20 <li><a href="qchartview.html">QChartView</a></li>
21 <li><a href="qchartview.html">QChartView</a></li>
21 <li><a href="qlineseries.html">QLineSeries</a></li>
22 <li><a href="qlineseries.html">QLineSeries</a></li>
22 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
23 <li><a href="qpercentbarseries.html">QPercentBarSeries</a></li>
23 <li><a href="qpieseries.html">QPieSeries</a></li>
24 <li><a href="qpieseries.html">QPieSeries</a></li>
24 <li><a href="qpieslice.html">QPieSlice</a></li>
25 <li><a href="qpieslice.html">QPieSlice</a></li>
25 <li><a href="qscatterseries.html">QScatterSeries</a></li>
26 <li><a href="qscatterseries.html">QScatterSeries</a></li>
26 <li><a href="qseries.html">QSeries</a></li>
27 <li><a href="qseries.html">QSeries</a></li>
27 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
28 <li><a href="qstackedbarseries.html">QStackedBarSeries</a></li>
28 </ul>
29 </ul>
29 </td>
30 </td>
30 </tr>
31 </tr>
31 </table>
32 </table>
32
33
33 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
34 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
34 <tr>
35 <tr>
35 <th class="titleheader" width="33%">
36 <th class="titleheader" width="33%">
36 Other files:
37 Other files:
37 </th>
38 </th>
38 </tr>
39 </tr>
39 <tr>
40 <tr>
40 <td valign="top">
41 <td valign="top">
41 <ul>
42 <ul>
42 <li><a href="qchartglobal.html">QChartGlobal</a></li>
43 <li><a href="qchartglobal.html">QChartGlobal</a></li>
43 </ul>
44 </ul>
44 </td>
45 </td>
45 </tr>
46 </tr>
46 </table>
47 </table>
47
48
48 \endraw
49 \endraw
49
50
50 */
51 */
@@ -1,26 +1,27
1 /*!
1 /*!
2 \page examples.html
2 \page examples.html
3 \title Examples
3 \title Examples
4 \keyword Examples
4 \keyword Examples
5
5
6 \raw HTML
6 \raw HTML
7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
7 <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable">
8 <tr>
8 <tr>
9 <th class="titleheader" width="33%">
9 <th class="titleheader" width="33%">
10 List of examples
10 List of examples
11 </th>
11 </th>
12 </tr>
12 </tr>
13 <tr>
13 <tr>
14 <td valign="top">
14 <td valign="top">
15 <ul>
15 <ul>
16 <li><a href="example-areachart.html">Area Chart example</a></li>
16 <li><a href="example-barchart.html">Bar Chart example</a></li>
17 <li><a href="example-barchart.html">Bar Chart example</a></li>
17 <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li>
18 <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li>
18 <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li>
19 <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li>
19 <li><a href="example-linechart.html">Line Chart example</a></li>
20 <li><a href="example-linechart.html">Line Chart example</a></li>
20 <li><a href="example-piechart.html">Pie Chart example</a></li>
21 <li><a href="example-piechart.html">Pie Chart example</a></li>
21 </ul>
22 </ul>
22 </td>
23 </td>
23 </tr>
24 </tr>
24 </table>
25 </table>
25 \endraw
26 \endraw
26 */
27 */
@@ -1,40 +1,41
1 /*!
1 /*!
2 \page index.html
2 \page index.html
3 \keyword About
3 \keyword About
4
4
5 \raw HTML
5 \raw HTML
6 <div class="qchart">
6 <div class="qchart">
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
7 <img src="images/qt_commercial_logo.png" alt="qtcommercial"/>
8
8
9 <p>
9 <p>
10 QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart
10 QCharts is a part of Qt Commercial addons package. It provides a set of easy to use chart
11 components which are available for Qt Commercial customers. It uses Qt Graphics View
11 components which are available for Qt Commercial customers. It uses Qt Graphics View
12 Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can
12 Framework, therefore charts can be easily integrated to modern 2D user interfaces. QCharts can
13 be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive
13 be used as QWidgets, QGraphicsWidget or QML elements. Users can easily create impressive
14 graphs by selecting one of the charts themes.
14 graphs by selecting one of the charts themes.
15 </p>
15 </p>
16
16
17 <table><tr>
17 <table><tr>
18 <td><a href="example-linechart.html"><img src="images/linechart.png" alt="linechart" /></a></td>
18 <td><a href="example-linechart.html"><img src="images/linechart.png" alt="linechart" /></a></td>
19 <td><a href="example-barchart.html"><img src="images/barchart.png" alt="barchart" /></a></td>
19 <td><a href="example-areachart.html"><img src="images/areachart.png" alt="areachart" /></a></td>
20 </tr>
20 </tr>
21 <tr>
21 <tr>
22 <td><a href="example-barchart.html"><img src="images/barchart.png" alt="barchart" /></a></td>
22 <td><a href="example-percentbarchart.html"><img src="images/percentbarchart.png" alt="percentbarcchart" /></a></td>
23 <td><a href="example-percentbarchart.html"><img src="images/percentbarchart.png" alt="percentbarcchart" /></a></td>
23 <td><a href="example-stackedbarchart.html"><img src="images/stackedbarchart.png" alt="stackedbarchart" /></a></td>
24 </tr>
24 </tr>
25 <tr>
25 <tr>
26 <td><a href="example-stackedbarchart.html"><img src="images/stackedbarchart.png" alt="stackedbarchart" /></a></td>
26 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
27 <td><img src="images/chartview_example.jpg " alt="linechart" /></td>
27 <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td>
28 </tr><tr>
28 </tr><tr>
29 <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td>
29 <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td>
30 <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td>
30 <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td>
31 </tr>
31 </tr>
32 <tr>
32 <tr>
33 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
33 <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td>
34 <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td>
34 </tr>
35 </tr>
35 </table>
36 </table>
36 </div>
37 </div>
37 \endraw
38 \endraw
38
39
39
40
40 */
41 */
@@ -1,17 +1,18
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += linechart \
2 SUBDIRS += linechart \
3 zoomlinechart \
3 zoomlinechart \
4 colorlinechart \
4 colorlinechart \
5 barchart \
5 barchart \
6 stackedbarchart \
6 stackedbarchart \
7 percentbarchart \
7 percentbarchart \
8 scatter \
8 scatter \
9 piechart \
9 piechart \
10 piechartdrilldown \
10 piechartdrilldown \
11 dynamiclinechart \
11 dynamiclinechart \
12 axischart \
12 axischart \
13 multichart \
13 multichart \
14 gdpbarchart \
14 gdpbarchart \
15 presenterchart \
15 presenterchart \
16 chartview \
16 chartview \
17 scatterinteractions
17 scatterinteractions \
18 areachart
@@ -1,403 +1,432
1 #include "chartdataset_p.h"
1 #include "chartdataset_p.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 //series
3 //series
4 #include "qlineseries.h"
4 #include "qlineseries.h"
5 #include "qareaseries.h"
5 #include "qbarseries.h"
6 #include "qbarseries.h"
6 #include "qstackedbarseries.h"
7 #include "qstackedbarseries.h"
7 #include "qpercentbarseries.h"
8 #include "qpercentbarseries.h"
8 #include "qpieseries.h"
9 #include "qpieseries.h"
9 #include "qscatterseries.h"
10 #include "qscatterseries.h"
10
11
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
13
13 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
14 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
14 m_axisX(new QChartAxis(this)),
15 m_axisX(new QChartAxis(this)),
15 m_axisY(new QChartAxis(this)),
16 m_axisY(new QChartAxis(this)),
16 m_domainIndex(0),
17 m_domainIndex(0),
17 m_axisXInitialized(false)
18 m_axisXInitialized(false)
18 {
19 {
19 }
20 }
20
21
21 ChartDataSet::~ChartDataSet()
22 ChartDataSet::~ChartDataSet()
22 {
23 {
23 // TODO Auto-generated destructor stub
24 // TODO Auto-generated destructor stub
24 }
25 }
25
26
26 const Domain ChartDataSet::domain(QChartAxis *axisY) const
27 const Domain ChartDataSet::domain(QChartAxis *axisY) const
27 {
28 {
28 int i = m_domainMap.count(axisY);
29 int i = m_domainMap.count(axisY);
29 if(i == 0) {
30 if(i == 0) {
30 return Domain();
31 return Domain();
31 }
32 }
32 i = i - m_domainIndex -1;
33 i = i - m_domainIndex -1;
33 return m_domainMap.values(axisY).at(i);
34 return m_domainMap.values(axisY).at(i);
34 }
35 }
35
36
36 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
37 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
37 {
38 {
38 // TODO: we should check the series not already added
39 // TODO: we should check the series not already added
39
40
40 series->setParent(this);// take ownership
41 series->setParent(this);// take ownership
41 clearDomains();
42 clearDomains();
42
43
43 if(axisY==0) axisY = m_axisY;
44 if(axisY==0) axisY = m_axisY;
44 axisY->setParent(this);// take ownership
45 axisY->setParent(this);// take ownership
45
46
46 QList<QSeries*> seriesList = m_seriesMap.values(axisY);
47 QList<QSeries*> seriesList = m_seriesMap.values(axisY);
47
48
48 QList<Domain> domainList = m_domainMap.values(axisY);
49 QList<Domain> domainList = m_domainMap.values(axisY);
49
50
50 Q_ASSERT(domainList.size()<=1);
51 Q_ASSERT(domainList.size()<=1);
51
52
52 Domain domain;
53 Domain domain;
53
54
54 if(domainList.size()>0) domain = domainList.at(0);
55 if(domainList.size()>0) domain = domainList.at(0);
55
56
56 switch(series->type())
57 switch(series->type())
57 {
58 {
58 case QSeries::SeriesTypeLine: {
59 case QSeries::SeriesTypeLine: {
59
60
60 QLineSeries* xyseries = static_cast<QLineSeries*>(series);
61 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
61
62
62 for (int i = 0; i < xyseries->count(); i++)
63 for (int i = 0; i < lineSeries->count(); i++)
63 {
64 {
64 qreal x = xyseries->x(i);
65 qreal x = lineSeries->x(i);
65 qreal y = xyseries->y(i);
66 qreal y = lineSeries->y(i);
66 domain.m_minX = qMin(domain.m_minX,x);
67 domain.m_minX = qMin(domain.m_minX,x);
67 domain.m_minY = qMin(domain.m_minY,y);
68 domain.m_minY = qMin(domain.m_minY,y);
68 domain.m_maxX = qMax(domain.m_maxX,x);
69 domain.m_maxX = qMax(domain.m_maxX,x);
69 domain.m_maxY = qMax(domain.m_maxY,y);
70 domain.m_maxY = qMax(domain.m_maxY,y);
70 }
71 }
71 break;
72 break;
72 }
73 }
74 case QSeries::SeriesTypeArea: {
75
76 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
77
78 QLineSeries* upperSeries = areaSeries->upperSeries();
79 QLineSeries* lowerSeries = areaSeries->lowerSeries();
80
81 for (int i = 0; i < upperSeries->count(); i++)
82 {
83 qreal x = upperSeries->x(i);
84 qreal y = upperSeries->y(i);
85 domain.m_minX = qMin(domain.m_minX,x);
86 domain.m_minY = qMin(domain.m_minY,y);
87 domain.m_maxX = qMax(domain.m_maxX,x);
88 domain.m_maxY = qMax(domain.m_maxY,y);
89 }
90 if(lowerSeries){
91 for (int i = 0; i < lowerSeries->count(); i++)
92 {
93 qreal x = lowerSeries->x(i);
94 qreal y = lowerSeries->y(i);
95 domain.m_minX = qMin(domain.m_minX,x);
96 domain.m_minY = qMin(domain.m_minY,y);
97 domain.m_maxX = qMax(domain.m_maxX,x);
98 domain.m_maxY = qMax(domain.m_maxY,y);
99 }}
100 break;
101 }
73 case QSeries::SeriesTypeBar: {
102 case QSeries::SeriesTypeBar: {
74 qDebug() << "QChartSeries::SeriesTypeBar";
103 qDebug() << "QChartSeries::SeriesTypeBar";
75 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
104 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
76 qreal x = barSeries->categoryCount();
105 qreal x = barSeries->categoryCount();
77 qreal y = barSeries->max();
106 qreal y = barSeries->max();
78 domain.m_minX = qMin(domain.m_minX,x);
107 domain.m_minX = qMin(domain.m_minX,x);
79 domain.m_minY = qMin(domain.m_minY,y);
108 domain.m_minY = qMin(domain.m_minY,y);
80 domain.m_maxX = qMax(domain.m_maxX,x);
109 domain.m_maxX = qMax(domain.m_maxX,x);
81 domain.m_maxY = qMax(domain.m_maxY,y);
110 domain.m_maxY = qMax(domain.m_maxY,y);
82 break;
111 break;
83 }
112 }
84 case QSeries::SeriesTypeStackedBar: {
113 case QSeries::SeriesTypeStackedBar: {
85 qDebug() << "QChartSeries::SeriesTypeStackedBar";
114 qDebug() << "QChartSeries::SeriesTypeStackedBar";
86
115
87 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
116 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
88 qreal x = stackedBarSeries->categoryCount();
117 qreal x = stackedBarSeries->categoryCount();
89 qreal y = stackedBarSeries->maxCategorySum();
118 qreal y = stackedBarSeries->maxCategorySum();
90 domain.m_minX = qMin(domain.m_minX,x);
119 domain.m_minX = qMin(domain.m_minX,x);
91 domain.m_minY = qMin(domain.m_minY,y);
120 domain.m_minY = qMin(domain.m_minY,y);
92 domain.m_maxX = qMax(domain.m_maxX,x);
121 domain.m_maxX = qMax(domain.m_maxX,x);
93 domain.m_maxY = qMax(domain.m_maxY,y);
122 domain.m_maxY = qMax(domain.m_maxY,y);
94 break;
123 break;
95 }
124 }
96 case QSeries::SeriesTypePercentBar: {
125 case QSeries::SeriesTypePercentBar: {
97 qDebug() << "QChartSeries::SeriesTypePercentBar";
126 qDebug() << "QChartSeries::SeriesTypePercentBar";
98
127
99 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
128 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
100 qreal x = percentBarSeries->categoryCount();
129 qreal x = percentBarSeries->categoryCount();
101 domain.m_minX = qMin(domain.m_minX,x);
130 domain.m_minX = qMin(domain.m_minX,x);
102 domain.m_minY = 0;
131 domain.m_minY = 0;
103 domain.m_maxX = qMax(domain.m_maxX,x);
132 domain.m_maxX = qMax(domain.m_maxX,x);
104 domain.m_maxY = 100;
133 domain.m_maxY = 100;
105 break;
134 break;
106 }
135 }
107
136
108 case QSeries::SeriesTypePie: {
137 case QSeries::SeriesTypePie: {
109 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
138 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
110 // TODO: domain stuff
139 // TODO: domain stuff
111 break;
140 break;
112 }
141 }
113
142
114 case QSeries::SeriesTypeScatter: {
143 case QSeries::SeriesTypeScatter: {
115 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
144 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
116 Q_ASSERT(scatterSeries);
145 Q_ASSERT(scatterSeries);
117 foreach (QPointF point, scatterSeries->data()) {
146 foreach (QPointF point, scatterSeries->data()) {
118 domain.m_minX = qMin(domain.m_minX, point.x());
147 domain.m_minX = qMin(domain.m_minX, point.x());
119 domain.m_maxX = qMax(domain.m_maxX, point.x());
148 domain.m_maxX = qMax(domain.m_maxX, point.x());
120 domain.m_minY = qMin(domain.m_minY, point.y());
149 domain.m_minY = qMin(domain.m_minY, point.y());
121 domain.m_maxY = qMax(domain.m_maxY, point.y());
150 domain.m_maxY = qMax(domain.m_maxY, point.y());
122 }
151 }
123 break;
152 break;
124 }
153 }
125
154
126 default: {
155 default: {
127 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
156 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
128 return;
157 return;
129 break;
158 break;
130 }
159 }
131
160
132 }
161 }
133
162
134 if(!m_domainMap.contains(axisY))
163 if(!m_domainMap.contains(axisY))
135 {
164 {
136 emit axisAdded(axisY);
165 emit axisAdded(axisY);
137 QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
166 QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
138 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
167 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
139 }
168 }
140
169
141 if(!m_axisXInitialized)
170 if(!m_axisXInitialized)
142 {
171 {
143 emit axisAdded(axisX());
172 emit axisAdded(axisX());
144 QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
173 QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*)));
145 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
174 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
146 m_axisXInitialized=true;
175 m_axisXInitialized=true;
147 }
176 }
148
177
149 m_domainMap.replace(axisY,domain);
178 m_domainMap.replace(axisY,domain);
150 m_seriesMap.insert(axisY,series);
179 m_seriesMap.insert(axisY,series);
151 emit seriesAdded(series);
180 emit seriesAdded(series);
152 setDomain(m_domainIndex,axisY);
181 setDomain(m_domainIndex,axisY);
153
182
154 }
183 }
155
184
156 void ChartDataSet::removeSeries(QSeries* series)
185 void ChartDataSet::removeSeries(QSeries* series)
157 {
186 {
158 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
187 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
159 foreach(QChartAxis* axis , keys) {
188 foreach(QChartAxis* axis , keys) {
160 if(m_seriesMap.contains(axis,series)) {
189 if(m_seriesMap.contains(axis,series)) {
161 emit seriesRemoved(series);
190 emit seriesRemoved(series);
162 m_seriesMap.remove(axis,series);
191 m_seriesMap.remove(axis,series);
163 //remove axis if no longer there
192 //remove axis if no longer there
164 if(!m_seriesMap.contains(axis)) {
193 if(!m_seriesMap.contains(axis)) {
165 emit axisRemoved(axis);
194 emit axisRemoved(axis);
166 m_domainMap.remove(axis);
195 m_domainMap.remove(axis);
167 if(axis != m_axisY)
196 if(axis != m_axisY)
168 delete axis;
197 delete axis;
169 }
198 }
170 series->setParent(0);
199 series->setParent(0);
171 break;
200 break;
172 }
201 }
173 }
202 }
174 }
203 }
175
204
176 void ChartDataSet::removeAllSeries()
205 void ChartDataSet::removeAllSeries()
177 {
206 {
178 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
207 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
179 foreach(QChartAxis* axis , keys) {
208 foreach(QChartAxis* axis , keys) {
180 QList<QSeries*> seriesList = m_seriesMap.values(axis);
209 QList<QSeries*> seriesList = m_seriesMap.values(axis);
181 for(int i =0; i < seriesList.size();i++ )
210 for(int i =0; i < seriesList.size();i++ )
182 {
211 {
183 emit seriesRemoved(seriesList.at(i));
212 emit seriesRemoved(seriesList.at(i));
184 delete(seriesList.at(i));
213 delete(seriesList.at(i));
185 }
214 }
186 m_seriesMap.remove(axis);
215 m_seriesMap.remove(axis);
187 m_domainMap.remove(axis);
216 m_domainMap.remove(axis);
188 emit axisRemoved(axis);
217 emit axisRemoved(axis);
189 if(axis != m_axisY) delete axis;
218 if(axis != m_axisY) delete axis;
190 }
219 }
191 m_domainIndex=0;
220 m_domainIndex=0;
192 }
221 }
193
222
194 bool ChartDataSet::nextDomain()
223 bool ChartDataSet::nextDomain()
195 {
224 {
196 int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1;
225 int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1;
197
226
198 if (m_domainIndex < limit) {
227 if (m_domainIndex < limit) {
199 m_domainIndex++;
228 m_domainIndex++;
200 setDomain(m_domainIndex);
229 setDomain(m_domainIndex);
201 return true;
230 return true;
202 }
231 }
203 else {
232 else {
204 return false;
233 return false;
205 }
234 }
206 }
235 }
207
236
208 bool ChartDataSet::previousDomain()
237 bool ChartDataSet::previousDomain()
209 {
238 {
210 if (m_domainIndex > 0) {
239 if (m_domainIndex > 0) {
211 m_domainIndex--;
240 m_domainIndex--;
212 setDomain(m_domainIndex);
241 setDomain(m_domainIndex);
213 return true;
242 return true;
214 }
243 }
215 else {
244 else {
216 return false;
245 return false;
217 }
246 }
218 }
247 }
219
248
220 void ChartDataSet::setDomain(int index)
249 void ChartDataSet::setDomain(int index)
221 {
250 {
222 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
251 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
223
252
224 if(domainList.count()==0) return;
253 if(domainList.count()==0) return;
225
254
226 Domain domain;
255 Domain domain;
227
256
228 foreach (QChartAxis* axis , domainList) {
257 foreach (QChartAxis* axis , domainList) {
229 int i = m_domainMap.count(axis) - index -1;
258 int i = m_domainMap.count(axis) - index -1;
230 Q_ASSERT(i>=0);
259 Q_ASSERT(i>=0);
231 domain = m_domainMap.values(axis).at(i);
260 domain = m_domainMap.values(axis).at(i);
232 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
261 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
233 QList<QSeries*> seriesList = m_seriesMap.values(axis);
262 QList<QSeries*> seriesList = m_seriesMap.values(axis);
234 foreach(QSeries* series, seriesList) {
263 foreach(QSeries* series, seriesList) {
235 emit seriesDomainChanged(series,domain);
264 emit seriesDomainChanged(series,domain);
236 }
265 }
237 axis->updateRange(domain.m_minY,domain.m_maxY);
266 axis->updateRange(domain.m_minY,domain.m_maxY);
238 emit axisRangeChanged(axis,labels);
267 emit axisRangeChanged(axis,labels);
239
268
240 }
269 }
241
270
242 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
271 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
243 axisX()->updateRange(domain.m_minX,domain.m_maxY);
272 axisX()->updateRange(domain.m_minX,domain.m_maxY);
244 emit axisRangeChanged(axisX(),labels);
273 emit axisRangeChanged(axisX(),labels);
245 }
274 }
246
275
247 void ChartDataSet::setDomain(int index,QChartAxis* axis)
276 void ChartDataSet::setDomain(int index,QChartAxis* axis)
248 {
277 {
249 int i = m_domainMap.count(axis) - index -1;
278 int i = m_domainMap.count(axis) - index -1;
250 Q_ASSERT(i>=0);
279 Q_ASSERT(i>=0);
251 Domain domain = m_domainMap.values(axis).at(i);
280 Domain domain = m_domainMap.values(axis).at(i);
252 {
281 {
253 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
282 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
254 QList<QSeries*> seriesList = m_seriesMap.values(axis);
283 QList<QSeries*> seriesList = m_seriesMap.values(axis);
255 foreach(QSeries* series, seriesList) {
284 foreach(QSeries* series, seriesList) {
256 emit seriesDomainChanged(series,domain);
285 emit seriesDomainChanged(series,domain);
257 }
286 }
258 axis->updateRange(domain.m_minY,domain.m_maxY);
287 axis->updateRange(domain.m_minY,domain.m_maxY);
259 emit axisRangeChanged(axis,labels);
288 emit axisRangeChanged(axis,labels);
260 }
289 }
261
290
262 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
291 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
263 axisX()->updateRange(domain.m_minX,domain.m_maxY);
292 axisX()->updateRange(domain.m_minX,domain.m_maxY);
264 emit axisRangeChanged(axisX(),labels);
293 emit axisRangeChanged(axisX(),labels);
265 }
294 }
266
295
267 void ChartDataSet::clearDomains(int toIndex)
296 void ChartDataSet::clearDomains(int toIndex)
268 {
297 {
269 Q_ASSERT(toIndex>=0);
298 Q_ASSERT(toIndex>=0);
270
299
271 m_domainIndex = toIndex;
300 m_domainIndex = toIndex;
272
301
273 QList<QChartAxis*> keys = m_domainMap.uniqueKeys();
302 QList<QChartAxis*> keys = m_domainMap.uniqueKeys();
274
303
275 foreach (QChartAxis* key , keys)
304 foreach (QChartAxis* key , keys)
276 {
305 {
277 QList<Domain> domains = m_domainMap.values(key);
306 QList<Domain> domains = m_domainMap.values(key);
278 m_domainMap.remove(key);
307 m_domainMap.remove(key);
279 int i = domains.size() - toIndex - 1;
308 int i = domains.size() - toIndex - 1;
280 while(i--) {
309 while(i--) {
281 domains.removeFirst();
310 domains.removeFirst();
282 }
311 }
283 for(int j=domains.size()-1; j>=0;j--)
312 for(int j=domains.size()-1; j>=0;j--)
284 m_domainMap.insert(key,domains.at(j));
313 m_domainMap.insert(key,domains.at(j));
285 }
314 }
286 }
315 }
287
316
288 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
317 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
289 {
318 {
290 Q_ASSERT(rect.isValid());
319 Q_ASSERT(rect.isValid());
291 Q_ASSERT(viewport.isValid());
320 Q_ASSERT(viewport.isValid());
292
321
293 clearDomains(m_domainIndex);
322 clearDomains(m_domainIndex);
294
323
295 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
324 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
296
325
297 Domain domain;
326 Domain domain;
298
327
299 foreach (QChartAxis* axis , domainList) {
328 foreach (QChartAxis* axis , domainList) {
300 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
329 domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height());
301 m_domainMap.insert(axis,domain);
330 m_domainMap.insert(axis,domain);
302 }
331 }
303
332
304 setDomain(++m_domainIndex);
333 setDomain(++m_domainIndex);
305 }
334 }
306
335
307 QChartAxis* ChartDataSet::axisY(QSeries* series) const
336 QChartAxis* ChartDataSet::axisY(QSeries* series) const
308 {
337 {
309 if(series == 0) return m_axisY;
338 if(series == 0) return m_axisY;
310
339
311 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
340 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
312
341
313 foreach(QChartAxis* axis , keys) {
342 foreach(QChartAxis* axis , keys) {
314 if(m_seriesMap.contains(axis,series)) {
343 if(m_seriesMap.contains(axis,series)) {
315 return axis;
344 return axis;
316 }
345 }
317 }
346 }
318 return 0;
347 return 0;
319 }
348 }
320
349
321 QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
350 QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
322 {
351 {
323 Q_ASSERT(max>=min);
352 Q_ASSERT(max>=min);
324
353
325 QStringList labels;
354 QStringList labels;
326
355
327 int ticks = axis->ticksCount()-1;
356 int ticks = axis->ticksCount()-1;
328
357
329 for(int i=0; i<= ticks; i++) {
358 for(int i=0; i<= ticks; i++) {
330 qreal value = min + (i * (max - min)/ ticks);
359 qreal value = min + (i * (max - min)/ ticks);
331 QString label = axis->axisTickLabel(value);
360 QString label = axis->axisTickLabel(value);
332 if(label.isEmpty()) {
361 if(label.isEmpty()) {
333 labels << QString::number(value);
362 labels << QString::number(value);
334 }
363 }
335 else {
364 else {
336 labels << label;
365 labels << label;
337 }
366 }
338 }
367 }
339 return labels;
368 return labels;
340 }
369 }
341
370
342 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
371 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
343 {
372 {
344 qreal min = axis->min();
373 qreal min = axis->min();
345 qreal max = axis->max();
374 qreal max = axis->max();
346
375
347 if(axis==axisX()) {
376 if(axis==axisX()) {
348
377
349 m_domainIndex=0;
378 m_domainIndex=0;
350
379
351 clearDomains(m_domainIndex);
380 clearDomains(m_domainIndex);
352
381
353 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
382 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
354
383
355 foreach (QChartAxis* axis , domainList) {
384 foreach (QChartAxis* axis , domainList) {
356
385
357 Q_ASSERT(m_domainMap.values(axis).size()==1);
386 Q_ASSERT(m_domainMap.values(axis).size()==1);
358
387
359 Domain domain = m_domainMap.value(axis);
388 Domain domain = m_domainMap.value(axis);
360 domain.m_minX=min;
389 domain.m_minX=min;
361 domain.m_maxX=max;
390 domain.m_maxX=max;
362 m_domainMap.replace(axis,domain);
391 m_domainMap.replace(axis,domain);
363 }
392 }
364
393
365 setDomain(m_domainIndex);
394 setDomain(m_domainIndex);
366
395
367 }
396 }
368 else {
397 else {
369
398
370 QList<Domain> domains = m_domainMap.values(axis);
399 QList<Domain> domains = m_domainMap.values(axis);
371 m_domainMap.remove(axis);
400 m_domainMap.remove(axis);
372
401
373 for(int i=0;i<domains.size();i++)
402 for(int i=0;i<domains.size();i++)
374 {
403 {
375 domains[i].m_minY=min;
404 domains[i].m_minY=min;
376 domains[i].m_maxY=max;
405 domains[i].m_maxY=max;
377 }
406 }
378
407
379 for(int j=domains.size()-1; j>=0;j--)
408 for(int j=domains.size()-1; j>=0;j--)
380 m_domainMap.insert(axis,domains.at(j));
409 m_domainMap.insert(axis,domains.at(j));
381
410
382 setDomain(m_domainIndex,axis);
411 setDomain(m_domainIndex,axis);
383 }
412 }
384
413
385 }
414 }
386
415
387 void ChartDataSet::handleTickChanged(QChartAxis* axis)
416 void ChartDataSet::handleTickChanged(QChartAxis* axis)
388 {
417 {
389 if(axis==axisX()) {
418 if(axis==axisX()) {
390 Domain domain = m_domainMap.value(axisY());
419 Domain domain = m_domainMap.value(axisY());
391 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
420 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
392 emit axisRangeChanged(axis,labels);
421 emit axisRangeChanged(axis,labels);
393 }
422 }
394 else {
423 else {
395 Domain domain = m_domainMap.value(axis);
424 Domain domain = m_domainMap.value(axis);
396 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
425 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
397 emit axisRangeChanged(axis,labels);
426 emit axisRangeChanged(axis,labels);
398 }
427 }
399 }
428 }
400
429
401 #include "moc_chartdataset_p.cpp"
430 #include "moc_chartdataset_p.cpp"
402
431
403 QTCOMMERCIALCHART_END_NAMESPACE
432 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,287 +1,300
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 //series
6 //series
7 #include "qbarseries.h"
7 #include "qbarseries.h"
8 #include "qstackedbarseries.h"
8 #include "qstackedbarseries.h"
9 #include "qpercentbarseries.h"
9 #include "qpercentbarseries.h"
10 #include "qlineseries.h"
10 #include "qlineseries.h"
11 #include "qareaseries.h"
11 #include "qpieseries.h"
12 #include "qpieseries.h"
12 #include "qscatterseries.h"
13 #include "qscatterseries.h"
13 //items
14 //items
14 #include "axisitem_p.h"
15 #include "axisitem_p.h"
15 #include "axisanimationitem_p.h"
16 #include "axisanimationitem_p.h"
17 #include "areachartitem_p.h"
16 #include "barpresenter_p.h"
18 #include "barpresenter_p.h"
17 #include "stackedbarpresenter_p.h"
19 #include "stackedbarpresenter_p.h"
18 #include "percentbarpresenter_p.h"
20 #include "percentbarpresenter_p.h"
19 #include "linechartitem_p.h"
21 #include "linechartitem_p.h"
20 #include "linechartanimationitem_p.h"
22 #include "linechartanimationitem_p.h"
21 #include "piepresenter_p.h"
23 #include "piepresenter_p.h"
22 #include "scatterpresenter_p.h"
24 #include "scatterpresenter_p.h"
23
25
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
27
26 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
28 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
27 m_chart(chart),
29 m_chart(chart),
28 m_dataset(dataset),
30 m_dataset(dataset),
29 m_chartTheme(0),
31 m_chartTheme(0),
30 m_marginSize(0),
32 m_marginSize(0),
31 m_rect(QRectF(QPoint(0,0),m_chart->size())),
33 m_rect(QRectF(QPoint(0,0),m_chart->size())),
32 m_options(0)
34 m_options(0)
33 {
35 {
34 createConnections();
36 createConnections();
35 setChartTheme(QChart::ChartThemeDefault);
37 setChartTheme(QChart::ChartThemeDefault);
36
38
37 }
39 }
38
40
39 ChartPresenter::~ChartPresenter()
41 ChartPresenter::~ChartPresenter()
40 {
42 {
41 }
43 }
42
44
43 void ChartPresenter::createConnections()
45 void ChartPresenter::createConnections()
44 {
46 {
45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
47 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
48 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*)));
47 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
49 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
48 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
50 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
49 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
51 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
50 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
52 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&)));
51 QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&)));
53 QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&)));
52 }
54 }
53
55
54
56
55 QRectF ChartPresenter::geometry() const
57 QRectF ChartPresenter::geometry() const
56 {
58 {
57 return m_rect;
59 return m_rect;
58 }
60 }
59
61
60 void ChartPresenter::handleGeometryChanged()
62 void ChartPresenter::handleGeometryChanged()
61 {
63 {
62 m_rect = QRectF(QPoint(0,0),m_chart->size());
64 m_rect = QRectF(QPoint(0,0),m_chart->size());
63 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
65 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
64 Q_ASSERT(m_rect.isValid());
66 Q_ASSERT(m_rect.isValid());
65 emit geometryChanged(m_rect);
67 emit geometryChanged(m_rect);
66 }
68 }
67
69
68 int ChartPresenter::margin() const
70 int ChartPresenter::margin() const
69 {
71 {
70 return m_marginSize;
72 return m_marginSize;
71 }
73 }
72
74
73 void ChartPresenter::setMargin(int margin)
75 void ChartPresenter::setMargin(int margin)
74 {
76 {
75 m_marginSize = margin;
77 m_marginSize = margin;
76 }
78 }
77
79
78 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
80 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
79 {
81 {
80
82
81 AxisItem* item ;
83 AxisItem* item ;
82
84
83 if(!m_options.testFlag(QChart::GridAxisAnimations))
85 if(!m_options.testFlag(QChart::GridAxisAnimations))
84 {
86 {
85 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
87 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
86 }else{
88 }else{
87 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
89 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
88 }
90 }
89
91
90 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
91 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
93 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
92
94
93 item->handleAxisUpdate(axis);
95 item->handleAxisUpdate(axis);
94 item->handleGeometryChanged(m_rect);
96 item->handleGeometryChanged(m_rect);
95 m_chartTheme->decorate(axis,item);
97 m_chartTheme->decorate(axis,item);
96 m_axisItems.insert(axis,item);
98 m_axisItems.insert(axis,item);
97 }
99 }
98
100
99 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
101 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
100 {
102 {
101 AxisItem* item = m_axisItems.take(axis);
103 AxisItem* item = m_axisItems.take(axis);
102 Q_ASSERT(item);
104 Q_ASSERT(item);
103 delete item;
105 delete item;
104 }
106 }
105
107
106
108
107 void ChartPresenter::handleSeriesAdded(QSeries* series)
109 void ChartPresenter::handleSeriesAdded(QSeries* series)
108 {
110 {
109 switch(series->type())
111 switch(series->type())
110 {
112 {
111 case QSeries::SeriesTypeLine: {
113 case QSeries::SeriesTypeLine: {
114
112 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
115 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
113 LineChartItem* item;
116 LineChartItem* item;
114 if(m_options.testFlag(QChart::SeriesAnimations)){
117 if(m_options.testFlag(QChart::SeriesAnimations)){
115 item = new LineChartAnimationItem(this,lineSeries,m_chart);
118 item = new LineChartAnimationItem(this,lineSeries,m_chart);
116 }else{
119 }else{
117 item = new LineChartItem(this,lineSeries,m_chart);
120 item = new LineChartItem(this,lineSeries,m_chart);
118 }
121 }
119 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
122 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
121 QObject::connect(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int)));
122 QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int)));
123 QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int)));
124 QObject::connect(lineSeries,SIGNAL(updated()),item,SLOT(handleUpdated()));
125 m_chartItems.insert(series,item);
123 m_chartItems.insert(series,item);
126 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
124 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
127 item->handleUpdated();
125 break;
126 }
127
128 case QSeries::SeriesTypeArea: {
129
130 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
131 AreaChartItem* item;
132 if(m_options.testFlag(QChart::SeriesAnimations)) {
133 item = new AreaChartItem(this,areaSeries,m_chart);
134 }
135 else {
136 item = new AreaChartItem(this,areaSeries,m_chart);
137 }
138 m_chartTheme->decorate(item,areaSeries,m_chartItems.count());
139 m_chartItems.insert(series,item);
140 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
128 break;
141 break;
129 }
142 }
130
143
131 case QSeries::SeriesTypeBar: {
144 case QSeries::SeriesTypeBar: {
132 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
145 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
133 BarPresenter* item = new BarPresenter(barSeries,m_chart);
146 BarPresenter* item = new BarPresenter(barSeries,m_chart);
134 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
147 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
135 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
148 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
136 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
149 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
137 m_chartItems.insert(series,item);
150 m_chartItems.insert(series,item);
138 // m_axisXItem->setVisible(false);
151 // m_axisXItem->setVisible(false);
139 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
152 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
140 break;
153 break;
141 }
154 }
142
155
143 case QSeries::SeriesTypeStackedBar: {
156 case QSeries::SeriesTypeStackedBar: {
144
157
145 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
158 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
146 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
159 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
147 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
160 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
148 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
161 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
149 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
162 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
150 m_chartItems.insert(series,item);
163 m_chartItems.insert(series,item);
151 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
164 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
152 break;
165 break;
153 }
166 }
154
167
155 case QSeries::SeriesTypePercentBar: {
168 case QSeries::SeriesTypePercentBar: {
156
169
157 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
170 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
158 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
171 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
159 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
172 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
160 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
173 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
161 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
174 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
162 m_chartItems.insert(series,item);
175 m_chartItems.insert(series,item);
163 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
176 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
164 break;
177 break;
165 }
178 }
166 case QSeries::SeriesTypeScatter: {
179 case QSeries::SeriesTypeScatter: {
167 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
180 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
168 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
181 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
169 QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)),
182 QObject::connect(scatterPresenter, SIGNAL(clicked(QPointF)),
170 scatterSeries, SIGNAL(clicked(QPointF)));
183 scatterSeries, SIGNAL(clicked(QPointF)));
171 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
184 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
172 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
185 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
173 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
186 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
174 m_chartItems.insert(scatterSeries, scatterPresenter);
187 m_chartItems.insert(scatterSeries, scatterPresenter);
175 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
188 if(m_rect.isValid()) scatterPresenter->handleGeometryChanged(m_rect);
176 break;
189 break;
177 }
190 }
178 case QSeries::SeriesTypePie: {
191 case QSeries::SeriesTypePie: {
179 QPieSeries *s = qobject_cast<QPieSeries *>(series);
192 QPieSeries *s = qobject_cast<QPieSeries *>(series);
180 PiePresenter* pie = new PiePresenter(m_chart, s);
193 PiePresenter* pie = new PiePresenter(m_chart, s);
181 m_chartTheme->decorate(pie, s, m_chartItems.count());
194 m_chartTheme->decorate(pie, s, m_chartItems.count());
182 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
195 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
183
196
184 // Hide all from background when there is only piechart
197 // Hide all from background when there is only piechart
185 // TODO: refactor this ugly code... should be one setting for this
198 // TODO: refactor this ugly code... should be one setting for this
186 if (m_chartItems.count() == 0) {
199 if (m_chartItems.count() == 0) {
187 m_chart->axisX()->setAxisVisible(false);
200 m_chart->axisX()->setAxisVisible(false);
188 m_chart->axisY()->setAxisVisible(false);
201 m_chart->axisY()->setAxisVisible(false);
189 m_chart->axisX()->setGridVisible(false);
202 m_chart->axisX()->setGridVisible(false);
190 m_chart->axisY()->setGridVisible(false);
203 m_chart->axisY()->setGridVisible(false);
191 m_chart->axisX()->setLabelsVisible(false);
204 m_chart->axisX()->setLabelsVisible(false);
192 m_chart->axisY()->setLabelsVisible(false);
205 m_chart->axisY()->setLabelsVisible(false);
193 m_chart->axisX()->setShadesVisible(false);
206 m_chart->axisX()->setShadesVisible(false);
194 m_chart->axisY()->setShadesVisible(false);
207 m_chart->axisY()->setShadesVisible(false);
195 m_chart->setChartBackgroundBrush(Qt::transparent);
208 m_chart->setChartBackgroundBrush(Qt::transparent);
196 }
209 }
197
210
198 m_chartItems.insert(series, pie);
211 m_chartItems.insert(series, pie);
199 pie->handleGeometryChanged(m_rect);
212 pie->handleGeometryChanged(m_rect);
200 break;
213 break;
201 }
214 }
202 default: {
215 default: {
203 qDebug()<< "Series type" << series->type() << "not implemented.";
216 qDebug()<< "Series type" << series->type() << "not implemented.";
204 break;
217 break;
205 }
218 }
206 }
219 }
207 }
220 }
208
221
209 void ChartPresenter::handleSeriesRemoved(QSeries* series)
222 void ChartPresenter::handleSeriesRemoved(QSeries* series)
210 {
223 {
211 ChartItem* item = m_chartItems.take(series);
224 ChartItem* item = m_chartItems.take(series);
212 delete item;
225 delete item;
213 }
226 }
214
227
215 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
228 void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain)
216 {
229 {
217 m_chartItems.value(series)->handleDomainChanged(domain);
230 m_chartItems.value(series)->handleDomainChanged(domain);
218 }
231 }
219
232
220 void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels)
233 void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels)
221 {
234 {
222 m_axisItems.value(axis)->handleRangeChanged(axis,labels);
235 m_axisItems.value(axis)->handleRangeChanged(axis,labels);
223 }
236 }
224
237
225 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
238 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
226 {
239 {
227 delete m_chartTheme;
240 delete m_chartTheme;
228
241
229 m_chartTheme = ChartTheme::createTheme(theme);
242 m_chartTheme = ChartTheme::createTheme(theme);
230
243
231 m_chartTheme->decorate(m_chart);
244 m_chartTheme->decorate(m_chart);
232 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
245 QMapIterator<QSeries*,ChartItem*> i(m_chartItems);
233
246
234 int index=0;
247 int index=0;
235 while (i.hasNext()) {
248 while (i.hasNext()) {
236 i.next();
249 i.next();
237 m_chartTheme->decorate(i.value(),i.key(),index);
250 m_chartTheme->decorate(i.value(),i.key(),index);
238 index++;
251 index++;
239 }
252 }
240
253
241 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
254 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
242 while (j.hasNext()) {
255 while (j.hasNext()) {
243 j.next();
256 j.next();
244 m_chartTheme->decorate(j.key(),j.value());
257 m_chartTheme->decorate(j.key(),j.value());
245 }
258 }
246 }
259 }
247
260
248 QChart::ChartTheme ChartPresenter::chartTheme()
261 QChart::ChartTheme ChartPresenter::chartTheme()
249 {
262 {
250 return m_chartTheme->id();
263 return m_chartTheme->id();
251 }
264 }
252
265
253 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
266 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
254 {
267 {
255 if(m_options!=options) {
268 if(m_options!=options) {
256
269
257 m_options=options;
270 m_options=options;
258
271
259 //recreate elements
272 //recreate elements
260
273
261 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
274 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
262 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
275 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
263
276
264 foreach(QChartAxis* axis, axisList) {
277 foreach(QChartAxis* axis, axisList) {
265 handleAxisRemoved(axis);
278 handleAxisRemoved(axis);
266 handleAxisAdded(axis);
279 handleAxisAdded(axis);
267 }
280 }
268 foreach(QSeries* series, seriesList) {
281 foreach(QSeries* series, seriesList) {
269 handleSeriesRemoved(series);
282 handleSeriesRemoved(series);
270 handleSeriesAdded(series);
283 handleSeriesAdded(series);
271 }
284 }
272
285
273 //now reintialize view data
286 //now reintialize view data
274 //TODO: make it more nice
287 //TODO: make it more nice
275 m_dataset->setDomain(m_dataset->domainIndex());
288 m_dataset->setDomain(m_dataset->domainIndex());
276 }
289 }
277 }
290 }
278
291
279 QChart::AnimationOptions ChartPresenter::animationOptions() const
292 QChart::AnimationOptions ChartPresenter::animationOptions() const
280 {
293 {
281 return m_options;
294 return m_options;
282 }
295 }
283
296
284
297
285 #include "moc_chartpresenter_p.cpp"
298 #include "moc_chartpresenter_p.cpp"
286
299
287 QTCOMMERCIALCHART_END_NAMESPACE
300 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,270 +1,300
1 #include "charttheme_p.h"
1 #include "charttheme_p.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QTime>
4 #include <QTime>
5
5
6 //series
6 //series
7 #include "qbarset.h"
7 #include "qbarset.h"
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qscatterseries.h"
13 #include "qscatterseries.h"
13 #include "qpieseries.h"
14 #include "qpieseries.h"
14 #include "qpieslice.h"
15 #include "qpieslice.h"
15
16
16 //items
17 //items
17 #include "axisitem_p.h"
18 #include "axisitem_p.h"
18 #include "barpresenter_p.h"
19 #include "barpresenter_p.h"
19 #include "stackedbarpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
20 #include "percentbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
21 #include "linechartitem_p.h"
22 #include "linechartitem_p.h"
23 #include "areachartitem_p.h"
22 #include "scatterpresenter_p.h"
24 #include "scatterpresenter_p.h"
23 #include "piepresenter_p.h"
25 #include "piepresenter_p.h"
24
26
25 //themes
27 //themes
26 #include "chartthemevanilla_p.h"
28 #include "chartthemevanilla_p.h"
27 #include "chartthemeicy_p.h"
29 #include "chartthemeicy_p.h"
28 #include "chartthemegrayscale_p.h"
30 #include "chartthemegrayscale_p.h"
29 #include "chartthemescientific_p.h"
31 #include "chartthemescientific_p.h"
30
32
31
33
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
35
34 /* TODO
36 /* TODO
35 case QChart::ChartThemeUnnamed1:
37 case QChart::ChartThemeUnnamed1:
36 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
38 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2));
37 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
39 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2));
38 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
40 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2));
39 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
41 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2));
40 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
42 m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2));
41
43
42 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
44 m_gradientStartColor = QColor(QRgb(0xfff3dc9e));
43 m_gradientEndColor = QColor(QRgb(0xffafafaf));
45 m_gradientEndColor = QColor(QRgb(0xffafafaf));
44 */
46 */
45
47
46 ChartTheme::ChartTheme(QChart::ChartTheme id)
48 ChartTheme::ChartTheme(QChart::ChartTheme id)
47 {
49 {
48 m_id = id;
50 m_id = id;
49 m_seriesColor.append(QRgb(0xff000000));
51 m_seriesColor.append(QRgb(0xff000000));
50 m_seriesColor.append(QRgb(0xff707070));
52 m_seriesColor.append(QRgb(0xff707070));
51 m_gradientStartColor = QColor(QRgb(0xffffffff));
53 m_gradientStartColor = QColor(QRgb(0xffffffff));
52 m_gradientEndColor = QColor(QRgb(0xffafafaf));
54 m_gradientEndColor = QColor(QRgb(0xffafafaf));
53
55
54 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
56 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
55 }
57 }
56
58
57
59
58 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
60 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
59 {
61 {
60 switch(theme) {
62 switch(theme) {
61 case QChart::ChartThemeDefault:
63 case QChart::ChartThemeDefault:
62 return new ChartThemeIcy();
64 return new ChartTheme();
63 case QChart::ChartThemeVanilla:
65 case QChart::ChartThemeVanilla:
64 return new ChartThemeVanilla();
66 return new ChartThemeVanilla();
65 case QChart::ChartThemeIcy:
67 case QChart::ChartThemeIcy:
66 return new ChartThemeIcy();
68 return new ChartThemeIcy();
67 case QChart::ChartThemeGrayscale:
69 case QChart::ChartThemeGrayscale:
68 return new ChartThemeGrayscale();
70 return new ChartThemeGrayscale();
69 case QChart::ChartThemeScientific:
71 case QChart::ChartThemeScientific:
70 return new ChartThemeScientific();
72 return new ChartThemeScientific();
71 }
73 }
72 }
74 }
73
75
74 void ChartTheme::decorate(QChart* chart)
76 void ChartTheme::decorate(QChart* chart)
75 {
77 {
76 QLinearGradient backgroundGradient;
78 QLinearGradient backgroundGradient;
77 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
79 backgroundGradient.setColorAt(0.0, m_gradientStartColor);
78 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
80 backgroundGradient.setColorAt(1.0, m_gradientEndColor);
79 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
81 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
80 chart->setChartBackgroundBrush(backgroundGradient);
82 chart->setChartBackgroundBrush(backgroundGradient);
81 }
83 }
82 //TODO helper to by removed later
84 //TODO helper to by removed later
83 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
85 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count)
84 {
86 {
85 switch(series->type())
87 switch(series->type())
86 {
88 {
87 case QSeries::SeriesTypeLine: {
89 case QSeries::SeriesTypeLine: {
88 QLineSeries* s = static_cast<QLineSeries*>(series);
90 QLineSeries* s = static_cast<QLineSeries*>(series);
89 LineChartItem* i = static_cast<LineChartItem*>(item);
91 LineChartItem* i = static_cast<LineChartItem*>(item);
90 decorate(i,s,count);
92 decorate(i,s,count);
91 break;
93 break;
92 }
94 }
95 case QSeries::SeriesTypeArea: {
96 QAreaSeries* s = static_cast<QAreaSeries*>(series);
97 AreaChartItem* i = static_cast<AreaChartItem*>(item);
98 decorate(i,s,count);
99 break;
100 }
93 case QSeries::SeriesTypeBar: {
101 case QSeries::SeriesTypeBar: {
94 QBarSeries* b = static_cast<QBarSeries*>(series);
102 QBarSeries* b = static_cast<QBarSeries*>(series);
95 BarPresenter* i = static_cast<BarPresenter*>(item);
103 BarPresenter* i = static_cast<BarPresenter*>(item);
96 decorate(i,b,count);
104 decorate(i,b,count);
97 break;
105 break;
98 }
106 }
99 case QSeries::SeriesTypeStackedBar: {
107 case QSeries::SeriesTypeStackedBar: {
100 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
108 QStackedBarSeries* s = static_cast<QStackedBarSeries*>(series);
101 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
109 StackedBarPresenter* i = static_cast<StackedBarPresenter*>(item);
102 decorate(i,s,count);
110 decorate(i,s,count);
103 break;
111 break;
104 }
112 }
105 case QSeries::SeriesTypePercentBar: {
113 case QSeries::SeriesTypePercentBar: {
106 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
114 QPercentBarSeries* s = static_cast<QPercentBarSeries*>(series);
107 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
115 PercentBarPresenter* i = static_cast<PercentBarPresenter*>(item);
108 decorate(i,s,count);
116 decorate(i,s,count);
109 break;
117 break;
110 }
118 }
111 case QSeries::SeriesTypeScatter: {
119 case QSeries::SeriesTypeScatter: {
112 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
120 QScatterSeries* s = qobject_cast<QScatterSeries*>(series);
113 Q_ASSERT(s);
121 Q_ASSERT(s);
114 ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
122 ScatterPresenter* i = static_cast<ScatterPresenter*>(item);
115 Q_ASSERT(i);
123 Q_ASSERT(i);
116 decorate(i, s, count);
124 decorate(i, s, count);
117 break;
125 break;
118 }
126 }
119 case QSeries::SeriesTypePie: {
127 case QSeries::SeriesTypePie: {
120 QPieSeries* s = static_cast<QPieSeries*>(series);
128 QPieSeries* s = static_cast<QPieSeries*>(series);
121 PiePresenter* i = static_cast<PiePresenter*>(item);
129 PiePresenter* i = static_cast<PiePresenter*>(item);
122 decorate(i,s,count);
130 decorate(i,s,count);
123 break;
131 break;
124 }
132 }
125 default:
133 default:
126 qDebug()<<"Wrong item to be decorated by theme";
134 qDebug()<<"Wrong item to be decorated by theme";
127 break;
135 break;
128 }
136 }
129
137
130 }
138 }
131
139
140 void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count)
141 {
142 QPen pen;
143 QBrush brush;
144
145 if(pen != series->pen()){
146 item->setPen(series->pen());
147 }else{
148 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
149 pen.setWidthF(2);
150 item->setPen(pen);
151 }
152
153 if(brush != series->brush()){
154 item->setBrush(series->brush());
155 }else{
156 QBrush brush(m_seriesColor.at(count%m_seriesColor.size()));
157 item->setBrush(brush);
158 }
159 }
160
161
132 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
162 void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count)
133 {
163 {
134 QPen pen;
164 QPen pen;
135 if(pen != series->pen()){
165 if(pen != series->pen()){
136 item->setPen(series->pen());
166 item->setPen(series->pen());
137 return;
167 return;
138 }
168 }
139 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
169 pen.setColor(m_seriesColor.at(count%m_seriesColor.size()));
140 pen.setWidthF(2);
170 pen.setWidthF(2);
141 item->setPen(pen);
171 item->setPen(pen);
142 }
172 }
143
173
144 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
174 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
145 {
175 {
146 QList<QBarSet*> sets = series->barSets();
176 QList<QBarSet*> sets = series->barSets();
147 for (int i=0; i<series->barsetCount(); i++) {
177 for (int i=0; i<series->barsetCount(); i++) {
148 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
178 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
149 }
179 }
150 }
180 }
151
181
152 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
182 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count)
153 {
183 {
154 QList<QBarSet*> sets = series->barSets();
184 QList<QBarSet*> sets = series->barSets();
155 for (int i=0; i<series->barsetCount(); i++) {
185 for (int i=0; i<series->barsetCount(); i++) {
156 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
186 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
157 }
187 }
158 }
188 }
159
189
160 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
190 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count)
161 {
191 {
162 QList<QBarSet*> sets = series->barSets();
192 QList<QBarSet*> sets = series->barSets();
163 for (int i=0; i<series->barsetCount(); i++) {
193 for (int i=0; i<series->barsetCount(); i++) {
164 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
194 sets.at(i)->setBrush(QBrush(m_seriesColor.at(i%m_seriesColor.count())));
165 }
195 }
166 }
196 }
167
197
168 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count)
198 void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count)
169 {
199 {
170 Q_ASSERT(presenter);
200 Q_ASSERT(presenter);
171 Q_ASSERT(series);
201 Q_ASSERT(series);
172
202
173 QColor color = m_seriesColor.at(count % m_seriesColor.size());
203 QColor color = m_seriesColor.at(count % m_seriesColor.size());
174 // TODO: define alpha in the theme? or in the series?
204 // TODO: define alpha in the theme? or in the series?
175 //color.setAlpha(120);
205 //color.setAlpha(120);
176
206
177 QBrush brush(color, Qt::SolidPattern);
207 QBrush brush(color, Qt::SolidPattern);
178 presenter->m_markerBrush = brush;
208 presenter->m_markerBrush = brush;
179
209
180 QPen pen(brush, 3);
210 QPen pen(brush, 3);
181 pen.setColor(color);
211 pen.setColor(color);
182 presenter->m_markerPen = pen;
212 presenter->m_markerPen = pen;
183 }
213 }
184
214
185 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
215 void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/)
186 {
216 {
187 // create a list of slice colors based on current theme
217 // create a list of slice colors based on current theme
188 int i = 0;
218 int i = 0;
189 QList<QColor> colors;
219 QList<QColor> colors;
190 while (colors.count() < series->count()) {
220 while (colors.count() < series->count()) {
191
221
192 // get base color
222 // get base color
193 QColor c = m_seriesColor[i++];
223 QColor c = m_seriesColor[i++];
194 i = i % m_seriesColor.count();
224 i = i % m_seriesColor.count();
195
225
196 // dont use black colors... looks bad
226 // dont use black colors... looks bad
197 if (c == Qt::black)
227 if (c == Qt::black)
198 continue;
228 continue;
199
229
200 // by default use the "raw" theme color
230 // by default use the "raw" theme color
201 if (!colors.contains(c)) {
231 if (!colors.contains(c)) {
202 colors << c;
232 colors << c;
203 continue;
233 continue;
204 }
234 }
205 // ...ok we need to generate something that looks like the same color
235 // ...ok we need to generate something that looks like the same color
206 // but different lightness
236 // but different lightness
207
237
208 int tryCount = 0;
238 int tryCount = 0;
209 while (tryCount++ < 100) {
239 while (tryCount++ < 100) {
210
240
211 // find maximum value we can raise the lightness
241 // find maximum value we can raise the lightness
212 int lMax = 255;
242 int lMax = 255;
213 if (lMax > 255 - c.red())
243 if (lMax > 255 - c.red())
214 lMax = 255 - c.red();
244 lMax = 255 - c.red();
215 if (lMax > 255 - c.green())
245 if (lMax > 255 - c.green())
216 lMax = 255 - c.green();
246 lMax = 255 - c.green();
217 if (lMax > 255 - c.blue())
247 if (lMax > 255 - c.blue())
218 lMax = 255 - c.blue();
248 lMax = 255 - c.blue();
219
249
220 // find maximum value we can make it darker
250 // find maximum value we can make it darker
221 int dMax = 255;
251 int dMax = 255;
222 if (dMax > c.red())
252 if (dMax > c.red())
223 dMax = c.red();
253 dMax = c.red();
224 if (dMax > c.green())
254 if (dMax > c.green())
225 dMax = c.green();
255 dMax = c.green();
226 if (dMax > c.blue())
256 if (dMax > c.blue())
227 dMax = c.blue();
257 dMax = c.blue();
228
258
229 int max = dMax + lMax;
259 int max = dMax + lMax;
230 if (max == 0) {
260 if (max == 0) {
231 // no room to make color lighter or darker...
261 // no room to make color lighter or darker...
232 qDebug() << "cannot generate a color for pie!";
262 qDebug() << "cannot generate a color for pie!";
233 break;
263 break;
234 }
264 }
235
265
236 // generate random color
266 // generate random color
237 int r = c.red() - dMax;
267 int r = c.red() - dMax;
238 int g = c.green() - dMax;
268 int g = c.green() - dMax;
239 int b = c.blue() - dMax;
269 int b = c.blue() - dMax;
240 int d = qrand() % max;
270 int d = qrand() % max;
241 c.setRgb(r+d, g+d, b+d);
271 c.setRgb(r+d, g+d, b+d);
242
272
243 // found a unique color?
273 // found a unique color?
244 if (!colors.contains(c))
274 if (!colors.contains(c))
245 break;
275 break;
246 }
276 }
247
277
248 qDebug() << "generated a color for pie" << c;
278 qDebug() << "generated a color for pie" << c;
249 colors << c;
279 colors << c;
250 }
280 }
251
281
252 // finally update colors
282 // finally update colors
253 foreach (QPieSlice* s, series->slices()) {
283 foreach (QPieSlice* s, series->slices()) {
254 QColor c = colors.takeFirst();
284 QColor c = colors.takeFirst();
255 s->setPen(c);
285 s->setPen(c);
256 s->setBrush(c);
286 s->setBrush(c);
257 }
287 }
258 }
288 }
259
289
260
290
261 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item)
291 void ChartTheme::decorate(QChartAxis* axis,AxisItem* item)
262 {
292 {
263 //TODO: dummy defults for now
293 //TODO: dummy defults for now
264 axis->setLabelsBrush(Qt::black);
294 axis->setLabelsBrush(Qt::black);
265 axis->setLabelsPen(Qt::NoPen);
295 axis->setLabelsPen(Qt::NoPen);
266 axis->setShadesPen(Qt::NoPen);
296 axis->setShadesPen(Qt::NoPen);
267 axis->setShadesOpacity(0.5);
297 axis->setShadesOpacity(0.5);
268 }
298 }
269
299
270 QTCOMMERCIALCHART_END_NAMESPACE
300 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,55
1 #ifndef CHARTTHEME_H
1 #ifndef CHARTTHEME_H
2 #define CHARTTHEME_H
2 #define CHARTTHEME_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchart.h"
5 #include "qchart.h"
6 #include <QColor>
6 #include <QColor>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartItem;
10 class ChartItem;
11 class QSeries;
11 class QSeries;
12 class LineChartItem;
12 class LineChartItem;
13 class QLineSeries;
13 class QLineSeries;
14 class BarPresenter;
14 class BarPresenter;
15 class QBarSeries;
15 class QBarSeries;
16 class StackedBarPresenter;
16 class StackedBarPresenter;
17 class QStackedBarSeries;
17 class QStackedBarSeries;
18 class QPercentBarSeries;
18 class QPercentBarSeries;
19 class PercentBarPresenter;
19 class PercentBarPresenter;
20 class QScatterSeries;
20 class QScatterSeries;
21 class ScatterPresenter;
21 class ScatterPresenter;
22 class PiePresenter;
22 class PiePresenter;
23 class QPieSeries;
23 class QPieSeries;
24 class AreaChartItem;
25 class QAreaSeries;
24
26
25 class ChartTheme
27 class ChartTheme
26 {
28 {
27 protected:
29 protected:
28 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault);
30 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeDefault);
29 public:
31 public:
30 static ChartTheme* createTheme(QChart::ChartTheme theme);
32 static ChartTheme* createTheme(QChart::ChartTheme theme);
31 QChart::ChartTheme id() const {return m_id;}
33 QChart::ChartTheme id() const {return m_id;}
32 void decorate(QChart* chart);
34 void decorate(QChart* chart);
33 void decorate(ChartItem* item, QSeries* series,int count);
35 void decorate(ChartItem* item, QSeries* series,int count);
34 void decorate(BarPresenter* item, QBarSeries* series,int count);
36 void decorate(BarPresenter* item, QBarSeries* series,int count);
35 void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count);
37 void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count);
36 void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count);
38 void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count);
37 void decorate(LineChartItem* item, QLineSeries*, int count);
39 void decorate(LineChartItem* item, QLineSeries* series,int count);
40 void decorate(AreaChartItem* item, QAreaSeries* series,int count);
38 void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count);
41 void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count);
39 void decorate(PiePresenter* item, QPieSeries* series, int count);
42 void decorate(PiePresenter* item, QPieSeries* series, int count);
40 void decorate(QChartAxis* axis,AxisItem* item);
43 void decorate(QChartAxis* axis,AxisItem* item);
41
44
42 protected:
45 protected:
43 QChart::ChartTheme m_id;
46 QChart::ChartTheme m_id;
44 QColor m_gradientStartColor;
47 QColor m_gradientStartColor;
45 QColor m_gradientEndColor;
48 QColor m_gradientEndColor;
46 QList<QColor> m_seriesColor;
49 QList<QColor> m_seriesColor;
47
50
48 };
51 };
49
52
50 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
51
54
52 #endif // CHARTTHEME_H
55 #endif // CHARTTHEME_H
@@ -1,219 +1,225
1 #include "linechartitem_p.h"
1 #include "linechartitem_p.h"
2 #include "qlineseries.h"
2 #include "qlineseries.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include <QPainter>
4 #include <QPainter>
5
5
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 //TODO: optimize : remove points which are not visible
9 //TODO: optimize : remove points which are not visible
10
10
11 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent),
11 LineChartItem::LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent):ChartItem(parent),
12 m_presenter(presenter),
12 m_presenter(presenter),
13 m_series(series),
13 m_series(series),
14 m_items(this)
14 m_items(this)
15 {
15 {
16 //m_items.setZValue(ChartPresenter::LineChartZValue);
16 //m_items.setZValue(ChartPresenter::LineChartZValue);
17 setZValue(ChartPresenter::LineChartZValue);
17 setZValue(ChartPresenter::LineChartZValue);
18
19 QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&)));
20 QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int)));
21 QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int)));
22 QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int)));
23 QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated()));
18 }
24 }
19
25
20 QRectF LineChartItem::boundingRect() const
26 QRectF LineChartItem::boundingRect() const
21 {
27 {
22 return m_rect;
28 return m_rect;
23 }
29 }
24
30
25 QPainterPath LineChartItem::shape() const
31 QPainterPath LineChartItem::shape() const
26 {
32 {
27 return m_path;
33 return m_path;
28 }
34 }
29
35
30 void LineChartItem::createPoints(int count)
36 void LineChartItem::createPoints(int count)
31 {
37 {
32 for (int i = 0; i < count; ++i) {
38 for (int i = 0; i < count; ++i) {
33 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
39 QGraphicsRectItem* item = new QGraphicsRectItem(0,0,3,3);
34 m_items.addToGroup(item);
40 m_items.addToGroup(item);
35 }
41 }
36 }
42 }
37
43
38 void LineChartItem::clearPoints(int count)
44 void LineChartItem::clearPoints(int count)
39 {
45 {
40 QList<QGraphicsItem *> items = m_items.childItems();
46 QList<QGraphicsItem *> items = m_items.childItems();
41
47
42 for (int i = 0; i < count; ++i) {
48 for (int i = 0; i < count; ++i) {
43 delete(items.takeLast());
49 delete(items.takeLast());
44 }
50 }
45 }
51 }
46
52
47 QPointF LineChartItem::calculateGeometryPoint(int index) const
53 QPointF LineChartItem::calculateGeometryPoint(int index) const
48 {
54 {
49 const qreal deltaX = m_size.width()/m_domain.spanX();
55 const qreal deltaX = m_size.width()/m_domain.spanX();
50 const qreal deltaY = m_size.height()/m_domain.spanY();
56 const qreal deltaY = m_size.height()/m_domain.spanY();
51 qreal x = (m_series->x(index) - m_domain.m_minX)* deltaX;
57 qreal x = (m_series->x(index) - m_domain.m_minX)* deltaX;
52 qreal y = (m_series->y(index) - m_domain.m_minY)*-deltaY + m_size.height();
58 qreal y = (m_series->y(index) - m_domain.m_minY)*-deltaY + m_size.height();
53 return QPointF(x,y);
59 return QPointF(x,y);
54 }
60 }
55
61
56 QVector<QPointF> LineChartItem::calculateGeometryPoints() const
62 QVector<QPointF> LineChartItem::calculateGeometryPoints() const
57 {
63 {
58 const qreal deltaX = m_size.width()/m_domain.spanX();
64 const qreal deltaX = m_size.width()/m_domain.spanX();
59 const qreal deltaY = m_size.height()/m_domain.spanY();
65 const qreal deltaY = m_size.height()/m_domain.spanY();
60
66
61 QVector<QPointF> points;
67 QVector<QPointF> points;
62 points.reserve(m_series->count());
68 points.reserve(m_series->count());
63 for (int i = 0; i < m_series->count(); ++i) {
69 for (int i = 0; i < m_series->count(); ++i) {
64 qreal x = (m_series->x(i) - m_domain.m_minX)* deltaX;
70 qreal x = (m_series->x(i) - m_domain.m_minX)* deltaX;
65 qreal y = (m_series->y(i) - m_domain.m_minY)*-deltaY + m_size.height();
71 qreal y = (m_series->y(i) - m_domain.m_minY)*-deltaY + m_size.height();
66 points << QPointF(x,y);
72 points << QPointF(x,y);
67 }
73 }
68 return points;
74 return points;
69 }
75 }
70
76
71 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints)
77 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints)
72 {
78 {
73 applyGeometry(newPoints);
79 applyGeometry(newPoints);
74 oldPoints = newPoints;
80 oldPoints = newPoints;
75 }
81 }
76
82
77 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint)
83 void LineChartItem::updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint)
78 {
84 {
79 oldPoints.replace(index,newPoint);
85 oldPoints.replace(index,newPoint);
80 applyGeometry(oldPoints);
86 applyGeometry(oldPoints);
81 }
87 }
82
88
83 void LineChartItem::applyGeometry(QVector<QPointF>& points)
89 void LineChartItem::applyGeometry(QVector<QPointF>& points)
84 {
90 {
85 if(points.size()==0) return;
91 if(points.size()==0) return;
86
92
87 QList<QGraphicsItem*> items = m_items.childItems();
93 QList<QGraphicsItem*> items = m_items.childItems();
88
94
89 QPainterPath path;
95 QPainterPath path;
90 const QPointF& point = points.at(0);
96 const QPointF& point = points.at(0);
91 path.moveTo(point);
97 path.moveTo(point);
92 QGraphicsItem* item = items.at(0);
98 QGraphicsItem* item = items.at(0);
93 item->setPos(point.x()-1,point.y()-1);
99 item->setPos(point.x()-1,point.y()-1);
94 if(!m_clipRect.contains(point)) item->setVisible(false);
100 if(!m_clipRect.contains(point)) item->setVisible(false);
95
101
96 for(int i=1 ; i< points.size();i++) {
102 for(int i=1 ; i< points.size();i++) {
97 QGraphicsItem* item = items.at(i);
103 QGraphicsItem* item = items.at(i);
98 const QPointF& point = points.at(i);
104 const QPointF& point = points.at(i);
99 item->setPos(point.x()-1,point.y()-1);
105 item->setPos(point.x()-1,point.y()-1);
100 if(!m_clipRect.contains(point)) item->setVisible(false);
106 if(!m_clipRect.contains(point)) item->setVisible(false);
101 path.lineTo(point);
107 path.lineTo(point);
102 }
108 }
103
109
104 prepareGeometryChange();
110 prepareGeometryChange();
105 m_path = path;
111 m_path = path;
106 m_rect = path.boundingRect();
112 m_rect = path.boundingRect();
107 }
113 }
108
114
109 void LineChartItem::setPen(const QPen& pen)
115 void LineChartItem::setPen(const QPen& pen)
110 {
116 {
111 m_pen = pen;
117 m_pen = pen;
112 }
118 }
113
119
114 //handlers
120 //handlers
115
121
116 void LineChartItem::handlePointAdded(int index)
122 void LineChartItem::handlePointAdded(int index)
117 {
123 {
118 Q_ASSERT(index<m_series->count());
124 Q_ASSERT(index<m_series->count());
119 Q_ASSERT(index>=0);
125 Q_ASSERT(index>=0);
120
126
121 QPointF point = calculateGeometryPoint(index);
127 QPointF point = calculateGeometryPoint(index);
122 createPoints(1);
128 createPoints(1);
123 QVector<QPointF> points = m_points;
129 QVector<QPointF> points = m_points;
124 points.insert(index,point);
130 points.insert(index,point);
125 updateItem(m_points,points);
131 updateItem(m_points,points);
126 update();
132 update();
127 }
133 }
128 void LineChartItem::handlePointRemoved(int index)
134 void LineChartItem::handlePointRemoved(int index)
129 {
135 {
130 Q_ASSERT(index<m_series->count());
136 Q_ASSERT(index<m_series->count());
131 Q_ASSERT(index>=0);
137 Q_ASSERT(index>=0);
132 QPointF point = calculateGeometryPoint(index);
138 QPointF point = calculateGeometryPoint(index);
133 clearPoints(1);
139 clearPoints(1);
134 QVector<QPointF> points = m_points;
140 QVector<QPointF> points = m_points;
135 points.remove(index);
141 points.remove(index);
136 updateItem(m_points,points);
142 updateItem(m_points,points);
137 update();
143 update();
138 }
144 }
139
145
140 void LineChartItem::handlePointReplaced(int index)
146 void LineChartItem::handlePointReplaced(int index)
141 {
147 {
142 Q_ASSERT(index<m_series->count());
148 Q_ASSERT(index<m_series->count());
143 Q_ASSERT(index>=0);
149 Q_ASSERT(index>=0);
144 QPointF point = calculateGeometryPoint(index);
150 QPointF point = calculateGeometryPoint(index);
145 updateItem(m_points,index,point);
151 updateItem(m_points,index,point);
146 update();
152 update();
147 }
153 }
148
154
149 void LineChartItem::handleDomainChanged(const Domain& domain)
155 void LineChartItem::handleDomainChanged(const Domain& domain)
150 {
156 {
151
157
152 m_domain = domain;
158 m_domain = domain;
153
159
154 if(m_domain.isEmpty()) return;
160 if(m_domain.isEmpty()) return;
155 if(!m_clipRect.isValid()) return;
161 if(!m_clipRect.isValid()) return;
156
162
157 QVector<QPointF> points = calculateGeometryPoints();
163 QVector<QPointF> points = calculateGeometryPoints();
158
164
159 int diff = m_points.size() - points.size();
165 int diff = m_points.size() - points.size();
160
166
161 if(diff>0) {
167 if(diff>0) {
162 clearPoints(diff);
168 clearPoints(diff);
163 }
169 }
164 else if(diff<0) {
170 else if(diff<0) {
165 createPoints(-diff);
171 createPoints(-diff);
166 }
172 }
167
173
168 updateItem(m_points,points);
174 updateItem(m_points,points);
169 update();
175 update();
170 }
176 }
171
177
172 void LineChartItem::handleGeometryChanged(const QRectF& rect)
178 void LineChartItem::handleGeometryChanged(const QRectF& rect)
173 {
179 {
174 Q_ASSERT(rect.isValid());
180 Q_ASSERT(rect.isValid());
175 m_size=rect.size();
181 m_size=rect.size();
176 m_clipRect=rect.translated(-rect.topLeft());
182 m_clipRect=rect.translated(-rect.topLeft());
177 setPos(rect.topLeft());
183 setPos(rect.topLeft());
178
184
179 if(m_domain.isEmpty()) return;
185 if(m_domain.isEmpty()) return;
180
186
181 QVector<QPointF> points = calculateGeometryPoints();
187 QVector<QPointF> points = calculateGeometryPoints();
182
188
183 int diff = m_points.size() - points.size();
189 int diff = m_points.size() - points.size();
184
190
185 if(diff>0) {
191 if(diff>0) {
186 clearPoints(diff);
192 clearPoints(diff);
187 }
193 }
188 else if(diff<0) {
194 else if(diff<0) {
189 createPoints(-diff);
195 createPoints(-diff);
190 }
196 }
191
197
192 updateItem(m_points,points);
198 updateItem(m_points,points);
193 update();
199 update();
194 }
200 }
195
201
196 void LineChartItem::handleUpdated()
202 void LineChartItem::handleUpdated()
197 {
203 {
198 m_items.setVisible(m_series->pointsVisible());
204 m_items.setVisible(m_series->pointsVisible());
199 setPen(m_series->pen());
205 setPen(m_series->pen());
200 update();
206 update();
201 }
207 }
202
208
203 //painter
209 //painter
204
210
205 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
211 void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
206 {
212 {
207 Q_UNUSED(widget);
213 Q_UNUSED(widget);
208 Q_UNUSED(option);
214 Q_UNUSED(option);
209 painter->save();
215 painter->save();
210 painter->setPen(m_pen);
216 painter->setPen(m_pen);
211 painter->setClipRect(m_clipRect);
217 painter->setClipRect(m_clipRect);
212 painter->drawPath(m_path);
218 painter->drawPath(m_path);
213 painter->restore();
219 painter->restore();
214 }
220 }
215
221
216
222
217 #include "moc_linechartitem_p.cpp"
223 #include "moc_linechartitem_p.cpp"
218
224
219 QTCOMMERCIALCHART_END_NAMESPACE
225 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,61
1 #ifndef LINECHARTITEM_H
1 #ifndef LINECHARTITEM_H
2 #define LINECHARTITEM_H
2 #define LINECHARTITEM_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "chartitem_p.h"
5 #include "chartitem_p.h"
6 #include <QPen>
6 #include <QPen>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class ChartPresenter;
10 class ChartPresenter;
11 class QLineSeries;
11 class QLineSeries;
12
12
13 class LineChartItem : public QObject , public ChartItem
13 class LineChartItem : public QObject , public ChartItem
14 {
14 {
15 Q_OBJECT
15 Q_OBJECT
16 public:
16 public:
17 LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0);
17 LineChartItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent = 0);
18 ~ LineChartItem(){};
18 ~ LineChartItem(){};
19
19
20 //from QGraphicsItem
20 //from QGraphicsItem
21 QRectF boundingRect() const;
21 QRectF boundingRect() const;
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
22 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
23 QPainterPath shape() const;
23 QPainterPath shape() const;
24
24
25 void setPen(const QPen& pen);
25 void setPen(const QPen& pen);
26 void setPointsVisible(bool visible);
26 void setPointsVisible(bool visible);
27
27
28 public slots:
28 public slots:
29 void handlePointAdded(int index);
29 void handlePointAdded(int index);
30 void handlePointRemoved(int index);
30 void handlePointRemoved(int index);
31 void handlePointReplaced(int index);
31 void handlePointReplaced(int index);
32 void handleUpdated();
32 void handleUpdated();
33 void handleDomainChanged(const Domain& domain);
33 void handleDomainChanged(const Domain& domain);
34 void handleGeometryChanged(const QRectF& size);
34 void handleGeometryChanged(const QRectF& size);
35
35
36 public:
36 public:
37 virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints);
37 virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints);
38 virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint);
38 virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint);
39 void applyGeometry(QVector<QPointF>& points);
39 virtual void applyGeometry(QVector<QPointF>& points);
40 void createPoints(int count);
40 void createPoints(int count);
41 void clearPoints(int count);
41 void clearPoints(int count);
42 QPointF calculateGeometryPoint(int index) const;
42 QPointF calculateGeometryPoint(int index) const;
43 QVector<QPointF> calculateGeometryPoints() const;
43 QVector<QPointF> calculateGeometryPoints() const;
44
44
45 private:
45 private:
46 ChartPresenter* m_presenter;
46 ChartPresenter* m_presenter;
47 QPainterPath m_path;
47 QPainterPath m_path;
48 QLineSeries* m_series;
48 QLineSeries* m_series;
49 QSizeF m_size;
49 QSizeF m_size;
50 QRectF m_rect;
50 QRectF m_rect;
51 QRectF m_clipRect;
51 QRectF m_clipRect;
52 Domain m_domain;
52 Domain m_domain;
53 QGraphicsItemGroup m_items;
53 QGraphicsItemGroup m_items;
54 QVector<QPointF> m_points;
54 QVector<QPointF> m_points;
55 QPen m_pen;
55 QPen m_pen;
56
56
57 };
57 };
58
58
59 QTCOMMERCIALCHART_END_NAMESPACE
59 QTCOMMERCIALCHART_END_NAMESPACE
60
60
61 #endif
61 #endif
@@ -1,89 +1,90
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
1 !include( ../common.pri ):error( Couldn't find the common.pri file! )
2 TARGET = QtCommercialChart
2 TARGET = QtCommercialChart
3 DESTDIR = $$CHART_BUILD_LIB_DIR
3 DESTDIR = $$CHART_BUILD_LIB_DIR
4 TEMPLATE = lib
4 TEMPLATE = lib
5 QT += core \
5 QT += core \
6 gui
6 gui
7 CONFIG += debug_and_release
7 CONFIG += debug_and_release
8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
8 CONFIG(debug, debug|release):TARGET = QtCommercialChartd
9 SOURCES += axisitem.cpp \
9 SOURCES += axisitem.cpp \
10 axisanimationitem.cpp \
10 axisanimationitem.cpp \
11 chartdataset.cpp \
11 chartdataset.cpp \
12 chartpresenter.cpp \
12 chartpresenter.cpp \
13 charttheme.cpp \
13 charttheme.cpp \
14 domain.cpp \
14 domain.cpp \
15 qchart.cpp \
15 qchart.cpp \
16 qchartaxis.cpp \
16 qchartaxis.cpp \
17 qchartview.cpp \
17 qchartview.cpp \
18 qseries.cpp
18 qseries.cpp
19 PRIVATE_HEADERS += axisitem_p.h \
19 PRIVATE_HEADERS += axisitem_p.h \
20 axisanimationitem_p.h \
20 axisanimationitem_p.h \
21 chartdataset_p.h \
21 chartdataset_p.h \
22 chartitem_p.h \
22 chartitem_p.h \
23 chartpresenter_p.h \
23 chartpresenter_p.h \
24 charttheme_p.h \
24 charttheme_p.h \
25 domain_p.h
25 domain_p.h
26 PUBLIC_HEADERS += qchart.h \
26 PUBLIC_HEADERS += qchart.h \
27 qchartaxis.h \
27 qchartaxis.h \
28 qchartglobal.h \
28 qchartglobal.h \
29 qseries.h \
29 qseries.h \
30 qchartview.h
30 qchartview.h
31 include(linechart/linechart.pri)
31 include(linechart/linechart.pri)
32 include(areachart/areachart.pri)
32 include(barchart/barchart.pri)
33 include(barchart/barchart.pri)
33 include(piechart/piechart.pri)
34 include(piechart/piechart.pri)
34 include(scatterseries/scatter.pri)
35 include(scatterseries/scatter.pri)
35 THEMES += themes/chartthemeicy_p.h \
36 THEMES += themes/chartthemeicy_p.h \
36 themes/chartthemegrayscale_p.h \
37 themes/chartthemegrayscale_p.h \
37 themes/chartthemescientific_p.h \
38 themes/chartthemescientific_p.h \
38 themes/chartthemevanilla_p.h
39 themes/chartthemevanilla_p.h
39 HEADERS += $$PUBLIC_HEADERS
40 HEADERS += $$PUBLIC_HEADERS
40 HEADERS += $$PRIVATE_HEADERS
41 HEADERS += $$PRIVATE_HEADERS
41 HEADERS += $$THEMES
42 HEADERS += $$THEMES
42 INCLUDEPATH += linechart \
43 INCLUDEPATH += linechart \
43 barchart \
44 barchart \
44 themes \
45 themes \
45 .
46 .
46 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
47 OBJECTS_DIR = $$CHART_BUILD_DIR/lib
47 MOC_DIR = $$CHART_BUILD_DIR/lib
48 MOC_DIR = $$CHART_BUILD_DIR/lib
48 UI_DIR = $$CHART_BUILD_DIR/lib
49 UI_DIR = $$CHART_BUILD_DIR/lib
49 RCC_DIR = $$CHART_BUILD_DIR/lib
50 RCC_DIR = $$CHART_BUILD_DIR/lib
50 DEFINES += QTCOMMERCIALCHART_LIBRARY
51 DEFINES += QTCOMMERCIALCHART_LIBRARY
51 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
52 public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart
52 public_headers.files = $$PUBLIC_HEADERS
53 public_headers.files = $$PUBLIC_HEADERS
53 target.path = $$[QT_INSTALL_LIBS]
54 target.path = $$[QT_INSTALL_LIBS]
54 INSTALLS += target \
55 INSTALLS += target \
55 public_headers
56 public_headers
56 install_build_public_headers.name = bild_public_headers
57 install_build_public_headers.name = bild_public_headers
57 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
58 install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h
58 install_build_public_headers.input = PUBLIC_HEADERS
59 install_build_public_headers.input = PUBLIC_HEADERS
59 install_build_public_headers.commands = $$QMAKE_COPY \
60 install_build_public_headers.commands = $$QMAKE_COPY \
60 ${QMAKE_FILE_NAME} \
61 ${QMAKE_FILE_NAME} \
61 $$CHART_BUILD_PUBLIC_HEADER_DIR
62 $$CHART_BUILD_PUBLIC_HEADER_DIR
62 install_build_public_headers.CONFIG += target_predeps \
63 install_build_public_headers.CONFIG += target_predeps \
63 no_link
64 no_link
64 install_build_private_headers.name = bild_private_headers
65 install_build_private_headers.name = bild_private_headers
65 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
66 install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h
66 install_build_private_headers.input = PRIVATE_HEADERS
67 install_build_private_headers.input = PRIVATE_HEADERS
67 install_build_private_headers.commands = $$QMAKE_COPY \
68 install_build_private_headers.commands = $$QMAKE_COPY \
68 ${QMAKE_FILE_NAME} \
69 ${QMAKE_FILE_NAME} \
69 $$CHART_BUILD_PRIVATE_HEADER_DIR
70 $$CHART_BUILD_PRIVATE_HEADER_DIR
70 install_build_private_headers.CONFIG += target_predeps \
71 install_build_private_headers.CONFIG += target_predeps \
71 no_link
72 no_link
72 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
73 QMAKE_EXTRA_COMPILERS += install_build_public_headers \
73 install_build_private_headers
74 install_build_private_headers
74 chartversion.target = qchartversion_p.h
75 chartversion.target = qchartversion_p.h
75 chartversion.commands = @echo \
76 chartversion.commands = @echo \
76 "build_time" \
77 "build_time" \
77 > \
78 > \
78 $$chartversion.target;
79 $$chartversion.target;
79 chartversion.depends = $$HEADERS \
80 chartversion.depends = $$HEADERS \
80 $$SOURCES
81 $$SOURCES
81 PRE_TARGETDEPS += qchartversion_p.h
82 PRE_TARGETDEPS += qchartversion_p.h
82 QMAKE_CLEAN += qchartversion_p.h
83 QMAKE_CLEAN += qchartversion_p.h
83 QMAKE_EXTRA_TARGETS += chartversion
84 QMAKE_EXTRA_TARGETS += chartversion
84 unix:QMAKE_DISTCLEAN += -r \
85 unix:QMAKE_DISTCLEAN += -r \
85 $$CHART_BUILD_HEADER_DIR \
86 $$CHART_BUILD_HEADER_DIR \
86 $$CHART_BUILD_LIB_DIR
87 $$CHART_BUILD_LIB_DIR
87 win32:QMAKE_DISTCLEAN += /Q \
88 win32:QMAKE_DISTCLEAN += /Q \
88 $$CHART_BUILD_HEADER_DIR \
89 $$CHART_BUILD_HEADER_DIR \
89 $$CHART_BUILD_LIB_DIR
90 $$CHART_BUILD_LIB_DIR
General Comments 0
You need to be logged in to leave comments. Login now