@@ -0,0 +1,18 | |||
|
1 | #include <QtGui/QApplication> | |
|
2 | #include <QMainWindow> | |
|
3 | #include "multichartwidget.h" | |
|
4 | ||
|
5 | int main(int argc, char *argv[]) | |
|
6 | { | |
|
7 | QApplication a(argc, argv); | |
|
8 | ||
|
9 | MultiChartWidget *multi = new MultiChartWidget(); | |
|
10 | ||
|
11 | // Use the chart widget as the central widget | |
|
12 | QMainWindow w; | |
|
13 | w.resize(640, 480); | |
|
14 | w.setCentralWidget(multi); | |
|
15 | w.show(); | |
|
16 | ||
|
17 | return a.exec(); | |
|
18 | } |
@@ -0,0 +1,21 | |||
|
1 | !include( ../../common.pri ) { | |
|
2 | error( "Couldn't find the common.pri file!" ) | |
|
3 | } | |
|
4 | !include( ../../integrated.pri ) { | |
|
5 | error( "Couldn't find the integrated.pri file !") | |
|
6 | } | |
|
7 | ||
|
8 | QT += core gui | |
|
9 | ||
|
10 | TARGET = multichart | |
|
11 | TEMPLATE = app | |
|
12 | ||
|
13 | SOURCES += main.cpp \ | |
|
14 | multichartwidget.cpp | |
|
15 | ||
|
16 | HEADERS += \ | |
|
17 | multichartwidget.h | |
|
18 | ||
|
19 | ||
|
20 | ||
|
21 |
@@ -0,0 +1,35 | |||
|
1 | #include "multichartwidget.h" | |
|
2 | #include <QVBoxLayout> | |
|
3 | #include <qchartglobal.h> | |
|
4 | #include <qchartview.h> | |
|
5 | #include <qscatterseries.h> | |
|
6 | #include <qpieseries.h> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
9 | ||
|
10 | MultiChartWidget::MultiChartWidget(QWidget *parent) : | |
|
11 | QWidget(parent) | |
|
12 | { | |
|
13 | QVBoxLayout *l = new QVBoxLayout(this); | |
|
14 | ||
|
15 | // Create chart 1 and add a simple pie series onto it | |
|
16 | QChartView *chartView1 = new QChartView(); | |
|
17 | l->addWidget(chartView1); | |
|
18 | QPieSeries *pie = new QPieSeries(); | |
|
19 | pie->add(1.1, "label1"); | |
|
20 | pie->add(1.2, "label2"); | |
|
21 | chartView1->addSeries(pie); | |
|
22 | ||
|
23 | // Create chart 2 and add a simple scatter series onto it | |
|
24 | QChartView *chartView2 = new QChartView(); | |
|
25 | l->addWidget(chartView2); | |
|
26 | QScatterSeries *scatter = new QScatterSeries(); | |
|
27 | *scatter << QPointF(0.5, 5.0) | |
|
28 | << QPointF(1.0, 4.5) | |
|
29 | << QPointF(1.0, 5.5) | |
|
30 | << QPointF(1.5, 5.0) | |
|
31 | << QPointF(2.0, 4.5) | |
|
32 | << QPointF(2.0, 5.5) | |
|
33 | << QPointF(2.5, 5.0); | |
|
34 | chartView2->addSeries(scatter); | |
|
35 | } |
@@ -0,0 +1,18 | |||
|
1 | #ifndef MULTICHARTWIDGET_H | |
|
2 | #define MULTICHARTWIDGET_H | |
|
3 | ||
|
4 | #include <QWidget> | |
|
5 | ||
|
6 | class MultiChartWidget : public QWidget | |
|
7 | { | |
|
8 | Q_OBJECT | |
|
9 | public: | |
|
10 | explicit MultiChartWidget(QWidget *parent = 0); | |
|
11 | ||
|
12 | signals: | |
|
13 | ||
|
14 | public slots: | |
|
15 | ||
|
16 | }; | |
|
17 | ||
|
18 | #endif // MULTICHARTWIDGET_H |
@@ -0,0 +1,20 | |||
|
1 | #include "customslice.h" | |
|
2 | ||
|
3 | CustomSlice::CustomSlice(qreal value, QObject* parent) | |
|
4 | :QPieSlice(parent) | |
|
5 | { | |
|
6 | setValue(value); | |
|
7 | connect(this, SIGNAL(changed()), this, SLOT(updateLabel())); | |
|
8 | connect(this, SIGNAL(hoverEnter()), this, SLOT(toggleExploded())); | |
|
9 | connect(this, SIGNAL(hoverLeave()), this, SLOT(toggleExploded())); | |
|
10 | } | |
|
11 | ||
|
12 | void CustomSlice::updateLabel() | |
|
13 | { | |
|
14 | setLabel(QString::number(this->percentage())); | |
|
15 | } | |
|
16 | ||
|
17 | void CustomSlice::toggleExploded() | |
|
18 | { | |
|
19 | setExploded(!isExploded()); | |
|
20 | } |
@@ -0,0 +1,15 | |||
|
1 | #include <qpieslice.h> | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
4 | ||
|
5 | class CustomSlice : public QPieSlice | |
|
6 | { | |
|
7 | Q_OBJECT | |
|
8 | ||
|
9 | public: | |
|
10 | CustomSlice(qreal value, QObject* parent = 0); | |
|
11 | ||
|
12 | public Q_SLOTS: | |
|
13 | void updateLabel(); | |
|
14 | void toggleExploded(); | |
|
15 | }; |
@@ -0,0 +1,69 | |||
|
1 | #include "declarativescatterseries.h" | |
|
2 | #include "declarativechart.h" | |
|
3 | #include "qchart.h" | |
|
4 | #include "qscatterseries.h" | |
|
5 | #include <cmath> | |
|
6 | ||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | DeclarativeScatterSeries::DeclarativeScatterSeries(QDeclarativeItem *parent) : | |
|
10 | QDeclarativeItem(parent), | |
|
11 | m_chart(0), | |
|
12 | m_series(0) | |
|
13 | { | |
|
14 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
|
15 | connect(this, SIGNAL(parentChanged()), | |
|
16 | this, SLOT(setParentForSeries())); | |
|
17 | } | |
|
18 | ||
|
19 | void DeclarativeScatterSeries::setParentForSeries() | |
|
20 | { | |
|
21 | if (!m_series) | |
|
22 | initSeries(); | |
|
23 | } | |
|
24 | ||
|
25 | void DeclarativeScatterSeries::initSeries() | |
|
26 | { | |
|
27 | Q_ASSERT(!m_series); | |
|
28 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
|
29 | ||
|
30 | if (declarativeChart) { | |
|
31 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); | |
|
32 | qDebug() << "creating scatter series for chart: " << chart; | |
|
33 | Q_ASSERT(chart); | |
|
34 | ||
|
35 | m_series = new QScatterSeries(); | |
|
36 | Q_ASSERT(m_series); | |
|
37 | for (int i(0); i < m_data.count(); i++) { | |
|
38 | ScatterElement *element = m_data.at(i); | |
|
39 | *m_series << QPointF(element->x(), element->y()); | |
|
40 | } | |
|
41 | chart->addSeries(m_series); | |
|
42 | } | |
|
43 | } | |
|
44 | ||
|
45 | QDeclarativeListProperty<ScatterElement> DeclarativeScatterSeries::data() | |
|
46 | { | |
|
47 | return QDeclarativeListProperty<ScatterElement>(this, 0, | |
|
48 | &DeclarativeScatterSeries::appendData); | |
|
49 | } | |
|
50 | ||
|
51 | void DeclarativeScatterSeries::appendData(QDeclarativeListProperty<ScatterElement> *list, | |
|
52 | ScatterElement *element) | |
|
53 | { | |
|
54 | DeclarativeScatterSeries *series = qobject_cast<DeclarativeScatterSeries *>(list->object); | |
|
55 | qDebug() << "appendData: " << series; | |
|
56 | qDebug() << "appendData: " << element; | |
|
57 | qDebug() << "appendData: " << element->x(); | |
|
58 | qDebug() << "appendData: " << element->y(); | |
|
59 | qDebug() << "appendData: " << series->m_series; | |
|
60 | if (series) { | |
|
61 | series->m_data.append(element); | |
|
62 | if (series->m_series) | |
|
63 | series->m_series->addData(QPointF(element->x(), element->y())); | |
|
64 | } | |
|
65 | } | |
|
66 | ||
|
67 | #include "moc_declarativescatterseries.cpp" | |
|
68 | ||
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,42 | |||
|
1 | #ifndef DECLARATIVESCATTERSERIES_H | |
|
2 | #define DECLARATIVESCATTERSERIES_H | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include "scatterelement.h" | |
|
6 | #include <QDeclarativeItem> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class QChart; | |
|
11 | class QScatterSeries; | |
|
12 | ||
|
13 | class DeclarativeScatterSeries : public QDeclarativeItem | |
|
14 | { | |
|
15 | Q_OBJECT | |
|
16 | Q_PROPERTY(QDeclarativeListProperty<ScatterElement> data READ data) | |
|
17 | ||
|
18 | public: | |
|
19 | explicit DeclarativeScatterSeries(QDeclarativeItem *parent = 0); | |
|
20 | QDeclarativeListProperty<ScatterElement> data(); | |
|
21 | ||
|
22 | signals: | |
|
23 | ||
|
24 | public slots: | |
|
25 | static void appendData(QDeclarativeListProperty<ScatterElement> *list, | |
|
26 | ScatterElement *element); | |
|
27 | // void append(ScatterElement element); | |
|
28 | ||
|
29 | private slots: | |
|
30 | void setParentForSeries(); | |
|
31 | ||
|
32 | public: | |
|
33 | void initSeries(); | |
|
34 | ||
|
35 | QChart *m_chart; | |
|
36 | QScatterSeries *m_series; | |
|
37 | QList<ScatterElement *> m_data; | |
|
38 | }; | |
|
39 | ||
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
41 | ||
|
42 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -0,0 +1,12 | |||
|
1 | #include "scatterelement.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | ScatterElement::ScatterElement(QObject *parent) : | |
|
6 | QObject(parent) | |
|
7 | { | |
|
8 | } | |
|
9 | ||
|
10 | #include "moc_scatterelement.cpp" | |
|
11 | ||
|
12 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,30 | |||
|
1 | #ifndef SCATTERELEMENT_H | |
|
2 | #define SCATTERELEMENT_H | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include <QObject> | |
|
6 | ||
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
8 | ||
|
9 | class ScatterElement : public QObject | |
|
10 | { | |
|
11 | Q_OBJECT | |
|
12 | Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/) | |
|
13 | Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/) | |
|
14 | ||
|
15 | public: | |
|
16 | explicit ScatterElement(QObject *parent = 0); | |
|
17 | ||
|
18 | void setX(qreal x) {m_x = x;} | |
|
19 | qreal x() {return m_x;} | |
|
20 | void setY(qreal y) {m_y = y;} | |
|
21 | qreal y() {return m_y;} | |
|
22 | ||
|
23 | public: | |
|
24 | qreal m_x; | |
|
25 | qreal m_y; | |
|
26 | }; | |
|
27 | ||
|
28 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
29 | ||
|
30 | #endif // SCATTERELEMENT_H |
@@ -0,0 +1,181 | |||
|
1 | #include "qpieslice.h" | |
|
2 | ||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
4 | ||
|
5 | #define DEFAULT_PEN_COLOR Qt::black | |
|
6 | #define DEFAULT_BRUSH_COLOR Qt::white | |
|
7 | #define DEFAULT_LABEL_ARM_LENGTH 50 | |
|
8 | ||
|
9 | QPieSlice::QPieSlice(QObject *parent) | |
|
10 | :QObject(parent), | |
|
11 | m_value(0), | |
|
12 | m_isLabelVisible(true), | |
|
13 | m_isExploded(false), | |
|
14 | m_percentage(0), | |
|
15 | m_angle(0), | |
|
16 | m_span(0), | |
|
17 | m_pen(DEFAULT_PEN_COLOR), | |
|
18 | m_brush(DEFAULT_BRUSH_COLOR), | |
|
19 | m_labelPen(DEFAULT_PEN_COLOR), | |
|
20 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
|
21 | { | |
|
22 | ||
|
23 | } | |
|
24 | ||
|
25 | QPieSlice::QPieSlice(qreal value, QString label, bool labelVisible, QObject *parent) | |
|
26 | :QObject(parent), | |
|
27 | m_value(value), | |
|
28 | m_label(label), | |
|
29 | m_isLabelVisible(labelVisible), | |
|
30 | m_isExploded(false), | |
|
31 | m_percentage(0), | |
|
32 | m_angle(0), | |
|
33 | m_span(0), | |
|
34 | m_pen(DEFAULT_PEN_COLOR), | |
|
35 | m_brush(DEFAULT_BRUSH_COLOR), | |
|
36 | m_labelPen(DEFAULT_PEN_COLOR), | |
|
37 | m_labelArmLength(DEFAULT_LABEL_ARM_LENGTH) | |
|
38 | { | |
|
39 | ||
|
40 | } | |
|
41 | ||
|
42 | QPieSlice::~QPieSlice() | |
|
43 | { | |
|
44 | ||
|
45 | } | |
|
46 | ||
|
47 | qreal QPieSlice::value() const | |
|
48 | { | |
|
49 | return m_value; | |
|
50 | } | |
|
51 | ||
|
52 | QString QPieSlice::label() const | |
|
53 | { | |
|
54 | return m_label; | |
|
55 | } | |
|
56 | ||
|
57 | bool QPieSlice::isLabelVisible() const | |
|
58 | { | |
|
59 | return m_isLabelVisible; | |
|
60 | } | |
|
61 | ||
|
62 | bool QPieSlice::isExploded() const | |
|
63 | { | |
|
64 | return m_isExploded; | |
|
65 | } | |
|
66 | ||
|
67 | qreal QPieSlice::percentage() const | |
|
68 | { | |
|
69 | return m_percentage; | |
|
70 | } | |
|
71 | ||
|
72 | qreal QPieSlice::angle() const | |
|
73 | { | |
|
74 | return m_angle; | |
|
75 | } | |
|
76 | ||
|
77 | qreal QPieSlice::span() const | |
|
78 | { | |
|
79 | return m_span; | |
|
80 | } | |
|
81 | ||
|
82 | QPen QPieSlice::pen() const | |
|
83 | { | |
|
84 | return m_pen; | |
|
85 | } | |
|
86 | ||
|
87 | QBrush QPieSlice::brush() const | |
|
88 | { | |
|
89 | return m_brush; | |
|
90 | } | |
|
91 | ||
|
92 | QPen QPieSlice::labelPen() const | |
|
93 | { | |
|
94 | return m_labelPen; | |
|
95 | } | |
|
96 | ||
|
97 | QFont QPieSlice::labelFont() const | |
|
98 | { | |
|
99 | return m_labelFont; | |
|
100 | } | |
|
101 | ||
|
102 | qreal QPieSlice::labelArmLenght() const | |
|
103 | { | |
|
104 | return m_labelArmLength; | |
|
105 | } | |
|
106 | ||
|
107 | void QPieSlice::setValue(qreal value) | |
|
108 | { | |
|
109 | if (m_value != value) { | |
|
110 | m_value = value; | |
|
111 | emit changed(); | |
|
112 | } | |
|
113 | } | |
|
114 | ||
|
115 | void QPieSlice::setLabel(QString label) | |
|
116 | { | |
|
117 | if (m_label != label) { | |
|
118 | m_label = label; | |
|
119 | emit changed(); | |
|
120 | } | |
|
121 | } | |
|
122 | ||
|
123 | void QPieSlice::setLabelVisible(bool visible) | |
|
124 | { | |
|
125 | if (m_isLabelVisible != visible) { | |
|
126 | m_isLabelVisible = visible; | |
|
127 | emit changed(); | |
|
128 | } | |
|
129 | } | |
|
130 | ||
|
131 | void QPieSlice::setExploded(bool exploded) | |
|
132 | { | |
|
133 | if (m_isExploded != exploded) { | |
|
134 | m_isExploded = exploded; | |
|
135 | emit changed(); | |
|
136 | } | |
|
137 | } | |
|
138 | ||
|
139 | void QPieSlice::setPen(QPen pen) | |
|
140 | { | |
|
141 | if (m_pen != pen) { | |
|
142 | m_pen = pen; | |
|
143 | emit changed(); | |
|
144 | } | |
|
145 | } | |
|
146 | ||
|
147 | void QPieSlice::setBrush(QBrush brush) | |
|
148 | { | |
|
149 | if (m_brush != brush) { | |
|
150 | m_brush = brush; | |
|
151 | emit changed(); | |
|
152 | } | |
|
153 | } | |
|
154 | ||
|
155 | void QPieSlice::setLabelFont(QFont font) | |
|
156 | { | |
|
157 | if (m_labelFont != font) { | |
|
158 | m_labelFont = font; | |
|
159 | emit changed(); | |
|
160 | } | |
|
161 | } | |
|
162 | ||
|
163 | void QPieSlice::setLabelPen(QPen pen) | |
|
164 | { | |
|
165 | if (m_labelPen != pen) { | |
|
166 | m_labelPen = pen; | |
|
167 | emit changed(); | |
|
168 | } | |
|
169 | } | |
|
170 | ||
|
171 | void QPieSlice::setLabelArmLength(qreal len) | |
|
172 | { | |
|
173 | if (m_labelArmLength != len) { | |
|
174 | m_labelArmLength = len; | |
|
175 | emit changed(); | |
|
176 | } | |
|
177 | } | |
|
178 | ||
|
179 | #include "moc_qpieslice.cpp" | |
|
180 | ||
|
181 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,86 | |||
|
1 | #ifndef QPIESLICE_H | |
|
2 | #define QPIESLICE_H | |
|
3 | ||
|
4 | #include <qchartglobal.h> | |
|
5 | #include <QObject> | |
|
6 | #include <QPen> | |
|
7 | #include <QBrush> | |
|
8 | #include <QFont> | |
|
9 | ||
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
11 | ||
|
12 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject | |
|
13 | { | |
|
14 | Q_OBJECT | |
|
15 | ||
|
16 | public: | |
|
17 | QPieSlice(QObject *parent = 0); | |
|
18 | QPieSlice(qreal value, QString label, bool labelVisible = true, QObject *parent = 0); | |
|
19 | virtual ~QPieSlice(); | |
|
20 | ||
|
21 | // data | |
|
22 | qreal value() const; | |
|
23 | QString label() const; | |
|
24 | bool isLabelVisible() const; | |
|
25 | bool isExploded() const; | |
|
26 | ||
|
27 | // generated data | |
|
28 | qreal percentage() const; | |
|
29 | qreal angle() const; | |
|
30 | qreal span() const; | |
|
31 | ||
|
32 | // customization | |
|
33 | QPen pen() const; | |
|
34 | QBrush brush() const; | |
|
35 | QPen labelPen() const; | |
|
36 | QFont labelFont() const; | |
|
37 | qreal labelArmLenght() const; | |
|
38 | ||
|
39 | Q_SIGNALS: | |
|
40 | void clicked(); | |
|
41 | void hoverEnter(); | |
|
42 | void hoverLeave(); | |
|
43 | void changed(); | |
|
44 | ||
|
45 | public Q_SLOTS: | |
|
46 | ||
|
47 | // data | |
|
48 | void setLabel(QString label); | |
|
49 | void setLabelVisible(bool visible); | |
|
50 | void setValue(qreal value); | |
|
51 | void setExploded(bool exploded); | |
|
52 | ||
|
53 | // customization | |
|
54 | void setPen(QPen pen); | |
|
55 | void setBrush(QBrush brush); | |
|
56 | void setLabelFont(QFont font); | |
|
57 | void setLabelPen(QPen pen); | |
|
58 | void setLabelArmLength(qreal len); | |
|
59 | ||
|
60 | private: | |
|
61 | ||
|
62 | // TODO: use private class | |
|
63 | friend class QPieSeries; | |
|
64 | ||
|
65 | // data | |
|
66 | qreal m_value; | |
|
67 | QString m_label; | |
|
68 | bool m_isLabelVisible; | |
|
69 | bool m_isExploded; | |
|
70 | ||
|
71 | // generated data | |
|
72 | qreal m_percentage; | |
|
73 | qreal m_angle; | |
|
74 | qreal m_span; | |
|
75 | ||
|
76 | // customization | |
|
77 | QPen m_pen; | |
|
78 | QBrush m_brush; | |
|
79 | QPen m_labelPen; | |
|
80 | QFont m_labelFont; | |
|
81 | qreal m_labelArmLength; | |
|
82 | }; | |
|
83 | ||
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
85 | ||
|
86 | #endif // QPIESLICE_H |
@@ -0,0 +1,13 | |||
|
1 | INCLUDEPATH += $$PWD | |
|
2 | DEPENDPATH += $$PWD | |
|
3 | ||
|
4 | SOURCES += \ | |
|
5 | $$PWD/qscatterseries.cpp \ | |
|
6 | $$PWD/scatterpresenter.cpp | |
|
7 | ||
|
8 | PRIVATE_HEADERS += \ | |
|
9 | $$PWD/scatterpresenter_p.h \ | |
|
10 | $$PWD/scatterseries_p.h | |
|
11 | ||
|
12 | PUBLIC_HEADERS += \ | |
|
13 | $$PWD/qscatterseries.h |
@@ -1,15 +1,22 | |||
|
1 | 1 | !include(common.pri) { |
|
2 | 2 | error('missing common.pri') |
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 |
SUBDIRS += src |
|
|
6 | SUBDIRS += src example test qmlplugin | |
|
7 | ||
|
8 | integrated_build:{ | |
|
9 | message('Configured for integrated build') | |
|
10 | } else { | |
|
11 | message('Please build example test and qmlplugin after installing library.') | |
|
12 | } | |
|
13 | ||
|
7 | 14 | CONFIG += ordered |
|
8 | 15 | QMAKE_CXXFLAGS += -g -Wall |
|
9 | 16 | unix:QMAKE_DISTCLEAN += -r build bin |
|
10 | 17 | win32:QMAKE_DISTCLEAN += /Q build bin |
|
11 | 18 | |
|
12 | 19 | # install feature file |
|
13 | 20 | feature.path = $$[QT_INSTALL_DATA]/mkspecs/features |
|
14 | 21 | feature.files = $$PWD/features/qtcommercialchart.prf |
|
15 | 22 | INSTALLS += feature |
@@ -1,23 +1,25 | |||
|
1 | 1 | CONFIG+=integrated_build #remove if you want to build against installed libs |
|
2 | 2 | |
|
3 | CHART_BUILD_HEADER_DIR = $$PWD/include | |
|
3 | CHART_BUILD_PUBLIC_HEADER_DIR = $$PWD/include | |
|
4 | CHART_BUILD_PRIVATE_HEADER_DIR = $$CHART_BUILD_PUBLIC_HEADER_DIR/private | |
|
4 | 5 | CHART_BUILD_LIB_DIR = $$PWD/lib |
|
5 | 6 | CHART_BUILD_DIR = $$PWD/build |
|
6 | 7 | CHART_BUILD_BIN_DIR = $$PWD/bin |
|
7 | 8 | |
|
8 | 9 | # hack to fix windows builds |
|
9 | 10 | win32:{ |
|
10 | CHART_BUILD_HEADER_DIR = $$replace(CHART_BUILD_HEADER_DIR, "/","\\") | |
|
11 | CHART_BUILD_PUBLIC_HEADER_DIR = $$replace(CHART_BUILD_PUBLIC_HEADER_DIR, "/","\\") | |
|
12 | CHART_BUILD_PRIVATE_HEADER_DIR = $$replace(CHART_BUILD_PRIVATE_HEADER_DIR, "/","\\") | |
|
11 | 13 | CHART_BUILD_LIB_DIR = $$replace(CHART_BUILD_LIB_DIR, "/","\\") |
|
12 | 14 | CHART_BUILD_BUILD_DIR = $$replace(CHART_BUILD_BUILD_DIR, "/","\\") |
|
13 | 15 | CHART_BUILD_BIN_DIR = $$replace(CHART_BUILD_BIN_DIR, "/","\\") |
|
14 | 16 | } |
|
15 | 17 | |
|
16 | 18 | mac: { |
|
17 | 19 | # TODO: The following qmake flags are a work-around to make QtCommercial Charts compile on |
|
18 | 20 | # QtCommercial 4.8. On the other hand Charts builds successfully with Qt open source 4.8 |
|
19 | 21 | # without these definitions, so this is probably a configuration issue on QtCommercial 4.8; |
|
20 | 22 | # it should probably define the minimum OSX version to be 10.5... |
|
21 | 23 | QMAKE_CXXFLAGS *= -mmacosx-version-min=10.5 |
|
22 | 24 | QMAKE_LFLAGS *= -mmacosx-version-min=10.5 |
|
23 | 25 | } |
@@ -1,12 +1,13 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | SUBDIRS += linechart \ |
|
3 | 3 | zoomlinechart \ |
|
4 | 4 | colorlinechart \ |
|
5 | 5 | barchart \ |
|
6 | 6 | stackedbarchart \ |
|
7 | 7 | percentbarchart \ |
|
8 | 8 | scatter \ |
|
9 | 9 | piechart \ |
|
10 | 10 | dynamiclinechart \ |
|
11 | 11 | axischart\ |
|
12 |
|
|
|
12 | gdpbarchart\ | |
|
13 | multichart |
@@ -1,33 +1,42 | |||
|
1 | 1 | #include <QtGui/QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | #include <cmath> | |
|
4 | 3 | #include <qchartglobal.h> |
|
5 | 4 | #include <qchartview.h> |
|
6 | 5 | #include <qpieseries.h> |
|
6 | #include <qpieslice.h> | |
|
7 | #include "customslice.h" | |
|
7 | 8 | |
|
8 | 9 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | 10 | |
|
10 | 11 | int main(int argc, char *argv[]) |
|
11 | 12 | { |
|
12 | 13 | QApplication a(argc, argv); |
|
13 | 14 | |
|
14 | // Create widget and scatter series | |
|
15 | QChartView *chartWidget = new QChartView(); | |
|
16 | QPieSeries *series = qobject_cast<QPieSeries *>(chartWidget->createSeries(QChartSeries::SeriesTypePie)); | |
|
17 | Q_ASSERT(series); | |
|
18 | ||
|
19 | // Add test data to the series | |
|
20 | series->add(QPieSlice(1, "test1", true, true, QPen(Qt::red, 2), QBrush(Qt::red))); | |
|
21 |
series->add( |
|
|
22 |
series->add( |
|
|
23 |
series->add( |
|
|
24 |
series->add( |
|
|
25 | ||
|
26 | // Use the chart widget as the central widget | |
|
27 | QMainWindow w; | |
|
28 | w.resize(640, 480); | |
|
29 | w.setCentralWidget(chartWidget); | |
|
30 | w.show(); | |
|
15 | QMainWindow window; | |
|
16 | ||
|
17 | QPieSeries *series = new QPieSeries(); | |
|
18 | series->add(5, "Slice 1"); | |
|
19 | series->add(2, "Slice 2"); | |
|
20 | series->add(3, "Slice 3"); | |
|
21 | series->add(4, "Slice 4"); | |
|
22 | series->add(5, "Slice 5"); | |
|
23 | series->add(6, "Slice 6"); | |
|
24 | series->add(7, "Slice 7"); | |
|
25 | series->add(new CustomSlice(8)); | |
|
26 | series->enableClickExplodes(true); | |
|
27 | series->enableHoverHighlight(true); | |
|
28 | ||
|
29 | foreach (QPieSlice*s, series->slices()) | |
|
30 | qDebug() << s->angle() << s->span() << s->percentage(); | |
|
31 | ||
|
32 | QChartView* chartView = new QChartView(&window); | |
|
33 | chartView->addSeries(series); | |
|
34 | chartView->setChartTitle("simple piechart"); | |
|
35 | chartView->setChartTheme(QChart::ChartThemeIcy); | |
|
36 | ||
|
37 | window.setCentralWidget(chartView); | |
|
38 | window.resize(600, 600); | |
|
39 | window.show(); | |
|
31 | 40 | |
|
32 | 41 | return a.exec(); |
|
33 | 42 | } |
@@ -1,17 +1,19 | |||
|
1 | 1 | !include( ../../common.pri ) { |
|
2 | 2 | error( "Couldn't find the common.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | !include( ../../integrated.pri ) { |
|
5 | 5 | error( "Couldn't find the integrated.pri file !") |
|
6 | 6 | } |
|
7 | 7 | |
|
8 | 8 | QT += core gui |
|
9 | 9 | |
|
10 | 10 | TARGET = piechart |
|
11 | 11 | TEMPLATE = app |
|
12 | 12 | |
|
13 | SOURCES += main.cpp | |
|
13 | SOURCES += main.cpp customslice.cpp | |
|
14 | HEADERS += customslice.h | |
|
14 | 15 | |
|
15 | HEADERS += | |
|
16 | OBJECTS_DIR = tmp | |
|
17 | MOC_DIR = tmp | |
|
16 | 18 | |
|
17 | 19 |
@@ -1,39 +1,57 | |||
|
1 | 1 | #include <QtGui/QApplication> |
|
2 | 2 | #include <QMainWindow> |
|
3 | 3 | #include <cmath> |
|
4 | 4 | #include <qchartglobal.h> |
|
5 | 5 | #include <qchartview.h> |
|
6 | 6 | #include <qscatterseries.h> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | int main(int argc, char *argv[]) |
|
11 | 11 | { |
|
12 | 12 | QApplication a(argc, argv); |
|
13 | 13 | |
|
14 | 14 | // Create chart widget |
|
15 | 15 | QChartView *chartWidget = new QChartView(); |
|
16 | 16 | |
|
17 |
// |
|
|
17 | // Add scatter series with simple test data | |
|
18 | 18 | QScatterSeries *scatter = new QScatterSeries(); |
|
19 |
*scatter << QPointF(0.5, |
|
|
20 |
<< QPointF(1.0, |
|
|
21 |
<< QPointF(1. |
|
|
22 |
<< QPointF( |
|
|
19 | *scatter << QPointF(0.5, 5.0) | |
|
20 | << QPointF(1.0, 4.5) | |
|
21 | << QPointF(1.0, 5.5) | |
|
22 | << QPointF(1.5, 5.0) | |
|
23 | << QPointF(2.0, 4.5) | |
|
24 | << QPointF(2.0, 5.5) | |
|
25 | << QPointF(2.5, 5.0); | |
|
23 | 26 | chartWidget->addSeries(scatter); |
|
24 | 27 | |
|
25 | // Add another scatter series with more complex data with random component | |
|
28 | // Add another scatter series | |
|
29 | // - more data with random component | |
|
26 | 30 | QScatterSeries *scatter2 = new QScatterSeries(); |
|
27 | for (qreal i(0.0); i < 20; i += 0.5) | |
|
31 | for (qreal i(0.0); i < 20; i += 0.05) { | |
|
28 | 32 | (*scatter2) << QPointF(i + (qreal)(rand() % 100) / 100.0, |
|
29 | i + (qreal)(rand() % 100) / 100.0); | |
|
33 | i + (qreal)(rand() % 100) / 100.0); | |
|
34 | } | |
|
30 | 35 | chartWidget->addSeries(scatter2); |
|
36 | // Custom pen and brush (not those defined by the chart theme) | |
|
37 | // - uses opaque color | |
|
38 | QColor color("#2685BF"); | |
|
39 | color.setAlpha(80); | |
|
40 | QBrush brush(Qt::SolidPattern); | |
|
41 | brush.setColor(color); | |
|
42 | scatter2->setMarkerBrush(brush); | |
|
43 | QPen pen; | |
|
44 | pen.setColor(color); | |
|
45 | pen.setWidth(2); | |
|
46 | scatter2->setMarkerPen(pen); | |
|
47 | // use a rectangle as the marker shape | |
|
48 | scatter2->setMarkerShape(QScatterSeries::MarkerShapeRectangle); | |
|
31 | 49 | |
|
32 | 50 | // Use the chart widget as the central widget |
|
33 | 51 | QMainWindow w; |
|
34 | 52 | w.resize(640, 480); |
|
35 | 53 | w.setCentralWidget(chartWidget); |
|
36 | 54 | w.show(); |
|
37 | 55 | |
|
38 | 56 | return a.exec(); |
|
39 | 57 | } |
@@ -1,49 +1,56 | |||
|
1 | 1 | integrated_build:{ |
|
2 | message('Internal build within charts core source tree') | |
|
3 | INCLUDEPATH += $$CHART_BUILD_HEADER_DIR | |
|
2 | message('Running integrated build against local libs...') | |
|
3 | INCLUDEPATH += $$CHART_BUILD_PUBLIC_HEADER_DIR | |
|
4 | 4 | |
|
5 | 5 | !win32: { |
|
6 | 6 | LIBS += -L $$CHART_BUILD_LIB_DIR -Wl,-rpath,$$CHART_BUILD_LIB_DIR |
|
7 | 7 | }else{ |
|
8 | LIBS += -L $$CHART_BUILD_LIB_DIR | |
|
8 | win32-msvc*: { | |
|
9 | # hack fix for error: | |
|
10 | # "LINK : fatal error LNK1146: no argument specified with option '/LIBPATH:'" | |
|
11 | QMAKE_LIBDIR += $$CHART_BUILD_LIB_DIR | |
|
12 | }else{ | |
|
13 | LIBS += -L $$CHART_BUILD_LIB_DIR | |
|
14 | } | |
|
9 | 15 | } |
|
10 | 16 | |
|
11 | 17 | DESTDIR = $$CHART_BUILD_BIN_DIR |
|
12 | 18 | |
|
13 | 19 | CONFIG(debug, debug|release) { |
|
14 | 20 | LIBS += -lQtCommercialChartd |
|
15 | 21 | #this is ugly hack to work around missing rpath, it simply copies lib |
|
16 | 22 | win32:{ |
|
17 | 23 | copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll |
|
18 | 24 | copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChartd.dll $$CHART_BUILD_BIN_DIR |
|
19 | 25 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChartd.dll |
|
20 | 26 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChartd.dll |
|
21 | 27 | QMAKE_EXTRA_TARGETS +=copylib |
|
22 | 28 | } |
|
23 | 29 | } else { |
|
24 | 30 | LIBS += -lQtCommercialChart |
|
25 | 31 | |
|
26 | 32 | #this is ugly hack to work around missing rpath, it simply copies lib |
|
27 | 33 | win32: { |
|
28 | 34 | copylib.target = $$CHART_BUILD_BIN_DIR/QtCommercialChart |
|
29 | 35 | copylib.commands = $$QMAKE_COPY $$CHART_BUILD_LIB_DIR\\QtCommercialChart.dll $$CHART_BUILD_BIN_DIR |
|
30 | 36 | copylib.depends = $$CHART_BUILD_LIB_DIR/QtCommercialChart.dll |
|
31 | 37 | PRE_TARGETDEPS += $$CHART_BUILD_BIN_DIR/QtCommercialChart |
|
32 | 38 | QMAKE_EXTRA_TARGETS +=copylib |
|
33 | 39 | } |
|
34 | 40 | } |
|
35 | 41 | |
|
36 | 42 | mac: { |
|
37 | 43 | # This is a hack to make binaries to use the internal version of the QtCommercial Charts library on OSX |
|
38 | 44 | QMAKE_POST_LINK += install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/chartwidgettest.app/Contents/MacOS/chartwidgettest |
|
39 | 45 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/barchart.app/Contents/MacOS/barchart |
|
40 | 46 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/colorlineChart.app/Contents/MacOS/colorlineChart |
|
41 | 47 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/lineChart.app/Contents/MacOS/lineChart |
|
42 | 48 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/percentbarchart.app/Contents/MacOS/percentbarchart |
|
43 | 49 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/stackedbarchart.app/Contents/MacOS/stackedbarchart |
|
44 | 50 | QMAKE_POST_LINK += && install_name_tool -change "libQtCommercialChartd.1.dylib" "@rpath/libQtCommercialChartd.dylib" $$CHART_BUILD_BIN_DIR/zoomLineChart.app/Contents/MacOS/zoomLineChart |
|
45 | 51 | } |
|
46 | 52 | |
|
47 | 53 | } else { |
|
54 | message('Running build aginst system libs...') | |
|
48 | 55 | CONFIG+=qtcommercialchart |
|
49 | 56 | } |
@@ -1,27 +1,39 | |||
|
1 | 1 | #include "declarativechart.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
6 | 6 | : QDeclarativeItem(parent), |
|
7 | 7 | m_chart(new QChart(this)) |
|
8 | 8 | { |
|
9 | 9 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
10 | // m_chart->setMargin(50); // TODO: should not be needed? | |
|
11 | 10 | } |
|
12 | 11 | |
|
13 | 12 | DeclarativeChart::ChartTheme DeclarativeChart::theme() |
|
14 | 13 | { |
|
15 | 14 | if (m_chart) |
|
16 | 15 | return (ChartTheme) m_chart->chartTheme(); |
|
17 | 16 | } |
|
18 | 17 | |
|
19 | 18 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
20 | 19 | { |
|
21 | if (newGeometry.isValid()) | |
|
22 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
|
20 | qDebug() << "geometryChanged " << this << " old geometry: " << oldGeometry; | |
|
21 | if (newGeometry.isValid()) { | |
|
22 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
|
23 | // TODO: setting margin should not be needed to make axis visible? | |
|
24 | const int margin = 30; | |
|
25 | if (m_chart->margin() == 0 | |
|
26 | && newGeometry.width() > (margin * 2) | |
|
27 | && newGeometry.height() > (margin * 2)) { | |
|
28 | m_chart->setMargin(margin); | |
|
29 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
|
30 | } else { | |
|
31 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
|
32 | } | |
|
33 | } | |
|
34 | } | |
|
23 | 35 | } |
|
24 | 36 | |
|
25 | 37 | #include "moc_declarativechart.cpp" |
|
26 | 38 | |
|
27 | 39 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,100 +1,91 | |||
|
1 | 1 | #include "declarativeseries.h" |
|
2 | 2 | #include "declarativechart.h" |
|
3 | 3 | #include <qscatterseries.h> |
|
4 | 4 | #include <qlinechartseries.h> |
|
5 | 5 | #include <cmath> |
|
6 | 6 | #include <QDebug> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | DeclarativeSeries::DeclarativeSeries(QDeclarativeItem *parent) : |
|
11 | 11 | QDeclarativeItem(parent), |
|
12 | 12 | m_seriesType(SeriesTypeInvalid), // TODO: default type? |
|
13 | 13 | m_chart(0), |
|
14 | 14 | m_series(0) |
|
15 | 15 | { |
|
16 | 16 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
17 | 17 | connect(this, SIGNAL(parentChanged()), |
|
18 | 18 | this, SLOT(setParentForSeries())); |
|
19 | 19 | } |
|
20 | 20 | |
|
21 | 21 | void DeclarativeSeries::setSeriesType(SeriesType type) |
|
22 | 22 | { |
|
23 | 23 | if (!m_series || type != m_seriesType) { |
|
24 | 24 | m_seriesType = type; |
|
25 | 25 | initSeries(); |
|
26 | 26 | } else { |
|
27 | 27 | m_seriesType = type; |
|
28 | 28 | } |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | void DeclarativeSeries::setParentForSeries() |
|
32 | 32 | { |
|
33 | 33 | if (!m_series) |
|
34 | 34 | initSeries(); |
|
35 | 35 | else if (m_series->type() != m_seriesType) |
|
36 | 36 | initSeries(); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void DeclarativeSeries::initSeries() |
|
40 | 40 | { |
|
41 | 41 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
42 | 42 | |
|
43 | 43 | if (declarativeChart && m_seriesType != SeriesTypeInvalid) { |
|
44 | 44 | delete m_series; |
|
45 | 45 | m_series = 0; |
|
46 | 46 | |
|
47 | 47 | QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart); |
|
48 | 48 | qDebug() << "creating series for chart: " << chart; |
|
49 | 49 | Q_ASSERT(chart); |
|
50 | 50 | |
|
51 | 51 | switch (m_seriesType) { |
|
52 | 52 | case SeriesTypeLine: { |
|
53 | 53 | m_series = new QLineChartSeries(this); |
|
54 | 54 | for (qreal i(0.0); i < 100.0; i += 1.0) |
|
55 | 55 | ((QLineChartSeries *)m_series)->add(i, i); |
|
56 | 56 | chart->addSeries(m_series); |
|
57 | 57 | break; |
|
58 | 58 | } |
|
59 | 59 | case SeriesTypeBar: |
|
60 | 60 | // fallthrough; bar and scatter use the same test data |
|
61 | 61 | case SeriesTypeScatter: { |
|
62 | 62 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); |
|
63 | 63 | QScatterSeries *scatter = qobject_cast<QScatterSeries *>(m_series); |
|
64 | 64 | Q_ASSERT(scatter); |
|
65 | 65 | for (qreal i = 0; i < 100; i += 0.1) |
|
66 | 66 | scatter->addData(QPointF(i + (rand() % 5), |
|
67 | 67 | abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5))); |
|
68 | 68 | break; |
|
69 | 69 | } |
|
70 | 70 | case SeriesTypeStackedBar: |
|
71 | 71 | break; |
|
72 | 72 | case SeriesTypePercentBar: |
|
73 | 73 | break; |
|
74 | 74 | case SeriesTypePie: { |
|
75 | 75 | m_series = chart->createSeries((QChartSeries::QChartSeriesType) m_seriesType); |
|
76 | 76 | QList<qreal> data; |
|
77 | 77 | data << 1.0; |
|
78 | 78 | data << 12.0; |
|
79 | 79 | data << 4.0; |
|
80 | 80 | Q_ASSERT(m_series->setData(data)); |
|
81 | 81 | break; |
|
82 | 82 | } |
|
83 | 83 | default: |
|
84 | 84 | break; |
|
85 | 85 | } |
|
86 | 86 | } |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | QVariant DeclarativeSeries::itemChange(GraphicsItemChange change, | |
|
90 | const QVariant &value) | |
|
91 | { | |
|
92 | // For debugging purposes only: | |
|
93 | // qDebug() << QString::number(change) << " : " << value.toString(); | |
|
94 | return QGraphicsItem::itemChange(change, value); | |
|
95 | } | |
|
96 | ||
|
97 | ||
|
98 | 89 | #include "moc_declarativeseries.cpp" |
|
99 | 90 | |
|
100 | 91 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,50 | |||
|
1 | 1 | #ifndef DECLARATIVESERIES_H |
|
2 | 2 | #define DECLARATIVESERIES_H |
|
3 | 3 | |
|
4 | 4 | #include <QDeclarativeItem> |
|
5 | 5 | #include <qchart.h> |
|
6 | 6 | #include <qchartseries.h> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | class DeclarativeSeries : public QDeclarativeItem |
|
11 | 11 | { |
|
12 | 12 | Q_OBJECT |
|
13 | 13 | Q_ENUMS(SeriesType) |
|
14 | 14 | Q_PROPERTY(SeriesType seriesType READ seriesType WRITE setSeriesType) |
|
15 | 15 | |
|
16 | 16 | public: |
|
17 | 17 | // TODO: how to re-use the existing enum from QChart? |
|
18 | 18 | enum SeriesType { |
|
19 | 19 | SeriesTypeInvalid = QChartSeries::SeriesTypeInvalid, |
|
20 | 20 | SeriesTypeLine, |
|
21 | 21 | // SeriesTypeArea, |
|
22 | 22 | SeriesTypeBar, |
|
23 | 23 | SeriesTypeStackedBar, |
|
24 | 24 | SeriesTypePercentBar, |
|
25 | 25 | SeriesTypePie, |
|
26 | 26 | SeriesTypeScatter |
|
27 | 27 | // SeriesTypeSpline |
|
28 | 28 | }; |
|
29 | 29 | |
|
30 | 30 | explicit DeclarativeSeries(QDeclarativeItem *parent = 0); |
|
31 | 31 | |
|
32 | 32 | signals: |
|
33 | 33 | |
|
34 | 34 | public slots: |
|
35 | 35 | void setParentForSeries(); |
|
36 | 36 | |
|
37 | public: // from QDeclarativeItem | |
|
38 | QVariant itemChange(GraphicsItemChange, const QVariant &); | |
|
39 | ||
|
40 | 37 | public: |
|
41 | 38 | void setSeriesType(SeriesType type); |
|
42 | 39 | SeriesType seriesType() { return m_seriesType; } |
|
43 | 40 | |
|
44 | 41 | private: |
|
45 | 42 | void initSeries(); |
|
46 | 43 | SeriesType m_seriesType; |
|
47 | 44 | QChart *m_chart; |
|
48 | 45 | QChartSeries *m_series; |
|
49 | 46 | }; |
|
50 | 47 | |
|
51 | 48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | 49 | |
|
53 | 50 | #endif // DECLARATIVESERIES_H |
@@ -1,27 +1,30 | |||
|
1 | 1 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
2 | 2 | #include <QtDeclarative/qdeclarative.h> |
|
3 | 3 | #include "declarativechart.h" |
|
4 | 4 | #include "declarativeseries.h" |
|
5 | #include "scatterelement.h" | |
|
6 | #include "declarativescatterseries.h" | |
|
5 | 7 | |
|
6 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 9 | |
|
8 | 10 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
9 | 11 | { |
|
10 | 12 | Q_OBJECT |
|
11 | 13 | public: |
|
12 | 14 | virtual void registerTypes(const char *uri) |
|
13 | 15 | { |
|
14 | 16 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
15 | 17 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart"); |
|
16 | 18 | qmlRegisterType<DeclarativeSeries>(uri, 1, 0, "Series"); |
|
17 | //qmlRegisterUncreatableType<QChartSeries::SeriesTypeBar>(uri, 1, 0, "Series.Se", QLatin1String("Do not create objects of this type.")); | |
|
19 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
|
20 | qmlRegisterType<ScatterElement>(uri, 1, 0, "ScatterElement"); | |
|
18 | 21 | } |
|
19 | 22 | }; |
|
20 | 23 | |
|
21 | 24 | #include "plugin.moc" |
|
22 | 25 | |
|
23 | 26 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | 27 | |
|
25 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | 29 | |
|
27 | 30 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,39 +1,57 | |||
|
1 | 1 | !include( ../common.pri ) { |
|
2 | 2 | error( "Couldn't find the common.pri file!" ) |
|
3 | 3 | } |
|
4 | 4 | !include( ../integrated.pri ) { |
|
5 | 5 | error( "Couldn't find the integrated.pri file !") |
|
6 | 6 | } |
|
7 | 7 | |
|
8 | 8 | TEMPLATE = lib |
|
9 | 9 | TARGET = qtcommercialchartqml |
|
10 | 10 | |
|
11 | 11 | CONFIG += qt plugin |
|
12 | 12 | QT += declarative |
|
13 | 13 | |
|
14 | 14 | contains(QT_MAJOR_VERSION, 5) { |
|
15 | 15 | # TODO: QtQuick2 not supported by the implementation currently |
|
16 | 16 | DEFINES += QTQUICK2 |
|
17 | 17 | } |
|
18 | 18 | |
|
19 | 19 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
20 | 20 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
21 | 21 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
22 | 22 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
23 | 23 | |
|
24 | 24 | SOURCES += \ |
|
25 | 25 | plugin.cpp \ |
|
26 | 26 | declarativechart.cpp \ |
|
27 | declarativeseries.cpp | |
|
27 | declarativeseries.cpp \ | |
|
28 | declarativescatterseries.cpp \ | |
|
29 | scatterelement.cpp | |
|
28 | 30 | HEADERS += \ |
|
29 | 31 | declarativechart.h \ |
|
30 | declarativeseries.h | |
|
32 | declarativeseries.h \ | |
|
33 | declarativescatterseries.h \ | |
|
34 | scatterelement.h | |
|
31 | 35 | |
|
32 | 36 | TARGETPATH = QtCommercial/Chart |
|
33 | 37 | target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
|
34 | 38 | qmldir.files += $$PWD/qmldir |
|
35 | 39 | qmldir.path += $$[QT_INSTALL_IMPORTS]/$$TARGETPATH |
|
36 | 40 | |
|
37 | 41 | INSTALLS += target qmldir |
|
38 | 42 | |
|
39 | 43 | |
|
44 | ||
|
45 | ||
|
46 | ||
|
47 | ||
|
48 | ||
|
49 | ||
|
50 | ||
|
51 | ||
|
52 | ||
|
53 | ||
|
54 | ||
|
55 | ||
|
56 | ||
|
57 |
@@ -1,162 +1,163 | |||
|
1 | 1 | #include "chartdataset_p.h" |
|
2 | 2 | //series |
|
3 | 3 | #include "qlinechartseries.h" |
|
4 | 4 | #include "barchartseries.h" |
|
5 | 5 | #include "stackedbarchartseries.h" |
|
6 | 6 | #include "percentbarchartseries.h" |
|
7 | 7 | #include "qpieseries.h" |
|
8 | 8 | #include "qscatterseries.h" |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | 12 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent) |
|
13 | 13 | { |
|
14 | 14 | Domain domain; |
|
15 | 15 | m_domains<<domain; |
|
16 | 16 | } |
|
17 | 17 | |
|
18 | 18 | ChartDataSet::~ChartDataSet() |
|
19 | 19 | { |
|
20 | 20 | // TODO Auto-generated destructor stub |
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | const Domain& ChartDataSet::domain() const |
|
24 | 24 | { |
|
25 | 25 | return m_domains[m_domainIndex]; |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | void ChartDataSet::addSeries(QChartSeries* series) |
|
29 | 29 | { |
|
30 | 30 | // TODO: we should check the series not already added |
|
31 | 31 | m_chartSeries << series; |
|
32 | series->setParent(this); // take ownership | |
|
32 | 33 | m_domainIndex = 0; |
|
33 | 34 | m_domains.resize(1); |
|
34 | 35 | |
|
35 | 36 | Domain& domain = m_domains[m_domainIndex]; |
|
36 | 37 | |
|
37 | 38 | switch(series->type()) |
|
38 | 39 | { |
|
39 | 40 | case QChartSeries::SeriesTypeLine: { |
|
40 | 41 | |
|
41 | 42 | QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series); |
|
42 | 43 | |
|
43 | 44 | for (int i = 0; i < xyseries->count(); i++) |
|
44 | 45 | { |
|
45 | 46 | qreal x = xyseries->x(i); |
|
46 | 47 | qreal y = xyseries->y(i); |
|
47 | 48 | domain.m_minX = qMin(domain.m_minX,x); |
|
48 | 49 | domain.m_minY = qMin(domain.m_minY,y); |
|
49 | 50 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
50 | 51 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
51 | 52 | } |
|
52 | 53 | break; |
|
53 | 54 | } |
|
54 | 55 | case QChartSeries::SeriesTypeBar: { |
|
55 | 56 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
56 | 57 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
57 | 58 | qreal x = barSeries->countCategories(); |
|
58 | 59 | qreal y = barSeries->max(); |
|
59 | 60 | domain.m_minX = qMin(domain.m_minX,x); |
|
60 | 61 | domain.m_minY = qMin(domain.m_minY,y); |
|
61 | 62 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
62 | 63 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
63 | 64 | break; |
|
64 | 65 | } |
|
65 | 66 | case QChartSeries::SeriesTypeStackedBar: { |
|
66 | 67 | qDebug() << "QChartSeries::SeriesTypeStackedBar"; |
|
67 | 68 | |
|
68 | 69 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
69 | 70 | qreal x = stackedBarSeries->countCategories(); |
|
70 | 71 | qreal y = stackedBarSeries->maxCategorySum(); |
|
71 | 72 | domain.m_minX = qMin(domain.m_minX,x); |
|
72 | 73 | domain.m_minY = qMin(domain.m_minY,y); |
|
73 | 74 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
74 | 75 | domain.m_maxY = qMax(domain.m_maxY,y); |
|
75 | 76 | break; |
|
76 | 77 | } |
|
77 | 78 | case QChartSeries::SeriesTypePercentBar: { |
|
78 | 79 | qDebug() << "QChartSeries::SeriesTypePercentBar"; |
|
79 | 80 | |
|
80 | 81 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
81 | 82 | qreal x = percentBarSeries->countCategories(); |
|
82 | 83 | domain.m_minX = qMin(domain.m_minX,x); |
|
83 | 84 | domain.m_minY = 0; |
|
84 | 85 | domain.m_maxX = qMax(domain.m_maxX,x); |
|
85 | 86 | domain.m_maxY = 100; |
|
86 | 87 | break; |
|
87 | 88 | } |
|
88 | 89 | |
|
89 | 90 | case QChartSeries::SeriesTypePie: { |
|
90 | 91 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
91 | 92 | // TODO: domain stuff |
|
92 | 93 | break; |
|
93 | 94 | } |
|
94 | 95 | |
|
95 | 96 | case QChartSeries::SeriesTypeScatter: { |
|
96 | 97 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
97 | 98 | Q_ASSERT(scatterSeries); |
|
98 | 99 | foreach (QPointF point, scatterSeries->data()) { |
|
99 | 100 | domain.m_minX = qMin(domain.m_minX, point.x()); |
|
100 | 101 | domain.m_maxX = qMax(domain.m_maxX, point.x()); |
|
101 | 102 | domain.m_minY = qMin(domain.m_minY, point.y()); |
|
102 | 103 | domain.m_maxY = qMax(domain.m_maxY, point.y()); |
|
103 | 104 | } |
|
104 | 105 | break; |
|
105 | 106 | } |
|
106 | 107 | |
|
107 | 108 | default: { |
|
108 | 109 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
109 | 110 | return; |
|
110 | 111 | break; |
|
111 | 112 | } |
|
112 | 113 | |
|
113 | 114 | } |
|
114 | 115 | |
|
115 | 116 | emit seriesAdded(series); |
|
116 | 117 | emit domainChanged(domain); |
|
117 | 118 | } |
|
118 | 119 | |
|
119 | 120 | bool ChartDataSet::nextDomain() |
|
120 | 121 | { |
|
121 | 122 | if (m_domainIndex < m_domains.count() - 1) { |
|
122 | 123 | m_domainIndex++; |
|
123 | 124 | emit domainChanged(m_domains[m_domainIndex]); |
|
124 | 125 | return true; |
|
125 | 126 | } |
|
126 | 127 | else { |
|
127 | 128 | return false; |
|
128 | 129 | } |
|
129 | 130 | } |
|
130 | 131 | |
|
131 | 132 | bool ChartDataSet::previousDomain() |
|
132 | 133 | { |
|
133 | 134 | if (m_domainIndex > 0) { |
|
134 | 135 | m_domainIndex--; |
|
135 | 136 | emit domainChanged(m_domains[m_domainIndex]); |
|
136 | 137 | return true; |
|
137 | 138 | } |
|
138 | 139 | else { |
|
139 | 140 | return false; |
|
140 | 141 | } |
|
141 | 142 | } |
|
142 | 143 | |
|
143 | 144 | void ChartDataSet::clearDomains() |
|
144 | 145 | { |
|
145 | 146 | if (m_domainIndex > 0) { |
|
146 | 147 | m_domainIndex = 0; |
|
147 | 148 | emit domainChanged(m_domains[m_domainIndex]); |
|
148 | 149 | } |
|
149 | 150 | } |
|
150 | 151 | |
|
151 | 152 | void ChartDataSet::addDomain(const Domain& domain) |
|
152 | 153 | { |
|
153 | 154 | m_domains.resize(m_domainIndex + 1); |
|
154 | 155 | m_domains << domain; |
|
155 | 156 | m_domainIndex++; |
|
156 | 157 | |
|
157 | 158 | emit domainChanged(domain); |
|
158 | 159 | } |
|
159 | 160 | |
|
160 | 161 | #include "moc_chartdataset_p.cpp" |
|
161 | 162 | |
|
162 | 163 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,272 +1,269 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | #include "chartpresenter_p.h" |
|
4 | 4 | #include "chartdataset_p.h" |
|
5 | 5 | #include "charttheme_p.h" |
|
6 | 6 | //series |
|
7 | 7 | #include "barchartseries.h" |
|
8 | 8 | #include "stackedbarchartseries.h" |
|
9 | 9 | #include "percentbarchartseries.h" |
|
10 | 10 | #include "qlinechartseries.h" |
|
11 | 11 | #include "qpieseries.h" |
|
12 | 12 | #include "qscatterseries.h" |
|
13 | 13 | //items |
|
14 | 14 | #include "axisitem_p.h" |
|
15 | 15 | #include "bargroup.h" |
|
16 | 16 | #include "stackedbargroup.h" |
|
17 | 17 | #include "linechartitem_p.h" |
|
18 | 18 | #include "percentbargroup.h" |
|
19 | 19 | #include "linechartanimationitem_p.h" |
|
20 | 20 | #include "piepresenter.h" |
|
21 | #include "scatterpresenter.h" | |
|
21 | #include "scatterpresenter_p.h" | |
|
22 | 22 | |
|
23 | 23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | 24 | |
|
25 | 25 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
26 | 26 | m_chart(chart), |
|
27 | 27 | m_dataset(dataset), |
|
28 | 28 | m_chartTheme(0), |
|
29 | 29 | m_axisXItem(new AxisItem(AxisItem::X_AXIS,m_chart)), |
|
30 | 30 | m_axisYItem(new AxisItem(AxisItem::Y_AXIS,m_chart)), |
|
31 | 31 | m_domainIndex(0), |
|
32 | 32 | m_marginSize(0), |
|
33 | 33 | m_rect(QRectF(QPoint(0,0),m_chart->size())) |
|
34 | 34 | { |
|
35 | 35 | setChartTheme(QChart::ChartThemeDefault); |
|
36 | 36 | createConnections(); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | ChartPresenter::~ChartPresenter() |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void ChartPresenter::createConnections() |
|
44 | 44 | { |
|
45 | 45 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
46 | 46 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*))); |
|
47 | 47 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisXItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
48 | 48 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisXItem,SLOT(handleDomainChanged(const Domain&))); |
|
49 | 49 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),m_axisYItem,SLOT(handleGeometryChanged(const QRectF&))); |
|
50 | 50 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),m_axisYItem,SLOT(handleDomainChanged(const Domain&))); |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | void ChartPresenter::handleGeometryChanged() |
|
54 | 54 | { |
|
55 | 55 | m_rect = QRectF(QPoint(0,0),m_chart->size()); |
|
56 | 56 | m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); |
|
57 | 57 | Q_ASSERT(m_rect.isValid()); |
|
58 | 58 | emit geometryChanged(m_rect); |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | int ChartPresenter::margin() const |
|
62 | 62 | { |
|
63 | 63 | return m_marginSize; |
|
64 | 64 | } |
|
65 | 65 | |
|
66 | 66 | void ChartPresenter::setMargin(int margin) |
|
67 | 67 | { |
|
68 | 68 | m_marginSize = margin; |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void ChartPresenter::handleSeriesAdded(QChartSeries* series) |
|
72 | 72 | { |
|
73 | 73 | qDebug() << " ChartPresenter::handleSeriesAdded"; |
|
74 | 74 | switch(series->type()) |
|
75 | 75 | { |
|
76 | 76 | case QChartSeries::SeriesTypeLine: { |
|
77 | 77 | QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series); |
|
78 | 78 | LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart); |
|
79 | 79 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
80 | 80 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
81 | 81 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
82 | 82 | QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
83 | 83 | m_chartItems.insert(series,item); |
|
84 | 84 | break; |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | case QChartSeries::SeriesTypeBar: { |
|
88 | 88 | BarChartSeries* barSeries = static_cast<BarChartSeries*>(series); |
|
89 | 89 | BarGroup* item = new BarGroup(barSeries->model(),m_chart); |
|
90 | 90 | m_chartTheme->decorate(item,barSeries,m_chartItems.count()); |
|
91 | 91 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
92 | 92 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
93 | 93 | QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
94 | 94 | m_chartItems.insert(series,item); |
|
95 | 95 | // m_axisXItem->setVisible(false); |
|
96 | 96 | break; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | case QChartSeries::SeriesTypeStackedBar: { |
|
100 | 100 | |
|
101 | 101 | StackedBarChartSeries* stackedBarSeries = static_cast<StackedBarChartSeries*>(series); |
|
102 | 102 | StackedBarGroup* item = new StackedBarGroup(stackedBarSeries->model(),m_chart); |
|
103 | 103 | m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count()); |
|
104 | 104 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
105 | 105 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
106 | 106 | QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
107 | 107 | m_chartItems.insert(series,item); |
|
108 | 108 | break; |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | case QChartSeries::SeriesTypePercentBar: { |
|
112 | 112 | |
|
113 | 113 | PercentBarChartSeries* percentBarSeries = static_cast<PercentBarChartSeries*>(series); |
|
114 | 114 | PercentBarGroup* item = new PercentBarGroup(percentBarSeries->model(),m_chart); |
|
115 | 115 | m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count()); |
|
116 | 116 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
117 | 117 | QObject::connect(m_dataset,SIGNAL(domainChanged(const Domain&)),item,SLOT(handleDomainChanged(const Domain&))); |
|
118 | 118 | QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int))); |
|
119 | 119 | m_chartItems.insert(series,item); |
|
120 | 120 | break; |
|
121 | 121 | } |
|
122 | 122 | case QChartSeries::SeriesTypeScatter: { |
|
123 | 123 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
124 | 124 | ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart); |
|
125 | 125 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), |
|
126 | 126 | scatterPresenter, SLOT(handleGeometryChanged(const QRectF&))); |
|
127 | 127 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), |
|
128 | 128 | scatterPresenter, SLOT(handleDomainChanged(const Domain&))); |
|
129 | 129 | m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count()); |
|
130 | // scatterSeries->d->m_theme = m_chartTheme->themeForSeries(); | |
|
131 | // scatterSeries->d->setParentItem(this); | |
|
132 | // scatterSeries->d->m_boundingRect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
|
133 | 130 | m_chartItems.insert(scatterSeries, scatterPresenter); |
|
134 | 131 | break; |
|
135 | 132 | } |
|
136 | 133 | case QChartSeries::SeriesTypePie: { |
|
137 | 134 | QPieSeries *s = qobject_cast<QPieSeries *>(series); |
|
138 | 135 | PiePresenter* pie = new PiePresenter(m_chart, s); |
|
139 | 136 | m_chartTheme->decorate(pie, s, m_chartItems.count()); |
|
140 | 137 | QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&))); |
|
141 | 138 | QObject::connect(m_dataset, SIGNAL(domainChanged(const Domain&)), pie, SLOT(handleDomainChanged(const Domain&))); |
|
142 | 139 | m_chartItems.insert(series, pie); |
|
143 | 140 | break; |
|
144 | 141 | } |
|
145 | 142 | default: { |
|
146 | 143 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
147 | 144 | break; |
|
148 | 145 | } |
|
149 | 146 | } |
|
150 | 147 | |
|
151 | 148 | if(m_rect.isValid()) emit geometryChanged(m_rect); |
|
152 | 149 | } |
|
153 | 150 | |
|
154 | 151 | void ChartPresenter::handleSeriesChanged(QChartSeries* series) |
|
155 | 152 | { |
|
156 | 153 | //TODO: |
|
157 | 154 | } |
|
158 | 155 | |
|
159 | 156 | void ChartPresenter::zoomInToRect(const QRectF& rect) |
|
160 | 157 | { |
|
161 | 158 | if(!rect.isValid()) return; |
|
162 | 159 | QRectF r = rect.normalized(); |
|
163 | 160 | r.translate(-m_marginSize, -m_marginSize); |
|
164 | 161 | Domain domain (m_dataset->domain().subDomain(r,m_rect.width(),m_rect.height())); |
|
165 | 162 | m_dataset->addDomain(domain); |
|
166 | 163 | } |
|
167 | 164 | |
|
168 | 165 | void ChartPresenter::zoomIn() |
|
169 | 166 | { |
|
170 | 167 | if (!m_dataset->nextDomain()) { |
|
171 | 168 | QRectF rect = m_rect; |
|
172 | 169 | rect.setWidth(rect.width()/2); |
|
173 | 170 | rect.setHeight(rect.height()/2); |
|
174 | 171 | rect.moveCenter(m_rect.center()); |
|
175 | 172 | Domain domain (m_dataset->domain().subDomain(rect,m_rect.width(),m_rect.height())); |
|
176 | 173 | m_dataset->addDomain(domain); |
|
177 | 174 | } |
|
178 | 175 | } |
|
179 | 176 | |
|
180 | 177 | void ChartPresenter::zoomOut() |
|
181 | 178 | { |
|
182 | 179 | m_dataset->previousDomain(); |
|
183 | 180 | } |
|
184 | 181 | |
|
185 | 182 | void ChartPresenter::zoomReset() |
|
186 | 183 | { |
|
187 | 184 | m_dataset->clearDomains(); |
|
188 | 185 | } |
|
189 | 186 | |
|
190 | 187 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
191 | 188 | { |
|
192 | 189 | delete m_chartTheme; |
|
193 | 190 | |
|
194 | 191 | m_chartTheme = ChartTheme::createTheme(theme); |
|
195 | 192 | |
|
196 | 193 | m_chartTheme->decorate(m_chart); |
|
197 | 194 | QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems); |
|
198 | 195 | |
|
199 | 196 | int index=0; |
|
200 | 197 | while (i.hasNext()) { |
|
201 | 198 | i.next(); |
|
202 | 199 | index++; |
|
203 | 200 | m_chartTheme->decorate(i.value(),i.key(),index); |
|
204 | 201 | } |
|
205 | 202 | |
|
206 | 203 | m_chartTheme->decorate(m_axisX, m_axisXItem); |
|
207 | 204 | m_chartTheme->decorate(m_axisY, m_axisYItem); |
|
208 | 205 | |
|
209 | 206 | } |
|
210 | 207 | |
|
211 | 208 | |
|
212 | 209 | QChart::ChartTheme ChartPresenter::chartTheme() |
|
213 | 210 | { |
|
214 | 211 | return m_chartTheme->id(); |
|
215 | 212 | } |
|
216 | 213 | |
|
217 | 214 | void ChartPresenter::setDefaultAxisX(const QChartAxis& axis) |
|
218 | 215 | { |
|
219 | 216 | //if(m_axisX != axis) { |
|
220 | 217 | m_axisX = axis; |
|
221 | 218 | m_axisXItem->handleAxisChanged(m_axisX); |
|
222 | 219 | //} |
|
223 | 220 | } |
|
224 | 221 | |
|
225 | 222 | void ChartPresenter::setDefaultAxisY(const QChartAxis& axis) |
|
226 | 223 | { |
|
227 | 224 | // if(m_axisY != axis) { |
|
228 | 225 | m_axisY = axis; |
|
229 | 226 | m_axisYItem->handleAxisChanged(m_axisY); |
|
230 | 227 | //} |
|
231 | 228 | } |
|
232 | 229 | |
|
233 | 230 | QChartAxis ChartPresenter::defaultAxisX() const |
|
234 | 231 | { |
|
235 | 232 | return m_axisX; |
|
236 | 233 | } |
|
237 | 234 | |
|
238 | 235 | QChartAxis ChartPresenter::defaultAxisY() const |
|
239 | 236 | { |
|
240 | 237 | return m_axisY; |
|
241 | 238 | } |
|
242 | 239 | |
|
243 | 240 | QChartAxis ChartPresenter::axisY(int id) const |
|
244 | 241 | { |
|
245 | 242 | return m_axis.value(id); |
|
246 | 243 | } |
|
247 | 244 | |
|
248 | 245 | int ChartPresenter::addAxisY(const QChartAxis& axis) |
|
249 | 246 | { |
|
250 | 247 | int key =0 ; |
|
251 | 248 | |
|
252 | 249 | while(m_axis.contains(key)){ |
|
253 | 250 | key++; |
|
254 | 251 | //TODO overflow |
|
255 | 252 | } |
|
256 | 253 | |
|
257 | 254 | m_axis.insert(key,axis); |
|
258 | 255 | m_axisItems.insert(key,new AxisItem(AxisItem::Y_AXIS,m_chart)); |
|
259 | 256 | |
|
260 | 257 | return key; |
|
261 | 258 | } |
|
262 | 259 | |
|
263 | 260 | |
|
264 | 261 | void ChartPresenter::removeAxisY(int id) |
|
265 | 262 | { |
|
266 | 263 | m_axis.remove(id); |
|
267 | 264 | delete m_axisItems.take(id); |
|
268 | 265 | } |
|
269 | 266 | |
|
270 | 267 | #include "moc_chartpresenter_p.cpp" |
|
271 | 268 | |
|
272 | 269 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,247 +1,254 | |||
|
1 | 1 | #include "charttheme_p.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | 3 | #include "qchartaxis.h" |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | //series |
|
7 | 7 | #include "barchartseries.h" |
|
8 | 8 | #include "stackedbarchartseries.h" |
|
9 | 9 | #include "percentbarchartseries.h" |
|
10 | 10 | #include "qlinechartseries.h" |
|
11 | 11 | #include "qscatterseries.h" |
|
12 | 12 | #include "qpieseries.h" |
|
13 | #include "qpieslice.h" | |
|
13 | 14 | |
|
14 | 15 | //items |
|
15 | 16 | #include "axisitem_p.h" |
|
16 | 17 | #include "bargroup.h" |
|
17 | 18 | #include "stackedbargroup.h" |
|
18 | 19 | #include "linechartitem_p.h" |
|
19 | 20 | #include "percentbargroup.h" |
|
20 | #include "scatterpresenter.h" | |
|
21 | #include "scatterpresenter_p.h" | |
|
21 | 22 | #include "piepresenter.h" |
|
22 | 23 | |
|
23 | 24 | //themes |
|
24 | 25 | #include "chartthemevanilla_p.h" |
|
25 | 26 | #include "chartthemeicy_p.h" |
|
26 | 27 | #include "chartthemegrayscale_p.h" |
|
27 | 28 | #include "chartthemescientific_p.h" |
|
28 | 29 | |
|
29 | 30 | |
|
30 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 32 | |
|
32 | 33 | /* TODO |
|
33 | 34 | case QChart::ChartThemeUnnamed1: |
|
34 | 35 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff3fa9f5)), 2)); |
|
35 | 36 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xff7AC943)), 2)); |
|
36 | 37 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF931E)), 2)); |
|
37 | 38 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF1D25)), 2)); |
|
38 | 39 | m_seriesThemes.append(SeriesTheme(QColor(QRgb(0xffFF7BAC)), 2)); |
|
39 | 40 | |
|
40 | 41 | m_gradientStartColor = QColor(QRgb(0xfff3dc9e)); |
|
41 | 42 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
42 | 43 | */ |
|
43 | 44 | |
|
44 | 45 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
45 | 46 | { |
|
46 | 47 | m_id = id; |
|
47 | 48 | m_seriesColor.append(QRgb(0xff000000)); |
|
48 | 49 | m_seriesColor.append(QRgb(0xff707070)); |
|
49 | 50 | m_gradientStartColor = QColor(QRgb(0xffffffff)); |
|
50 | 51 | m_gradientEndColor = QColor(QRgb(0xffafafaf)); |
|
51 | 52 | } |
|
52 | 53 | |
|
53 | 54 | |
|
54 | 55 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
55 | 56 | { |
|
56 | 57 | switch(theme) { |
|
57 | 58 | case QChart::ChartThemeDefault: |
|
58 | 59 | return new ChartTheme(); |
|
59 | 60 | case QChart::ChartThemeVanilla: |
|
60 | 61 | return new ChartThemeVanilla(); |
|
61 | 62 | case QChart::ChartThemeIcy: |
|
62 | 63 | return new ChartThemeIcy(); |
|
63 | 64 | case QChart::ChartThemeGrayscale: |
|
64 | 65 | return new ChartThemeGrayscale(); |
|
65 | 66 | case QChart::ChartThemeScientific: |
|
66 | 67 | return new ChartThemeScientific(); |
|
67 | 68 | } |
|
68 | 69 | } |
|
69 | 70 | |
|
70 | 71 | void ChartTheme::decorate(QChart* chart) |
|
71 | 72 | { |
|
72 | 73 | QLinearGradient backgroundGradient; |
|
73 | 74 | backgroundGradient.setColorAt(0.0, m_gradientStartColor); |
|
74 | 75 | backgroundGradient.setColorAt(1.0, m_gradientEndColor); |
|
75 | 76 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
76 | 77 | chart->setChartBackgroundBrush(backgroundGradient); |
|
77 | 78 | } |
|
78 | 79 | //TODO helper to by removed later |
|
79 | 80 | void ChartTheme::decorate(ChartItem* item, QChartSeries* series,int count) |
|
80 | 81 | { |
|
81 | 82 | switch(series->type()) |
|
82 | 83 | { |
|
83 | 84 | case QChartSeries::SeriesTypeLine: { |
|
84 | 85 | QLineChartSeries* s = static_cast<QLineChartSeries*>(series); |
|
85 | 86 | LineChartItem* i = static_cast<LineChartItem*>(item); |
|
86 | 87 | decorate(i,s,count); |
|
87 | 88 | break; |
|
88 | 89 | } |
|
89 | 90 | case QChartSeries::SeriesTypeBar: { |
|
90 | 91 | BarChartSeries* b = static_cast<BarChartSeries*>(series); |
|
91 | 92 | BarGroup* i = static_cast<BarGroup*>(item); |
|
92 | 93 | decorate(i,b,count); |
|
93 | 94 | break; |
|
94 | 95 | } |
|
95 | 96 | case QChartSeries::SeriesTypeStackedBar: { |
|
96 | 97 | StackedBarChartSeries* s = static_cast<StackedBarChartSeries*>(series); |
|
97 | 98 | StackedBarGroup* i = static_cast<StackedBarGroup*>(item); |
|
98 | 99 | decorate(i,s,count); |
|
99 | 100 | break; |
|
100 | 101 | } |
|
101 | 102 | case QChartSeries::SeriesTypePercentBar: { |
|
102 | 103 | PercentBarChartSeries* s = static_cast<PercentBarChartSeries*>(series); |
|
103 | 104 | PercentBarGroup* i = static_cast<PercentBarGroup*>(item); |
|
104 | 105 | decorate(i,s,count); |
|
105 | 106 | break; |
|
106 | 107 | } |
|
108 | case QChartSeries::SeriesTypeScatter: { | |
|
109 | QScatterSeries* s = qobject_cast<QScatterSeries*>(series); | |
|
110 | Q_ASSERT(s); | |
|
111 | ScatterPresenter* i = static_cast<ScatterPresenter*>(item); | |
|
112 | Q_ASSERT(i); | |
|
113 | decorate(i, s, count); | |
|
114 | break; | |
|
115 | } | |
|
107 | 116 | case QChartSeries::SeriesTypePie: { |
|
108 | 117 | QPieSeries* s = static_cast<QPieSeries*>(series); |
|
109 | 118 | PiePresenter* i = static_cast<PiePresenter*>(item); |
|
110 | 119 | decorate(i,s,count); |
|
111 | 120 | break; |
|
112 | 121 | } |
|
113 | 122 | default: |
|
114 | 123 | qDebug()<<"Wrong item to be decorated by theme"; |
|
115 | 124 | break; |
|
116 | 125 | } |
|
117 | 126 | |
|
118 | 127 | } |
|
119 | 128 | |
|
120 | 129 | void ChartTheme::decorate(LineChartItem* item, QLineChartSeries* series,int count) |
|
121 | 130 | { |
|
122 | 131 | QPen pen; |
|
123 | 132 | if(pen != series->pen()){ |
|
124 | 133 | item->setPen(series->pen()); |
|
125 | 134 | return; |
|
126 | 135 | } |
|
127 | 136 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); |
|
128 | 137 | pen.setWidthF(2); |
|
129 | 138 | item->setPen(pen); |
|
130 | 139 | } |
|
131 | 140 | |
|
132 | 141 | void ChartTheme::decorate(BarGroup* item, BarChartSeries* series,int count) |
|
133 | 142 | { |
|
134 | 143 | // TODO: better way to descide series color and remove hard coded colors. |
|
135 | 144 | item->resetBrushes(); |
|
136 | 145 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
137 | 146 | QBrush brush(m_seriesColor.at(i)); |
|
138 | 147 | item->addBrush(brush); |
|
139 | 148 | } |
|
140 | 149 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
141 | 150 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
142 | 151 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
143 | 152 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
144 | 153 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
145 | 154 | } |
|
146 | 155 | |
|
147 | 156 | void ChartTheme::decorate(StackedBarGroup* item, StackedBarChartSeries* series,int count) |
|
148 | 157 | { |
|
149 | 158 | // TODO: better way to descide series color and remove hard coded colors. |
|
150 | 159 | item->resetBrushes(); |
|
151 | 160 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
152 | 161 | QBrush brush(m_seriesColor.at(i)); |
|
153 | 162 | item->addBrush(brush); |
|
154 | 163 | } |
|
155 | 164 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
156 | 165 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
157 | 166 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
158 | 167 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
159 | 168 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
160 | 169 | } |
|
161 | 170 | |
|
162 | 171 | void ChartTheme::decorate(PercentBarGroup* item, PercentBarChartSeries* series,int count) |
|
163 | 172 | { |
|
164 | 173 | // TODO: better way to descide series color and remove hard coded colors. |
|
165 | 174 | item->resetBrushes(); |
|
166 | 175 | for (int i=0; i<m_seriesColor.count(); i++) { |
|
167 | 176 | QBrush brush(m_seriesColor.at(i)); |
|
168 | 177 | item->addBrush(brush); |
|
169 | 178 | } |
|
170 | 179 | item->addBrush(QBrush(QColor(255,0,0,128))); |
|
171 | 180 | item->addBrush(QBrush(QColor(255,255,0,128))); |
|
172 | 181 | item->addBrush(QBrush(QColor(0,255,0,128))); |
|
173 | 182 | item->addBrush(QBrush(QColor(0,0,255,128))); |
|
174 | 183 | item->addBrush(QBrush(QColor(255,128,0,128))); |
|
175 | 184 | } |
|
176 | 185 | |
|
177 | 186 | void ChartTheme::decorate(ScatterPresenter* presenter, QScatterSeries* series, int count) |
|
178 | 187 | { |
|
179 | 188 | Q_ASSERT(presenter); |
|
180 | 189 | Q_ASSERT(series); |
|
181 | 190 | |
|
182 |
|
|
|
191 | QColor color = m_seriesColor.at(count % m_seriesColor.size()); | |
|
192 | // TODO: define alpha in the theme? or in the series? | |
|
193 | color.setAlpha(120); | |
|
194 | ||
|
195 | QBrush brush(color, Qt::SolidPattern); | |
|
196 | presenter->m_markerBrush = brush; | |
|
183 | 197 | |
|
184 |
|
|
|
185 | // if(pen != series->pen()){ | |
|
186 | // item->setPen(series->pen()); | |
|
187 | // return; | |
|
188 | // } | |
|
189 | // pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
|
190 | // pen.setWidthF(2); | |
|
191 | // item->setPen(pen); | |
|
198 | QPen pen(brush, 1); | |
|
199 | pen.setColor(color); | |
|
200 | presenter->m_markerPen = pen; | |
|
192 | 201 | } |
|
193 | 202 | |
|
194 | 203 | void ChartTheme::decorate(PiePresenter* item, QPieSeries* series, int /*count*/) |
|
195 | 204 | { |
|
196 | 205 | // create a list of slice colors based on current theme |
|
197 | 206 | int i = 0; |
|
198 | 207 | QList<QColor> colors; |
|
199 | 208 | while (colors.count() < series->count()) { |
|
200 | 209 | |
|
201 | 210 | // get base color |
|
202 | 211 | QColor c = m_seriesColor[i++]; |
|
203 | 212 | i = i % m_seriesColor.count(); |
|
204 | 213 | |
|
205 | 214 | // -1 means achromatic color -> cannot manipulate lightness |
|
206 | 215 | // TODO: find a better way to randomize lightness |
|
207 | 216 | if (c.toHsv().hue() == -1) |
|
208 | 217 | qWarning() << "ChartTheme::decorate() warning: achromatic theme color"; |
|
209 | 218 | |
|
210 | 219 | // randomize lightness |
|
211 | 220 | qreal f = 50 + (qrand() % 100); // 50 is 50% darker, 100 is the same, 150 is 50% lighter |
|
212 | 221 | c = c.lighter(f); |
|
213 | 222 | |
|
214 | 223 | // find duplicates |
|
215 | 224 | bool isUnique = true; |
|
216 | 225 | foreach (QColor color, colors) { |
|
217 | 226 | if (c == color) |
|
218 | 227 | isUnique = false; |
|
219 | 228 | } |
|
220 | 229 | |
|
221 | 230 | // add to array if unique |
|
222 | 231 | //if (isUnique) |
|
223 | 232 | colors << c; |
|
224 | 233 | } |
|
225 | 234 | |
|
226 | 235 | // finally update colors |
|
227 |
foreach (QPieSlice |
|
|
228 | QPieSlice s = series->slice(id); | |
|
229 | s.setPen(QPen(Qt::black)); // TODO: get from theme | |
|
230 | s.setBrush(colors.takeFirst()); | |
|
231 | series->update(s); | |
|
236 | foreach (QPieSlice* s, series->slices()) { | |
|
237 | s->setPen(QPen(Qt::black)); // TODO: get from theme | |
|
238 | s->setBrush(colors.takeFirst()); | |
|
232 | 239 | } |
|
233 | 240 | } |
|
234 | 241 | |
|
235 | 242 | |
|
236 | 243 | void ChartTheme::decorate(QChartAxis& axis,AxisItem* item) |
|
237 | 244 | { |
|
238 | 245 | //TODO: dummy defults for now |
|
239 | 246 | |
|
240 | 247 | axis.setLabelsBrush(Qt::black); |
|
241 | 248 | axis.setLabelsPen(Qt::NoPen); |
|
242 | 249 | axis.setShadesPen(Qt::NoPen); |
|
243 | 250 | axis.setShadesOpacity(0.5); |
|
244 | 251 | item->handleAxisChanged(axis); |
|
245 | 252 | } |
|
246 | 253 | |
|
247 | 254 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,16 +1,18 | |||
|
1 | 1 | INCLUDEPATH += $$PWD |
|
2 | 2 | DEPENDPATH += $$PWD |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | $$PWD/qpieseries.cpp \ |
|
6 | 6 | $$PWD/pieslice.cpp \ |
|
7 | 7 | $$PWD/piepresenter.cpp \ |
|
8 | $$PWD/pieslicelabel.cpp | |
|
8 | $$PWD/pieslicelabel.cpp \ | |
|
9 | $$PWD/qpieslice.cpp | |
|
9 | 10 | |
|
10 | 11 | PRIVATE_HEADERS += \ |
|
11 | 12 | $$PWD/piepresenter.h \ |
|
12 | 13 | $$PWD/pieslice.h \ |
|
13 | 14 | $$PWD/pieslicelabel.h |
|
14 | 15 | |
|
15 | 16 | PUBLIC_HEADERS += \ |
|
16 | $$PWD/qpieseries.h | |
|
17 | $$PWD/qpieseries.h \ | |
|
18 | $$PWD/qpieslice.h |
@@ -1,170 +1,155 | |||
|
1 | 1 | |
|
2 | 2 | #include "piepresenter.h" |
|
3 | 3 | #include "pieslice.h" |
|
4 | #include "qpieslice.h" | |
|
4 | 5 | #include <QDebug> |
|
5 | 6 | #include <QTime> |
|
6 | 7 | |
|
7 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 9 | |
|
9 | 10 | PiePresenter::PiePresenter(QGraphicsItem *parent, QPieSeries *series) |
|
10 | 11 | :ChartItem(parent), |
|
11 | 12 | m_series(series) |
|
12 | 13 | { |
|
13 | 14 | Q_ASSERT(series); |
|
14 | 15 | connect(series, SIGNAL(changed(const QPieSeries::ChangeSet&)), this, SLOT(handleSeriesChanged(const QPieSeries::ChangeSet&))); |
|
15 | 16 | connect(series, SIGNAL(sizeFactorChanged()), this, SLOT(updateGeometry())); |
|
16 | 17 | connect(series, SIGNAL(positionChanged()), this, SLOT(updateGeometry())); |
|
17 | 18 | } |
|
18 | 19 | |
|
19 | 20 | PiePresenter::~PiePresenter() |
|
20 | 21 | { |
|
21 | 22 | // slices deleted automatically through QGraphicsItem |
|
22 | 23 | } |
|
23 | 24 | |
|
24 | 25 | void PiePresenter::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) |
|
25 | 26 | { |
|
26 | 27 | // TODO: paint shadows for all components |
|
27 | 28 | // - get paths from items & merge & offset and draw with shadow color? |
|
28 | 29 | } |
|
29 | 30 | |
|
30 | 31 | void PiePresenter::handleSeriesChanged(const QPieSeries::ChangeSet& changeSet) |
|
31 | 32 | { |
|
32 | qDebug() << "PiePresenter::handleSeriesChanged()"; | |
|
33 |
qDebug() << " added : " << changeSet. |
|
|
34 |
qDebug() << " changed: " << changeSet. |
|
|
35 |
qDebug() << " removed: " << changeSet. |
|
|
33 | //qDebug() << "PiePresenter::handleSeriesChanged()"; | |
|
34 | //qDebug() << " added : " << changeSet.added(); | |
|
35 | //qDebug() << " changed: " << changeSet.changed(); | |
|
36 | //qDebug() << " removed: " << changeSet.removed(); | |
|
36 | 37 | |
|
37 | 38 | // ignore changeset when there are no visual slices |
|
38 | 39 | // changeset might not be valid about the added slices |
|
39 | 40 | if (m_slices.count() == 0) { |
|
40 |
foreach (QPieSlice |
|
|
41 |
addSlice( |
|
|
41 | foreach (QPieSlice* s, m_series->m_slices) | |
|
42 | addSlice(s); | |
|
42 | 43 | return; |
|
43 | 44 | } |
|
44 | 45 | |
|
45 |
foreach (QPieSlice |
|
|
46 |
deleteSlice( |
|
|
46 | foreach (QPieSlice* s, changeSet.removed()) | |
|
47 | deleteSlice(s); | |
|
47 | 48 | |
|
48 |
foreach (QPieSlice |
|
|
49 |
|
|
|
49 | foreach (QPieSlice* s, changeSet.added()) | |
|
50 | addSlice(s); | |
|
51 | } | |
|
50 | 52 | |
|
51 | foreach (QPieSliceId id, changeSet.m_added) | |
|
52 | addSlice(id); | |
|
53 | void PiePresenter::handleDomainChanged(const Domain& domain) | |
|
54 | { | |
|
55 | // TODO | |
|
56 | } | |
|
57 | ||
|
58 | void PiePresenter::handleGeometryChanged(const QRectF& rect) | |
|
59 | { | |
|
60 | m_rect = rect; | |
|
61 | updateGeometry(); | |
|
53 | 62 | } |
|
54 | 63 | |
|
55 | 64 | void PiePresenter::updateGeometry() |
|
56 | 65 | { |
|
57 | 66 | prepareGeometryChange(); |
|
58 | 67 | |
|
59 |
|
|
|
68 | QRectF pieRect = m_rect; | |
|
60 | 69 | |
|
61 |
if ( |
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
70 | if (pieRect.width() < pieRect.height()) { | |
|
71 | pieRect.setWidth(pieRect.width() * m_series->sizeFactor()); | |
|
72 | pieRect.setHeight(pieRect.width()); | |
|
73 | pieRect.moveCenter(m_rect.center()); | |
|
65 | 74 | } else { |
|
66 |
|
|
|
67 |
|
|
|
68 |
|
|
|
75 | pieRect.setHeight(pieRect.height() * m_series->sizeFactor()); | |
|
76 | pieRect.setWidth(pieRect.height()); | |
|
77 | pieRect.moveCenter(m_rect.center()); | |
|
69 | 78 | } |
|
70 | 79 | |
|
71 | 80 | switch (m_series->position()) { |
|
72 | 81 | case QPieSeries::PiePositionTopLeft: { |
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
82 | pieRect.setHeight(pieRect.height() / 2); | |
|
83 | pieRect.setWidth(pieRect.height()); | |
|
84 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, m_rect.center().y() / 2)); | |
|
76 | 85 | break; |
|
77 | 86 | } |
|
78 | 87 | case QPieSeries::PiePositionTopRight: { |
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
88 | pieRect.setHeight(pieRect.height() / 2); | |
|
89 | pieRect.setWidth(pieRect.height()); | |
|
90 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, m_rect.center().y() / 2)); | |
|
82 | 91 | break; |
|
83 | 92 | } |
|
84 | 93 | case QPieSeries::PiePositionBottomLeft: { |
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
94 | pieRect.setHeight(pieRect.height() / 2); | |
|
95 | pieRect.setWidth(pieRect.height()); | |
|
96 | pieRect.moveCenter(QPointF(m_rect.center().x() / 2, (m_rect.center().y() / 2) * 3)); | |
|
88 | 97 | break; |
|
89 | 98 | } |
|
90 | 99 | case QPieSeries::PiePositionBottomRight: { |
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
100 | pieRect.setHeight(pieRect.height() / 2); | |
|
101 | pieRect.setWidth(pieRect.height()); | |
|
102 | pieRect.moveCenter(QPointF((m_rect.center().x() / 2) * 3, (m_rect.center().y() / 2) * 3)); | |
|
94 | 103 | break; |
|
95 | 104 | } |
|
96 | 105 | default: |
|
97 | 106 | break; |
|
98 | 107 | } |
|
99 | 108 | |
|
100 | // update slice geometry | |
|
101 | const qreal fullPie = 360; | |
|
102 | qreal angle = 0; | |
|
103 |
foreach ( |
|
|
104 | qreal span = fullPie * m_series->slice(id).percentage(); | |
|
105 |
|
|
|
106 | angle += span; | |
|
109 | if (m_pieRect != pieRect) { | |
|
110 | m_pieRect = pieRect; | |
|
111 | //qDebug() << "PiePresenter::updateGeometry()" << m_pieRect; | |
|
112 | foreach (PieSlice* s, m_slices.values()) { | |
|
113 | s->setPieRect(m_pieRect); | |
|
114 | s->updateGeometry(); | |
|
115 | } | |
|
107 | 116 | } |
|
108 | ||
|
109 | //qDebug() << "PiePresenter::updateGeometry" << m_rect << m_pieRect; | |
|
110 | 117 | } |
|
111 | 118 | |
|
112 | void PiePresenter::handleDomainChanged(const Domain& domain) | |
|
119 | void PiePresenter::addSlice(QPieSlice* sliceData) | |
|
113 | 120 | { |
|
114 | // TODO | |
|
115 | } | |
|
121 | //qDebug() << "PiePresenter::addSlice()" << sliceData; | |
|
116 | 122 | |
|
117 | void PiePresenter::handleGeometryChanged(const QRectF& rect) | |
|
118 | { | |
|
119 | m_rect = rect; | |
|
120 | updateGeometry(); | |
|
121 | } | |
|
122 | ||
|
123 | void PiePresenter::addSlice(QPieSliceId id) | |
|
124 | { | |
|
125 | qDebug() << "PiePresenter::addSlice()" << id; | |
|
126 | ||
|
127 | if (m_slices.contains(id)) { | |
|
128 | qWarning() << "PiePresenter::addSlice(): slice already exists!" << id; | |
|
129 | updateSlice(id); | |
|
123 | if (m_slices.keys().contains(sliceData)) { | |
|
124 | //qWarning() << "PiePresenter::addSlice(): slice already exists!" << sliceData; | |
|
125 | Q_ASSERT(0); | |
|
130 | 126 | return; |
|
131 | 127 | } |
|
132 | 128 | |
|
133 | 129 | // create slice |
|
134 |
PieSlice *slice = new PieSlice( |
|
|
135 | m_slices.insert(id, slice); | |
|
136 | ||
|
137 | updateGeometry(); | |
|
130 | PieSlice *slice = new PieSlice(this); | |
|
131 | slice->updateData(sliceData); | |
|
132 | m_slices.insert(sliceData, slice); | |
|
133 | ||
|
134 | // connect signals | |
|
135 | connect(sliceData, SIGNAL(changed()), slice, SLOT(handleSliceDataChanged())); | |
|
136 | connect(slice, SIGNAL(clicked()), sliceData, SIGNAL(clicked())); | |
|
137 | connect(slice, SIGNAL(hoverEnter()), sliceData, SIGNAL(hoverEnter())); | |
|
138 | connect(slice, SIGNAL(hoverLeave()), sliceData, SIGNAL(hoverLeave())); | |
|
138 | 139 | } |
|
139 | 140 | |
|
140 |
void PiePresenter:: |
|
|
141 | void PiePresenter::deleteSlice(QPieSlice* sliceData) | |
|
141 | 142 | { |
|
142 |
qDebug() << "PiePresenter:: |
|
|
143 | //qDebug() << "PiePresenter::deleteSlice()" << sliceData; | |
|
143 | 144 | |
|
144 | // TODO: animation | |
|
145 | if (m_slices.contains(id)) | |
|
146 | m_slices.value(id)->updateData(); | |
|
145 | if (m_slices.contains(sliceData)) | |
|
146 | delete m_slices.take(sliceData); | |
|
147 | 147 | else { |
|
148 | qWarning() << "PiePresenter::updateSlice(): slice does not exist!" << id; | |
|
149 | addSlice(id); | |
|
148 | // nothing to remove | |
|
149 | Q_ASSERT(0); // TODO: remove before release | |
|
150 | 150 | } |
|
151 | ||
|
152 | updateGeometry(); | |
|
153 | } | |
|
154 | ||
|
155 | void PiePresenter::deleteSlice(QPieSliceId id) | |
|
156 | { | |
|
157 | qDebug() << "PiePresenter::deleteSlice()" << id; | |
|
158 | ||
|
159 | // TODO: animation | |
|
160 | if (m_slices.contains(id)) | |
|
161 | delete m_slices.take(id); | |
|
162 | else | |
|
163 | qWarning() << "PiePresenter::deleteSlice(): slice does not exist!" << id; | |
|
164 | ||
|
165 | updateGeometry(); | |
|
166 | 151 | } |
|
167 | 152 | |
|
168 | 153 | #include "moc_piepresenter.cpp" |
|
169 | 154 | |
|
170 | 155 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,49 +1,48 | |||
|
1 | 1 | #ifndef PIEPRESENTER_H |
|
2 | 2 | #define PIEPRESENTER_H |
|
3 | 3 | |
|
4 | 4 | #include "chartitem_p.h" |
|
5 | 5 | #include "qpieseries.h" |
|
6 | 6 | #include <QSignalMapper> |
|
7 | 7 | |
|
8 | 8 | class QGraphicsItem; |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | class PieSlice; |
|
11 | 11 | |
|
12 | 12 | class PiePresenter : public QObject, public ChartItem |
|
13 | 13 | { |
|
14 | 14 | Q_OBJECT |
|
15 | 15 | |
|
16 | 16 | public: |
|
17 | 17 | // TODO: use a generic data class instead of x and y |
|
18 | 18 | PiePresenter(QGraphicsItem *parent, QPieSeries *series); |
|
19 | 19 | ~PiePresenter(); |
|
20 | 20 | |
|
21 | 21 | public: // from QGraphicsItem |
|
22 | 22 | QRectF boundingRect() const { return m_rect; } |
|
23 | 23 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
|
24 | 24 | |
|
25 | 25 | public: |
|
26 | 26 | QRectF pieRect() const { return m_pieRect; } |
|
27 | 27 | |
|
28 | 28 | public Q_SLOTS: |
|
29 | 29 | void handleSeriesChanged(const QPieSeries::ChangeSet& changeSet); |
|
30 | 30 | void handleDomainChanged(const Domain& domain); |
|
31 | 31 | void handleGeometryChanged(const QRectF& rect); |
|
32 | 32 | void updateGeometry(); |
|
33 | 33 | |
|
34 | 34 | private: |
|
35 |
void addSlice(QPieSlice |
|
|
36 |
void |
|
|
37 | void deleteSlice(QPieSliceId id); | |
|
35 | void addSlice(QPieSlice* sliceData); | |
|
36 | void deleteSlice(QPieSlice* sliceData); | |
|
38 | 37 | |
|
39 | 38 | private: |
|
40 | 39 | friend class PieSlice; |
|
41 |
QHash<QPieSlice |
|
|
40 | QHash<QPieSlice*, PieSlice*> m_slices; | |
|
42 | 41 | QPieSeries *m_series; |
|
43 | 42 | QRectF m_rect; |
|
44 | 43 | QRectF m_pieRect; |
|
45 | 44 | }; |
|
46 | 45 | |
|
47 | 46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | 47 | |
|
49 | 48 | #endif // PIEPRESENTER_H |
@@ -1,142 +1,143 | |||
|
1 | 1 | #include "pieslice.h" |
|
2 | 2 | #include "pieslicelabel.h" |
|
3 | 3 | #include "piepresenter.h" |
|
4 | 4 | #include "qpieseries.h" |
|
5 | #include "qpieslice.h" | |
|
5 | 6 | #include <QPainter> |
|
6 | 7 | #include <QDebug> |
|
7 | 8 | #include <qmath.h> |
|
8 | 9 | #include <QGraphicsSceneEvent> |
|
9 | 10 | #include <QTime> |
|
10 | 11 | |
|
11 | 12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | 13 | |
|
13 | 14 | #define PI 3.14159265 |
|
14 | 15 | #define EXPLODE_OFFSET 20 |
|
15 | 16 | |
|
16 | 17 | QPointF offset(qreal angle, qreal length) |
|
17 | 18 | { |
|
18 | 19 | qreal dx = qSin(angle*(PI/180)) * length; |
|
19 | 20 | qreal dy = qCos(angle*(PI/180)) * length; |
|
20 | 21 | return QPointF(dx, -dy); |
|
21 | 22 | } |
|
22 | 23 | |
|
23 |
PieSlice::PieSlice( |
|
|
24 | PieSlice::PieSlice(QGraphicsItem* parent) | |
|
24 | 25 | :QGraphicsObject(parent), |
|
25 | m_id(id), | |
|
26 | m_series(series), | |
|
27 | 26 | m_slicelabel(new PieSliceLabel(this)), |
|
28 | m_isHovering(false) | |
|
27 | m_angle(0), | |
|
28 | m_span(0), | |
|
29 | m_isExploded(false) | |
|
29 | 30 | { |
|
30 | Q_ASSERT(series); | |
|
31 | 31 | setAcceptHoverEvents(true); |
|
32 | 32 | setAcceptedMouseButtons(Qt::LeftButton); |
|
33 | updateData(); | |
|
34 | 33 | } |
|
35 | 34 | |
|
36 | 35 | PieSlice::~PieSlice() |
|
37 | 36 | { |
|
38 | qDebug() << "~PieSlice()" << m_id; | |
|
37 | ||
|
39 | 38 | } |
|
40 | 39 | |
|
41 | 40 | QRectF PieSlice::boundingRect() const |
|
42 | 41 | { |
|
43 |
return m_ |
|
|
42 | return m_path.boundingRect(); | |
|
44 | 43 | } |
|
45 | 44 | |
|
46 | 45 | QPainterPath PieSlice::shape() const |
|
47 | 46 | { |
|
48 | 47 | return m_path; |
|
49 | 48 | } |
|
50 | 49 | |
|
51 | 50 | void PieSlice::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/) |
|
52 | 51 | { |
|
53 | // set hover brush | |
|
54 | // TODO: what if we are using gradients... | |
|
55 | QBrush brush = m_data.brush(); | |
|
56 | if (m_isHovering) | |
|
57 | brush.setColor(brush.color().lighter()); | |
|
58 | ||
|
59 | 52 | painter->setRenderHint(QPainter::Antialiasing); |
|
60 |
painter->setPen(m_ |
|
|
61 | painter->setBrush(brush); | |
|
53 | painter->setPen(m_pen); | |
|
54 | painter->setBrush(m_brush); | |
|
62 | 55 | painter->drawPath(m_path); |
|
63 | 56 | } |
|
64 | 57 | |
|
65 | 58 | void PieSlice::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
66 | 59 | { |
|
67 |
|
|
|
68 | update(); | |
|
69 | // TODO: emit hoverEnter() | |
|
60 | emit hoverEnter(); | |
|
70 | 61 | } |
|
71 | 62 | |
|
72 | 63 | void PieSlice::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) |
|
73 | 64 | { |
|
74 | m_isHovering = false; | |
|
75 | update(); | |
|
76 | // TODO: emit hoverLeave() | |
|
65 | emit hoverLeave(); | |
|
77 | 66 | } |
|
78 | 67 | |
|
79 | 68 | void PieSlice::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) |
|
80 | 69 | { |
|
81 |
|
|
|
82 | // TODO: should we let the user decide if this can be exploded? | |
|
83 | m_data.setExploded(!m_data.isExploded()); | |
|
84 | m_series->update(m_data); | |
|
70 | emit clicked(); | |
|
71 | } | |
|
72 | ||
|
73 | void PieSlice::setPieRect(QRectF rect) | |
|
74 | { | |
|
75 | m_pieRect = rect; | |
|
85 | 76 | } |
|
86 | 77 | |
|
87 |
void PieSlice::updateGeometry( |
|
|
78 | void PieSlice::updateGeometry() | |
|
88 | 79 | { |
|
89 | 80 | prepareGeometryChange(); |
|
90 | 81 | |
|
91 | 82 | // calculate center angle |
|
92 |
qreal centerAngle = |
|
|
83 | qreal centerAngle = m_angle + (m_span/2); | |
|
93 | 84 | |
|
94 | 85 | // adjust rect for exploding |
|
86 | QRectF rect = m_pieRect; | |
|
95 | 87 | rect.adjust(EXPLODE_OFFSET, EXPLODE_OFFSET, -EXPLODE_OFFSET ,-EXPLODE_OFFSET); |
|
96 |
if (m_ |
|
|
88 | if (m_isExploded) { | |
|
97 | 89 | QPointF d = offset((centerAngle), EXPLODE_OFFSET); |
|
98 | 90 | rect.translate(d.x(), d.y()); |
|
99 | 91 | } |
|
100 | 92 | |
|
101 | 93 | // update slice path |
|
102 | 94 | // TODO: draw the shape so that it might have a hole in the center |
|
103 | 95 | QPainterPath path; |
|
104 | 96 | path.moveTo(rect.center()); |
|
105 |
path.arcTo(rect, - |
|
|
97 | path.arcTo(rect, -m_angle + 90, -m_span); | |
|
98 | path.closeSubpath(); | |
|
106 | 99 | m_path = path; |
|
107 | m_rect = path.boundingRect(); | |
|
108 | 100 | |
|
109 | 101 | // update label position |
|
110 | 102 | qreal radius = rect.height() / 2; |
|
111 | 103 | QPointF edgeCenter = rect.center() + offset(centerAngle, radius + 5); |
|
112 | 104 | |
|
113 | 105 | m_slicelabel->setArmStartPoint(edgeCenter); |
|
114 | 106 | m_slicelabel->setArmAngle(centerAngle); |
|
115 | m_slicelabel->setArmLength(50); | |
|
116 | 107 | m_slicelabel->updateGeometry(); |
|
117 | 108 | |
|
118 |
//qDebug() << "PieSlice::updateGeometry" << m_ |
|
|
109 | //qDebug() << "PieSlice::updateGeometry" << m_slicelabel->text() << boundingRect() << m_angle << m_span; | |
|
110 | } | |
|
111 | ||
|
112 | void PieSlice::handleSliceDataChanged() | |
|
113 | { | |
|
114 | QPieSlice *slice = qobject_cast<QPieSlice*>(sender()); | |
|
115 | Q_ASSERT(slice); | |
|
116 | updateData(slice); | |
|
119 | 117 | } |
|
120 | 118 | |
|
121 | void PieSlice::updateData() | |
|
119 | void PieSlice::updateData(const QPieSlice* sliceData) | |
|
122 | 120 | { |
|
123 | if (!m_series->m_slices.contains(m_id)) | |
|
124 | qWarning() << "PieSlice::updateData(): cannot find slice data!" << m_id; | |
|
121 | // TODO: compare what has changes to avoid unneccesary geometry updates | |
|
125 | 122 | |
|
126 | QPieSlice data = m_series->slice(m_id); | |
|
127 | // TODO: find out what has changed and trigger some animation | |
|
128 | m_data = data; | |
|
123 | m_angle = sliceData->angle(); | |
|
124 | m_span = sliceData->span(); | |
|
125 | m_isExploded = sliceData->isExploded(); | |
|
126 | m_pen = sliceData->pen(); | |
|
127 | m_brush = sliceData->brush(); | |
|
129 | 128 | |
|
129 | updateGeometry(); | |
|
130 | 130 | update(); |
|
131 | 131 | |
|
132 |
m_slicelabel->setVisible( |
|
|
133 |
m_slicelabel->setText( |
|
|
134 |
|
|
|
135 |
|
|
|
132 | m_slicelabel->setVisible(sliceData->isLabelVisible()); | |
|
133 | m_slicelabel->setText(sliceData->label()); | |
|
134 | m_slicelabel->setPen(sliceData->labelPen()); | |
|
135 | m_slicelabel->setFont(sliceData->labelFont()); | |
|
136 | m_slicelabel->setArmLength(sliceData->labelArmLenght()); | |
|
136 | 137 | m_slicelabel->updateGeometry(); // text size & font modifies the geometry |
|
137 | 138 | m_slicelabel->update(); |
|
138 | 139 | } |
|
139 | 140 | |
|
140 | 141 | #include "moc_pieslice.cpp" |
|
141 | 142 | |
|
142 | 143 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,51 +1,60 | |||
|
1 | 1 | #ifndef PIESLICE_H |
|
2 | 2 | #define PIESLICE_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "charttheme_p.h" |
|
6 | 6 | #include "qpieseries.h" |
|
7 | 7 | #include <QGraphicsItem> |
|
8 | 8 | #include <QRectF> |
|
9 | 9 | #include <QColor> |
|
10 | 10 | #include <QPen> |
|
11 | 11 | |
|
12 | 12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | 13 | class PiePresenter; |
|
14 | 14 | class PieSliceLabel; |
|
15 | class QPieSlice; | |
|
15 | 16 | |
|
16 | 17 | class PieSlice : public QGraphicsObject |
|
17 | 18 | { |
|
18 | 19 | Q_OBJECT |
|
19 | 20 | |
|
20 | 21 | public: |
|
21 |
PieSlice( |
|
|
22 | PieSlice(QGraphicsItem* parent = 0); | |
|
22 | 23 | ~PieSlice(); |
|
23 | 24 | |
|
24 | 25 | public: // from QGraphicsItem |
|
25 | 26 | QRectF boundingRect() const; |
|
26 | 27 | QPainterPath shape() const; |
|
27 | 28 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
28 | 29 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
29 | 30 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
30 | 31 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
31 | 32 | |
|
32 | 33 | Q_SIGNALS: |
|
33 | 34 | void clicked(); |
|
35 | void hoverEnter(); | |
|
36 | void hoverLeave(); | |
|
34 | 37 | |
|
35 | public: | |
|
36 | void updateGeometry(QRectF rect, qreal startAngle, qreal span); | |
|
37 | void updateData(); | |
|
38 | public Q_SLOTS: | |
|
39 | void handleSliceDataChanged(); | |
|
40 | void setPieRect(QRectF rect); | |
|
41 | void updateGeometry(); | |
|
42 | void updateData(const QPieSlice *sliceData); | |
|
38 | 43 | |
|
39 | 44 | private: |
|
40 | QPieSliceId m_id; | |
|
41 | QPieSeries* m_series; | |
|
42 | QPieSlice m_data; | |
|
43 | 45 | PieSliceLabel* m_slicelabel; |
|
46 | ||
|
47 | QRectF m_pieRect; | |
|
44 | 48 | QPainterPath m_path; |
|
45 | QRectF m_rect; | |
|
46 | bool m_isHovering; | |
|
49 | ||
|
50 | qreal m_angle; | |
|
51 | qreal m_span; | |
|
52 | bool m_isExploded; | |
|
53 | ||
|
54 | QPen m_pen; | |
|
55 | QBrush m_brush; | |
|
47 | 56 | }; |
|
48 | 57 | |
|
49 | 58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | 59 | |
|
51 | 60 | #endif // PIESLICE_H |
@@ -1,152 +1,299 | |||
|
1 | 1 | #include "qpieseries.h" |
|
2 | #include "qpieslice.h" | |
|
2 | 3 | #include "piepresenter.h" |
|
3 | 4 | #include "pieslice.h" |
|
4 | 5 | #include <QDebug> |
|
5 | 6 | |
|
6 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | 8 | |
|
8 | QPieSeries::QPieSeries(QObject *parent) : | |
|
9 | QChartSeries(parent), | |
|
10 | m_sizeFactor(1.0), | |
|
11 | m_position(PiePositionMaximized), | |
|
12 | m_sliceIdSeed(0) | |
|
9 | void QPieSeries::ChangeSet::appendAdded(QPieSlice* slice) | |
|
13 | 10 | { |
|
11 | if (!m_added.contains(slice)) | |
|
12 | m_added << slice; | |
|
14 | 13 | } |
|
15 | 14 | |
|
16 | QPieSeries::~QPieSeries() | |
|
15 | void QPieSeries::ChangeSet::appendChanged(QPieSlice* slice) | |
|
16 | { | |
|
17 | if (!m_changed.contains(slice)) | |
|
18 | m_changed << slice; | |
|
19 | } | |
|
20 | ||
|
21 | void QPieSeries::ChangeSet::appendRemoved(QPieSlice* slice) | |
|
17 | 22 | { |
|
23 | if (!m_removed.contains(slice)) | |
|
24 | m_removed << slice; | |
|
25 | } | |
|
18 | 26 | |
|
27 | QList<QPieSlice*> QPieSeries::ChangeSet::added() const | |
|
28 | { | |
|
29 | return m_added; | |
|
19 | 30 | } |
|
20 | 31 | |
|
21 | bool QPieSeries::setData(QList<qreal> data) | |
|
32 | QList<QPieSlice*> QPieSeries::ChangeSet::changed() const | |
|
22 | 33 | { |
|
23 | // TODO: remove this function | |
|
24 | QList<QPieSlice> slices; | |
|
25 | foreach (int value, data) | |
|
26 | slices << QPieSlice(value, QString::number(value)); | |
|
27 | return set(slices); | |
|
34 | return m_changed; | |
|
28 | 35 | } |
|
29 | 36 | |
|
30 | bool QPieSeries::set(const QList<QPieSlice>& slices) | |
|
37 | QList<QPieSlice*> QPieSeries::ChangeSet::removed() const | |
|
31 | 38 | { |
|
32 | if (!slices.count()) | |
|
39 | return m_removed; | |
|
40 | } | |
|
41 | ||
|
42 | bool QPieSeries::ChangeSet::isEmpty() const | |
|
43 | { | |
|
44 | if (m_added.count() || m_changed.count() || m_removed.count()) | |
|
33 | 45 | return false; |
|
46 | return true; | |
|
47 | } | |
|
34 | 48 | |
|
35 | ChangeSet changeSet; | |
|
36 | 49 | |
|
37 | foreach (QPieSlice s, m_slices.values()) | |
|
38 | changeSet.m_removed << s.id(); | |
|
50 | QPieSeries::QPieSeries(QObject *parent) : | |
|
51 | QChartSeries(parent), | |
|
52 | m_sizeFactor(1.0), | |
|
53 | m_position(PiePositionMaximized), | |
|
54 | m_pieStartAngle(0), | |
|
55 | m_pieSpan(360) | |
|
56 | { | |
|
39 | 57 | |
|
40 | m_slices.clear(); | |
|
58 | } | |
|
41 | 59 | |
|
42 | foreach (QPieSlice s, slices) { | |
|
43 | s.m_id = generateSliceId(); | |
|
44 | m_slices.insert(s.id(), s); | |
|
45 | changeSet.m_added << s.id(); | |
|
46 | } | |
|
60 | QPieSeries::~QPieSeries() | |
|
61 | { | |
|
47 | 62 | |
|
48 | updateDerivativeData(); | |
|
49 | emit changed(changeSet); | |
|
63 | } | |
|
50 | 64 | |
|
65 | bool QPieSeries::setData(QList<qreal> data) | |
|
66 | { | |
|
67 | // TODO: remove this function | |
|
68 | QList<QPieSlice*> slices; | |
|
69 | foreach (int value, data) | |
|
70 | slices << new QPieSlice(value, QString::number(value)); | |
|
71 | set(slices); | |
|
51 | 72 | return true; |
|
52 | 73 | } |
|
53 | 74 | |
|
54 |
|
|
|
75 | void QPieSeries::set(QList<QPieSlice*> slices) | |
|
55 | 76 | { |
|
56 | if (!slices.count()) | |
|
57 | return false; | |
|
77 | clear(); | |
|
78 | add(slices); | |
|
79 | } | |
|
58 | 80 | |
|
81 | void QPieSeries::add(QList<QPieSlice*> slices) | |
|
82 | { | |
|
59 | 83 | ChangeSet changeSet; |
|
60 | foreach (QPieSlice s, slices) { | |
|
61 | s.m_id = generateSliceId(); | |
|
62 |
m_slices |
|
|
63 |
changeSet. |
|
|
84 | foreach (QPieSlice* s, slices) { | |
|
85 | s->setParent(this); | |
|
86 | m_slices << s; | |
|
87 | changeSet.appendAdded(s); | |
|
64 | 88 | } |
|
65 | 89 | |
|
66 | 90 | updateDerivativeData(); |
|
67 | emit changed(changeSet); | |
|
68 | 91 | |
|
69 | return true; | |
|
92 | foreach (QPieSlice* s, slices) { | |
|
93 | connect(s, SIGNAL(changed()), this, SLOT(sliceChanged())); | |
|
94 | connect(s, SIGNAL(clicked()), this, SLOT(sliceClicked())); | |
|
95 | connect(s, SIGNAL(hoverEnter()), this, SLOT(sliceHoverEnter())); | |
|
96 | connect(s, SIGNAL(hoverLeave()), this, SLOT(sliceHoverLeave())); | |
|
97 | } | |
|
98 | ||
|
99 | emit changed(changeSet); | |
|
70 | 100 | } |
|
71 | 101 | |
|
72 |
|
|
|
102 | void QPieSeries::add(QPieSlice* slice) | |
|
73 | 103 | { |
|
74 |
|
|
|
104 | add(QList<QPieSlice*>() << slice); | |
|
75 | 105 | } |
|
76 | 106 | |
|
77 | bool QPieSeries::update(const QPieSlice& slice) | |
|
107 | QPieSlice* QPieSeries::add(qreal value, QString name) | |
|
78 | 108 | { |
|
79 | if (!m_slices.contains(slice.id())) | |
|
80 | return false; // series does not contain this slice | |
|
109 | QPieSlice* slice = new QPieSlice(value, name); | |
|
110 | add(slice); | |
|
111 | return slice; | |
|
112 | } | |
|
81 | 113 | |
|
82 | m_slices[slice.id()] = slice; | |
|
114 | void QPieSeries::remove(QPieSlice* slice) | |
|
115 | { | |
|
116 | if (!m_slices.removeOne(slice)) { | |
|
117 | Q_ASSERT(0); // TODO: remove before release | |
|
118 | return; | |
|
119 | } | |
|
83 | 120 | |
|
84 | 121 | ChangeSet changeSet; |
|
85 |
changeSet. |
|
|
86 | updateDerivativeData(); | |
|
122 | changeSet.appendRemoved(slice); | |
|
87 | 123 | emit changed(changeSet); |
|
88 | 124 | |
|
89 | return true; | |
|
125 | delete slice; | |
|
126 | slice = NULL; | |
|
127 | ||
|
128 | updateDerivativeData(); | |
|
90 | 129 | } |
|
91 | 130 | |
|
92 | bool QPieSeries::remove(QPieSliceId id) | |
|
131 | void QPieSeries::clear() | |
|
93 | 132 | { |
|
94 |
if ( |
|
|
95 | return false; // series does not contain this slice | |
|
96 | ||
|
97 | m_slices.remove(id); | |
|
133 | if (m_slices.count() == 0) | |
|
134 | return; | |
|
98 | 135 | |
|
99 | 136 | ChangeSet changeSet; |
|
100 | changeSet.m_removed << id; | |
|
101 | updateDerivativeData(); | |
|
137 | foreach (QPieSlice* s, m_slices) { | |
|
138 | changeSet.appendRemoved(s); | |
|
139 | m_slices.removeOne(s); | |
|
140 | delete s; | |
|
141 | } | |
|
102 | 142 | emit changed(changeSet); |
|
103 | ||
|
104 | return true; | |
|
105 | } | |
|
106 | ||
|
107 | QPieSlice QPieSeries::slice(QPieSliceId id) const | |
|
108 | { | |
|
109 | return m_slices.value(id); | |
|
143 | updateDerivativeData(); | |
|
110 | 144 | } |
|
111 | 145 | |
|
112 | 146 | void QPieSeries::setSizeFactor(qreal factor) |
|
113 | 147 | { |
|
114 | 148 | if (factor < 0.0) |
|
115 | 149 | return; |
|
116 | 150 | |
|
117 | 151 | if (m_sizeFactor != factor) { |
|
118 | 152 | m_sizeFactor = factor; |
|
119 | 153 | emit sizeFactorChanged(); |
|
120 | 154 | } |
|
121 | 155 | } |
|
122 | 156 | |
|
123 | 157 | void QPieSeries::setPosition(PiePosition position) |
|
124 | 158 | { |
|
125 | 159 | if (m_position != position) { |
|
126 | 160 | m_position = position; |
|
127 | 161 | emit positionChanged(); |
|
128 | 162 | } |
|
129 | 163 | } |
|
130 | 164 | |
|
131 | QPieSliceId QPieSeries::generateSliceId() | |
|
165 | void QPieSeries::setSpan(qreal startAngle, qreal span) | |
|
166 | { | |
|
167 | if (startAngle >= 0 && startAngle < 360 && | |
|
168 | span > 0 && span <= 360) { | |
|
169 | m_pieStartAngle = startAngle; | |
|
170 | m_pieSpan = span; | |
|
171 | updateDerivativeData(); | |
|
172 | } | |
|
173 | } | |
|
174 | ||
|
175 | void QPieSeries::setLabelsVisible(bool visible) | |
|
176 | { | |
|
177 | foreach (QPieSlice* s, m_slices) | |
|
178 | s->setLabelVisible(visible); | |
|
179 | } | |
|
180 | ||
|
181 | void QPieSeries::enableClickExplodes(bool enable) | |
|
132 | 182 | { |
|
133 | // Id is quint64 so it should be enough for us. | |
|
134 | // Note that id is not unique between pie series. | |
|
135 | return m_sliceIdSeed++; | |
|
183 | if (enable) | |
|
184 | connect(this, SIGNAL(clicked(QPieSlice*)), this, SLOT(toggleExploded(QPieSlice*))); | |
|
185 | else | |
|
186 | disconnect(this, SLOT(toggleExploded(QPieSlice*))); | |
|
187 | } | |
|
188 | ||
|
189 | void QPieSeries::enableHoverHighlight(bool enable) | |
|
190 | { | |
|
191 | if (enable) { | |
|
192 | connect(this, SIGNAL(hoverEnter(QPieSlice*)), this, SLOT(highlightOn(QPieSlice*))); | |
|
193 | connect(this, SIGNAL(hoverLeave(QPieSlice*)), this, SLOT(highlightOff(QPieSlice*))); | |
|
194 | } else { | |
|
195 | disconnect(this, SLOT(hoverEnter(QPieSlice*))); | |
|
196 | disconnect(this, SLOT(hoverLeave(QPieSlice*))); | |
|
197 | } | |
|
198 | } | |
|
199 | ||
|
200 | void QPieSeries::sliceChanged() | |
|
201 | { | |
|
202 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
203 | Q_ASSERT(m_slices.contains(slice)); | |
|
204 | ||
|
205 | ChangeSet changeSet; | |
|
206 | changeSet.appendChanged(slice); | |
|
207 | emit changed(changeSet); | |
|
208 | ||
|
209 | updateDerivativeData(); | |
|
210 | } | |
|
211 | ||
|
212 | void QPieSeries::sliceClicked() | |
|
213 | { | |
|
214 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
215 | Q_ASSERT(m_slices.contains(slice)); | |
|
216 | emit clicked(slice); | |
|
217 | } | |
|
218 | ||
|
219 | void QPieSeries::sliceHoverEnter() | |
|
220 | { | |
|
221 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
222 | Q_ASSERT(m_slices.contains(slice)); | |
|
223 | emit hoverEnter(slice); | |
|
224 | } | |
|
225 | ||
|
226 | void QPieSeries::sliceHoverLeave() | |
|
227 | { | |
|
228 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
|
229 | Q_ASSERT(m_slices.contains(slice)); | |
|
230 | emit hoverLeave(slice); | |
|
231 | } | |
|
232 | ||
|
233 | void QPieSeries::toggleExploded(QPieSlice* slice) | |
|
234 | { | |
|
235 | Q_ASSERT(slice); | |
|
236 | slice->setExploded(!slice->isExploded()); | |
|
237 | } | |
|
238 | ||
|
239 | void QPieSeries::highlightOn(QPieSlice* slice) | |
|
240 | { | |
|
241 | Q_ASSERT(slice); | |
|
242 | QColor c = slice->brush().color().lighter(); | |
|
243 | slice->setBrush(c); | |
|
244 | } | |
|
245 | ||
|
246 | void QPieSeries::highlightOff(QPieSlice* slice) | |
|
247 | { | |
|
248 | Q_ASSERT(slice); | |
|
249 | QColor c = slice->brush().color().darker(150); | |
|
250 | slice->setBrush(c); | |
|
136 | 251 | } |
|
137 | 252 | |
|
138 | 253 | void QPieSeries::updateDerivativeData() |
|
139 | 254 | { |
|
140 | 255 | m_total = 0; |
|
141 | foreach (const QPieSlice& s, m_slices.values()) | |
|
142 | m_total += s.value(); | |
|
143 | 256 | |
|
144 | Q_ASSERT(m_total > 0); // TODO: remove this before release | |
|
257 | // nothing to do? | |
|
258 | if (m_slices.count() == 0) | |
|
259 | return; | |
|
260 | ||
|
261 | // calculate total | |
|
262 | foreach (QPieSlice* s, m_slices) | |
|
263 | m_total += s->value(); | |
|
264 | ||
|
265 | // we must have some values | |
|
266 | Q_ASSERT(m_total > 0); // TODO | |
|
145 | 267 | |
|
146 | foreach (QPieSliceId id, m_slices.keys()) | |
|
147 | m_slices[id].m_percentage = m_slices.value(id).value() / m_total; | |
|
268 | // update slice attributes | |
|
269 | qreal sliceAngle = m_pieStartAngle; | |
|
270 | foreach (QPieSlice* s, m_slices) { | |
|
271 | ||
|
272 | bool changed = false; | |
|
273 | ||
|
274 | qreal percentage = s->value() / m_total; | |
|
275 | if (s->m_percentage != percentage) { | |
|
276 | s->m_percentage = percentage; | |
|
277 | changed = true; | |
|
278 | } | |
|
279 | ||
|
280 | qreal sliceSpan = m_pieSpan * percentage; | |
|
281 | if (s->m_span != sliceSpan) { | |
|
282 | s->m_span = sliceSpan; | |
|
283 | changed = true; | |
|
284 | } | |
|
285 | ||
|
286 | if (s->m_angle != sliceAngle) { | |
|
287 | s->m_angle = sliceAngle; | |
|
288 | changed = true; | |
|
289 | } | |
|
290 | sliceAngle += sliceSpan; | |
|
291 | ||
|
292 | if (changed) | |
|
293 | emit s->changed(); | |
|
294 | } | |
|
148 | 295 | } |
|
149 | 296 | |
|
150 | 297 | #include "moc_qpieseries.cpp" |
|
151 | 298 | |
|
152 | 299 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,163 +1,127 | |||
|
1 | 1 | #ifndef PIESERIES_H |
|
2 | 2 | #define PIESERIES_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartseries.h" |
|
5 | 5 | #include <QObject> |
|
6 | 6 | #include <QRectF> |
|
7 | 7 | #include <QColor> |
|
8 | 8 | #include <QPen> |
|
9 | 9 | #include <QBrush> |
|
10 | #include <QSignalMapper> | |
|
10 | 11 | |
|
11 | 12 | class QGraphicsObject; |
|
12 | 13 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | 14 | class PiePresenter; |
|
14 | 15 | class PieSlice; |
|
15 | ||
|
16 | typedef quint64 QPieSliceId; | |
|
17 | ||
|
18 | class QPieSlice | |
|
19 | { | |
|
20 | public: | |
|
21 | QPieSlice() | |
|
22 | :m_id(-1), m_value(0), m_isLabelVisible(true), m_isExploded(false), m_percentage(0) {} | |
|
23 | ||
|
24 | QPieSlice(qreal value, QString label = QString(), bool labelVisible = true, bool exploded = false, QPen pen = QPen(), QBrush brush = QBrush()) | |
|
25 | :m_id(-1), m_value(value), m_label(label), m_isLabelVisible(labelVisible), m_isExploded(exploded), m_pen(pen), m_brush(brush), m_percentage(0) {} | |
|
26 | ||
|
27 | QPieSliceId id() const { return m_id; } | |
|
28 | ||
|
29 | void setValue(qreal value) { m_value = value; } | |
|
30 | qreal value() const { return m_value; } | |
|
31 | ||
|
32 | void setLabel(QString label) { m_label = label; } | |
|
33 | QString label() const { return m_label; } | |
|
34 | ||
|
35 | void setLabelVisible(bool visible) { m_isLabelVisible = visible; } | |
|
36 | bool isLabelVisible() const { return m_isLabelVisible; } | |
|
37 | ||
|
38 | // TODO: | |
|
39 | //void setLabelPen(QPen pen) {}; | |
|
40 | //QPen labelPen() const {}; | |
|
41 | //void setLabelFont(QFont font); | |
|
42 | //QFont labelFont() const; | |
|
43 | //void setLabelArmLenght(qreal len) {}; | |
|
44 | //qreal labelArmLenght() const {}; | |
|
45 | ||
|
46 | void setExploded(bool exploded) { m_isExploded = exploded; } | |
|
47 | bool isExploded() const { return m_isExploded; } | |
|
48 | ||
|
49 | void setPen(QPen pen) { m_pen = pen; } | |
|
50 | QPen pen() const { return m_pen; } | |
|
51 | ||
|
52 | void setBrush(QBrush brush) { m_brush = brush; } | |
|
53 | QBrush brush() const { return m_brush; } | |
|
54 | ||
|
55 | qreal percentage() const { return m_percentage; } | |
|
56 | ||
|
57 | private: | |
|
58 | ||
|
59 | // TODO: use private class | |
|
60 | friend class QPieSeries; | |
|
61 | ||
|
62 | QPieSliceId m_id; | |
|
63 | qreal m_value; | |
|
64 | QString m_label; | |
|
65 | bool m_isLabelVisible; | |
|
66 | bool m_isExploded; | |
|
67 | ||
|
68 | QPen m_pen; | |
|
69 | QBrush m_brush; | |
|
70 | ||
|
71 | qreal m_percentage; // generated content | |
|
72 | }; | |
|
16 | class QPieSlice; | |
|
73 | 17 | |
|
74 | 18 | class QTCOMMERCIALCHART_EXPORT QPieSeries : public QChartSeries |
|
75 | 19 | { |
|
76 | 20 | Q_OBJECT |
|
77 | 21 | |
|
78 | 22 | public: |
|
79 | 23 | enum PiePosition { |
|
80 | 24 | PiePositionMaximized = 0, |
|
81 | 25 | PiePositionTopLeft, |
|
82 | 26 | PiePositionTopRight, |
|
83 | 27 | PiePositionBottomLeft, |
|
84 | 28 | PiePositionBottomRight |
|
85 | 29 | }; |
|
86 | 30 | |
|
87 | 31 | class ChangeSet |
|
88 | 32 | { |
|
89 | 33 | public: |
|
90 | QList<QPieSliceId> m_added; | |
|
91 | QList<QPieSliceId> m_removed; | |
|
92 | QList<QPieSliceId> m_changed; | |
|
34 | void appendAdded(QPieSlice* slice); | |
|
35 | void appendChanged(QPieSlice* slice); | |
|
36 | void appendRemoved(QPieSlice* slice); | |
|
37 | ||
|
38 | QList<QPieSlice*> added() const; | |
|
39 | QList<QPieSlice*> changed() const; | |
|
40 | QList<QPieSlice*> removed() const; | |
|
41 | ||
|
42 | bool isEmpty() const; | |
|
43 | ||
|
44 | private: | |
|
45 | QList<QPieSlice*> m_added; | |
|
46 | QList<QPieSlice*> m_changed; | |
|
47 | QList<QPieSlice*> m_removed; | |
|
93 | 48 | }; |
|
94 | 49 | |
|
95 | 50 | public: |
|
96 | 51 | QPieSeries(QObject *parent = 0); |
|
97 | ~QPieSeries(); | |
|
52 | virtual ~QPieSeries(); | |
|
98 | 53 | |
|
99 | 54 | public: // from QChartSeries |
|
100 | 55 | QChartSeriesType type() const { return QChartSeries::SeriesTypePie; } |
|
101 | 56 | virtual bool setData(QList<qreal> data); // TODO: remove this |
|
102 | 57 | |
|
103 | 58 | public: |
|
104 | // TODO: should we return id/bool or what? | |
|
105 | // TODO: should we prefer passing a modifiable reference? | |
|
106 |
|
|
|
107 | bool add(const QList<QPieSlice>& slices); | |
|
108 |
|
|
|
109 | bool update(const QPieSlice& slice); | |
|
110 | bool remove(QPieSliceId id); | |
|
59 | void set(QList<QPieSlice*> slices); | |
|
60 | void add(QList<QPieSlice*> slices); | |
|
61 | void add(QPieSlice* slice); | |
|
62 | QPieSlice* add(qreal value, QString name); | |
|
63 | void remove(QPieSlice* slice); | |
|
64 | void clear(); | |
|
111 | 65 | |
|
112 | 66 | int count() const { return m_slices.count(); } |
|
113 | 67 | |
|
114 |
QList<QPieSlice> slices() const { return m_slices |
|
|
115 | QList<QPieSliceId> ids() const { return m_slices.keys(); } | |
|
116 | QPieSlice slice(QPieSliceId id) const; | |
|
68 | QList<QPieSlice*> slices() const { return m_slices; } | |
|
117 | 69 | |
|
118 |
// TODO: |
|
|
70 | // TODO: find slices? | |
|
71 | // QList<QPieSlice*> findByValue(qreal value); | |
|
72 | // ... | |
|
119 | 73 | |
|
120 |
// TODO: |
|
|
121 |
//void s |
|
|
122 | //void setLabel(QPieSliceId id, QString label); | |
|
123 | //void setPen(QPieSliceId id, QPen pen); | |
|
124 | //void setBrush(QPieSliceId id, QBrush brush); | |
|
125 | //void setExploded(QPieSliceId id, bool exploded); | |
|
74 | // TODO: sorting slices? | |
|
75 | // void sort(QPieSeries::SortByValue) | |
|
126 | 76 | |
|
127 | 77 | void setSizeFactor(qreal sizeFactor); |
|
128 | 78 | qreal sizeFactor() const { return m_sizeFactor; } |
|
129 | 79 | |
|
130 | 80 | void setPosition(PiePosition position); |
|
131 | 81 | PiePosition position() const { return m_position; } |
|
132 | 82 | |
|
83 | void setSpan(qreal startAngle, qreal span); | |
|
84 | ||
|
85 | void setLabelsVisible(bool visible); | |
|
86 | void enableClickExplodes(bool enable); | |
|
87 | void enableHoverHighlight(bool enable); | |
|
88 | ||
|
133 | 89 | Q_SIGNALS: |
|
134 | 90 | void changed(const QPieSeries::ChangeSet& changeSet); |
|
91 | void clicked(QPieSlice* slice); | |
|
92 | void hoverEnter(QPieSlice* slice); | |
|
93 | void hoverLeave(QPieSlice* slice); | |
|
135 | 94 | void sizeFactorChanged(); |
|
136 | 95 | void positionChanged(); |
|
137 | 96 | |
|
138 | // TODO: | |
|
139 |
|
|
|
140 | // ?? void sliceHoverEnter(QPieSliceId id); | |
|
141 |
|
|
|
97 | private Q_SLOTS: // should be private and not in the interface | |
|
98 | void sliceChanged(); | |
|
99 | void sliceClicked(); | |
|
100 | void sliceHoverEnter(); | |
|
101 | void sliceHoverLeave(); | |
|
102 | ||
|
103 | void toggleExploded(QPieSlice* slice); | |
|
104 | void highlightOn(QPieSlice* slice); | |
|
105 | void highlightOff(QPieSlice* slice); | |
|
142 | 106 | |
|
143 | 107 | private: |
|
144 | QPieSliceId generateSliceId(); | |
|
145 | 108 | void updateDerivativeData(); |
|
146 | 109 | |
|
147 | 110 | private: |
|
148 | 111 | Q_DISABLE_COPY(QPieSeries) |
|
149 | 112 | |
|
150 | 113 | // TODO: use PIML |
|
151 | 114 | friend class PiePresenter; |
|
152 | 115 | friend class PieSlice; |
|
153 | 116 | |
|
154 |
Q |
|
|
117 | QList<QPieSlice*> m_slices; | |
|
155 | 118 | qreal m_sizeFactor; |
|
156 | 119 | PiePosition m_position; |
|
157 | 120 | qreal m_total; |
|
158 | QPieSliceId m_sliceIdSeed; | |
|
121 | qreal m_pieStartAngle; | |
|
122 | qreal m_pieSpan; | |
|
159 | 123 | }; |
|
160 | 124 | |
|
161 | 125 | QTCOMMERCIALCHART_END_NAMESPACE |
|
162 | 126 | |
|
163 | 127 | #endif // PIESERIES_H |
@@ -1,209 +1,209 | |||
|
1 | 1 | #include "qchart.h" |
|
2 | #include "qscatterseries.h" | |
|
3 | #include "qscatterseries_p.h" | |
|
4 | #include "qpieseries.h" | |
|
5 | 2 | #include "qchartaxis.h" |
|
6 | 3 | #include "chartpresenter_p.h" |
|
7 | 4 | #include "chartdataset_p.h" |
|
8 | 5 | |
|
9 | 6 | //series |
|
10 | 7 | #include "barchartseries.h" |
|
11 | 8 | #include "stackedbarchartseries.h" |
|
12 | 9 | #include "percentbarchartseries.h" |
|
13 | 10 | #include "qlinechartseries.h" |
|
11 | #include "qscatterseries.h" | |
|
12 | //#include "scatterseries_p.h" | |
|
13 | #include "qpieseries.h" | |
|
14 | 14 | |
|
15 | 15 | #include <QGraphicsScene> |
|
16 | 16 | #include <QGraphicsSceneResizeEvent> |
|
17 | 17 | #include <QDebug> |
|
18 | 18 | |
|
19 | 19 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
20 | 20 | |
|
21 | 21 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
22 | 22 | m_backgroundItem(0), |
|
23 | 23 | m_titleItem(0), |
|
24 | 24 | m_dataset(new ChartDataSet(this)), |
|
25 | 25 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
26 | 26 | { |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | QChart::~QChart() {} |
|
30 | 30 | |
|
31 | 31 | void QChart::addSeries(QChartSeries* series) |
|
32 | 32 | { |
|
33 | 33 | m_dataset->addSeries(series); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | //TODO on review, is it really needed ?? |
|
37 | 37 | QChartSeries* QChart::createSeries(QChartSeries::QChartSeriesType type) |
|
38 | 38 | { |
|
39 | 39 | QChartSeries *series(0); |
|
40 | 40 | |
|
41 | 41 | switch (type) { |
|
42 | 42 | case QChartSeries::SeriesTypeLine: { |
|
43 | 43 | series = new QLineChartSeries(this); |
|
44 | 44 | break; |
|
45 | 45 | } |
|
46 | 46 | case QChartSeries::SeriesTypeBar: { |
|
47 | 47 | //series = new BarChartSeries(this); |
|
48 | 48 | break; |
|
49 | 49 | } |
|
50 | 50 | case QChartSeries::SeriesTypeStackedBar: { |
|
51 | 51 | //series = new StackedBarChartSeries(this); |
|
52 | 52 | break; |
|
53 | 53 | } |
|
54 | 54 | case QChartSeries::SeriesTypePercentBar: { |
|
55 | 55 | //series = new PercentBarChartSeries(this); |
|
56 | 56 | break; |
|
57 | 57 | } |
|
58 | 58 | case QChartSeries::SeriesTypeScatter: { |
|
59 | 59 | series = new QScatterSeries(this); |
|
60 | 60 | break; |
|
61 | 61 | } |
|
62 | 62 | case QChartSeries::SeriesTypePie: { |
|
63 | 63 | series = new QPieSeries(this); |
|
64 | 64 | break; |
|
65 | 65 | } |
|
66 | 66 | default: |
|
67 | 67 | Q_ASSERT(false); |
|
68 | 68 | break; |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | addSeries(series); |
|
72 | 72 | return series; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
76 | 76 | { |
|
77 | 77 | |
|
78 | 78 | if(!m_backgroundItem) { |
|
79 | 79 | m_backgroundItem = new QGraphicsRectItem(this); |
|
80 | 80 | m_backgroundItem->setZValue(-1); |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | m_backgroundItem->setBrush(brush); |
|
84 | 84 | m_backgroundItem->update(); |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
88 | 88 | { |
|
89 | 89 | |
|
90 | 90 | if(!m_backgroundItem) { |
|
91 | 91 | m_backgroundItem = new QGraphicsRectItem(this); |
|
92 | 92 | m_backgroundItem->setZValue(-1); |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | m_backgroundItem->setPen(pen); |
|
96 | 96 | m_backgroundItem->update(); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void QChart::setChartTitle(const QString& title) |
|
100 | 100 | { |
|
101 | 101 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
102 | 102 | m_titleItem->setPlainText(title); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | void QChart::setChartTitleFont(const QFont& font) |
|
106 | 106 | { |
|
107 | 107 | if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this); |
|
108 | 108 | m_titleItem->setFont(font); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | int QChart::margin() const |
|
112 | 112 | { |
|
113 | 113 | return m_presenter->margin(); |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | void QChart::setMargin(int margin) |
|
117 | 117 | { |
|
118 | 118 | m_presenter->setMargin(margin); |
|
119 | 119 | } |
|
120 | 120 | |
|
121 | 121 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
122 | 122 | { |
|
123 | 123 | m_presenter->setChartTheme(theme); |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | QChart::ChartTheme QChart::chartTheme() const |
|
127 | 127 | { |
|
128 | 128 | return m_presenter->chartTheme(); |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | void QChart::zoomInToRect(const QRectF& rectangle) |
|
132 | 132 | { |
|
133 | 133 | m_presenter->zoomInToRect(rectangle); |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | void QChart::zoomIn() |
|
137 | 137 | { |
|
138 | 138 | m_presenter->zoomIn(); |
|
139 | 139 | } |
|
140 | 140 | |
|
141 | 141 | void QChart::zoomOut() |
|
142 | 142 | { |
|
143 | 143 | m_presenter->zoomOut(); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | void QChart::zoomReset() |
|
147 | 147 | { |
|
148 | 148 | m_presenter->zoomReset(); |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | void QChart::setDefaultAxisX(const QChartAxis& axis) |
|
152 | 152 | { |
|
153 | 153 | m_presenter->setDefaultAxisX(axis); |
|
154 | 154 | } |
|
155 | 155 | |
|
156 | 156 | void QChart::setDefaultAxisY(const QChartAxis& axis) |
|
157 | 157 | { |
|
158 | 158 | m_presenter->setDefaultAxisY(axis); |
|
159 | 159 | } |
|
160 | 160 | |
|
161 | 161 | QChartAxis QChart::defaultAxisX() const |
|
162 | 162 | { |
|
163 | 163 | return m_presenter->defaultAxisX(); |
|
164 | 164 | } |
|
165 | 165 | |
|
166 | 166 | QChartAxis QChart::defaultAxisY() const |
|
167 | 167 | { |
|
168 | 168 | return m_presenter->defaultAxisY(); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | int QChart::addAxisY(const QChartAxis& axis) |
|
172 | 172 | { |
|
173 | 173 | return m_presenter->addAxisY(axis); |
|
174 | 174 | } |
|
175 | 175 | |
|
176 | 176 | QChartAxis QChart::axisY(int id) const |
|
177 | 177 | { |
|
178 | 178 | return m_presenter->axisY(id); |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | void QChart::removeAxisY(int id) |
|
182 | 182 | { |
|
183 | 183 | m_presenter->removeAxisY(id); |
|
184 | 184 | } |
|
185 | 185 | |
|
186 | 186 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
187 | 187 | { |
|
188 | 188 | |
|
189 | 189 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
190 | 190 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
191 | 191 | |
|
192 | 192 | // recalculate title position |
|
193 | 193 | if (m_titleItem) { |
|
194 | 194 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
195 | 195 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
196 | 196 | } |
|
197 | 197 | |
|
198 | 198 | //recalculate background gradient |
|
199 | 199 | if (m_backgroundItem) { |
|
200 | 200 | m_backgroundItem->setRect(rect); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | QGraphicsWidget::resizeEvent(event); |
|
204 | 204 | update(); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | #include "moc_qchart.cpp" |
|
208 | 208 | |
|
209 | 209 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,241 +1,241 | |||
|
1 | 1 | #include "qchartview.h" |
|
2 | 2 | #include "qchart.h" |
|
3 | 3 | #include "qchartaxis.h" |
|
4 | 4 | #include <QGraphicsView> |
|
5 | 5 | #include <QGraphicsScene> |
|
6 | 6 | #include <QRubberBand> |
|
7 | 7 | #include <QResizeEvent> |
|
8 | 8 | #include <QDebug> |
|
9 | 9 | |
|
10 | 10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
11 | 11 | |
|
12 | 12 | QChartView::QChartView(QWidget *parent) : |
|
13 | 13 | QGraphicsView(parent), |
|
14 | m_scene(new QGraphicsScene()), | |
|
14 | m_scene(new QGraphicsScene(this)), | |
|
15 | 15 | m_chart(new QChart()), |
|
16 | 16 | m_rubberBand(0), |
|
17 | 17 | m_verticalRubberBand(false), |
|
18 | 18 | m_horizonalRubberBand(false) |
|
19 | 19 | { |
|
20 | 20 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
21 | 21 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
22 | 22 | setScene(m_scene); |
|
23 | 23 | m_chart->setMargin(50); |
|
24 | 24 | m_scene->addItem(m_chart); |
|
25 | 25 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | QChartView::~QChartView() |
|
29 | 29 | { |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | void QChartView::resizeEvent(QResizeEvent *event) |
|
33 | 33 | { |
|
34 | 34 | m_scene->setSceneRect(0,0,size().width(),size().height()); |
|
35 | 35 | m_chart->resize(size()); |
|
36 | 36 | QWidget::resizeEvent(event); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void QChartView::addSeries(QChartSeries* series) |
|
40 | 40 | { |
|
41 | 41 | m_chart->addSeries(series); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | QChartSeries* QChartView::createSeries(QChartSeries::QChartSeriesType type) |
|
45 | 45 | { |
|
46 | 46 | |
|
47 | 47 | return m_chart->createSeries(type); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | void QChartView::zoomInToRect(const QRect& rectangle) |
|
51 | 51 | { |
|
52 | 52 | m_chart->zoomInToRect(rectangle); |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | void QChartView::zoomIn() |
|
56 | 56 | { |
|
57 | 57 | m_chart->zoomIn(); |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | void QChartView::zoomOut() |
|
61 | 61 | { |
|
62 | 62 | m_chart->zoomOut(); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | int QChartView::margin() const |
|
66 | 66 | { |
|
67 | 67 | return m_chart->margin(); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void QChartView::setChartTitle(const QString& title) |
|
71 | 71 | { |
|
72 | 72 | m_chart->setChartTitle(title); |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | void QChartView::setChartTitleFont(const QFont& font) |
|
76 | 76 | { |
|
77 | 77 | m_chart->setChartTitleFont(font); |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void QChartView::setChartBackgroundBrush(const QBrush& brush) |
|
81 | 81 | { |
|
82 | 82 | m_chart->setChartBackgroundBrush(brush); |
|
83 | 83 | } |
|
84 | 84 | void QChartView::setChartBackgroundPen(const QPen& pen) |
|
85 | 85 | { |
|
86 | 86 | m_chart->setChartBackgroundPen(pen); |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | void QChartView::setRubberBandPolicy(const RubberBandPolicy policy) |
|
90 | 90 | { |
|
91 | 91 | switch(policy) { |
|
92 | 92 | case VerticalRubberBand: |
|
93 | 93 | m_verticalRubberBand = true; |
|
94 | 94 | m_horizonalRubberBand = false; |
|
95 | 95 | break; |
|
96 | 96 | case HorizonalRubberBand: |
|
97 | 97 | m_verticalRubberBand = false; |
|
98 | 98 | m_horizonalRubberBand = true; |
|
99 | 99 | break; |
|
100 | 100 | case RectangleRubberBand: |
|
101 | 101 | m_verticalRubberBand = true; |
|
102 | 102 | m_horizonalRubberBand = true; |
|
103 | 103 | break; |
|
104 | 104 | case NoRubberBand: |
|
105 | 105 | default: |
|
106 | 106 | delete m_rubberBand; |
|
107 | 107 | m_rubberBand=0; |
|
108 | 108 | m_horizonalRubberBand = false; |
|
109 | 109 | m_verticalRubberBand = false; |
|
110 | 110 | return; |
|
111 | 111 | } |
|
112 | 112 | if(!m_rubberBand) { |
|
113 | 113 | m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
114 | 114 | m_rubberBand->setEnabled(true); |
|
115 | 115 | } |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const |
|
119 | 119 | { |
|
120 | 120 | if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand; |
|
121 | 121 | if(m_horizonalRubberBand) return HorizonalRubberBand; |
|
122 | 122 | if(m_verticalRubberBand) return VerticalRubberBand; |
|
123 | 123 | return NoRubberBand; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
127 | 127 | { |
|
128 | 128 | if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
129 | 129 | |
|
130 | 130 | int margin = m_chart->margin(); |
|
131 | 131 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
132 | 132 | |
|
133 | 133 | if (rect.contains(event->pos())) { |
|
134 | 134 | m_rubberBandOrigin = event->pos(); |
|
135 | 135 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize())); |
|
136 | 136 | m_rubberBand->show(); |
|
137 | 137 | event->accept(); |
|
138 | 138 | } |
|
139 | 139 | } |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
143 | 143 | { |
|
144 | 144 | if(m_rubberBand && m_rubberBand->isVisible()) { |
|
145 | 145 | int margin = m_chart->margin(); |
|
146 | 146 | QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin); |
|
147 | 147 | int width = event->pos().x() - m_rubberBandOrigin.x(); |
|
148 | 148 | int height = event->pos().y() - m_rubberBandOrigin.y(); |
|
149 | 149 | if(!m_verticalRubberBand) { |
|
150 | 150 | m_rubberBandOrigin.setY(rect.top()); |
|
151 | 151 | height = rect.height(); |
|
152 | 152 | } |
|
153 | 153 | if(!m_horizonalRubberBand) { |
|
154 | 154 | m_rubberBandOrigin.setX(rect.left()); |
|
155 | 155 | width= rect.width(); |
|
156 | 156 | } |
|
157 | 157 | m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized()); |
|
158 | 158 | } |
|
159 | 159 | else { |
|
160 | 160 | QGraphicsView::mouseMoveEvent(event); |
|
161 | 161 | } |
|
162 | 162 | } |
|
163 | 163 | |
|
164 | 164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
165 | 165 | { |
|
166 | 166 | if(m_rubberBand) { |
|
167 | 167 | if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) { |
|
168 | 168 | m_rubberBand->hide(); |
|
169 | 169 | QRect rect = m_rubberBand->geometry(); |
|
170 | 170 | m_chart->zoomInToRect(rect); |
|
171 | 171 | event->accept(); |
|
172 | 172 | } |
|
173 | 173 | |
|
174 | 174 | if(event->button()==Qt::RightButton) |
|
175 | 175 | m_chart->zoomReset(); |
|
176 | 176 | } |
|
177 | 177 | else { |
|
178 | 178 | QGraphicsView::mouseReleaseEvent(event); |
|
179 | 179 | } |
|
180 | 180 | } |
|
181 | 181 | |
|
182 | 182 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
183 | 183 | { |
|
184 | 184 | switch (event->key()) { |
|
185 | 185 | case Qt::Key_Plus: |
|
186 | 186 | zoomIn(); |
|
187 | 187 | break; |
|
188 | 188 | case Qt::Key_Minus: |
|
189 | 189 | zoomOut(); |
|
190 | 190 | break; |
|
191 | 191 | default: |
|
192 | 192 | QGraphicsView::keyPressEvent(event); |
|
193 | 193 | break; |
|
194 | 194 | } |
|
195 | 195 | } |
|
196 | 196 | |
|
197 | 197 | void QChartView::setChartTheme(QChart::ChartTheme theme) |
|
198 | 198 | { |
|
199 | 199 | m_chart->setChartTheme(theme); |
|
200 | 200 | } |
|
201 | 201 | |
|
202 | 202 | QChart::ChartTheme QChartView::chartTheme() const |
|
203 | 203 | { |
|
204 | 204 | return m_chart->chartTheme(); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | void QChartView::setDefaultAxisX(const QChartAxis& axis) |
|
208 | 208 | { |
|
209 | 209 | m_chart->setDefaultAxisX(axis); |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | void QChartView::setDefaultAxisY(const QChartAxis& axis) |
|
213 | 213 | { |
|
214 | 214 | m_chart->setDefaultAxisY(axis); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | QChartAxis QChartView::defaultAxisX() const |
|
218 | 218 | { |
|
219 | 219 | return m_chart->defaultAxisX(); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 | 222 | QChartAxis QChartView::defaultAxisY() const |
|
223 | 223 | { |
|
224 | 224 | return m_chart->defaultAxisY(); |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | int QChartView::addAxisY(const QChartAxis& axis) |
|
228 | 228 | { |
|
229 | 229 | return m_chart->addAxisY(axis); |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | QChartAxis QChartView::axisY(int id) const |
|
233 | 233 | { |
|
234 | 234 | return m_chart->axisY(id); |
|
235 | 235 | } |
|
236 | 236 | |
|
237 | 237 | void QChartView::removeAxisY(int id) |
|
238 | 238 | { |
|
239 | 239 | m_chart->removeAxisY(id); |
|
240 | 240 | } |
|
241 | 241 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,78 +1,78 | |||
|
1 | 1 | #ifndef QCHARTWIDGET_H |
|
2 | 2 | #define QCHARTWIDGET_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchartseries.h" |
|
6 | 6 | #include "qchart.h" |
|
7 | 7 | #include <QGraphicsView> |
|
8 | 8 | |
|
9 | 9 | class QGraphicsScene; |
|
10 | 10 | class QRubberBand; |
|
11 | 11 | |
|
12 | 12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
13 | 13 | |
|
14 | 14 | class QChart; |
|
15 | 15 | |
|
16 | 16 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
17 | 17 | { |
|
18 | 18 | public: |
|
19 | 19 | enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand }; |
|
20 | 20 | |
|
21 | 21 | explicit QChartView(QWidget *parent = 0); |
|
22 | 22 | ~QChartView(); |
|
23 | 23 | |
|
24 | 24 | //implement from QWidget |
|
25 | 25 | void resizeEvent(QResizeEvent *event); |
|
26 | 26 | |
|
27 | void addSeries(QChartSeries* series); | |
|
27 | void addSeries(QChartSeries* series); // takes ownership | |
|
28 | 28 | |
|
29 | 29 | // Convenience function |
|
30 | 30 | QChartSeries* createSeries(QChartSeries::QChartSeriesType type); |
|
31 | 31 | |
|
32 | 32 | int margin() const; |
|
33 | 33 | |
|
34 | 34 | void setChartTitle(const QString& title); |
|
35 | 35 | void setChartTitleFont(const QFont& font); |
|
36 | 36 | void setChartBackgroundBrush(const QBrush& brush); |
|
37 | 37 | void setChartBackgroundPen(const QPen& pen); |
|
38 | 38 | |
|
39 | 39 | void zoomInToRect(const QRect& rectangle); |
|
40 | 40 | void zoomIn(); |
|
41 | 41 | void zoomOut(); |
|
42 | 42 | |
|
43 | 43 | void setRubberBandPolicy(const RubberBandPolicy ); |
|
44 | 44 | RubberBandPolicy rubberBandPolicy() const; |
|
45 | 45 | |
|
46 | 46 | void setChartTheme(QChart::ChartTheme theme); |
|
47 | 47 | QChart::ChartTheme chartTheme() const; |
|
48 | 48 | |
|
49 | 49 | void setDefaultAxisX(const QChartAxis& axis); |
|
50 | 50 | void setDefaultAxisY(const QChartAxis& axis); |
|
51 | 51 | QChartAxis defaultAxisX() const; |
|
52 | 52 | QChartAxis defaultAxisY() const; |
|
53 | 53 | QChartAxis axisY(int id) const; |
|
54 | 54 | int addAxisY(const QChartAxis& axis); |
|
55 | 55 | void removeAxisY(int id); |
|
56 | 56 | |
|
57 | 57 | protected: |
|
58 | 58 | void mousePressEvent(QMouseEvent *event); |
|
59 | 59 | void mouseMoveEvent(QMouseEvent *event); |
|
60 | 60 | void mouseReleaseEvent(QMouseEvent *event); |
|
61 | 61 | void keyPressEvent(QKeyEvent *event); |
|
62 | 62 | |
|
63 | 63 | |
|
64 | 64 | private: |
|
65 | 65 | QGraphicsScene *m_scene; |
|
66 | 66 | QChart* m_chart; |
|
67 | 67 | QPoint m_rubberBandOrigin; |
|
68 | 68 | QRubberBand* m_rubberBand; |
|
69 | 69 | bool m_verticalRubberBand; |
|
70 | 70 | bool m_horizonalRubberBand; |
|
71 | 71 | Q_DISABLE_COPY(QChartView) |
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | }; |
|
75 | 75 | |
|
76 | 76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
77 | 77 | |
|
78 | 78 | #endif // QCHARTWIDGET_H |
@@ -1,59 +1,85 | |||
|
1 | 1 | #include "qscatterseries.h" |
|
2 |
#include " |
|
|
2 | #include "scatterseries_p.h" | |
|
3 | 3 | #include "qchart.h" |
|
4 | 4 | |
|
5 | 5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | 6 | |
|
7 | 7 | QScatterSeriesPrivate::QScatterSeriesPrivate() : |
|
8 | m_data(QList<QPointF>()) | |
|
8 | m_data(QList<QPointF>()), | |
|
9 | m_markerPen(QPen()), | |
|
10 | m_markerBrush(QBrush()), | |
|
11 | m_markerShape(QScatterSeries::MarkerShapeDefault) | |
|
9 | 12 | { |
|
13 | // Initialize pen color to invalid to use a theme color by default | |
|
14 | m_markerPen.setColor(QColor::Invalid); | |
|
15 | m_markerBrush.setColor(QColor::Invalid); | |
|
10 | 16 | } |
|
11 | 17 | |
|
12 | 18 | QScatterSeries::QScatterSeries(QObject *parent) : |
|
13 | 19 | QChartSeries(parent), |
|
14 | 20 | d(new QScatterSeriesPrivate()) |
|
15 | 21 | { |
|
16 | 22 | } |
|
17 | 23 | |
|
18 | 24 | QScatterSeries::~QScatterSeries() |
|
19 | 25 | { |
|
20 | 26 | delete d; |
|
21 | 27 | } |
|
22 | 28 | |
|
23 | 29 | void QScatterSeries::addData(QPointF value) |
|
24 | 30 | { |
|
25 | 31 | d->m_data.append(value); |
|
26 | 32 | emit changed(); |
|
27 | 33 | } |
|
28 | 34 | |
|
29 | 35 | QScatterSeries& QScatterSeries::operator << (const QPointF &value) |
|
30 | 36 | { |
|
31 | 37 | d->m_data.append(value); |
|
32 | 38 | emit changed(); |
|
33 | 39 | return *this; |
|
34 | 40 | } |
|
35 | 41 | |
|
36 | 42 | void QScatterSeries::setData(QList<QPointF> data) |
|
37 | 43 | { |
|
38 | 44 | d->m_data = data; |
|
39 | 45 | emit changed(); |
|
40 | 46 | } |
|
41 | 47 | |
|
42 | 48 | QList<QPointF> QScatterSeries::data() |
|
43 | 49 | { |
|
44 | 50 | return d->m_data; |
|
45 | 51 | } |
|
46 | 52 | |
|
47 | 53 | void QScatterSeries::setMarkerPen(QPen pen) |
|
48 | 54 | { |
|
49 | 55 | d->m_markerPen = pen; |
|
50 | 56 | } |
|
51 | 57 | |
|
52 | 58 | QPen QScatterSeries::markerPen() |
|
53 | 59 | { |
|
54 | 60 | return d->m_markerPen; |
|
55 | 61 | } |
|
56 | 62 | |
|
63 | void QScatterSeries::setMarkerBrush(QBrush brush) | |
|
64 | { | |
|
65 | d->m_markerBrush = brush; | |
|
66 | } | |
|
67 | ||
|
68 | QBrush QScatterSeries::markerBrush() | |
|
69 | { | |
|
70 | return d->m_markerBrush; | |
|
71 | } | |
|
72 | ||
|
73 | void QScatterSeries::setMarkerShape(MarkerShape shape) | |
|
74 | { | |
|
75 | d->m_markerShape = shape; | |
|
76 | } | |
|
77 | ||
|
78 | QScatterSeries::MarkerShape QScatterSeries::markerShape() | |
|
79 | { | |
|
80 | return (QScatterSeries::MarkerShape) d->m_markerShape; | |
|
81 | } | |
|
82 | ||
|
57 | 83 | #include "moc_qscatterseries.cpp" |
|
58 | 84 | |
|
59 | 85 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,66 | |||
|
1 | 1 | #ifndef QSCATTERSERIES_H |
|
2 | 2 | #define QSCATTERSERIES_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartseries.h" |
|
5 | 5 | #include <QRectF> |
|
6 | 6 | #include <QColor> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | class QScatterSeriesPrivate; |
|
10 | 10 | |
|
11 | 11 | class QTCOMMERCIALCHART_EXPORT QScatterSeries : public QChartSeries |
|
12 | 12 | { |
|
13 | 13 | Q_OBJECT |
|
14 | ||
|
15 | public: | |
|
16 | enum MarkerShape { | |
|
17 | // TODO: to be defined by the graphics design | |
|
18 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
|
19 | MarkerShapeDefault = 0, | |
|
20 | MarkerShapePoint, | |
|
21 | MarkerShapeX, | |
|
22 | MarkerShapeRectangle, | |
|
23 | MarkerShapeTiltedRectangle, | |
|
24 | MarkerShapeTriangle, | |
|
25 | MarkerShapeCircle | |
|
26 | }; | |
|
27 | ||
|
14 | 28 | public: |
|
15 | //QScatterSeries(QSeriesData *data, QObject *chart); | |
|
16 | 29 | QScatterSeries(QObject *parent = 0); |
|
17 | 30 | ~QScatterSeries(); |
|
18 | 31 | |
|
19 | 32 | public: // from QChartSeries |
|
20 | 33 | QChartSeriesType type() const { return QChartSeries::SeriesTypeScatter; } |
|
21 | 34 | |
|
22 | 35 | public: |
|
23 | 36 | // TODO: the name of the function? addPoint? addData? addValue? |
|
24 | 37 | void addData(QPointF value); |
|
25 | 38 | QScatterSeries& operator << (const QPointF &value); |
|
26 | 39 | void setData(QList<QPointF> data); |
|
27 | 40 | QList<QPointF> data(); |
|
28 | ||
|
29 | //TODO? void insertData(int index, QPointF data); | |
|
41 | //TODO: insertData? | |
|
30 | 42 | |
|
31 | 43 | void setMarkerPen(QPen pen); |
|
32 | 44 | QPen markerPen(); |
|
33 | // TODO: marker shapes: "x", star, rectangle, tilted rect, triangle, circle, dot | |
|
34 | //void setMarkerShape(MarkerShape shape); | |
|
45 | void setMarkerBrush(QBrush brush); | |
|
46 | QBrush markerBrush(); | |
|
47 | void setMarkerShape(MarkerShape shape); | |
|
48 | MarkerShape markerShape(); | |
|
49 | // TODO: marker size? | |
|
35 | 50 | |
|
36 | 51 | Q_SIGNALS: |
|
37 | // TODO: move to PIMPL? | |
|
52 | // TODO: move to PIMPL for simplicity or does the user ever need these signals? | |
|
38 | 53 | // TODO: more finegrained signaling for performance reasons |
|
54 | // (check QPieSeries implementation with change sets) | |
|
39 | 55 | void changed(); |
|
40 | 56 | |
|
41 | 57 | //public Q_SLOTS: |
|
42 | 58 | private: |
|
43 | 59 | Q_DECLARE_PRIVATE(QScatterSeries) |
|
44 | 60 | Q_DISABLE_COPY(QScatterSeries) |
|
45 | 61 | QScatterSeriesPrivate *const d; |
|
46 | 62 | }; |
|
47 | 63 | |
|
48 | 64 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | 65 | |
|
50 | 66 | #endif // QSCATTERSERIES_H |
@@ -1,94 +1,112 | |||
|
1 | #include "scatterpresenter.h" | |
|
1 | #include "scatterpresenter_p.h" | |
|
2 | 2 | #include "qscatterseries.h" |
|
3 | 3 | #include <QPen> |
|
4 | 4 | #include <QPainter> |
|
5 | 5 | #include <QGraphicsScene> |
|
6 | 6 | #include <QDebug> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
11 | 11 | ChartItem(parent), |
|
12 | 12 | m_series(series), |
|
13 | 13 | m_boundingRect(), |
|
14 | 14 | //m_markerColor(QColor()), |
|
15 | 15 | // m_markerColor(QColor(255, 0, 0)), |
|
16 | 16 | m_visibleChartArea() |
|
17 | 17 | { |
|
18 | 18 | if (parent) |
|
19 | 19 | m_boundingRect = parent->boundingRect(); |
|
20 | 20 | |
|
21 | 21 | if (series) { |
|
22 | 22 | connect(series, SIGNAL(changed()), this, SLOT(handleModelChanged())); |
|
23 | 23 | } |
|
24 | 24 | } |
|
25 | 25 | |
|
26 | 26 | void ScatterPresenter::handleDomainChanged(const Domain& domain) |
|
27 | 27 | { |
|
28 | 28 | m_visibleChartArea = domain; |
|
29 | 29 | changeGeometry(); |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | void ScatterPresenter::handleGeometryChanged(const QRectF& rect) |
|
33 | 33 | { |
|
34 | 34 | m_boundingRect = rect; |
|
35 | 35 | changeGeometry(); |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | void ScatterPresenter::handleModelChanged() |
|
39 | 39 | { |
|
40 | 40 | // TODO: more fine grained modelChanged signaling |
|
41 | 41 | changeGeometry(); |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | void ScatterPresenter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) |
|
45 | 45 | { |
|
46 | // TODO: The opacity should be user definable? | |
|
47 | //brush.setColor(QColor(255, 82, 0, 100)); | |
|
48 |
|
|
|
49 | if (false) { | |
|
50 | QPen pen = painter->pen(); | |
|
51 | QBrush brush = pen.brush(); | |
|
52 | brush.setColor(m_series->markerPen().color()); | |
|
53 |
p |
|
|
54 | pen.setWidth(4); | |
|
55 | painter->setPen(pen); | |
|
56 | } | |
|
57 | else { | |
|
58 | // TODO: fix this | |
|
59 | QPen pen = painter->pen(); | |
|
60 | QBrush brush = pen.brush(); | |
|
61 | brush.setColor(m_markerPen.color()); | |
|
62 | pen.setBrush(brush); | |
|
63 | pen.setWidth(4); | |
|
64 | painter->setPen(pen); | |
|
46 | // TODO: Optimization: avoid setting on every paint method call? | |
|
47 | // The custom settings in series override those defined by the theme | |
|
48 | if (m_series->markerPen().color().isValid()) { | |
|
49 | painter->setPen(m_series->markerPen()); | |
|
50 | painter->setBrush(m_series->markerBrush()); | |
|
51 | } else { | |
|
52 | painter->setPen(m_markerPen); | |
|
53 | painter->setBrush(m_markerBrush); | |
|
65 | 54 | } |
|
66 | 55 | |
|
56 | int shape = m_series->markerShape(); | |
|
57 | ||
|
67 | 58 | for (int i(0); i < m_scenex.count() && i < m_sceney.count(); i++) { |
|
68 | 59 | if (scene()->width() > m_scenex.at(i) && scene()->height() > m_sceney.at(i)) |
|
69 | //painter->drawArc(m_scenex.at(i), m_sceney.at(i), 2, 2, 0, 5760); | |
|
70 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
|
60 | // Paint a shape | |
|
61 | switch (shape) { | |
|
62 | case QScatterSeries::MarkerShapeDefault: | |
|
63 | // Fallthrough, defaults to circle | |
|
64 | case QScatterSeries::MarkerShapeCircle: | |
|
65 | painter->drawChord(m_scenex.at(i), m_sceney.at(i), 9, 9, 0, 5760); | |
|
66 | break; | |
|
67 | case QScatterSeries::MarkerShapePoint: | |
|
68 | painter->drawPoint(m_scenex.at(i), m_sceney.at(i)); | |
|
69 | break; | |
|
70 | case QScatterSeries::MarkerShapeRectangle: | |
|
71 | painter->drawRect(m_scenex.at(i), m_sceney.at(i), 9, 9); | |
|
72 | break; | |
|
73 | case QScatterSeries::MarkerShapeTiltedRectangle: { | |
|
74 | // TODO: | |
|
75 | static const QPointF points[4] = { | |
|
76 | QPointF(-1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |
|
77 | QPointF(0.0 + m_scenex.at(i), 1.0 + m_sceney.at(i)), | |
|
78 | QPointF(1.0 + m_scenex.at(i), 0.0 + m_sceney.at(i)), | |
|
79 | QPointF(0.0 + m_scenex.at(i), -1.0 + m_sceney.at(i)) | |
|
80 | }; | |
|
81 | painter->drawPolygon(points, 4); | |
|
82 | } | |
|
83 | break; | |
|
84 | default: | |
|
85 | // TODO: implement the rest of the shapes | |
|
86 | Q_ASSERT(false); | |
|
87 | break; | |
|
88 | } | |
|
71 | 89 | } |
|
72 | 90 | } |
|
73 | 91 | |
|
74 | 92 | void ScatterPresenter::changeGeometry() |
|
75 | 93 | { |
|
76 | 94 | if (m_boundingRect.isValid()) { |
|
77 | 95 | |
|
78 | 96 | prepareGeometryChange(); |
|
79 | 97 | qreal scalex = m_boundingRect.width() / m_visibleChartArea.spanX(); |
|
80 | 98 | qreal scaley = m_boundingRect.height() / m_visibleChartArea.spanY(); |
|
81 | 99 | m_scenex.clear(); |
|
82 | 100 | m_sceney.clear(); |
|
83 | 101 | |
|
84 | 102 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
85 | 103 | foreach (QPointF point, m_series->data()) { |
|
86 | 104 | m_scenex.append(m_boundingRect.left() + point.x() * scalex - m_visibleChartArea.m_minX * scalex); |
|
87 | 105 | m_sceney.append(m_boundingRect.bottom() - point.y() * scaley + m_visibleChartArea.m_minY * scaley); |
|
88 | 106 | } |
|
89 | 107 | } |
|
90 | 108 | } |
|
91 | 109 | |
|
92 | #include "moc_scatterpresenter.cpp" | |
|
110 | #include "moc_scatterpresenter_p.cpp" | |
|
93 | 111 | |
|
94 | 112 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,47 +1,48 | |||
|
1 | 1 | #ifndef SCATTERPRESENTER_H |
|
2 | 2 | #define SCATTERPRESENTER_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "chartitem_p.h" |
|
6 | 6 | #include <QObject> |
|
7 | 7 | #include <QPen> |
|
8 | 8 | |
|
9 | 9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | 10 | |
|
11 | 11 | class QScatterSeries; |
|
12 | 12 | |
|
13 | 13 | /*! |
|
14 | 14 | * The "business logic" of scatter series. This is a QObject that does not have a parent QObject. |
|
15 | 15 | * The QGraphicsItem parent owns the object instead. |
|
16 | 16 | */ |
|
17 | 17 | class ScatterPresenter : public QObject, public ChartItem |
|
18 | 18 | { |
|
19 | 19 | Q_OBJECT |
|
20 | 20 | public: |
|
21 | 21 | explicit ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent = 0); |
|
22 | 22 | |
|
23 | 23 | public: // from ChartItem |
|
24 | 24 | QRectF boundingRect() const { return m_boundingRect; } |
|
25 | 25 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
|
26 | 26 | |
|
27 | 27 | signals: |
|
28 | 28 | |
|
29 | 29 | public Q_SLOTS: |
|
30 | 30 | void handleDomainChanged(const Domain& domain); |
|
31 | 31 | void handleGeometryChanged(const QRectF& rect); |
|
32 | 32 | void handleModelChanged(); |
|
33 | 33 | |
|
34 | 34 | public: |
|
35 | 35 | void changeGeometry(); |
|
36 | 36 | |
|
37 | 37 | QScatterSeries *m_series; |
|
38 | 38 | QRectF m_boundingRect; |
|
39 | 39 | QList<qreal> m_scenex; |
|
40 | 40 | QList<qreal> m_sceney; |
|
41 | 41 | Domain m_visibleChartArea; |
|
42 | 42 | QPen m_markerPen; |
|
43 | QBrush m_markerBrush; | |
|
43 | 44 | }; |
|
44 | 45 | |
|
45 | 46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
46 | 47 | |
|
47 | 48 | #endif // SCATTERPRESENTER_H |
@@ -1,25 +1,27 | |||
|
1 | 1 | #ifndef QSCATTERSERIESPRIVATE_H |
|
2 | 2 | #define QSCATTERSERIESPRIVATE_H |
|
3 | 3 | |
|
4 | 4 | #include "qchartglobal.h" |
|
5 | 5 | #include "qchartseries.h" |
|
6 | 6 | #include <QPen> |
|
7 | 7 | |
|
8 | 8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | 9 | |
|
10 | 10 | /*! |
|
11 | 11 | * The PIMPL class of QScatterSeries. |
|
12 | 12 | */ |
|
13 | 13 | class QScatterSeriesPrivate |
|
14 | 14 | { |
|
15 | 15 | public: |
|
16 | 16 | QScatterSeriesPrivate(); |
|
17 | 17 | |
|
18 | 18 | public: |
|
19 | 19 | QList<QPointF> m_data; |
|
20 | 20 | QPen m_markerPen; |
|
21 | QBrush m_markerBrush; | |
|
22 | int m_markerShape; | |
|
21 | 23 | }; |
|
22 | 24 | |
|
23 | 25 | QTCOMMERCIALCHART_END_NAMESPACE |
|
24 | 26 | |
|
25 | 27 | #endif // QSCATTERSERIESPRIVATE_H |
@@ -1,116 +1,119 | |||
|
1 | 1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
2 | 2 | TARGET = QtCommercialChart |
|
3 | 3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
4 | 4 | TEMPLATE = lib |
|
5 | 5 | QT += core \ |
|
6 | 6 | gui |
|
7 | 7 | CONFIG += debug_and_release |
|
8 | 8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | 9 | SOURCES += barchart/barchartseries.cpp \ |
|
10 | 10 | barchart/bargroup.cpp \ |
|
11 | 11 | barchart/bar.cpp \ |
|
12 | 12 | barchart/stackedbarchartseries.cpp \ |
|
13 | 13 | barchart/stackedbargroup.cpp \ |
|
14 | 14 | barchart/percentbarchartseries.cpp \ |
|
15 | 15 | barchart/percentbargroup.cpp \ |
|
16 | 16 | barchart/barlabel.cpp \ |
|
17 | 17 | barchart/barchartmodel.cpp \ |
|
18 | 18 | barchart/separator.cpp \ |
|
19 | 19 | barchart/bargroupbase.cpp \ |
|
20 | 20 | barchart/qbarset.cpp \ |
|
21 | 21 | barchart/qbarcategory.cpp \ |
|
22 | 22 | linechart/linechartanimationitem.cpp \ |
|
23 | 23 | linechart/linechartitem.cpp \ |
|
24 | 24 | linechart/qlinechartseries.cpp \ |
|
25 | qscatterseries.cpp \ | |
|
26 | #scatterpresentation.cpp \ | |
|
27 | 25 | qchart.cpp \ |
|
28 | 26 | axisitem.cpp \ |
|
29 | 27 | qchartview.cpp \ |
|
30 | 28 | qchartseries.cpp \ |
|
31 | 29 | qchartaxis.cpp \ |
|
32 | 30 | charttheme.cpp \ |
|
33 | 31 | chartdataset.cpp \ |
|
34 | 32 | chartpresenter.cpp \ |
|
35 |
domain.cpp |
|
|
36 | scatterpresenter.cpp | |
|
33 | domain.cpp | |
|
37 | 34 | PRIVATE_HEADERS += linechart/linechartitem_p.h \ |
|
38 | 35 | linechart/linechartanimationitem_p.h \ |
|
39 | 36 | barchart/barlabel_p.h \ |
|
40 | 37 | barchart/bar_p.h \ |
|
41 | 38 | barchart/separator_p.h \ |
|
42 | 39 | barchart/barchartmodel_p.h \ |
|
43 | qscatterseries_p.h \ | |
|
44 | #scatterpresentation.h \ | |
|
45 | 40 | axisitem_p.h \ |
|
46 | 41 | chartitem_p.h \ |
|
47 | 42 | charttheme_p.h \ |
|
48 | 43 | chartdataset_p.h \ |
|
49 | 44 | chartpresenter_p.h \ |
|
50 | 45 | domain_p.h |
|
51 | 46 | PUBLIC_HEADERS += linechart/qlinechartseries.h \ |
|
52 | 47 | barchart/barchartseries.h \ |
|
53 | 48 | barchart/bargroup.h \ |
|
54 | 49 | barchart/stackedbarchartseries.h \ |
|
55 | 50 | barchart/stackedbargroup.h \ |
|
56 | 51 | barchart/percentbarchartseries.h \ |
|
57 | 52 | barchart/percentbargroup.h \ |
|
58 | 53 | barchart/bargroupbase.h \ |
|
59 | 54 | barchart/qbarset.h \ |
|
60 | 55 | barchart/qbarcategory.h \ |
|
61 | 56 | qchartseries.h \ |
|
62 | qscatterseries.h \ | |
|
63 | 57 | qchart.h \ |
|
64 | 58 | qchartglobal.h \ |
|
65 | 59 | qchartview.h \ |
|
66 | 60 | qchartaxis.h |
|
67 | 61 | |
|
68 | 62 | include(piechart/piechart.pri) |
|
69 | ||
|
63 | include(scatterseries/scatter.pri) | |
|
64 | ||
|
70 | 65 | THEMES += themes/chartthemeicy_p.h \ |
|
71 | 66 | themes/chartthemegrayscale_p.h \ |
|
72 | 67 | themes/chartthemescientific_p.h \ |
|
73 | 68 | themes/chartthemevanilla_p.h |
|
74 |
HEADERS += $$PUBLIC_HEADERS |
|
|
75 | scatterpresenter.h | |
|
69 | HEADERS += $$PUBLIC_HEADERS | |
|
76 | 70 | HEADERS += $$PRIVATE_HEADERS |
|
77 | 71 | HEADERS += $$THEMES |
|
78 | 72 | INCLUDEPATH += linechart \ |
|
79 | 73 | barchart \ |
|
80 | 74 | themes \ |
|
81 | 75 | . |
|
82 | 76 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
83 | 77 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
84 | 78 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
85 | 79 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
86 | 80 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
87 | 81 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
88 | 82 | public_headers.files = $$PUBLIC_HEADERS |
|
89 | 83 | target.path = $$[QT_INSTALL_LIBS] |
|
90 | 84 | INSTALLS += target \ |
|
91 | 85 | public_headers |
|
92 | install_build_headers.name = bild_headers | |
|
93 | install_build_headers.output = $$CHART_BUILD_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
|
94 | install_build_headers.input = PUBLIC_HEADERS | |
|
95 | install_build_headers.commands = $$QMAKE_COPY \ | |
|
86 | install_build_public_headers.name = bild_public_headers | |
|
87 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
|
88 | install_build_public_headers.input = PUBLIC_HEADERS | |
|
89 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
|
90 | ${QMAKE_FILE_NAME} \ | |
|
91 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
|
92 | install_build_public_headers.CONFIG += target_predeps \ | |
|
93 | no_link | |
|
94 | install_build_private_headers.name = bild_private_headers | |
|
95 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
|
96 | install_build_private_headers.input = PRIVATE_HEADERS | |
|
97 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
|
96 | 98 | ${QMAKE_FILE_NAME} \ |
|
97 | $$CHART_BUILD_HEADER_DIR | |
|
98 | install_build_headers.CONFIG += target_predeps \ | |
|
99 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
|
100 | install_build_private_headers.CONFIG += target_predeps \ | |
|
99 | 101 | no_link |
|
100 | QMAKE_EXTRA_COMPILERS += install_build_headers | |
|
102 | QMAKE_EXTRA_COMPILERS += install_build_public_headers install_build_private_headers | |
|
101 | 103 | chartversion.target = qchartversion_p.h |
|
102 | 104 | chartversion.commands = @echo \ |
|
103 | 105 | "build_time" \ |
|
104 | 106 | > \ |
|
105 | 107 | $$chartversion.target; |
|
106 | 108 | chartversion.depends = $$HEADERS \ |
|
107 | 109 | $$SOURCES |
|
108 | 110 | PRE_TARGETDEPS += qchartversion_p.h |
|
109 | 111 | QMAKE_CLEAN += qchartversion_p.h |
|
110 | 112 | QMAKE_EXTRA_TARGETS += chartversion |
|
111 | 113 | unix:QMAKE_DISTCLEAN += -r \ |
|
112 | 114 | $$CHART_BUILD_HEADER_DIR \ |
|
113 | 115 | $$CHART_BUILD_LIB_DIR |
|
114 | 116 | win32:QMAKE_DISTCLEAN += /Q \ |
|
115 | 117 | $$CHART_BUILD_HEADER_DIR \ |
|
116 | 118 | $$CHART_BUILD_LIB_DIR |
|
119 |
@@ -1,117 +1,96 | |||
|
1 | 1 | import QtQuick 1.0 |
|
2 | 2 | import QtCommercial.Chart 1.0 |
|
3 | 3 | |
|
4 | 4 | Rectangle { |
|
5 | 5 | width: 360 |
|
6 | 6 | height: 360 |
|
7 | Text { | |
|
8 | text: qsTr("Hello World") | |
|
9 | anchors.centerIn: parent | |
|
10 | } | |
|
11 | 7 | |
|
8 | // Another option for QML data api: | |
|
12 | 9 | // ListModel { |
|
13 | 10 | // id: listModelForPie |
|
14 | 11 | // // PieDataElement |
|
15 | 12 | // ListElement { |
|
16 | 13 | // label: "Apple" |
|
17 |
// value: 4 |
|
|
18 | // } | |
|
19 | // ListElement { | |
|
20 | // label: "Pumpkin" | |
|
21 | // value: 10.1 | |
|
14 | // value: 4.3 | |
|
22 | 15 | // } |
|
23 | 16 | // ListElement { |
|
24 |
// label: " |
|
|
17 | // label: "Blackberry" | |
|
25 | 18 | // value: 15.1 |
|
26 | 19 | // } |
|
27 | // ListElement { | |
|
28 | // label: "Strawberry" | |
|
29 | // value: 29.9 | |
|
30 | // } | |
|
31 | 20 | // } |
|
32 | 21 | |
|
33 | // ChartModel { | |
|
34 | // id: chartModel | |
|
35 | // ListElement { | |
|
36 | // label: "dada" | |
|
37 | // x: 1.1 | |
|
38 | // y: 3.2 | |
|
39 | // } | |
|
40 | // } | |
|
41 | ||
|
42 | // ChartModel { | |
|
43 | // ScatterElement {x: 1.1; y: 1.2} | |
|
44 | // ScatterElement {x: 1.3; y: 1.9} | |
|
45 | // ScatterElement {x: 1.1; y: 1.2} | |
|
46 | // } | |
|
47 | ||
|
48 | ListModel { | |
|
49 | id: listModelScatter | |
|
50 | ListElement { | |
|
51 | height: 154 | |
|
52 | weight: 54 | |
|
53 | } | |
|
54 | ListElement { | |
|
55 | height: 166 | |
|
56 | weight: 64 | |
|
57 | } | |
|
58 | ListElement { | |
|
59 | height: 199 | |
|
60 | weight: 97 | |
|
61 | } | |
|
22 | Component.onCompleted: { | |
|
23 | // console.log("Component.onCompleted: " + scatterElement.x); | |
|
24 | // console.log("Component.onCompleted: " + scatterElement.y); | |
|
25 | // console.log("Component.onCompleted: " + scatterElement.dataX); | |
|
26 | // console.log("Component.onCompleted: " + scatterElement.dataY); | |
|
27 | //console.log("Component.onCompleted: " + chartModel.get(0).x); | |
|
28 | //console.log("Component.onCompleted: " + chartModel.scatterElements); | |
|
29 | // console.log("Component.onCompleted: " + elementt.dataX); | |
|
30 | // console.log("Component.onCompleted: " + chartModel.get(0).dataX); | |
|
62 | 31 | } |
|
63 | 32 | |
|
64 | // Chart { | |
|
65 | // anchors.fill: parent | |
|
66 | // theme: Chart.ThemeIcy | |
|
67 | // ScatterSeries { | |
|
68 | // model: listModelScatter | |
|
69 | // name: "scatter" | |
|
70 | // xValue: x | |
|
71 | // yValue: y | |
|
72 | // } | |
|
73 | // } | |
|
74 | ||
|
75 | 33 | Chart { |
|
76 | anchors.fill: parent | |
|
34 | id: chart1 | |
|
35 | anchors.top: parent.top | |
|
36 | anchors.left: parent.left | |
|
37 | anchors.right: parent.right | |
|
38 | height: parent.height / 2 | |
|
77 | 39 | theme: Chart.ThemeIcy |
|
40 | // opacity: 0.3 | |
|
78 | 41 | |
|
79 | // PieSeries { | |
|
80 | // labels: ["point1", "point2", "point3", "point4", "point5"] | |
|
81 | // datax: [2, 1.5, 3, 3, 3] | |
|
82 | // } | |
|
83 | // PieSeries { | |
|
84 | // name: "raspberry pie" | |
|
85 | // seriesLabels: ["point1", "point2", "point3", "point4", "point5"] | |
|
86 | // seriesData: [2, 1.5, 3, 3, 3] | |
|
87 | // } | |
|
88 | // ScatterSeries { | |
|
89 | // name: "scatter1" | |
|
90 | // datax: [2, 1.5, 3, 3, 3] | |
|
91 | // datay: [2, 1.5, 3, 3, 3] | |
|
92 | // } | |
|
93 | // Series { | |
|
94 | // labels: ["point1", "point2", "point3", "point4", "point5"] | |
|
95 | // datax: [2, 1.5, 3, 3, 3] | |
|
96 | // seriesType: Series.SeriesTypePie | |
|
97 | // } | |
|
98 | 42 |
|
|
99 | 43 | seriesType: Series.SeriesTypePie |
|
100 | //model: listModelForPie | |
|
101 | //seriesData: {11.0, 6.4, 12.6, 22.4} | |
|
102 | //seriesLabels: {"Strawberry", "Blackberry", "Apple", "Pumpkin"} | |
|
103 | 44 |
|
|
104 | 45 | |
|
105 | Series { | |
|
106 | // data: {[1.2], "y":2.2 } | |
|
107 | seriesType: Series.SeriesTypeScatter | |
|
108 | } | |
|
109 | Series { | |
|
110 | seriesType: Series.SeriesTypeLine | |
|
111 | } | |
|
46 | // TODO: a bug: drawing order affects the drawing; if you draw chart1 first (by changing the | |
|
47 | // z-order), then chart2 is not shown at all. By drawing chart2 first, both are visible. | |
|
48 | // Also, if you don't draw line series on chart1 (only pie), both charts are visible. | |
|
49 | // Series { | |
|
50 | // seriesType: Series.SeriesTypeLine | |
|
51 | // } | |
|
112 | 52 | // TODO: |
|
113 | 53 |
|
|
114 | 54 | // seriesType: Series.SeriesTypeBar |
|
115 | 55 | // } |
|
116 | 56 | } |
|
57 | ||
|
58 | ||
|
59 | Chart { | |
|
60 | id: chart2 | |
|
61 | anchors.top: chart1.bottom | |
|
62 | anchors.bottom: parent.bottom | |
|
63 | anchors.left: parent.left | |
|
64 | anchors.right: parent.right | |
|
65 | theme: Chart.ThemeScientific | |
|
66 | ||
|
67 | ScatterSeries { | |
|
68 | data: [ | |
|
69 | ScatterElement { x: 1.1; y: 2.1 }, | |
|
70 | ScatterElement { x: 1.2; y: 2.0 }, | |
|
71 | ScatterElement { x: 1.4; y: 2.3 } | |
|
72 | ] | |
|
73 | } | |
|
74 | ScatterSeries { | |
|
75 | data: [ | |
|
76 | ScatterElement { x: 1.2; y: 2.2 }, | |
|
77 | ScatterElement { x: 1.3; y: 2.2 }, | |
|
78 | ScatterElement { x: 1.7; y: 2.6 } | |
|
79 | ] | |
|
80 | } | |
|
81 | ScatterSeries { | |
|
82 | data: [ | |
|
83 | ScatterElement { x: 1.3; y: 2.3 }, | |
|
84 | ScatterElement { x: 1.5; y: 2.4 }, | |
|
85 | ScatterElement { x: 2.0; y: 2.9 } | |
|
86 | ] | |
|
87 | } | |
|
88 | ScatterSeries { | |
|
89 | data: [ | |
|
90 | ScatterElement { x: 1.4; y: 2.4 }, | |
|
91 | ScatterElement { x: 1.8; y: 2.7 }, | |
|
92 | ScatterElement { x: 2.5; y: 3.2 } | |
|
93 | ] | |
|
94 | } | |
|
95 | } | |
|
117 | 96 | } |
General Comments 0
You need to be logged in to leave comments.
Login now