@@ -0,0 +1,36 | |||||
|
1 | #include "charttheme_p.h" | |||
|
2 | ||||
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
4 | ||||
|
5 | class ChartThemeBlueCerulean: public ChartTheme | |||
|
6 | { | |||
|
7 | public: | |||
|
8 | ChartThemeBlueCerulean() : ChartTheme(QChart::ChartThemeBlueCerulean) | |||
|
9 | { | |||
|
10 | // Series colors | |||
|
11 | m_seriesColors << QRgb(0xc7e85b); | |||
|
12 | m_seriesColors << QRgb(0x5dbe9b); | |||
|
13 | m_seriesColors << QRgb(0x4fbef3); | |||
|
14 | generateSeriesGradients(); | |||
|
15 | ||||
|
16 | // Background | |||
|
17 | QLinearGradient backgroundGradient; | |||
|
18 | backgroundGradient.setColorAt(0.0, QRgb(0x056188)); | |||
|
19 | backgroundGradient.setColorAt(1.0, QRgb(0x101a33)); | |||
|
20 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |||
|
21 | m_backgroundGradient = backgroundGradient; | |||
|
22 | ||||
|
23 | // Axes and other | |||
|
24 | m_masterFont = QFont(); | |||
|
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); | |||
|
26 | m_axisLinePen.setWidth(2); | |||
|
27 | m_axisLabelBrush = QBrush(QRgb(0x3f3f3f)); | |||
|
28 | m_axisLabelPen = Qt::NoPen; // NoPen for performance reasons | |||
|
29 | m_backgroundShadesPen = Qt::NoPen; | |||
|
30 | m_backgroundShades = BackgroundShadesNone; | |||
|
31 | m_gridLinePen = QPen(QRgb(0x0f0f0f)); | |||
|
32 | m_gridLinePen.setWidth(2); | |||
|
33 | } | |||
|
34 | }; | |||
|
35 | ||||
|
36 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,198 +1,199 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qpieseries.h> |
|
5 | #include <qpieseries.h> | |
6 | #include <qpieslice.h> |
|
6 | #include <qpieslice.h> | |
7 | #include <qpercentbarseries.h> |
|
7 | #include <qpercentbarseries.h> | |
8 | #include <qbarset.h> |
|
8 | #include <qbarset.h> | |
9 | #include <QGridLayout> |
|
9 | #include <QGridLayout> | |
10 | #include <QFormLayout> |
|
10 | #include <QFormLayout> | |
11 | #include <QComboBox> |
|
11 | #include <QComboBox> | |
12 | #include <QSpinBox> |
|
12 | #include <QSpinBox> | |
13 | #include <QCheckBox> |
|
13 | #include <QCheckBox> | |
14 | #include <QGroupBox> |
|
14 | #include <QGroupBox> | |
15 | #include <QLabel> |
|
15 | #include <QLabel> | |
16 | #include <QTime> |
|
16 | #include <QTime> | |
17 | #include <qlineseries.h> |
|
17 | #include <qlineseries.h> | |
18 | #include <qsplineseries.h> |
|
18 | #include <qsplineseries.h> | |
19 | #include <qscatterseries.h> |
|
19 | #include <qscatterseries.h> | |
20 | #include <qareaseries.h> |
|
20 | #include <qareaseries.h> | |
21 |
|
21 | |||
22 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
22 | QTCOMMERCIALCHART_USE_NAMESPACE | |
23 |
|
23 | |||
24 | typedef QPair<QPointF, QString> Data; |
|
24 | typedef QPair<QPointF, QString> Data; | |
25 | typedef QList<Data> DataList; |
|
25 | typedef QList<Data> DataList; | |
26 | typedef QList<DataList> DataTable; |
|
26 | typedef QList<DataList> DataTable; | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | class MainWidget : public QWidget |
|
29 | class MainWidget : public QWidget | |
30 | { |
|
30 | { | |
31 | Q_OBJECT |
|
31 | Q_OBJECT | |
32 |
|
32 | |||
33 | public: |
|
33 | public: | |
34 | explicit MainWidget(QWidget* parent = 0) |
|
34 | explicit MainWidget(QWidget* parent = 0) | |
35 | :QWidget(parent) |
|
35 | :QWidget(parent) | |
36 | { |
|
36 | { | |
37 | // set seed for random stuff |
|
37 | // set seed for random stuff | |
38 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
38 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
39 |
|
39 | |||
40 | // generate random data |
|
40 | // generate random data | |
41 | int listCount = 3; |
|
41 | int listCount = 3; | |
42 | int valueMax = 100; |
|
42 | int valueMax = 100; | |
43 | int valueCount = 21; |
|
43 | int valueCount = 21; | |
44 | for (int i(0); i < listCount; i++) { |
|
44 | for (int i(0); i < listCount; i++) { | |
45 | DataList dataList; |
|
45 | DataList dataList; | |
46 | for (int j(0); j < valueCount; j++) { |
|
46 | for (int j(0); j < valueCount; j++) { | |
47 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
47 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
48 | QString label = QString::number(i) + ":" + QString::number(j); |
|
48 | QString label = QString::number(i) + ":" + QString::number(j); | |
49 | dataList << Data(value, label); |
|
49 | dataList << Data(value, label); | |
50 | } |
|
50 | } | |
51 | m_dataTable << dataList; |
|
51 | m_dataTable << dataList; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | // create layout |
|
54 | // create layout | |
55 | QGridLayout* baseLayout = new QGridLayout(); |
|
55 | QGridLayout* baseLayout = new QGridLayout(); | |
56 |
|
56 | |||
57 | // theme combo |
|
57 | // theme combo | |
58 | m_themeComboBox = new QComboBox(); |
|
58 | m_themeComboBox = new QComboBox(); | |
59 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
59 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
60 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); |
|
60 | m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla); | |
61 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); |
|
61 | m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy); | |
62 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); |
|
62 | m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale); | |
63 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); |
|
63 | m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific); | |
|
64 | m_themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |||
64 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); |
|
65 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateTheme())); | |
65 | baseLayout->addWidget(new QLabel("Theme:"), 0, 0); |
|
66 | baseLayout->addWidget(new QLabel("Theme:"), 0, 0); | |
66 | baseLayout->addWidget(m_themeComboBox, 0, 1); |
|
67 | baseLayout->addWidget(m_themeComboBox, 0, 1); | |
67 |
|
68 | |||
68 | // area chart |
|
69 | // area chart | |
69 | QChartView *chart = new QChartView(); |
|
70 | QChartView *chart = new QChartView(); | |
70 | chart->setChartTitle("Area chart"); |
|
71 | chart->setChartTitle("Area chart"); | |
71 | chart->setRenderHint(QPainter::Antialiasing); |
|
72 | chart->setRenderHint(QPainter::Antialiasing); | |
72 | baseLayout->addWidget(chart, 1, 0); |
|
73 | baseLayout->addWidget(chart, 1, 0); | |
73 | { |
|
74 | { | |
74 | for (int i(0); i < m_dataTable.count(); i++) { |
|
75 | for (int i(0); i < m_dataTable.count(); i++) { | |
75 | QLineSeries *series1 = new QLineSeries(chart); |
|
76 | QLineSeries *series1 = new QLineSeries(chart); | |
76 | QLineSeries *series2 = new QLineSeries(chart); |
|
77 | QLineSeries *series2 = new QLineSeries(chart); | |
77 | foreach (Data data, m_dataTable[i]) { |
|
78 | foreach (Data data, m_dataTable[i]) { | |
78 | series1->add(data.first); |
|
79 | series1->add(data.first); | |
79 | series2->add(QPointF(data.first.x(), 0.0)); |
|
80 | series2->add(QPointF(data.first.x(), 0.0)); | |
80 | } |
|
81 | } | |
81 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
82 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
82 | chart->addSeries(area); |
|
83 | chart->addSeries(area); | |
83 | } |
|
84 | } | |
84 | } |
|
85 | } | |
85 | m_charts << chart; |
|
86 | m_charts << chart; | |
86 |
|
87 | |||
87 | // bar chart |
|
88 | // bar chart | |
88 | chart = new QChartView(); |
|
89 | chart = new QChartView(); | |
89 | chart->setChartTitle("bar chart"); |
|
90 | chart->setChartTitle("bar chart"); | |
90 | chart->setRenderHint(QPainter::Antialiasing); |
|
91 | chart->setRenderHint(QPainter::Antialiasing); | |
91 | baseLayout->addWidget(chart, 1, 1); |
|
92 | baseLayout->addWidget(chart, 1, 1); | |
92 | { |
|
93 | { | |
93 | QStringList categories; |
|
94 | QStringList categories; | |
94 | // TODO: categories |
|
95 | // TODO: categories | |
95 | for (int i(0); i < valueCount; i++) |
|
96 | for (int i(0); i < valueCount; i++) | |
96 | categories << QString::number(i); |
|
97 | categories << QString::number(i); | |
97 | QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
98 | QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
98 | for (int i(0); i < m_dataTable.count(); i++) { |
|
99 | for (int i(0); i < m_dataTable.count(); i++) { | |
99 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
100 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
100 | foreach (Data data, m_dataTable[i]) |
|
101 | foreach (Data data, m_dataTable[i]) | |
101 | *set << data.first.y(); |
|
102 | *set << data.first.y(); | |
102 | series->addBarSet(set); |
|
103 | series->addBarSet(set); | |
103 | } |
|
104 | } | |
104 | chart->addSeries(series); |
|
105 | chart->addSeries(series); | |
105 | } |
|
106 | } | |
106 | m_charts << chart; |
|
107 | m_charts << chart; | |
107 |
|
108 | |||
108 | // line chart |
|
109 | // line chart | |
109 | chart = new QChartView(); |
|
110 | chart = new QChartView(); | |
110 | chart->setChartTitle("line chart"); |
|
111 | chart->setChartTitle("line chart"); | |
111 | chart->setRenderHint(QPainter::Antialiasing); |
|
112 | chart->setRenderHint(QPainter::Antialiasing); | |
112 | baseLayout->addWidget(chart, 1, 2); |
|
113 | baseLayout->addWidget(chart, 1, 2); | |
113 | foreach (DataList list, m_dataTable) { |
|
114 | foreach (DataList list, m_dataTable) { | |
114 | QLineSeries *series = new QLineSeries(chart); |
|
115 | QLineSeries *series = new QLineSeries(chart); | |
115 | foreach (Data data, list) |
|
116 | foreach (Data data, list) | |
116 | series->add(data.first); |
|
117 | series->add(data.first); | |
117 | chart->addSeries(series); |
|
118 | chart->addSeries(series); | |
118 | } |
|
119 | } | |
119 | m_charts << chart; |
|
120 | m_charts << chart; | |
120 |
|
121 | |||
121 | // pie chart |
|
122 | // pie chart | |
122 | chart = new QChartView(); |
|
123 | chart = new QChartView(); | |
123 | chart->setChartTitle("pie chart"); |
|
124 | chart->setChartTitle("pie chart"); | |
124 | chart->setRenderHint(QPainter::Antialiasing); |
|
125 | chart->setRenderHint(QPainter::Antialiasing); | |
125 | baseLayout->addWidget(chart, 2, 0); |
|
126 | baseLayout->addWidget(chart, 2, 0); | |
126 |
|
127 | |||
127 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
128 | qreal pieSize = 1.0 / m_dataTable.count(); | |
128 | for (int i=0; i<m_dataTable.count(); i++) { |
|
129 | for (int i=0; i<m_dataTable.count(); i++) { | |
129 | QPieSeries *series = new QPieSeries(chart); |
|
130 | QPieSeries *series = new QPieSeries(chart); | |
130 | foreach (Data data, m_dataTable[i]) |
|
131 | foreach (Data data, m_dataTable[i]) | |
131 | series->add(data.first.y(), data.second); |
|
132 | series->add(data.first.y(), data.second); | |
132 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
133 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
133 | series->setPieSize(pieSize); |
|
134 | series->setPieSize(pieSize); | |
134 | series->setPiePosition(hPos, 0.5); |
|
135 | series->setPiePosition(hPos, 0.5); | |
135 | chart->addSeries(series); |
|
136 | chart->addSeries(series); | |
136 | } |
|
137 | } | |
137 | m_charts << chart; |
|
138 | m_charts << chart; | |
138 |
|
139 | |||
139 | // spine chart |
|
140 | // spine chart | |
140 | chart = new QChartView(); |
|
141 | chart = new QChartView(); | |
141 | chart->setChartTitle("spline chart"); |
|
142 | chart->setChartTitle("spline chart"); | |
142 | chart->setRenderHint(QPainter::Antialiasing); |
|
143 | chart->setRenderHint(QPainter::Antialiasing); | |
143 | baseLayout->addWidget(chart, 2, 1); |
|
144 | baseLayout->addWidget(chart, 2, 1); | |
144 | foreach (DataList list, m_dataTable) { |
|
145 | foreach (DataList list, m_dataTable) { | |
145 | QSplineSeries *series = new QSplineSeries(chart); |
|
146 | QSplineSeries *series = new QSplineSeries(chart); | |
146 | foreach (Data data, list) |
|
147 | foreach (Data data, list) | |
147 | series->add(data.first); |
|
148 | series->add(data.first); | |
148 | chart->addSeries(series); |
|
149 | chart->addSeries(series); | |
149 | } |
|
150 | } | |
150 | m_charts << chart; |
|
151 | m_charts << chart; | |
151 |
|
152 | |||
152 | // scatter chart |
|
153 | // scatter chart | |
153 | chart = new QChartView(); |
|
154 | chart = new QChartView(); | |
154 | chart->setChartTitle("scatter chart"); |
|
155 | chart->setChartTitle("scatter chart"); | |
155 | chart->setRenderHint(QPainter::Antialiasing); |
|
156 | chart->setRenderHint(QPainter::Antialiasing); | |
156 | baseLayout->addWidget(chart, 2, 2); |
|
157 | baseLayout->addWidget(chart, 2, 2); | |
157 | foreach (DataList list, m_dataTable) { |
|
158 | foreach (DataList list, m_dataTable) { | |
158 | QScatterSeries *series = new QScatterSeries(chart); |
|
159 | QScatterSeries *series = new QScatterSeries(chart); | |
159 | foreach (Data data, list) |
|
160 | foreach (Data data, list) | |
160 | series->add(data.first); |
|
161 | series->add(data.first); | |
161 | chart->addSeries(series); |
|
162 | chart->addSeries(series); | |
162 | } |
|
163 | } | |
163 | m_charts << chart; |
|
164 | m_charts << chart; | |
164 |
|
165 | |||
165 | setLayout(baseLayout); |
|
166 | setLayout(baseLayout); | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | public Q_SLOTS: |
|
169 | public Q_SLOTS: | |
169 |
|
170 | |||
170 | void updateTheme() |
|
171 | void updateTheme() | |
171 | { |
|
172 | { | |
172 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
173 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
173 | foreach (QChartView *chart, m_charts) |
|
174 | foreach (QChartView *chart, m_charts) | |
174 | chart->setChartTheme(theme); |
|
175 | chart->setChartTheme(theme); | |
175 | } |
|
176 | } | |
176 |
|
177 | |||
177 | private: |
|
178 | private: | |
178 | QList<QChartView*> m_charts; |
|
179 | QList<QChartView*> m_charts; | |
179 | QComboBox *m_themeComboBox; |
|
180 | QComboBox *m_themeComboBox; | |
180 | DataTable m_dataTable; |
|
181 | DataTable m_dataTable; | |
181 | }; |
|
182 | }; | |
182 |
|
183 | |||
183 | int main(int argc, char *argv[]) |
|
184 | int main(int argc, char *argv[]) | |
184 | { |
|
185 | { | |
185 | QApplication a(argc, argv); |
|
186 | QApplication a(argc, argv); | |
186 |
|
187 | |||
187 | QMainWindow window; |
|
188 | QMainWindow window; | |
188 |
|
189 | |||
189 | MainWidget* widget = new MainWidget(); |
|
190 | MainWidget* widget = new MainWidget(); | |
190 |
|
191 | |||
191 | window.setCentralWidget(widget); |
|
192 | window.setCentralWidget(widget); | |
192 | window.resize(900, 600); |
|
193 | window.resize(900, 600); | |
193 | window.show(); |
|
194 | window.show(); | |
194 |
|
195 | |||
195 | return a.exec(); |
|
196 | return a.exec(); | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | #include "main.moc" |
|
199 | #include "main.moc" |
@@ -1,304 +1,310 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "qchartaxis.h" |
|
4 | #include "qchartaxis.h" | |
5 | #include <QTime> |
|
5 | #include <QTime> | |
6 |
|
6 | |||
7 | //series |
|
7 | //series | |
8 | #include "qbarset.h" |
|
8 | #include "qbarset.h" | |
9 | #include "qbarseries.h" |
|
9 | #include "qbarseries.h" | |
10 | #include "qstackedbarseries.h" |
|
10 | #include "qstackedbarseries.h" | |
11 | #include "qpercentbarseries.h" |
|
11 | #include "qpercentbarseries.h" | |
12 | #include "qlineseries.h" |
|
12 | #include "qlineseries.h" | |
13 | #include "qareaseries.h" |
|
13 | #include "qareaseries.h" | |
14 | #include "qscatterseries.h" |
|
14 | #include "qscatterseries.h" | |
15 | #include "qpieseries.h" |
|
15 | #include "qpieseries.h" | |
16 | #include "qpieslice.h" |
|
16 | #include "qpieslice.h" | |
17 | #include "qsplineseries.h" |
|
17 | #include "qsplineseries.h" | |
18 |
|
18 | |||
19 | //items |
|
19 | //items | |
20 | #include "axisitem_p.h" |
|
20 | #include "axisitem_p.h" | |
21 | #include "barpresenter_p.h" |
|
21 | #include "barpresenter_p.h" | |
22 | #include "stackedbarpresenter_p.h" |
|
22 | #include "stackedbarpresenter_p.h" | |
23 | #include "percentbarpresenter_p.h" |
|
23 | #include "percentbarpresenter_p.h" | |
24 | #include "linechartitem_p.h" |
|
24 | #include "linechartitem_p.h" | |
25 | #include "areachartitem_p.h" |
|
25 | #include "areachartitem_p.h" | |
26 | #include "scatterchartitem_p.h" |
|
26 | #include "scatterchartitem_p.h" | |
27 | #include "piechartitem_p.h" |
|
27 | #include "piechartitem_p.h" | |
28 | #include "splinechartitem_p.h" |
|
28 | #include "splinechartitem_p.h" | |
29 |
|
29 | |||
30 | //themes |
|
30 | //themes | |
31 | #include "chartthemedefault_p.h" |
|
31 | #include "chartthemedefault_p.h" | |
32 | #include "chartthemevanilla_p.h" |
|
32 | #include "chartthemevanilla_p.h" | |
33 | #include "chartthemeicy_p.h" |
|
33 | #include "chartthemeicy_p.h" | |
34 | #include "chartthemegrayscale_p.h" |
|
34 | #include "chartthemegrayscale_p.h" | |
35 | #include "chartthemescientific_p.h" |
|
35 | #include "chartthemescientific_p.h" | |
|
36 | #include "chartthemebluecerulean_p.h" | |||
36 |
|
37 | |||
37 |
|
38 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
40 | |||
40 | ChartTheme::ChartTheme(QChart::ChartTheme id) |
|
41 | ChartTheme::ChartTheme(QChart::ChartTheme id) | |
41 | { |
|
42 | { | |
42 | m_id = id; |
|
43 | m_id = id; | |
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
44 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
44 | } |
|
45 | } | |
45 |
|
46 | |||
46 |
|
47 | |||
47 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
48 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
48 | { |
|
49 | { | |
49 | switch(theme) { |
|
50 | switch(theme) { | |
50 | case QChart::ChartThemeVanilla: |
|
51 | case QChart::ChartThemeVanilla: | |
51 | return new ChartThemeVanilla(); |
|
52 | return new ChartThemeVanilla(); | |
52 | case QChart::ChartThemeIcy: |
|
53 | case QChart::ChartThemeIcy: | |
53 | return new ChartThemeIcy(); |
|
54 | return new ChartThemeIcy(); | |
54 | case QChart::ChartThemeGrayscale: |
|
55 | case QChart::ChartThemeGrayscale: | |
55 | return new ChartThemeGrayscale(); |
|
56 | return new ChartThemeGrayscale(); | |
56 | case QChart::ChartThemeScientific: |
|
57 | case QChart::ChartThemeScientific: | |
57 | return new ChartThemeScientific(); |
|
58 | return new ChartThemeScientific(); | |
|
59 | case QChart::ChartThemeBlueCerulean: | |||
|
60 | return new ChartThemeBlueCerulean(); | |||
58 | default: |
|
61 | default: | |
59 | return new ChartThemeDefault(); |
|
62 | return new ChartThemeDefault(); | |
60 | } |
|
63 | } | |
61 | } |
|
64 | } | |
62 |
|
65 | |||
63 | void ChartTheme::decorate(QChart* chart) |
|
66 | void ChartTheme::decorate(QChart* chart) | |
64 | { |
|
67 | { | |
65 | chart->setChartBackgroundBrush(m_backgroundGradient); |
|
68 | if (m_backgroundShades == BackgroundShadesNone) | |
|
69 | chart->setChartBackgroundBrush(m_backgroundGradient); | |||
|
70 | else | |||
|
71 | chart->setChartBackgroundBrush(Qt::NoBrush); | |||
66 | chart->setChartTitleFont(m_masterFont); |
|
72 | chart->setChartTitleFont(m_masterFont); | |
67 | } |
|
73 | } | |
68 |
|
74 | |||
69 | void ChartTheme::decorate(QLegend* legend) |
|
75 | void ChartTheme::decorate(QLegend* legend) | |
70 | { |
|
76 | { | |
71 | legend->setBackgroundBrush(m_backgroundGradient); |
|
77 | legend->setBackgroundBrush(m_backgroundGradient); | |
72 | } |
|
78 | } | |
73 |
|
79 | |||
74 | void ChartTheme::decorate(QAreaSeries* series, int index) |
|
80 | void ChartTheme::decorate(QAreaSeries* series, int index) | |
75 | { |
|
81 | { | |
76 | QPen pen; |
|
82 | QPen pen; | |
77 | QBrush brush; |
|
83 | QBrush brush; | |
78 |
|
84 | |||
79 | if (pen == series->pen()){ |
|
85 | if (pen == series->pen()){ | |
80 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
86 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
81 | pen.setWidthF(2); |
|
87 | pen.setWidthF(2); | |
82 | series->setPen(pen); |
|
88 | series->setPen(pen); | |
83 | } |
|
89 | } | |
84 |
|
90 | |||
85 | if (brush == series->brush()) { |
|
91 | if (brush == series->brush()) { | |
86 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
92 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
87 | series->setBrush(brush); |
|
93 | series->setBrush(brush); | |
88 | } |
|
94 | } | |
89 | } |
|
95 | } | |
90 |
|
96 | |||
91 |
|
97 | |||
92 | void ChartTheme::decorate(QLineSeries* series,int index) |
|
98 | void ChartTheme::decorate(QLineSeries* series,int index) | |
93 | { |
|
99 | { | |
94 | QPen pen; |
|
100 | QPen pen; | |
95 | if(pen == series->pen()){ |
|
101 | if(pen == series->pen()){ | |
96 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
102 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
97 | pen.setWidthF(2); |
|
103 | pen.setWidthF(2); | |
98 | series->setPen(pen); |
|
104 | series->setPen(pen); | |
99 | } |
|
105 | } | |
100 | } |
|
106 | } | |
101 |
|
107 | |||
102 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) |
|
108 | void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int index) | |
103 | { |
|
109 | { | |
104 | QList<QBarSet*> sets = series->barSets(); |
|
110 | QList<QBarSet*> sets = series->barSets(); | |
105 | for (int i=0; i<sets.count(); i++) { |
|
111 | for (int i=0; i<sets.count(); i++) { | |
106 | qreal pos = 0.5; |
|
112 | qreal pos = 0.5; | |
107 | if (sets.count() > 1) |
|
113 | if (sets.count() > 1) | |
108 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
114 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
109 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
115 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
110 | sets.at(i)->setBrush(QBrush(c)); |
|
116 | sets.at(i)->setBrush(QBrush(c)); | |
111 |
|
117 | |||
112 | // Pick label color as far as possible from bar color (within gradient). |
|
118 | // Pick label color as far as possible from bar color (within gradient). | |
113 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) |
|
119 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) | |
114 | // TODO: better picking of label color? |
|
120 | // TODO: better picking of label color? | |
115 | if (pos < 0.3) { |
|
121 | if (pos < 0.3) { | |
116 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
122 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
117 | } else { |
|
123 | } else { | |
118 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
124 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
119 | } |
|
125 | } | |
120 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
126 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
121 | } |
|
127 | } | |
122 | } |
|
128 | } | |
123 |
|
129 | |||
124 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) |
|
130 | void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,int index) | |
125 | { |
|
131 | { | |
126 | QList<QBarSet*> sets = series->barSets(); |
|
132 | QList<QBarSet*> sets = series->barSets(); | |
127 | for (int i=0; i<sets.count(); i++) { |
|
133 | for (int i=0; i<sets.count(); i++) { | |
128 | qreal pos = 0.5; |
|
134 | qreal pos = 0.5; | |
129 | if (sets.count() > 1) |
|
135 | if (sets.count() > 1) | |
130 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
136 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
131 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
137 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
132 | sets.at(i)->setBrush(QBrush(c)); |
|
138 | sets.at(i)->setBrush(QBrush(c)); | |
133 |
|
139 | |||
134 | if (pos < 0.3) { |
|
140 | if (pos < 0.3) { | |
135 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
141 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
136 | } else { |
|
142 | } else { | |
137 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
143 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
138 | } |
|
144 | } | |
139 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
145 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
140 | } |
|
146 | } | |
141 | } |
|
147 | } | |
142 |
|
148 | |||
143 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) |
|
149 | void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,int index) | |
144 | { |
|
150 | { | |
145 | QList<QBarSet*> sets = series->barSets(); |
|
151 | QList<QBarSet*> sets = series->barSets(); | |
146 | for (int i=0; i<sets.count(); i++) { |
|
152 | for (int i=0; i<sets.count(); i++) { | |
147 | qreal pos = 0.5; |
|
153 | qreal pos = 0.5; | |
148 | if (sets.count() > 1) |
|
154 | if (sets.count() > 1) | |
149 | pos = (qreal) i / (qreal) (sets.count() - 1); |
|
155 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
150 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
156 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
151 | sets.at(i)->setBrush(QBrush(c)); |
|
157 | sets.at(i)->setBrush(QBrush(c)); | |
152 |
|
158 | |||
153 | if (pos < 0.3) { |
|
159 | if (pos < 0.3) { | |
154 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); |
|
160 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
155 | } else { |
|
161 | } else { | |
156 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); |
|
162 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
157 | } |
|
163 | } | |
158 | sets.at(i)->setFloatingValuePen(QPen(c)); |
|
164 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
159 | } |
|
165 | } | |
160 | } |
|
166 | } | |
161 |
|
167 | |||
162 | void ChartTheme::decorate(QScatterSeries* series, int index) |
|
168 | void ChartTheme::decorate(QScatterSeries* series, int index) | |
163 | { |
|
169 | { | |
164 |
|
170 | |||
165 | QPen pen; |
|
171 | QPen pen; | |
166 | QBrush brush; |
|
172 | QBrush brush; | |
167 |
|
173 | |||
168 | if (pen == series->pen()) { |
|
174 | if (pen == series->pen()) { | |
169 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); |
|
175 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1.0)); | |
170 | pen.setWidthF(2); |
|
176 | pen.setWidthF(2); | |
171 | series->setPen(pen); |
|
177 | series->setPen(pen); | |
172 | } |
|
178 | } | |
173 |
|
179 | |||
174 | if (brush == series->brush()) { |
|
180 | if (brush == series->brush()) { | |
175 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
181 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
176 | series->setBrush(brush); |
|
182 | series->setBrush(brush); | |
177 | } |
|
183 | } | |
178 | } |
|
184 | } | |
179 |
|
185 | |||
180 | void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index) |
|
186 | void ChartTheme::decorate(PieChartItem* item, QPieSeries* series, int index) | |
181 | { |
|
187 | { | |
182 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
188 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
183 | for (int i(0); i < series->slices().count(); i++) { |
|
189 | for (int i(0); i < series->slices().count(); i++) { | |
184 | qreal pos = (qreal) i / (qreal) series->count(); |
|
190 | qreal pos = (qreal) i / (qreal) series->count(); | |
185 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); |
|
191 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.1); | |
186 | series->slices().at(i)->setSlicePen(penColor); |
|
192 | series->slices().at(i)->setSlicePen(penColor); | |
187 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
193 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
188 | series->slices().at(i)->setSliceBrush(brushColor); |
|
194 | series->slices().at(i)->setSliceBrush(brushColor); | |
189 | } |
|
195 | } | |
190 | } |
|
196 | } | |
191 |
|
197 | |||
192 | void ChartTheme::decorate(QSplineSeries* series, int index) |
|
198 | void ChartTheme::decorate(QSplineSeries* series, int index) | |
193 | { |
|
199 | { | |
194 | QPen pen; |
|
200 | QPen pen; | |
195 | if(pen == series->pen()){ |
|
201 | if(pen == series->pen()){ | |
196 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
202 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
197 | pen.setWidthF(2); |
|
203 | pen.setWidthF(2); | |
198 | series->setPen(pen); |
|
204 | series->setPen(pen); | |
199 | } |
|
205 | } | |
200 | } |
|
206 | } | |
201 |
|
207 | |||
202 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) |
|
208 | void ChartTheme::decorate(QChartAxis* axis,bool axisX) | |
203 | { |
|
209 | { | |
204 | if (axis->isAxisVisible()) { |
|
210 | if (axis->isAxisVisible()) { | |
205 | axis->setLabelsBrush(m_axisLabelBrush); |
|
211 | axis->setLabelsBrush(m_axisLabelBrush); | |
206 | axis->setLabelsPen(m_axisLabelPen); |
|
212 | axis->setLabelsPen(m_axisLabelPen); | |
207 | // TODO: check the axis type (x or y) should define whether to show the shades or not |
|
213 | // TODO: check the axis type (x or y) should define whether to show the shades or not | |
208 | if (m_backgroundShades == BackgroundShadesBoth |
|
214 | if (m_backgroundShades == BackgroundShadesBoth | |
209 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
215 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
210 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { |
|
216 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX)) { | |
211 | axis->setShadesPen(m_backgroundShadesPen); |
|
217 | axis->setShadesPen(m_backgroundShadesPen); | |
212 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
218 | axis->setShadesBrush(m_backgroundShadesBrush); | |
213 | } else { |
|
219 | } else { | |
214 | // The shades not supposed to be shown for this axis, clear possible brush and pen |
|
220 | // The shades not supposed to be shown for this axis, clear possible brush and pen | |
215 | axis->setShadesPen(Qt::NoPen); |
|
221 | axis->setShadesPen(Qt::NoPen); | |
216 | axis->setShadesBrush(Qt::NoBrush); |
|
222 | axis->setShadesBrush(Qt::NoBrush); | |
217 | } |
|
223 | } | |
218 | axis->setAxisPen(m_axisLinePen); |
|
224 | axis->setAxisPen(m_axisLinePen); | |
219 | axis->setGridLinePen(m_gridLinePen); |
|
225 | axis->setGridLinePen(m_gridLinePen); | |
220 | axis->setLabelsFont(m_masterFont); |
|
226 | axis->setLabelsFont(m_masterFont); | |
221 | } |
|
227 | } | |
222 | } |
|
228 | } | |
223 |
|
229 | |||
224 | void ChartTheme::generateSeriesGradients() |
|
230 | void ChartTheme::generateSeriesGradients() | |
225 | { |
|
231 | { | |
226 | // Generate gradients in HSV color space |
|
232 | // Generate gradients in HSV color space | |
227 | foreach (QColor color, m_seriesColors) { |
|
233 | foreach (QColor color, m_seriesColors) { | |
228 | QLinearGradient g; |
|
234 | QLinearGradient g; | |
229 | qreal h = color.hsvHueF(); |
|
235 | qreal h = color.hsvHueF(); | |
230 | qreal s = color.hsvSaturationF(); |
|
236 | qreal s = color.hsvSaturationF(); | |
231 |
|
237 | |||
232 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
238 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
233 | // most themes. The rest of the gradients we can define manually in theme specific |
|
239 | // most themes. The rest of the gradients we can define manually in theme specific | |
234 | // implementation. |
|
240 | // implementation. | |
235 | QColor start = color; |
|
241 | QColor start = color; | |
236 | start.setHsvF(h, 0.05, 0.95); |
|
242 | start.setHsvF(h, 0.05, 0.95); | |
237 | g.setColorAt(0.0, start); |
|
243 | g.setColorAt(0.0, start); | |
238 |
|
244 | |||
239 | g.setColorAt(0.5, color); |
|
245 | g.setColorAt(0.5, color); | |
240 |
|
246 | |||
241 | QColor end = color; |
|
247 | QColor end = color; | |
242 | end.setHsvF(h, s, 0.25); |
|
248 | end.setHsvF(h, s, 0.25); | |
243 | g.setColorAt(1.0, end); |
|
249 | g.setColorAt(1.0, end); | |
244 |
|
250 | |||
245 | m_seriesGradients << g; |
|
251 | m_seriesGradients << g; | |
246 | } |
|
252 | } | |
247 | } |
|
253 | } | |
248 |
|
254 | |||
249 |
|
255 | |||
250 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
256 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
251 | { |
|
257 | { | |
252 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
258 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
253 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
259 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
254 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
260 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
255 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
261 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
256 | QColor c; |
|
262 | QColor c; | |
257 | c.setRgbF(r, g, b); |
|
263 | c.setRgbF(r, g, b); | |
258 | return c; |
|
264 | return c; | |
259 | } |
|
265 | } | |
260 |
|
266 | |||
261 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
267 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
262 | { |
|
268 | { | |
263 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
269 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
264 |
|
270 | |||
265 | // another possibility: |
|
271 | // another possibility: | |
266 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
272 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
267 |
|
273 | |||
268 | QGradientStops stops = gradient.stops(); |
|
274 | QGradientStops stops = gradient.stops(); | |
269 | int count = stops.count(); |
|
275 | int count = stops.count(); | |
270 |
|
276 | |||
271 | // find previous stop relative to position |
|
277 | // find previous stop relative to position | |
272 | QGradientStop prev = stops.first(); |
|
278 | QGradientStop prev = stops.first(); | |
273 | for (int i=0; i<count; i++) { |
|
279 | for (int i=0; i<count; i++) { | |
274 | QGradientStop stop = stops.at(i); |
|
280 | QGradientStop stop = stops.at(i); | |
275 | if (pos > stop.first) |
|
281 | if (pos > stop.first) | |
276 | prev = stop; |
|
282 | prev = stop; | |
277 |
|
283 | |||
278 | // given position is actually a stop position? |
|
284 | // given position is actually a stop position? | |
279 | if (pos == stop.first) { |
|
285 | if (pos == stop.first) { | |
280 | //qDebug() << "stop color" << pos; |
|
286 | //qDebug() << "stop color" << pos; | |
281 | return stop.second; |
|
287 | return stop.second; | |
282 | } |
|
288 | } | |
283 | } |
|
289 | } | |
284 |
|
290 | |||
285 | // find next stop relative to position |
|
291 | // find next stop relative to position | |
286 | QGradientStop next = stops.last(); |
|
292 | QGradientStop next = stops.last(); | |
287 | for (int i=count-1; i>=0; i--) { |
|
293 | for (int i=count-1; i>=0; i--) { | |
288 | QGradientStop stop = stops.at(i); |
|
294 | QGradientStop stop = stops.at(i); | |
289 | if (pos < stop.first) |
|
295 | if (pos < stop.first) | |
290 | next = stop; |
|
296 | next = stop; | |
291 | } |
|
297 | } | |
292 |
|
298 | |||
293 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
299 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
294 |
|
300 | |||
295 | qreal range = next.first - prev.first; |
|
301 | qreal range = next.first - prev.first; | |
296 | qreal posDelta = pos - prev.first; |
|
302 | qreal posDelta = pos - prev.first; | |
297 | qreal relativePos = posDelta / range; |
|
303 | qreal relativePos = posDelta / range; | |
298 |
|
304 | |||
299 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
305 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
300 |
|
306 | |||
301 | return colorAt(prev.second, next.second, relativePos); |
|
307 | return colorAt(prev.second, next.second, relativePos); | |
302 | } |
|
308 | } | |
303 |
|
309 | |||
304 | QTCOMMERCIALCHART_END_NAMESPACE |
|
310 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,342 +1,344 | |||||
1 | #include "qchart.h" |
|
1 | #include "qchart.h" | |
2 | #include "qchartaxis.h" |
|
2 | #include "qchartaxis.h" | |
3 | #include "qlegend.h" |
|
3 | #include "qlegend.h" | |
4 | #include "chartpresenter_p.h" |
|
4 | #include "chartpresenter_p.h" | |
5 | #include "chartdataset_p.h" |
|
5 | #include "chartdataset_p.h" | |
6 | #include <QGraphicsScene> |
|
6 | #include <QGraphicsScene> | |
7 | #include <QGraphicsSceneResizeEvent> |
|
7 | #include <QGraphicsSceneResizeEvent> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
11 |
|
11 | |||
12 | /*! |
|
12 | /*! | |
13 | \enum QChart::ChartTheme |
|
13 | \enum QChart::ChartTheme | |
14 |
|
14 | |||
15 | This enum describes the theme used by the chart. |
|
15 | This enum describes the theme used by the chart. | |
16 |
|
16 | |||
17 | \value ChartThemeDefault |
|
17 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
18 | \value ChartThemeVanilla |
|
18 | \value ChartThemeVanilla | |
19 | \value ChartThemeIcy |
|
19 | \value ChartThemeIcy | |
20 | \value ChartThemeGrayscale |
|
20 | \value ChartThemeGrayscale | |
21 | \value ChartThemeScientific |
|
21 | \value ChartThemeScientific | |
|
22 | \value ChartThemeBlueCerulean | |||
|
23 | \value ChartThemeCount Not really a theme; the total count of themes. | |||
22 | */ |
|
24 | */ | |
23 |
|
25 | |||
24 | /*! |
|
26 | /*! | |
25 | \enum QChart::AnimationOption |
|
27 | \enum QChart::AnimationOption | |
26 |
|
28 | |||
27 | For enabling/disabling animations. Defaults to NoAnimation. |
|
29 | For enabling/disabling animations. Defaults to NoAnimation. | |
28 |
|
30 | |||
29 | \value NoAnimation |
|
31 | \value NoAnimation | |
30 | \value GridAxisAnimations |
|
32 | \value GridAxisAnimations | |
31 | \value SeriesAnimations |
|
33 | \value SeriesAnimations | |
32 | \value AllAnimations |
|
34 | \value AllAnimations | |
33 | */ |
|
35 | */ | |
34 |
|
36 | |||
35 | /*! |
|
37 | /*! | |
36 | \class QChart |
|
38 | \class QChart | |
37 | \brief QtCommercial chart API. |
|
39 | \brief QtCommercial chart API. | |
38 |
|
40 | |||
39 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
41 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
40 | representation of different types of QChartSeries and other chart related objects like |
|
42 | representation of different types of QChartSeries and other chart related objects like | |
41 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
43 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
42 | convenience class QChartView instead of QChart. |
|
44 | convenience class QChartView instead of QChart. | |
43 | \sa QChartView |
|
45 | \sa QChartView | |
44 | */ |
|
46 | */ | |
45 |
|
47 | |||
46 | /*! |
|
48 | /*! | |
47 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
49 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
48 | */ |
|
50 | */ | |
49 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
51 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
50 | m_backgroundItem(0), |
|
52 | m_backgroundItem(0), | |
51 | m_titleItem(0), |
|
53 | m_titleItem(0), | |
52 | m_legend(new QLegend(this)), |
|
54 | m_legend(new QLegend(this)), | |
53 | m_dataset(new ChartDataSet(this)), |
|
55 | m_dataset(new ChartDataSet(this)), | |
54 | m_presenter(new ChartPresenter(this,m_dataset)) |
|
56 | m_presenter(new ChartPresenter(this,m_dataset)) | |
55 | { |
|
57 | { | |
56 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
58 | connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
57 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
59 | connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
58 | } |
|
60 | } | |
59 |
|
61 | |||
60 | /*! |
|
62 | /*! | |
61 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
63 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
62 | */ |
|
64 | */ | |
63 | QChart::~QChart() |
|
65 | QChart::~QChart() | |
64 | { |
|
66 | { | |
65 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
67 | disconnect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
66 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
68 | disconnect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
67 | } |
|
69 | } | |
68 |
|
70 | |||
69 | /*! |
|
71 | /*! | |
70 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
72 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
71 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
73 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
72 | the y axis). |
|
74 | the y axis). | |
73 | */ |
|
75 | */ | |
74 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
76 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
75 | { |
|
77 | { | |
76 | m_dataset->addSeries(series, axisY); |
|
78 | m_dataset->addSeries(series, axisY); | |
77 | } |
|
79 | } | |
78 |
|
80 | |||
79 | /*! |
|
81 | /*! | |
80 | Removes the \a series specified in a perameter from the QChartView. |
|
82 | Removes the \a series specified in a perameter from the QChartView. | |
81 | It releses its ownership of the specified QChartSeries object. |
|
83 | It releses its ownership of the specified QChartSeries object. | |
82 | It does not delete the pointed QChartSeries data object |
|
84 | It does not delete the pointed QChartSeries data object | |
83 | \sa addSeries(), removeAllSeries() |
|
85 | \sa addSeries(), removeAllSeries() | |
84 | */ |
|
86 | */ | |
85 | void QChart::removeSeries(QSeries* series) |
|
87 | void QChart::removeSeries(QSeries* series) | |
86 | { |
|
88 | { | |
87 | m_dataset->removeSeries(series); |
|
89 | m_dataset->removeSeries(series); | |
88 | } |
|
90 | } | |
89 |
|
91 | |||
90 | /*! |
|
92 | /*! | |
91 | Removes all the QChartSeries that have been added to the QChartView |
|
93 | Removes all the QChartSeries that have been added to the QChartView | |
92 | It also deletes the pointed QChartSeries data objects |
|
94 | It also deletes the pointed QChartSeries data objects | |
93 | \sa addSeries(), removeSeries() |
|
95 | \sa addSeries(), removeSeries() | |
94 | */ |
|
96 | */ | |
95 | void QChart::removeAllSeries() |
|
97 | void QChart::removeAllSeries() | |
96 | { |
|
98 | { | |
97 | m_dataset->removeAllSeries(); |
|
99 | m_dataset->removeAllSeries(); | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | /*! |
|
102 | /*! | |
101 | Sets the \a brush that is used for painting the background of the chart area. |
|
103 | Sets the \a brush that is used for painting the background of the chart area. | |
102 | */ |
|
104 | */ | |
103 | void QChart::setChartBackgroundBrush(const QBrush& brush) |
|
105 | void QChart::setChartBackgroundBrush(const QBrush& brush) | |
104 | { |
|
106 | { | |
105 | createChartBackgroundItem(); |
|
107 | createChartBackgroundItem(); | |
106 | m_backgroundItem->setBrush(brush); |
|
108 | m_backgroundItem->setBrush(brush); | |
107 | m_backgroundItem->update(); |
|
109 | m_backgroundItem->update(); | |
108 | } |
|
110 | } | |
109 |
|
111 | |||
110 | /*! |
|
112 | /*! | |
111 | Sets the \a pen that is used for painting the background of the chart area. |
|
113 | Sets the \a pen that is used for painting the background of the chart area. | |
112 | */ |
|
114 | */ | |
113 | void QChart::setChartBackgroundPen(const QPen& pen) |
|
115 | void QChart::setChartBackgroundPen(const QPen& pen) | |
114 | { |
|
116 | { | |
115 | createChartBackgroundItem(); |
|
117 | createChartBackgroundItem(); | |
116 | m_backgroundItem->setPen(pen); |
|
118 | m_backgroundItem->setPen(pen); | |
117 | m_backgroundItem->update(); |
|
119 | m_backgroundItem->update(); | |
118 | } |
|
120 | } | |
119 |
|
121 | |||
120 | /*! |
|
122 | /*! | |
121 | Sets the chart \a title. The description text that is drawn above the chart. |
|
123 | Sets the chart \a title. The description text that is drawn above the chart. | |
122 | */ |
|
124 | */ | |
123 | void QChart::setChartTitle(const QString& title) |
|
125 | void QChart::setChartTitle(const QString& title) | |
124 | { |
|
126 | { | |
125 | createChartTitleItem(); |
|
127 | createChartTitleItem(); | |
126 | m_titleItem->setText(title); |
|
128 | m_titleItem->setText(title); | |
127 | updateLayout(); |
|
129 | updateLayout(); | |
128 | } |
|
130 | } | |
129 |
|
131 | |||
130 | /*! |
|
132 | /*! | |
131 | Returns the chart title. The description text that is drawn above the chart. |
|
133 | Returns the chart title. The description text that is drawn above the chart. | |
132 | */ |
|
134 | */ | |
133 | QString QChart::chartTitle() const |
|
135 | QString QChart::chartTitle() const | |
134 | { |
|
136 | { | |
135 | if(m_titleItem) |
|
137 | if(m_titleItem) | |
136 | return m_titleItem->text(); |
|
138 | return m_titleItem->text(); | |
137 | else |
|
139 | else | |
138 | return QString(); |
|
140 | return QString(); | |
139 | } |
|
141 | } | |
140 |
|
142 | |||
141 | /*! |
|
143 | /*! | |
142 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
144 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
143 | */ |
|
145 | */ | |
144 | void QChart::setChartTitleFont(const QFont& font) |
|
146 | void QChart::setChartTitleFont(const QFont& font) | |
145 | { |
|
147 | { | |
146 | createChartTitleItem(); |
|
148 | createChartTitleItem(); | |
147 | m_titleItem->setFont(font); |
|
149 | m_titleItem->setFont(font); | |
148 | updateLayout(); |
|
150 | updateLayout(); | |
149 | } |
|
151 | } | |
150 |
|
152 | |||
151 | /*! |
|
153 | /*! | |
152 | Sets the \a brush used for rendering the title text. |
|
154 | Sets the \a brush used for rendering the title text. | |
153 | */ |
|
155 | */ | |
154 | void QChart::setChartTitleBrush(const QBrush &brush) |
|
156 | void QChart::setChartTitleBrush(const QBrush &brush) | |
155 | { |
|
157 | { | |
156 | createChartTitleItem(); |
|
158 | createChartTitleItem(); | |
157 | m_titleItem->setBrush(brush); |
|
159 | m_titleItem->setBrush(brush); | |
158 | updateLayout(); |
|
160 | updateLayout(); | |
159 | } |
|
161 | } | |
160 |
|
162 | |||
161 | /*! |
|
163 | /*! | |
162 | Returns the brush used for rendering the title text. |
|
164 | Returns the brush used for rendering the title text. | |
163 | */ |
|
165 | */ | |
164 | QBrush QChart::chartTitleBrush() |
|
166 | QBrush QChart::chartTitleBrush() | |
165 | { |
|
167 | { | |
166 | createChartTitleItem(); |
|
168 | createChartTitleItem(); | |
167 | return m_titleItem->brush(); |
|
169 | return m_titleItem->brush(); | |
168 | } |
|
170 | } | |
169 |
|
171 | |||
170 | void QChart::createChartBackgroundItem() |
|
172 | void QChart::createChartBackgroundItem() | |
171 | { |
|
173 | { | |
172 | if(!m_backgroundItem) { |
|
174 | if(!m_backgroundItem) { | |
173 | m_backgroundItem = new QGraphicsRectItem(this); |
|
175 | m_backgroundItem = new QGraphicsRectItem(this); | |
174 | m_backgroundItem->setPen(Qt::NoPen); |
|
176 | m_backgroundItem->setPen(Qt::NoPen); | |
175 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
177 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
176 | } |
|
178 | } | |
177 | } |
|
179 | } | |
178 |
|
180 | |||
179 | void QChart::createChartTitleItem() |
|
181 | void QChart::createChartTitleItem() | |
180 | { |
|
182 | { | |
181 | if(!m_titleItem) { |
|
183 | if(!m_titleItem) { | |
182 | m_titleItem = new QGraphicsSimpleTextItem(this); |
|
184 | m_titleItem = new QGraphicsSimpleTextItem(this); | |
183 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
185 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
184 | } |
|
186 | } | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | /*! |
|
189 | /*! | |
188 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
190 | Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
189 | \sa setMargin() |
|
191 | \sa setMargin() | |
190 | */ |
|
192 | */ | |
191 | int QChart::margin() const |
|
193 | int QChart::margin() const | |
192 | { |
|
194 | { | |
193 | return m_presenter->margin(); |
|
195 | return m_presenter->margin(); | |
194 | } |
|
196 | } | |
195 |
|
197 | |||
196 | /*! |
|
198 | /*! | |
197 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. |
|
199 | Sets the chart \a margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed. | |
198 | \sa margin() |
|
200 | \sa margin() | |
199 | */ |
|
201 | */ | |
200 | void QChart::setMargin(int margin) |
|
202 | void QChart::setMargin(int margin) | |
201 | { |
|
203 | { | |
202 | m_presenter->setMargin(margin); |
|
204 | m_presenter->setMargin(margin); | |
203 | updateLayout(); |
|
205 | updateLayout(); | |
204 | } |
|
206 | } | |
205 |
|
207 | |||
206 | /*! |
|
208 | /*! | |
207 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
209 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
208 | \sa ChartTheme, chartTheme() |
|
210 | \sa ChartTheme, chartTheme() | |
209 | */ |
|
211 | */ | |
210 | void QChart::setChartTheme(QChart::ChartTheme theme) |
|
212 | void QChart::setChartTheme(QChart::ChartTheme theme) | |
211 | { |
|
213 | { | |
212 | m_presenter->setChartTheme(theme); |
|
214 | m_presenter->setChartTheme(theme); | |
213 | } |
|
215 | } | |
214 |
|
216 | |||
215 | /*! |
|
217 | /*! | |
216 | Returns the theme enum used by the chart. |
|
218 | Returns the theme enum used by the chart. | |
217 | \sa ChartTheme, setChartTheme() |
|
219 | \sa ChartTheme, setChartTheme() | |
218 | */ |
|
220 | */ | |
219 | QChart::ChartTheme QChart::chartTheme() const |
|
221 | QChart::ChartTheme QChart::chartTheme() const | |
220 | { |
|
222 | { | |
221 | return m_presenter->chartTheme(); |
|
223 | return m_presenter->chartTheme(); | |
222 | } |
|
224 | } | |
223 |
|
225 | |||
224 | /*! |
|
226 | /*! | |
225 | Zooms in the view by a factor of 2 |
|
227 | Zooms in the view by a factor of 2 | |
226 | */ |
|
228 | */ | |
227 | void QChart::zoomIn() |
|
229 | void QChart::zoomIn() | |
228 | { |
|
230 | { | |
229 | m_presenter->zoomIn(); |
|
231 | m_presenter->zoomIn(); | |
230 | } |
|
232 | } | |
231 |
|
233 | |||
232 | /*! |
|
234 | /*! | |
233 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
235 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
234 | */ |
|
236 | */ | |
235 | void QChart::zoomIn(const QRectF& rect) |
|
237 | void QChart::zoomIn(const QRectF& rect) | |
236 | { |
|
238 | { | |
237 |
|
239 | |||
238 | if(!rect.isValid()) return; |
|
240 | if(!rect.isValid()) return; | |
239 | m_presenter->zoomIn(rect); |
|
241 | m_presenter->zoomIn(rect); | |
240 | } |
|
242 | } | |
241 |
|
243 | |||
242 | /*! |
|
244 | /*! | |
243 | Restores the view zoom level to the previous one. |
|
245 | Restores the view zoom level to the previous one. | |
244 | */ |
|
246 | */ | |
245 | void QChart::zoomOut() |
|
247 | void QChart::zoomOut() | |
246 | { |
|
248 | { | |
247 | m_presenter->zoomOut(); |
|
249 | m_presenter->zoomOut(); | |
248 | } |
|
250 | } | |
249 |
|
251 | |||
250 | /*! |
|
252 | /*! | |
251 | Resets to the default view. |
|
253 | Resets to the default view. | |
252 | */ |
|
254 | */ | |
253 | void QChart::zoomReset() |
|
255 | void QChart::zoomReset() | |
254 | { |
|
256 | { | |
255 | m_presenter->zoomReset(); |
|
257 | m_presenter->zoomReset(); | |
256 | } |
|
258 | } | |
257 |
|
259 | |||
258 | /*! |
|
260 | /*! | |
259 | Returns the pointer to the x axis object of the chart |
|
261 | Returns the pointer to the x axis object of the chart | |
260 | */ |
|
262 | */ | |
261 | QChartAxis* QChart::axisX() const |
|
263 | QChartAxis* QChart::axisX() const | |
262 | { |
|
264 | { | |
263 | return m_dataset->axisX(); |
|
265 | return m_dataset->axisX(); | |
264 | } |
|
266 | } | |
265 |
|
267 | |||
266 | /*! |
|
268 | /*! | |
267 | Returns the pointer to the y axis object of the chart |
|
269 | Returns the pointer to the y axis object of the chart | |
268 | */ |
|
270 | */ | |
269 | QChartAxis* QChart::axisY() const |
|
271 | QChartAxis* QChart::axisY() const | |
270 | { |
|
272 | { | |
271 | return m_dataset->axisY(); |
|
273 | return m_dataset->axisY(); | |
272 | } |
|
274 | } | |
273 |
|
275 | |||
274 | /*! |
|
276 | /*! | |
275 | Returns the legend object of the chart |
|
277 | Returns the legend object of the chart | |
276 | */ |
|
278 | */ | |
277 | QLegend* QChart::legend() |
|
279 | QLegend* QChart::legend() | |
278 | { |
|
280 | { | |
279 | return m_legend; |
|
281 | return m_legend; | |
280 | } |
|
282 | } | |
281 |
|
283 | |||
282 | /*! |
|
284 | /*! | |
283 | Resizes and updates the chart area using the \a event data |
|
285 | Resizes and updates the chart area using the \a event data | |
284 | */ |
|
286 | */ | |
285 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
287 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
286 | { |
|
288 | { | |
287 |
|
289 | |||
288 | m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
290 | m_rect = QRectF(QPoint(0,0),event->newSize()); | |
289 | updateLayout(); |
|
291 | updateLayout(); | |
290 | QGraphicsWidget::resizeEvent(event); |
|
292 | QGraphicsWidget::resizeEvent(event); | |
291 | update(); |
|
293 | update(); | |
292 | } |
|
294 | } | |
293 |
|
295 | |||
294 | /*! |
|
296 | /*! | |
295 | Sets animation \a options for the chart |
|
297 | Sets animation \a options for the chart | |
296 | */ |
|
298 | */ | |
297 | void QChart::setAnimationOptions(AnimationOptions options) |
|
299 | void QChart::setAnimationOptions(AnimationOptions options) | |
298 | { |
|
300 | { | |
299 | m_presenter->setAnimationOptions(options); |
|
301 | m_presenter->setAnimationOptions(options); | |
300 | } |
|
302 | } | |
301 |
|
303 | |||
302 | /*! |
|
304 | /*! | |
303 | Returns animation options for the chart |
|
305 | Returns animation options for the chart | |
304 | */ |
|
306 | */ | |
305 | QChart::AnimationOptions QChart::animationOptions() const |
|
307 | QChart::AnimationOptions QChart::animationOptions() const | |
306 | { |
|
308 | { | |
307 | return m_presenter->animationOptions(); |
|
309 | return m_presenter->animationOptions(); | |
308 | } |
|
310 | } | |
309 |
|
311 | |||
310 | void QChart::scroll(int dx,int dy) |
|
312 | void QChart::scroll(int dx,int dy) | |
311 | { |
|
313 | { | |
312 | //temporary |
|
314 | //temporary | |
313 | if(dx>0) |
|
315 | if(dx>0) | |
314 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
316 | m_presenter->scroll(m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
315 | if(dx<0) |
|
317 | if(dx<0) | |
316 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
318 | m_presenter->scroll(-m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
317 | if(dy>0) |
|
319 | if(dy>0) | |
318 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
320 | m_presenter->scroll(0,m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
319 | if(dy<0) |
|
321 | if(dy<0) | |
320 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
322 | m_presenter->scroll(0,-m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
321 | } |
|
323 | } | |
322 |
|
324 | |||
323 | void QChart::updateLayout() |
|
325 | void QChart::updateLayout() | |
324 | { |
|
326 | { | |
325 | if(!m_rect.isValid()) return; |
|
327 | if(!m_rect.isValid()) return; | |
326 |
|
328 | |||
327 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); |
|
329 | QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin()); | |
328 |
|
330 | |||
329 | // recalculate title position |
|
331 | // recalculate title position | |
330 | if (m_titleItem) { |
|
332 | if (m_titleItem) { | |
331 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
333 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
332 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); |
|
334 | m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2); | |
333 | } |
|
335 | } | |
334 |
|
336 | |||
335 | //recalculate background gradient |
|
337 | //recalculate background gradient | |
336 | if (m_backgroundItem) { |
|
338 | if (m_backgroundItem) { | |
337 | m_backgroundItem->setRect(rect); |
|
339 | m_backgroundItem->setRect(rect); | |
338 | } |
|
340 | } | |
339 | } |
|
341 | } | |
340 | #include "moc_qchart.cpp" |
|
342 | #include "moc_qchart.cpp" | |
341 |
|
343 | |||
342 | QTCOMMERCIALCHART_END_NAMESPACE |
|
344 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,104 +1,104 | |||||
1 | #ifndef QCHART_H |
|
1 | #ifndef QCHART_H | |
2 | #define QCHART_H |
|
2 | #define QCHART_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <qseries.h> |
|
5 | #include <qseries.h> | |
6 | #include <QGraphicsWidget> |
|
6 | #include <QGraphicsWidget> | |
7 | #include <QLinearGradient> |
|
7 | #include <QLinearGradient> | |
8 | #include <QFont> |
|
8 | #include <QFont> | |
9 |
|
9 | |||
10 | class QGraphicsSceneResizeEvent; |
|
10 | class QGraphicsSceneResizeEvent; | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
12 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
13 |
|
13 | |||
14 | class AxisItem; |
|
14 | class AxisItem; | |
15 | class QSeries; |
|
15 | class QSeries; | |
16 | class PlotDomain; |
|
16 | class PlotDomain; | |
17 | class BarPresenter; |
|
17 | class BarPresenter; | |
18 | class QChartAxis; |
|
18 | class QChartAxis; | |
19 | class ChartTheme; |
|
19 | class ChartTheme; | |
20 | class ChartItem; |
|
20 | class ChartItem; | |
21 | class ChartDataSet; |
|
21 | class ChartDataSet; | |
22 | class ChartPresenter; |
|
22 | class ChartPresenter; | |
23 | class QLegend; |
|
23 | class QLegend; | |
24 |
|
24 | |||
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
25 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
26 | { |
|
26 | { | |
27 | Q_OBJECT |
|
27 | Q_OBJECT | |
28 | public: |
|
28 | public: | |
29 | enum ChartTheme { |
|
29 | enum ChartTheme { | |
30 | ChartThemeDefault, |
|
30 | ChartThemeDefault, | |
31 | ChartThemeVanilla, |
|
31 | ChartThemeVanilla, | |
32 | ChartThemeIcy, |
|
32 | ChartThemeIcy, | |
33 | ChartThemeGrayscale, |
|
33 | ChartThemeGrayscale, | |
34 | ChartThemeScientific |
|
34 | ChartThemeScientific, | |
35 |
|
|
35 | ChartThemeBlueCerulean, | |
36 | /*! The default theme follows the GUI style of the Operating System */ |
|
36 | ChartThemeCount | |
37 | }; |
|
37 | }; | |
38 |
|
38 | |||
39 | enum AnimationOption { |
|
39 | enum AnimationOption { | |
40 | NoAnimation = 0x0, |
|
40 | NoAnimation = 0x0, | |
41 | GridAxisAnimations = 0x1, |
|
41 | GridAxisAnimations = 0x1, | |
42 | SeriesAnimations =0x2, |
|
42 | SeriesAnimations =0x2, | |
43 | AllAnimations = 0x3 |
|
43 | AllAnimations = 0x3 | |
44 | }; |
|
44 | }; | |
45 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
45 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
48 | QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
49 | ~QChart(); |
|
49 | ~QChart(); | |
50 |
|
50 | |||
51 | void addSeries(QSeries* series, QChartAxis* axisY = 0); |
|
51 | void addSeries(QSeries* series, QChartAxis* axisY = 0); | |
52 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached |
|
52 | void removeSeries(QSeries* series); //returns ownership , deletes axis if no series attached | |
53 | void removeAllSeries(); // deletes series and axis |
|
53 | void removeAllSeries(); // deletes series and axis | |
54 |
|
54 | |||
55 | void setMargin(int margin); |
|
55 | void setMargin(int margin); | |
56 | int margin() const; |
|
56 | int margin() const; | |
57 | void setChartTheme(QChart::ChartTheme theme); |
|
57 | void setChartTheme(QChart::ChartTheme theme); | |
58 | QChart::ChartTheme chartTheme() const; |
|
58 | QChart::ChartTheme chartTheme() const; | |
59 |
|
59 | |||
60 | void setChartTitle(const QString& title); |
|
60 | void setChartTitle(const QString& title); | |
61 | QString chartTitle() const; |
|
61 | QString chartTitle() const; | |
62 | void setChartTitleFont(const QFont& font); |
|
62 | void setChartTitleFont(const QFont& font); | |
63 | void setChartTitleBrush(const QBrush &brush); |
|
63 | void setChartTitleBrush(const QBrush &brush); | |
64 | QBrush chartTitleBrush(); |
|
64 | QBrush chartTitleBrush(); | |
65 | void setChartBackgroundBrush(const QBrush& brush); |
|
65 | void setChartBackgroundBrush(const QBrush& brush); | |
66 | void setChartBackgroundPen(const QPen& pen); |
|
66 | void setChartBackgroundPen(const QPen& pen); | |
67 |
|
67 | |||
68 | void setAnimationOptions(AnimationOptions options); |
|
68 | void setAnimationOptions(AnimationOptions options); | |
69 | AnimationOptions animationOptions() const; |
|
69 | AnimationOptions animationOptions() const; | |
70 |
|
70 | |||
71 | void zoomIn(); |
|
71 | void zoomIn(); | |
72 | void zoomIn(const QRectF& rect); |
|
72 | void zoomIn(const QRectF& rect); | |
73 | void zoomOut(); |
|
73 | void zoomOut(); | |
74 | void zoomReset(); |
|
74 | void zoomReset(); | |
75 | void scroll(int dx,int dy); |
|
75 | void scroll(int dx,int dy); | |
76 |
|
76 | |||
77 | QChartAxis* axisX() const; |
|
77 | QChartAxis* axisX() const; | |
78 | QChartAxis* axisY() const; |
|
78 | QChartAxis* axisY() const; | |
79 |
|
79 | |||
80 | QLegend* legend(); |
|
80 | QLegend* legend(); | |
81 |
|
81 | |||
82 | protected: |
|
82 | protected: | |
83 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
83 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
84 |
|
84 | |||
85 | private: |
|
85 | private: | |
86 | inline void createChartBackgroundItem(); |
|
86 | inline void createChartBackgroundItem(); | |
87 | inline void createChartTitleItem(); |
|
87 | inline void createChartTitleItem(); | |
88 | void updateLayout(); |
|
88 | void updateLayout(); | |
89 |
|
89 | |||
90 | private: |
|
90 | private: | |
91 | Q_DISABLE_COPY(QChart) |
|
91 | Q_DISABLE_COPY(QChart) | |
92 | QGraphicsRectItem* m_backgroundItem; |
|
92 | QGraphicsRectItem* m_backgroundItem; | |
93 | QGraphicsSimpleTextItem* m_titleItem; |
|
93 | QGraphicsSimpleTextItem* m_titleItem; | |
94 | QRectF m_rect; |
|
94 | QRectF m_rect; | |
95 | QLegend* m_legend; |
|
95 | QLegend* m_legend; | |
96 | ChartDataSet *m_dataset; |
|
96 | ChartDataSet *m_dataset; | |
97 | ChartPresenter *m_presenter; |
|
97 | ChartPresenter *m_presenter; | |
98 | }; |
|
98 | }; | |
99 |
|
99 | |||
100 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
101 |
|
101 | |||
102 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
102 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
103 |
|
103 | |||
104 | #endif |
|
104 | #endif |
@@ -1,98 +1,99 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | CONFIG += debug_and_release |
|
7 | CONFIG += debug_and_release | |
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
8 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
9 | SOURCES += \ |
|
9 | SOURCES += \ | |
10 | chartdataset.cpp \ |
|
10 | chartdataset.cpp \ | |
11 | chartpresenter.cpp \ |
|
11 | chartpresenter.cpp \ | |
12 | charttheme.cpp \ |
|
12 | charttheme.cpp \ | |
13 | domain.cpp \ |
|
13 | domain.cpp \ | |
14 | qchart.cpp \ |
|
14 | qchart.cpp \ | |
15 | qchartview.cpp \ |
|
15 | qchartview.cpp \ | |
16 | qseries.cpp \ |
|
16 | qseries.cpp \ | |
17 | qlegend.cpp \ |
|
17 | qlegend.cpp \ | |
18 | legendmarker.cpp |
|
18 | legendmarker.cpp | |
19 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += \ | |
20 | chartdataset_p.h \ |
|
20 | chartdataset_p.h \ | |
21 | chartitem_p.h \ |
|
21 | chartitem_p.h \ | |
22 | chartpresenter_p.h \ |
|
22 | chartpresenter_p.h \ | |
23 | charttheme_p.h \ |
|
23 | charttheme_p.h \ | |
24 | domain_p.h \ |
|
24 | domain_p.h \ | |
25 | legendmarker_p.h |
|
25 | legendmarker_p.h | |
26 | PUBLIC_HEADERS += \ |
|
26 | PUBLIC_HEADERS += \ | |
27 | qchart.h \ |
|
27 | qchart.h \ | |
28 | qchartglobal.h \ |
|
28 | qchartglobal.h \ | |
29 | qseries.h \ |
|
29 | qseries.h \ | |
30 | qchartview.h \ |
|
30 | qchartview.h \ | |
31 | qlegend.h |
|
31 | qlegend.h | |
32 |
|
32 | |||
33 | include(animations/animations.pri) |
|
33 | include(animations/animations.pri) | |
34 | include(axis/axis.pri) |
|
34 | include(axis/axis.pri) | |
35 | include(xychart/xychart.pri) |
|
35 | include(xychart/xychart.pri) | |
36 | include(linechart/linechart.pri) |
|
36 | include(linechart/linechart.pri) | |
37 | include(areachart/areachart.pri) |
|
37 | include(areachart/areachart.pri) | |
38 | include(barchart/barchart.pri) |
|
38 | include(barchart/barchart.pri) | |
39 | include(piechart/piechart.pri) |
|
39 | include(piechart/piechart.pri) | |
40 | include(scatterseries/scatter.pri) |
|
40 | include(scatterseries/scatter.pri) | |
41 | include(splinechart/splinechart.pri) |
|
41 | include(splinechart/splinechart.pri) | |
42 |
|
42 | |||
43 | THEMES += themes/chartthemedefault_p.h \ |
|
43 | THEMES += themes/chartthemedefault_p.h \ | |
44 | themes/chartthemeicy_p.h \ |
|
44 | themes/chartthemeicy_p.h \ | |
45 | themes/chartthemegrayscale_p.h \ |
|
45 | themes/chartthemegrayscale_p.h \ | |
46 | themes/chartthemescientific_p.h \ |
|
46 | themes/chartthemescientific_p.h \ | |
47 | themes/chartthemevanilla_p.h |
|
47 | themes/chartthemevanilla_p.h \ | |
|
48 | themes/chartthemebluecerulean_p.h | |||
48 | HEADERS += $$PUBLIC_HEADERS |
|
49 | HEADERS += $$PUBLIC_HEADERS | |
49 | HEADERS += $$PRIVATE_HEADERS |
|
50 | HEADERS += $$PRIVATE_HEADERS | |
50 | HEADERS += $$THEMES |
|
51 | HEADERS += $$THEMES | |
51 | INCLUDEPATH += linechart \ |
|
52 | INCLUDEPATH += linechart \ | |
52 | barchart \ |
|
53 | barchart \ | |
53 | themes \ |
|
54 | themes \ | |
54 | . |
|
55 | . | |
55 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
56 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
56 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
57 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
57 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
58 | UI_DIR = $$CHART_BUILD_DIR/lib | |
58 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
59 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
59 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
60 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
60 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
61 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
61 | public_headers.files = $$PUBLIC_HEADERS |
|
62 | public_headers.files = $$PUBLIC_HEADERS | |
62 | target.path = $$[QT_INSTALL_LIBS] |
|
63 | target.path = $$[QT_INSTALL_LIBS] | |
63 | INSTALLS += target \ |
|
64 | INSTALLS += target \ | |
64 | public_headers |
|
65 | public_headers | |
65 | install_build_public_headers.name = bild_public_headers |
|
66 | install_build_public_headers.name = bild_public_headers | |
66 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
67 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
67 | install_build_public_headers.input = PUBLIC_HEADERS |
|
68 | install_build_public_headers.input = PUBLIC_HEADERS | |
68 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
69 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
69 | ${QMAKE_FILE_NAME} \ |
|
70 | ${QMAKE_FILE_NAME} \ | |
70 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
71 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
71 | install_build_public_headers.CONFIG += target_predeps \ |
|
72 | install_build_public_headers.CONFIG += target_predeps \ | |
72 | no_link |
|
73 | no_link | |
73 | install_build_private_headers.name = bild_private_headers |
|
74 | install_build_private_headers.name = bild_private_headers | |
74 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
75 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
75 | install_build_private_headers.input = PRIVATE_HEADERS |
|
76 | install_build_private_headers.input = PRIVATE_HEADERS | |
76 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
77 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
77 | ${QMAKE_FILE_NAME} \ |
|
78 | ${QMAKE_FILE_NAME} \ | |
78 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
79 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
79 | install_build_private_headers.CONFIG += target_predeps \ |
|
80 | install_build_private_headers.CONFIG += target_predeps \ | |
80 | no_link |
|
81 | no_link | |
81 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
82 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
82 | install_build_private_headers |
|
83 | install_build_private_headers | |
83 | chartversion.target = qchartversion_p.h |
|
84 | chartversion.target = qchartversion_p.h | |
84 | chartversion.commands = @echo \ |
|
85 | chartversion.commands = @echo \ | |
85 | "build_time" \ |
|
86 | "build_time" \ | |
86 | > \ |
|
87 | > \ | |
87 | $$chartversion.target; |
|
88 | $$chartversion.target; | |
88 | chartversion.depends = $$HEADERS \ |
|
89 | chartversion.depends = $$HEADERS \ | |
89 | $$SOURCES |
|
90 | $$SOURCES | |
90 | PRE_TARGETDEPS += qchartversion_p.h |
|
91 | PRE_TARGETDEPS += qchartversion_p.h | |
91 | QMAKE_CLEAN += qchartversion_p.h |
|
92 | QMAKE_CLEAN += qchartversion_p.h | |
92 | QMAKE_EXTRA_TARGETS += chartversion |
|
93 | QMAKE_EXTRA_TARGETS += chartversion | |
93 | unix:QMAKE_DISTCLEAN += -r \ |
|
94 | unix:QMAKE_DISTCLEAN += -r \ | |
94 | $$CHART_BUILD_HEADER_DIR \ |
|
95 | $$CHART_BUILD_HEADER_DIR \ | |
95 | $$CHART_BUILD_LIB_DIR |
|
96 | $$CHART_BUILD_LIB_DIR | |
96 | win32:QMAKE_DISTCLEAN += /Q \ |
|
97 | win32:QMAKE_DISTCLEAN += /Q \ | |
97 | $$CHART_BUILD_HEADER_DIR \ |
|
98 | $$CHART_BUILD_HEADER_DIR \ | |
98 | $$CHART_BUILD_LIB_DIR |
|
99 | $$CHART_BUILD_LIB_DIR |
General Comments 0
You need to be logged in to leave comments.
Login now