@@ -0,0 +1,121 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef QLEGENDMARKERPRIVATE_H | |||
|
31 | #define QLEGENDMARKERPRIVATE_H | |||
|
32 | ||||
|
33 | #include "qchartglobal.h" | |||
|
34 | #include <QGraphicsObject> | |||
|
35 | #include <QBrush> | |||
|
36 | #include <QPen> | |||
|
37 | #include <QGraphicsSimpleTextItem> | |||
|
38 | #include <QGraphicsLayoutItem> | |||
|
39 | ||||
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
41 | ||||
|
42 | // TODO: check these | |||
|
43 | class QAbstractSeries; | |||
|
44 | class QAreaSeries; | |||
|
45 | class QXYSeries; | |||
|
46 | class QBarSet; | |||
|
47 | class QAbstractBarSeries; | |||
|
48 | class QPieSlice; | |||
|
49 | class QLegend; | |||
|
50 | class QPieSeries; | |||
|
51 | ||||
|
52 | class QLegendMarker; | |||
|
53 | ||||
|
54 | class QLegendMarkerPrivate : public QGraphicsObject, public QGraphicsLayoutItem | |||
|
55 | { | |||
|
56 | Q_OBJECT | |||
|
57 | Q_INTERFACES(QGraphicsLayoutItem) | |||
|
58 | public: | |||
|
59 | explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); | |||
|
60 | /* | |||
|
61 | void setPen(const QPen &pen); | |||
|
62 | QPen pen() const; | |||
|
63 | ||||
|
64 | void setBrush(const QBrush &brush); | |||
|
65 | QBrush brush() const; | |||
|
66 | ||||
|
67 | void setFont(const QFont &font); | |||
|
68 | QFont font() const; | |||
|
69 | ||||
|
70 | void setLabel(const QString label); | |||
|
71 | QString label() const; | |||
|
72 | ||||
|
73 | void setLabelBrush(const QBrush &brush); | |||
|
74 | QBrush labelBrush() const; | |||
|
75 | */ | |||
|
76 | void setGeometry(const QRectF& rect); | |||
|
77 | ||||
|
78 | QRectF boundingRect() const; | |||
|
79 | ||||
|
80 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |||
|
81 | ||||
|
82 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; | |||
|
83 | ||||
|
84 | protected: | |||
|
85 | // From QGraphicsObject | |||
|
86 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |||
|
87 | ||||
|
88 | public Q_SLOTS: | |||
|
89 | virtual void updated() {}; | |||
|
90 | ||||
|
91 | private: | |||
|
92 | QLegendMarker *q_ptr; | |||
|
93 | ||||
|
94 | /* | |||
|
95 | QLegend* m_legend; | |||
|
96 | */ | |||
|
97 | ||||
|
98 | // New legend marker properties | |||
|
99 | QAbstractSeries* m_series; | |||
|
100 | QString m_label; | |||
|
101 | QBrush m_labelBrush; | |||
|
102 | QFont m_font; | |||
|
103 | QPen m_pen; | |||
|
104 | QBrush m_brush; | |||
|
105 | bool m_visible; | |||
|
106 | ||||
|
107 | // Implementation details of new marker | |||
|
108 | QRectF m_markerRect; | |||
|
109 | QRectF m_boundingRect; | |||
|
110 | QGraphicsSimpleTextItem *m_textItem; | |||
|
111 | QGraphicsRectItem *m_rectItem; | |||
|
112 | qreal m_margin; | |||
|
113 | qreal m_space; | |||
|
114 | ||||
|
115 | friend class QLegendPrivate; // TODO: Is this needed? | |||
|
116 | Q_DECLARE_PUBLIC(QLegendMarker) | |||
|
117 | }; | |||
|
118 | ||||
|
119 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
120 | ||||
|
121 | #endif // QLEGENDMARKERPRIVATE_H |
@@ -1,246 +1,259 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include <QChart> |
|
22 | #include <QChart> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPushButton> |
|
24 | #include <QPushButton> | |
25 | #include <QLabel> |
|
25 | #include <QLabel> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 | #include <QFormLayout> |
|
28 | #include <QFormLayout> | |
29 | #include <QPieSeries> |
|
29 | #include <QPieSeries> | |
30 | #include <QPieSlice> |
|
30 | #include <QPieSlice> | |
|
31 | #include <QLegendMarker> | |||
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
34 | |||
34 | MainWidget::MainWidget(QWidget *parent) : |
|
35 | MainWidget::MainWidget(QWidget *parent) : | |
35 | QWidget(parent) |
|
36 | QWidget(parent) | |
36 | { |
|
37 | { | |
37 | // Create buttons for ui |
|
38 | // Create buttons for ui | |
38 | m_buttonLayout = new QGridLayout(); |
|
39 | m_buttonLayout = new QGridLayout(); | |
39 | QPushButton *detachLegendButton = new QPushButton("Toggle attached"); |
|
40 | QPushButton *detachLegendButton = new QPushButton("Toggle attached"); | |
40 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); |
|
41 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); | |
41 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
42 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); | |
42 |
|
43 | |||
43 | QPushButton *addSliceButton = new QPushButton("add slice"); |
|
44 | QPushButton *addSliceButton = new QPushButton("add slice"); | |
44 | connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSlice())); |
|
45 | connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSlice())); | |
45 | m_buttonLayout->addWidget(addSliceButton, 2, 0); |
|
46 | m_buttonLayout->addWidget(addSliceButton, 2, 0); | |
46 | QPushButton *removeSliceButton = new QPushButton("remove slice"); |
|
47 | QPushButton *removeSliceButton = new QPushButton("remove slice"); | |
47 | connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
48 | connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
48 | m_buttonLayout->addWidget(removeSliceButton, 3, 0); |
|
49 | m_buttonLayout->addWidget(removeSliceButton, 3, 0); | |
49 |
|
50 | |||
50 | QPushButton *alignButton = new QPushButton("Align (Bottom)"); |
|
51 | QPushButton *alignButton = new QPushButton("Align (Bottom)"); | |
51 | connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); |
|
52 | connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); | |
52 | m_buttonLayout->addWidget(alignButton, 4, 0); |
|
53 | m_buttonLayout->addWidget(alignButton, 4, 0); | |
53 |
|
54 | |||
54 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
55 | QPushButton *boldButton = new QPushButton("Toggle bold"); | |
55 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
56 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); | |
56 |
m_buttonLayout->addWidget(boldButton, |
|
57 | m_buttonLayout->addWidget(boldButton, 5, 0); | |
57 |
|
58 | |||
58 | QPushButton *italicButton = new QPushButton("Toggle italic"); |
|
59 | QPushButton *italicButton = new QPushButton("Toggle italic"); | |
59 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); |
|
60 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); | |
60 |
m_buttonLayout->addWidget(italicButton, |
|
61 | m_buttonLayout->addWidget(italicButton, 6, 0); | |
|
62 | ||||
|
63 | QPushButton *infoButton = new QPushButton("Debug info"); | |||
|
64 | connect(infoButton, SIGNAL(clicked()), this, SLOT(showDebugInfo())); | |||
|
65 | m_buttonLayout->addWidget(infoButton, 7, 0); | |||
61 |
|
66 | |||
62 | m_legendPosX = new QDoubleSpinBox(); |
|
67 | m_legendPosX = new QDoubleSpinBox(); | |
63 | m_legendPosY = new QDoubleSpinBox(); |
|
68 | m_legendPosY = new QDoubleSpinBox(); | |
64 | m_legendWidth = new QDoubleSpinBox(); |
|
69 | m_legendWidth = new QDoubleSpinBox(); | |
65 | m_legendHeight = new QDoubleSpinBox(); |
|
70 | m_legendHeight = new QDoubleSpinBox(); | |
66 |
|
71 | |||
67 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
72 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
68 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
73 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
69 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
74 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
70 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
75 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
71 |
|
76 | |||
72 | QFormLayout* legendLayout = new QFormLayout(); |
|
77 | QFormLayout* legendLayout = new QFormLayout(); | |
73 | legendLayout->addRow("HPos", m_legendPosX); |
|
78 | legendLayout->addRow("HPos", m_legendPosX); | |
74 | legendLayout->addRow("VPos", m_legendPosY); |
|
79 | legendLayout->addRow("VPos", m_legendPosY); | |
75 | legendLayout->addRow("Width", m_legendWidth); |
|
80 | legendLayout->addRow("Width", m_legendWidth); | |
76 | legendLayout->addRow("Height", m_legendHeight); |
|
81 | legendLayout->addRow("Height", m_legendHeight); | |
77 | m_legendSettings = new QGroupBox("Detached legend"); |
|
82 | m_legendSettings = new QGroupBox("Detached legend"); | |
78 | m_legendSettings->setLayout(legendLayout); |
|
83 | m_legendSettings->setLayout(legendLayout); | |
79 | m_buttonLayout->addWidget(m_legendSettings); |
|
84 | m_buttonLayout->addWidget(m_legendSettings); | |
80 | m_legendSettings->setVisible(false); |
|
85 | m_legendSettings->setVisible(false); | |
81 |
|
86 | |||
82 | // Create chart view with the chart |
|
87 | // Create chart view with the chart | |
83 | m_chart = new QChart(); |
|
88 | m_chart = new QChart(); | |
84 | m_chartView = new QChartView(m_chart, this); |
|
89 | m_chartView = new QChartView(m_chart, this); | |
85 |
|
90 | |||
86 | // Create spinbox to modify font size |
|
91 | // Create spinbox to modify font size | |
87 | m_fontSize = new QDoubleSpinBox(); |
|
92 | m_fontSize = new QDoubleSpinBox(); | |
88 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); |
|
93 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); | |
89 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); |
|
94 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); | |
90 |
|
95 | |||
91 | QFormLayout* fontLayout = new QFormLayout(); |
|
96 | QFormLayout* fontLayout = new QFormLayout(); | |
92 | fontLayout->addRow("Legend font size", m_fontSize); |
|
97 | fontLayout->addRow("Legend font size", m_fontSize); | |
93 |
|
98 | |||
94 | // Create layout for grid and detached legend |
|
99 | // Create layout for grid and detached legend | |
95 | m_mainLayout = new QGridLayout(); |
|
100 | m_mainLayout = new QGridLayout(); | |
96 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
101 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); | |
97 | m_mainLayout->addLayout(fontLayout,1,0); |
|
102 | m_mainLayout->addLayout(fontLayout,1,0); | |
98 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
103 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
99 | setLayout(m_mainLayout); |
|
104 | setLayout(m_mainLayout); | |
100 |
|
105 | |||
101 | createSeries(); |
|
106 | createSeries(); | |
102 | } |
|
107 | } | |
103 |
|
108 | |||
104 | void MainWidget::createSeries() |
|
109 | void MainWidget::createSeries() | |
105 | { |
|
110 | { | |
106 | m_series = new QPieSeries(); |
|
111 | m_series = new QPieSeries(); | |
107 | addSlice(); |
|
112 | addSlice(); | |
108 | addSlice(); |
|
113 | addSlice(); | |
109 | addSlice(); |
|
114 | addSlice(); | |
110 | addSlice(); |
|
115 | addSlice(); | |
111 |
|
116 | |||
112 | m_chart->addSeries(m_series); |
|
117 | m_chart->addSeries(m_series); | |
113 | m_chart->setTitle("Legend detach example"); |
|
118 | m_chart->setTitle("Legend detach example"); | |
114 | m_chart->createDefaultAxes(); |
|
119 | m_chart->createDefaultAxes(); | |
115 | //![1] |
|
120 | //![1] | |
116 | m_chart->legend()->setVisible(true); |
|
121 | m_chart->legend()->setVisible(true); | |
117 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
122 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
118 | //![1] |
|
123 | //![1] | |
119 |
|
124 | |||
120 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
125 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
121 | } |
|
126 | } | |
122 |
|
127 | |||
123 | void MainWidget::showLegendSpinbox() |
|
128 | void MainWidget::showLegendSpinbox() | |
124 | { |
|
129 | { | |
125 | m_legendSettings->setVisible(true); |
|
130 | m_legendSettings->setVisible(true); | |
126 | QRectF chartViewRect = m_chartView->rect(); |
|
131 | QRectF chartViewRect = m_chartView->rect(); | |
127 |
|
132 | |||
128 | m_legendPosX->setMinimum(0); |
|
133 | m_legendPosX->setMinimum(0); | |
129 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
134 | m_legendPosX->setMaximum(chartViewRect.width()); | |
130 | m_legendPosX->setValue(150); |
|
135 | m_legendPosX->setValue(150); | |
131 |
|
136 | |||
132 | m_legendPosY->setMinimum(0); |
|
137 | m_legendPosY->setMinimum(0); | |
133 | m_legendPosY->setMaximum(chartViewRect.height()); |
|
138 | m_legendPosY->setMaximum(chartViewRect.height()); | |
134 | m_legendPosY->setValue(150); |
|
139 | m_legendPosY->setValue(150); | |
135 |
|
140 | |||
136 | m_legendWidth->setMinimum(0); |
|
141 | m_legendWidth->setMinimum(0); | |
137 | m_legendWidth->setMaximum(chartViewRect.width()); |
|
142 | m_legendWidth->setMaximum(chartViewRect.width()); | |
138 | m_legendWidth->setValue(150); |
|
143 | m_legendWidth->setValue(150); | |
139 |
|
144 | |||
140 | m_legendHeight->setMinimum(0); |
|
145 | m_legendHeight->setMinimum(0); | |
141 | m_legendHeight->setMaximum(chartViewRect.height()); |
|
146 | m_legendHeight->setMaximum(chartViewRect.height()); | |
142 | m_legendHeight->setValue(75); |
|
147 | m_legendHeight->setValue(75); | |
143 | } |
|
148 | } | |
144 |
|
149 | |||
145 | void MainWidget::hideLegendSpinbox() |
|
150 | void MainWidget::hideLegendSpinbox() | |
146 | { |
|
151 | { | |
147 | m_legendSettings->setVisible(false); |
|
152 | m_legendSettings->setVisible(false); | |
148 | } |
|
153 | } | |
149 |
|
154 | |||
150 |
|
155 | |||
151 | void MainWidget::toggleAttached() |
|
156 | void MainWidget::toggleAttached() | |
152 | { |
|
157 | { | |
153 | QLegend *legend = m_chart->legend(); |
|
158 | QLegend *legend = m_chart->legend(); | |
154 | if (legend->isAttachedToChart()) { |
|
159 | if (legend->isAttachedToChart()) { | |
155 | //![2] |
|
160 | //![2] | |
156 | legend->detachFromChart(); |
|
161 | legend->detachFromChart(); | |
157 | m_chart->legend()->setBackgroundVisible(true); |
|
162 | m_chart->legend()->setBackgroundVisible(true); | |
158 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
163 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); | |
159 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
164 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); | |
160 | //![2] |
|
165 | //![2] | |
161 | showLegendSpinbox(); |
|
166 | showLegendSpinbox(); | |
162 | updateLegendLayout(); |
|
167 | updateLegendLayout(); | |
163 | } else { |
|
168 | } else { | |
164 | //![3] |
|
169 | //![3] | |
165 | legend->attachToChart(); |
|
170 | legend->attachToChart(); | |
166 | legend->setBackgroundVisible(false); |
|
171 | legend->setBackgroundVisible(false); | |
167 | //![3] |
|
172 | //![3] | |
168 | hideLegendSpinbox(); |
|
173 | hideLegendSpinbox(); | |
169 | } |
|
174 | } | |
170 | update(); |
|
175 | update(); | |
171 | } |
|
176 | } | |
172 |
|
177 | |||
173 | void MainWidget::addSlice() |
|
178 | void MainWidget::addSlice() | |
174 | { |
|
179 | { | |
175 | QPieSlice* slice = new QPieSlice(QString("slice " + QString::number(m_series->count())), m_series->count()+1); |
|
180 | QPieSlice* slice = new QPieSlice(QString("slice " + QString::number(m_series->count())), m_series->count()+1); | |
176 | // slice->setValue(); |
|
181 | // slice->setValue(); | |
177 | m_series->append(slice); |
|
182 | m_series->append(slice); | |
178 | } |
|
183 | } | |
179 |
|
184 | |||
180 | void MainWidget::removeSlice() |
|
185 | void MainWidget::removeSlice() | |
181 | { |
|
186 | { | |
182 | QList<QPieSlice*> slices = m_series->slices(); |
|
187 | QList<QPieSlice*> slices = m_series->slices(); | |
183 | if (slices.count() > 0) { |
|
188 | if (slices.count() > 0) { | |
184 | m_series->remove(slices.at(slices.count()-1)); |
|
189 | m_series->remove(slices.at(slices.count()-1)); | |
185 | } |
|
190 | } | |
186 | } |
|
191 | } | |
187 |
|
192 | |||
188 | void MainWidget::setLegendAlignment() |
|
193 | void MainWidget::setLegendAlignment() | |
189 | { |
|
194 | { | |
190 | QPushButton *button = qobject_cast<QPushButton *>(sender()); |
|
195 | QPushButton *button = qobject_cast<QPushButton *>(sender()); | |
191 |
|
196 | |||
192 | switch (m_chart->legend()->alignment()) { |
|
197 | switch (m_chart->legend()->alignment()) { | |
193 | case Qt::AlignTop: |
|
198 | case Qt::AlignTop: | |
194 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
199 | m_chart->legend()->setAlignment(Qt::AlignLeft); | |
195 | if (button) |
|
200 | if (button) | |
196 | button->setText("Align (Left)"); |
|
201 | button->setText("Align (Left)"); | |
197 | break; |
|
202 | break; | |
198 | case Qt::AlignLeft: |
|
203 | case Qt::AlignLeft: | |
199 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
204 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
200 | if (button) |
|
205 | if (button) | |
201 | button->setText("Align (Bottom)"); |
|
206 | button->setText("Align (Bottom)"); | |
202 | break; |
|
207 | break; | |
203 | case Qt::AlignBottom: |
|
208 | case Qt::AlignBottom: | |
204 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
209 | m_chart->legend()->setAlignment(Qt::AlignRight); | |
205 | if (button) |
|
210 | if (button) | |
206 | button->setText("Align (Right)"); |
|
211 | button->setText("Align (Right)"); | |
207 | break; |
|
212 | break; | |
208 | default: |
|
213 | default: | |
209 | if (button) |
|
214 | if (button) | |
210 | button->setText("Align (Top)"); |
|
215 | button->setText("Align (Top)"); | |
211 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
216 | m_chart->legend()->setAlignment(Qt::AlignTop); | |
212 | break; |
|
217 | break; | |
213 | } |
|
218 | } | |
214 | } |
|
219 | } | |
215 |
|
220 | |||
216 | void MainWidget::toggleBold() |
|
221 | void MainWidget::toggleBold() | |
217 | { |
|
222 | { | |
218 | QFont font = m_chart->legend()->font(); |
|
223 | QFont font = m_chart->legend()->font(); | |
219 | font.setBold(!font.bold()); |
|
224 | font.setBold(!font.bold()); | |
220 | m_chart->legend()->setFont(font); |
|
225 | m_chart->legend()->setFont(font); | |
221 | } |
|
226 | } | |
222 |
|
227 | |||
223 | void MainWidget::toggleItalic() |
|
228 | void MainWidget::toggleItalic() | |
224 | { |
|
229 | { | |
225 | QFont font = m_chart->legend()->font(); |
|
230 | QFont font = m_chart->legend()->font(); | |
226 | font.setItalic(!font.italic()); |
|
231 | font.setItalic(!font.italic()); | |
227 | m_chart->legend()->setFont(font); |
|
232 | m_chart->legend()->setFont(font); | |
228 | } |
|
233 | } | |
229 |
|
234 | |||
|
235 | void MainWidget::showDebugInfo() | |||
|
236 | { | |||
|
237 | qDebug() << "marker count:" << m_chart->legend()->markers().count(); | |||
|
238 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { | |||
|
239 | qDebug() << "label:" << marker->label(); | |||
|
240 | } | |||
|
241 | } | |||
|
242 | ||||
230 | void MainWidget::fontSizeChanged() |
|
243 | void MainWidget::fontSizeChanged() | |
231 | { |
|
244 | { | |
232 | QFont font = m_chart->legend()->font(); |
|
245 | QFont font = m_chart->legend()->font(); | |
233 | font.setPointSizeF(m_fontSize->value()); |
|
246 | font.setPointSizeF(m_fontSize->value()); | |
234 | m_chart->legend()->setFont(font); |
|
247 | m_chart->legend()->setFont(font); | |
235 | } |
|
248 | } | |
236 |
|
249 | |||
237 | void MainWidget::updateLegendLayout() |
|
250 | void MainWidget::updateLegendLayout() | |
238 | { |
|
251 | { | |
239 | //![4] |
|
252 | //![4] | |
240 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() |
|
253 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() | |
241 | ,m_legendPosY->value() |
|
254 | ,m_legendPosY->value() | |
242 | ,m_legendWidth->value() |
|
255 | ,m_legendWidth->value() | |
243 | ,m_legendHeight->value())); |
|
256 | ,m_legendHeight->value())); | |
244 | m_chart->legend()->update(); |
|
257 | m_chart->legend()->update(); | |
245 | //![4] |
|
258 | //![4] | |
246 | } |
|
259 | } |
@@ -1,83 +1,84 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef MAINWIDGET_H |
|
21 | #ifndef MAINWIDGET_H | |
22 | #define MAINWIDGET_H |
|
22 | #define MAINWIDGET_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include "qchartview.h" |
|
26 | #include "qchartview.h" | |
27 | #include <QWidget> |
|
27 | #include <QWidget> | |
28 | #include <QGraphicsWidget> |
|
28 | #include <QGraphicsWidget> | |
29 | #include <QGridLayout> |
|
29 | #include <QGridLayout> | |
30 | #include <QGraphicsGridLayout> |
|
30 | #include <QGraphicsGridLayout> | |
31 | #include <QDoubleSpinBox> |
|
31 | #include <QDoubleSpinBox> | |
32 | #include <QGroupBox> |
|
32 | #include <QGroupBox> | |
33 | #include <QPieSlice> |
|
33 | #include <QPieSlice> | |
34 | #include <QPieSeries> |
|
34 | #include <QPieSeries> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
37 |
|
37 | |||
38 | class MainWidget : public QWidget |
|
38 | class MainWidget : public QWidget | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | explicit MainWidget(QWidget *parent = 0); |
|
42 | explicit MainWidget(QWidget *parent = 0); | |
43 | void createSeries(); |
|
43 | void createSeries(); | |
44 | void showLegendSpinbox(); |
|
44 | void showLegendSpinbox(); | |
45 | void hideLegendSpinbox(); |
|
45 | void hideLegendSpinbox(); | |
46 |
|
46 | |||
47 | signals: |
|
47 | signals: | |
48 |
|
48 | |||
49 | public slots: |
|
49 | public slots: | |
50 | void toggleAttached(); |
|
50 | void toggleAttached(); | |
51 | void addSlice(); |
|
51 | void addSlice(); | |
52 | void removeSlice(); |
|
52 | void removeSlice(); | |
53 |
|
53 | |||
54 | void setLegendAlignment(); |
|
54 | void setLegendAlignment(); | |
55 |
|
55 | |||
56 | void toggleBold(); |
|
56 | void toggleBold(); | |
57 | void toggleItalic(); |
|
57 | void toggleItalic(); | |
|
58 | void showDebugInfo(); | |||
58 | void fontSizeChanged(); |
|
59 | void fontSizeChanged(); | |
59 |
|
60 | |||
60 | void updateLegendLayout(); |
|
61 | void updateLegendLayout(); | |
61 |
|
62 | |||
62 |
|
63 | |||
63 | private: |
|
64 | private: | |
64 |
|
65 | |||
65 | QChart *m_chart; |
|
66 | QChart *m_chart; | |
66 | QPieSeries *m_series; |
|
67 | QPieSeries *m_series; | |
67 |
|
68 | |||
68 | QChartView *m_chartView; |
|
69 | QChartView *m_chartView; | |
69 | QGridLayout *m_mainLayout; |
|
70 | QGridLayout *m_mainLayout; | |
70 | QGridLayout *m_buttonLayout; |
|
71 | QGridLayout *m_buttonLayout; | |
71 | QGridLayout *m_fontLayout; |
|
72 | QGridLayout *m_fontLayout; | |
72 |
|
73 | |||
73 | QDoubleSpinBox *m_fontSize; |
|
74 | QDoubleSpinBox *m_fontSize; | |
74 |
|
75 | |||
75 | // For detached layout |
|
76 | // For detached layout | |
76 | QGroupBox* m_legendSettings; |
|
77 | QGroupBox* m_legendSettings; | |
77 | QDoubleSpinBox *m_legendPosX; |
|
78 | QDoubleSpinBox *m_legendPosX; | |
78 | QDoubleSpinBox *m_legendPosY; |
|
79 | QDoubleSpinBox *m_legendPosY; | |
79 | QDoubleSpinBox *m_legendWidth; |
|
80 | QDoubleSpinBox *m_legendWidth; | |
80 | QDoubleSpinBox *m_legendHeight; |
|
81 | QDoubleSpinBox *m_legendHeight; | |
81 | }; |
|
82 | }; | |
82 |
|
83 | |||
83 | #endif // MAINWIDGET_H |
|
84 | #endif // MAINWIDGET_H |
@@ -1,400 +1,409 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "legendmarker_p.h" |
|
25 | #include "legendmarker_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QAreaSeries |
|
34 | \class QAreaSeries | |
35 | \brief The QAreaSeries class is used for making area charts. |
|
35 | \brief The QAreaSeries class is used for making area charts. | |
36 |
|
36 | |||
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
44 |
|
44 | |||
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
46 | \image examples_areachart.png |
|
46 | \image examples_areachart.png | |
47 | */ |
|
47 | */ | |
48 | /*! |
|
48 | /*! | |
49 | \qmlclass AreaSeries QAreaSeries |
|
49 | \qmlclass AreaSeries QAreaSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple area chart: |
|
51 | The following QML shows how to create a simple area chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart4.png |
|
54 | \image demos_qmlchart4.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QAreaSeries::upperSeries |
|
60 | \property QAreaSeries::upperSeries | |
61 | \brief The upper one of the two line series used to define area series boundaries. |
|
61 | \brief The upper one of the two line series used to define area series boundaries. | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
64 | \qmlproperty LineSeries AreaSeries::upperSeries | |
65 | The upper one of the two line series used to define area series boundaries. |
|
65 | The upper one of the two line series used to define area series boundaries. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QAreaSeries::lowerSeries |
|
69 | \property QAreaSeries::lowerSeries | |
70 | The lower one of the two line series used to define are series boundaries. Note if |
|
70 | The lower one of the two line series used to define are series boundaries. Note if | |
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
74 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
75 | The lower one of the two line series used to define are series boundaries. Note if |
|
75 | The lower one of the two line series used to define are series boundaries. Note if | |
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QAreaSeries::color |
|
80 | \property QAreaSeries::color | |
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
82 | \sa QAreaSeries::brush() |
|
82 | \sa QAreaSeries::brush() | |
83 | */ |
|
83 | */ | |
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty color AreaSeries::color |
|
85 | \qmlproperty color AreaSeries::color | |
86 | Fill (brush) color of the series. |
|
86 | Fill (brush) color of the series. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QAreaSeries::borderColor |
|
90 | \property QAreaSeries::borderColor | |
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
92 | \sa QAreaSeries::pen() |
|
92 | \sa QAreaSeries::pen() | |
93 | */ |
|
93 | */ | |
94 | /*! |
|
94 | /*! | |
95 | \qmlproperty color AreaSeries::borderColor |
|
95 | \qmlproperty color AreaSeries::borderColor | |
96 | Line (pen) color of the series. |
|
96 | Line (pen) color of the series. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty real AreaSeries::borderWidth |
|
100 | \qmlproperty real AreaSeries::borderWidth | |
101 | The width of the border line. By default the width is 2.0. |
|
101 | The width of the border line. By default the width is 2.0. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \fn QPen QAreaSeries::pen() const |
|
105 | \fn QPen QAreaSeries::pen() const | |
106 | \brief Returns the pen used to draw line for this series. |
|
106 | \brief Returns the pen used to draw line for this series. | |
107 | \sa setPen() |
|
107 | \sa setPen() | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \fn QPen QAreaSeries::brush() const |
|
111 | \fn QPen QAreaSeries::brush() const | |
112 | \brief Returns the brush used to draw line for this series. |
|
112 | \brief Returns the brush used to draw line for this series. | |
113 | \sa setBrush() |
|
113 | \sa setBrush() | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \fn void QAreaSeries::colorChanged(QColor color) |
|
117 | \fn void QAreaSeries::colorChanged(QColor color) | |
118 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
118 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
121 | \qmlsignal AreaSeries::onColorChanged(color color) | |
122 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
122 | Signal is emitted when the fill (brush) color has changed to \a color. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
126 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
127 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
127 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
128 | */ |
|
128 | */ | |
129 | /*! |
|
129 | /*! | |
130 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
130 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
131 | Signal is emitted when the line (pen) color has changed to \a color. |
|
131 | Signal is emitted when the line (pen) color has changed to \a color. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
135 | \fn void QAreaSeries::clicked(const QPointF& point) | |
136 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
136 | \brief Signal is emitted when user clicks the \a point on area chart. | |
137 | */ |
|
137 | */ | |
138 | /*! |
|
138 | /*! | |
139 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
139 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
140 | Signal is emitted when user clicks the \a point on area chart. |
|
140 | Signal is emitted when user clicks the \a point on area chart. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QAreaSeries::selected() |
|
144 | \fn void QAreaSeries::selected() | |
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
146 | implemented by the user of QAreaSeries API. |
|
146 | implemented by the user of QAreaSeries API. | |
147 | */ |
|
147 | */ | |
148 | /*! |
|
148 | /*! | |
149 | \qmlsignal AreaSeries::onSelected() |
|
149 | \qmlsignal AreaSeries::onSelected() | |
150 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
150 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
151 | implemented by the user of AreaSeries API. |
|
151 | implemented by the user of AreaSeries API. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QAreaSeriesPrivate::updated() |
|
155 | \fn void QAreaSeriesPrivate::updated() | |
156 | \brief \internal |
|
156 | \brief \internal | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
160 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
161 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
161 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
162 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
162 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
163 | */ |
|
163 | */ | |
164 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
164 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
165 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
165 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) | |
166 | { |
|
166 | { | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | /*! |
|
169 | /*! | |
170 | Constructs area series object without upper or lower series with \a parent object. |
|
170 | Constructs area series object without upper or lower series with \a parent object. | |
171 | */ |
|
171 | */ | |
172 | QAreaSeries::QAreaSeries(QObject *parent) |
|
172 | QAreaSeries::QAreaSeries(QObject *parent) | |
173 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
173 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
174 | { |
|
174 | { | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Destroys the object. |
|
178 | Destroys the object. | |
179 | */ |
|
179 | */ | |
180 | QAreaSeries::~QAreaSeries() |
|
180 | QAreaSeries::~QAreaSeries() | |
181 | { |
|
181 | { | |
182 | Q_D(QAreaSeries); |
|
182 | Q_D(QAreaSeries); | |
183 | if (d->m_dataset) |
|
183 | if (d->m_dataset) | |
184 | d->m_dataset->removeSeries(this); |
|
184 | d->m_dataset->removeSeries(this); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Returns QChartSeries::SeriesTypeArea. |
|
188 | Returns QChartSeries::SeriesTypeArea. | |
189 | */ |
|
189 | */ | |
190 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
190 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
191 | { |
|
191 | { | |
192 | return QAbstractSeries::SeriesTypeArea; |
|
192 | return QAbstractSeries::SeriesTypeArea; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Sets the \a series that is to be used as the area chart upper series. |
|
196 | Sets the \a series that is to be used as the area chart upper series. | |
197 | */ |
|
197 | */ | |
198 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
198 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
199 | { |
|
199 | { | |
200 | Q_D(QAreaSeries); |
|
200 | Q_D(QAreaSeries); | |
201 | d->m_upperSeries = series; |
|
201 | d->m_upperSeries = series; | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | QLineSeries *QAreaSeries::upperSeries() const |
|
204 | QLineSeries *QAreaSeries::upperSeries() const | |
205 | { |
|
205 | { | |
206 | Q_D(const QAreaSeries); |
|
206 | Q_D(const QAreaSeries); | |
207 | return d->m_upperSeries; |
|
207 | return d->m_upperSeries; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Sets the \a series that is to be used as the area chart lower series. |
|
211 | Sets the \a series that is to be used as the area chart lower series. | |
212 | */ |
|
212 | */ | |
213 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
213 | void QAreaSeries::setLowerSeries(QLineSeries *series) | |
214 | { |
|
214 | { | |
215 | Q_D(QAreaSeries); |
|
215 | Q_D(QAreaSeries); | |
216 | d->m_lowerSeries = series; |
|
216 | d->m_lowerSeries = series; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | QLineSeries *QAreaSeries::lowerSeries() const |
|
219 | QLineSeries *QAreaSeries::lowerSeries() const | |
220 | { |
|
220 | { | |
221 | Q_D(const QAreaSeries); |
|
221 | Q_D(const QAreaSeries); | |
222 | return d->m_lowerSeries; |
|
222 | return d->m_lowerSeries; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | Sets \a pen used for drawing area outline. |
|
226 | Sets \a pen used for drawing area outline. | |
227 | */ |
|
227 | */ | |
228 | void QAreaSeries::setPen(const QPen &pen) |
|
228 | void QAreaSeries::setPen(const QPen &pen) | |
229 | { |
|
229 | { | |
230 | Q_D(QAreaSeries); |
|
230 | Q_D(QAreaSeries); | |
231 | if (d->m_pen != pen) { |
|
231 | if (d->m_pen != pen) { | |
232 | d->m_pen = pen; |
|
232 | d->m_pen = pen; | |
233 | emit d->updated(); |
|
233 | emit d->updated(); | |
234 | } |
|
234 | } | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | QPen QAreaSeries::pen() const |
|
237 | QPen QAreaSeries::pen() const | |
238 | { |
|
238 | { | |
239 | Q_D(const QAreaSeries); |
|
239 | Q_D(const QAreaSeries); | |
240 | return d->m_pen; |
|
240 | return d->m_pen; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Sets \a brush used for filling the area. |
|
244 | Sets \a brush used for filling the area. | |
245 | */ |
|
245 | */ | |
246 | void QAreaSeries::setBrush(const QBrush &brush) |
|
246 | void QAreaSeries::setBrush(const QBrush &brush) | |
247 | { |
|
247 | { | |
248 | Q_D(QAreaSeries); |
|
248 | Q_D(QAreaSeries); | |
249 | if (d->m_brush != brush) { |
|
249 | if (d->m_brush != brush) { | |
250 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
250 | bool emitColorChanged = brush.color() != d->m_brush.color(); | |
251 | d->m_brush = brush; |
|
251 | d->m_brush = brush; | |
252 | emit d->updated(); |
|
252 | emit d->updated(); | |
253 | if (emitColorChanged) |
|
253 | if (emitColorChanged) | |
254 | emit colorChanged(brush.color()); |
|
254 | emit colorChanged(brush.color()); | |
255 | } |
|
255 | } | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | QBrush QAreaSeries::brush() const |
|
258 | QBrush QAreaSeries::brush() const | |
259 | { |
|
259 | { | |
260 | Q_D(const QAreaSeries); |
|
260 | Q_D(const QAreaSeries); | |
261 | return d->m_brush; |
|
261 | return d->m_brush; | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | void QAreaSeries::setColor(const QColor &color) |
|
264 | void QAreaSeries::setColor(const QColor &color) | |
265 | { |
|
265 | { | |
266 | QBrush b = brush(); |
|
266 | QBrush b = brush(); | |
267 | if (b == QBrush()) |
|
267 | if (b == QBrush()) | |
268 | b.setStyle(Qt::SolidPattern); |
|
268 | b.setStyle(Qt::SolidPattern); | |
269 | b.setColor(color); |
|
269 | b.setColor(color); | |
270 | setBrush(b); |
|
270 | setBrush(b); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | QColor QAreaSeries::color() const |
|
273 | QColor QAreaSeries::color() const | |
274 | { |
|
274 | { | |
275 | return brush().color(); |
|
275 | return brush().color(); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void QAreaSeries::setBorderColor(const QColor &color) |
|
278 | void QAreaSeries::setBorderColor(const QColor &color) | |
279 | { |
|
279 | { | |
280 | QPen p = pen(); |
|
280 | QPen p = pen(); | |
281 | if (p.color() != color) { |
|
281 | if (p.color() != color) { | |
282 | p.setColor(color); |
|
282 | p.setColor(color); | |
283 | setPen(p); |
|
283 | setPen(p); | |
284 | emit borderColorChanged(color); |
|
284 | emit borderColorChanged(color); | |
285 | } |
|
285 | } | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | QColor QAreaSeries::borderColor() const |
|
288 | QColor QAreaSeries::borderColor() const | |
289 | { |
|
289 | { | |
290 | return pen().color(); |
|
290 | return pen().color(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | /*! |
|
293 | /*! | |
294 | Sets if data points are \a visible and should be drawn on line. |
|
294 | Sets if data points are \a visible and should be drawn on line. | |
295 | */ |
|
295 | */ | |
296 | void QAreaSeries::setPointsVisible(bool visible) |
|
296 | void QAreaSeries::setPointsVisible(bool visible) | |
297 | { |
|
297 | { | |
298 | Q_D(QAreaSeries); |
|
298 | Q_D(QAreaSeries); | |
299 | if (d->m_pointsVisible != visible) { |
|
299 | if (d->m_pointsVisible != visible) { | |
300 | d->m_pointsVisible = visible; |
|
300 | d->m_pointsVisible = visible; | |
301 | emit d->updated(); |
|
301 | emit d->updated(); | |
302 | } |
|
302 | } | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Returns if the points are drawn for this series. |
|
306 | Returns if the points are drawn for this series. | |
307 | \sa setPointsVisible() |
|
307 | \sa setPointsVisible() | |
308 | */ |
|
308 | */ | |
309 | bool QAreaSeries::pointsVisible() const |
|
309 | bool QAreaSeries::pointsVisible() const | |
310 | { |
|
310 | { | |
311 | Q_D(const QAreaSeries); |
|
311 | Q_D(const QAreaSeries); | |
312 | return d->m_pointsVisible; |
|
312 | return d->m_pointsVisible; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
316 |
|
316 | |||
317 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
317 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) | |
318 | : QAbstractSeriesPrivate(q), |
|
318 | : QAbstractSeriesPrivate(q), | |
319 | m_upperSeries(upperSeries), |
|
319 | m_upperSeries(upperSeries), | |
320 | m_lowerSeries(lowerSeries), |
|
320 | m_lowerSeries(lowerSeries), | |
321 | m_pointsVisible(false) |
|
321 | m_pointsVisible(false) | |
322 | { |
|
322 | { | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) |
|
325 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) | |
326 | { |
|
326 | { | |
327 | Q_Q(QAreaSeries); |
|
327 | Q_Q(QAreaSeries); | |
328 |
|
328 | |||
329 | qreal minX(domain.minX()); |
|
329 | qreal minX(domain.minX()); | |
330 | qreal minY(domain.minY()); |
|
330 | qreal minY(domain.minY()); | |
331 | qreal maxX(domain.maxX()); |
|
331 | qreal maxX(domain.maxX()); | |
332 | qreal maxY(domain.maxY()); |
|
332 | qreal maxY(domain.maxY()); | |
333 |
|
333 | |||
334 | QLineSeries *upperSeries = q->upperSeries(); |
|
334 | QLineSeries *upperSeries = q->upperSeries(); | |
335 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
335 | QLineSeries *lowerSeries = q->lowerSeries(); | |
336 |
|
336 | |||
337 | const QList<QPointF>& points = upperSeries->points(); |
|
337 | const QList<QPointF>& points = upperSeries->points(); | |
338 |
|
338 | |||
339 | for (int i = 0; i < points.count(); i++) { |
|
339 | for (int i = 0; i < points.count(); i++) { | |
340 | qreal x = points[i].x(); |
|
340 | qreal x = points[i].x(); | |
341 | qreal y = points[i].y(); |
|
341 | qreal y = points[i].y(); | |
342 | minX = qMin(minX, x); |
|
342 | minX = qMin(minX, x); | |
343 | minY = qMin(minY, y); |
|
343 | minY = qMin(minY, y); | |
344 | maxX = qMax(maxX, x); |
|
344 | maxX = qMax(maxX, x); | |
345 | maxY = qMax(maxY, y); |
|
345 | maxY = qMax(maxY, y); | |
346 | } |
|
346 | } | |
347 | if (lowerSeries) { |
|
347 | if (lowerSeries) { | |
348 |
|
348 | |||
349 | const QList<QPointF>& points = lowerSeries->points(); |
|
349 | const QList<QPointF>& points = lowerSeries->points(); | |
350 |
|
350 | |||
351 | for (int i = 0; i < points.count(); i++) { |
|
351 | for (int i = 0; i < points.count(); i++) { | |
352 | qreal x = points[i].x(); |
|
352 | qreal x = points[i].x(); | |
353 | qreal y = points[i].y(); |
|
353 | qreal y = points[i].y(); | |
354 | minX = qMin(minX, x); |
|
354 | minX = qMin(minX, x); | |
355 | minY = qMin(minY, y); |
|
355 | minY = qMin(minY, y); | |
356 | maxX = qMax(maxX, x); |
|
356 | maxX = qMax(maxX, x); | |
357 | maxY = qMax(maxY, y); |
|
357 | maxY = qMax(maxY, y); | |
358 | } |
|
358 | } | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | domain.setRange(minX, maxX, minY, maxY); |
|
361 | domain.setRange(minX, maxX, minY, maxY); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
365 | { |
|
365 | { | |
366 | Q_Q(QAreaSeries); |
|
366 | Q_Q(QAreaSeries); | |
367 |
|
367 | |||
368 | AreaChartItem *area = new AreaChartItem(q, presenter); |
|
368 | AreaChartItem *area = new AreaChartItem(q, presenter); | |
369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
371 | if (q->lowerSeries()) |
|
371 | if (q->lowerSeries()) | |
372 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
372 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
373 | } |
|
373 | } | |
374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
375 | return area; |
|
375 | return area; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | QList<LegendMarker *> QAreaSeriesPrivate::createLegendMarker(QLegend *legend) |
|
378 | QList<LegendMarker *> QAreaSeriesPrivate::createLegendMarker(QLegend *legend) | |
379 | { |
|
379 | { | |
380 | Q_Q(QAreaSeries); |
|
380 | Q_Q(QAreaSeries); | |
381 | QList<LegendMarker *> list; |
|
381 | QList<LegendMarker *> list; | |
382 | return list << new AreaLegendMarker(q, legend); |
|
382 | return list << new AreaLegendMarker(q, legend); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
|
385 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
386 | { | |||
|
387 | Q_UNUSED(legend); | |||
|
388 | // Q_Q(QAreaSeries); | |||
|
389 | QList<QLegendMarker*> list; | |||
|
390 | // TODO: | |||
|
391 | // return list << new AreaLegendMarker(q,legend); | |||
|
392 | return list; | |||
|
393 | } | |||
385 |
|
394 | |||
386 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
395 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
387 | { |
|
396 | { | |
388 | Q_UNUSED(axis); |
|
397 | Q_UNUSED(axis); | |
389 | } |
|
398 | } | |
390 |
|
399 | |||
391 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
400 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
392 | { |
|
401 | { | |
393 | Q_UNUSED(orientation); |
|
402 | Q_UNUSED(orientation); | |
394 | return QAbstractAxis::AxisTypeValue; |
|
403 | return QAbstractAxis::AxisTypeValue; | |
395 | } |
|
404 | } | |
396 |
|
405 | |||
397 | #include "moc_qareaseries.cpp" |
|
406 | #include "moc_qareaseries.cpp" | |
398 | #include "moc_qareaseries_p.cpp" |
|
407 | #include "moc_qareaseries_p.cpp" | |
399 |
|
408 | |||
400 | QTCOMMERCIALCHART_END_NAMESPACE |
|
409 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,69 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QAREASERIES_P_H |
|
30 | #ifndef QAREASERIES_P_H | |
31 | #define QAREASERIES_P_H |
|
31 | #define QAREASERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAreaSeries; |
|
37 | class QAreaSeries; | |
38 |
|
38 | |||
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate |
|
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q); |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q); | |
45 |
|
45 | |||
46 | void scaleDomain(Domain &domain); |
|
46 | void scaleDomain(Domain &domain); | |
47 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
47 | ChartElement *createGraphics(ChartPresenter *presenter); | |
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
49 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
49 | void initializeAxis(QAbstractAxis *axis); |
|
50 | void initializeAxis(QAbstractAxis *axis); | |
|
51 | ||||
50 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
51 |
|
53 | |||
52 | Q_SIGNALS: |
|
54 | Q_SIGNALS: | |
53 | void updated(); |
|
55 | void updated(); | |
54 |
|
56 | |||
55 | protected: |
|
57 | protected: | |
56 | QBrush m_brush; |
|
58 | QBrush m_brush; | |
57 | QPen m_pen; |
|
59 | QPen m_pen; | |
58 | QLineSeries *m_upperSeries; |
|
60 | QLineSeries *m_upperSeries; | |
59 | QLineSeries *m_lowerSeries; |
|
61 | QLineSeries *m_lowerSeries; | |
60 | bool m_pointsVisible; |
|
62 | bool m_pointsVisible; | |
61 | private: |
|
63 | private: | |
62 | Q_DECLARE_PUBLIC(QAreaSeries); |
|
64 | Q_DECLARE_PUBLIC(QAreaSeries); | |
63 | }; |
|
65 | }; | |
64 |
|
66 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
68 | |||
67 | #endif |
|
69 | #endif |
@@ -1,810 +1,826 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
36 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
42 | shows the x-values. |
|
42 | shows the x-values. | |
43 |
|
43 | |||
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
45 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
46 |
|
46 | |||
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
51 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
52 |
|
52 | |||
53 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
55 |
|
55 | |||
56 | \beginfloatleft |
|
56 | \beginfloatleft | |
57 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
58 | \endfloat |
|
58 | \endfloat | |
59 | \clearfloat |
|
59 | \clearfloat | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
68 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
80 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
84 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
89 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
93 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
99 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
142 | /*! |
|
142 | /*! | |
143 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) | |
144 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
149 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
150 | \sa remove() |
|
150 | \sa remove() | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) | |
154 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
164 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. | |
165 | For example: |
|
165 | For example: | |
166 | \code |
|
166 | \code | |
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
168 | \endcode |
|
168 | \endcode | |
169 | */ |
|
169 | */ | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
172 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
173 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
173 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
174 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
174 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
175 | appended. |
|
175 | appended. | |
176 | \sa AbstractBarSeries::append() |
|
176 | \sa AbstractBarSeries::append() | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
180 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
181 | Removes the barset from the series. Returns true if successful, false otherwise. |
|
181 | Removes the barset from the series. Returns true if successful, false otherwise. | |
182 | */ |
|
182 | */ | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | \qmlmethod AbstractBarSeries::clear() |
|
185 | \qmlmethod AbstractBarSeries::clear() | |
186 | Removes all barsets from the series. |
|
186 | Removes all barsets from the series. | |
187 | */ |
|
187 | */ | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Destructs abstractbarseries and owned barsets. |
|
190 | Destructs abstractbarseries and owned barsets. | |
191 | */ |
|
191 | */ | |
192 | QAbstractBarSeries::~QAbstractBarSeries() |
|
192 | QAbstractBarSeries::~QAbstractBarSeries() | |
193 | { |
|
193 | { | |
194 |
|
194 | |||
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \internal |
|
198 | \internal | |
199 | */ |
|
199 | */ | |
200 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) |
|
200 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) | |
201 | : QAbstractSeries(o, parent) |
|
201 | : QAbstractSeries(o, parent) | |
202 | { |
|
202 | { | |
203 | Q_D(QAbstractSeries); |
|
203 | Q_D(QAbstractSeries); | |
204 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
204 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
208 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
209 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
209 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
210 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
210 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
211 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
211 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
212 | */ |
|
212 | */ | |
213 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
213 | void QAbstractBarSeries::setBarWidth(qreal width) | |
214 | { |
|
214 | { | |
215 | Q_D(QAbstractBarSeries); |
|
215 | Q_D(QAbstractBarSeries); | |
216 | d->setBarWidth(width); |
|
216 | d->setBarWidth(width); | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Returns the width of the bars of the series. |
|
220 | Returns the width of the bars of the series. | |
221 | \sa setBarWidth() |
|
221 | \sa setBarWidth() | |
222 | */ |
|
222 | */ | |
223 | qreal QAbstractBarSeries::barWidth() const |
|
223 | qreal QAbstractBarSeries::barWidth() const | |
224 | { |
|
224 | { | |
225 | Q_D(const QAbstractBarSeries); |
|
225 | Q_D(const QAbstractBarSeries); | |
226 | return d->barWidth(); |
|
226 | return d->barWidth(); | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
230 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
231 | Returns true, if appending succeeded. |
|
231 | Returns true, if appending succeeded. | |
232 | */ |
|
232 | */ | |
233 | bool QAbstractBarSeries::append(QBarSet *set) |
|
233 | bool QAbstractBarSeries::append(QBarSet *set) | |
234 | { |
|
234 | { | |
235 | Q_D(QAbstractBarSeries); |
|
235 | Q_D(QAbstractBarSeries); | |
236 | bool success = d->append(set); |
|
236 | bool success = d->append(set); | |
237 | if (success) { |
|
237 | if (success) { | |
238 | QList<QBarSet *> sets; |
|
238 | QList<QBarSet *> sets; | |
239 | sets.append(set); |
|
239 | sets.append(set); | |
240 | set->setParent(this); |
|
240 | set->setParent(this); | |
241 | emit barsetsAdded(sets); |
|
241 | emit barsetsAdded(sets); | |
242 | emit countChanged(); |
|
242 | emit countChanged(); | |
243 | } |
|
243 | } | |
244 | return success; |
|
244 | return success; | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | /*! |
|
247 | /*! | |
248 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
248 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
249 | was successful. |
|
249 | was successful. | |
250 | Returns true, if set was removed. |
|
250 | Returns true, if set was removed. | |
251 | */ |
|
251 | */ | |
252 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
252 | bool QAbstractBarSeries::remove(QBarSet *set) | |
253 | { |
|
253 | { | |
254 | Q_D(QAbstractBarSeries); |
|
254 | Q_D(QAbstractBarSeries); | |
255 | bool success = d->remove(set); |
|
255 | bool success = d->remove(set); | |
256 | if (success) { |
|
256 | if (success) { | |
257 | QList<QBarSet *> sets; |
|
257 | QList<QBarSet *> sets; | |
258 | sets.append(set); |
|
258 | sets.append(set); | |
259 | set->setParent(0); |
|
259 | set->setParent(0); | |
260 | emit barsetsRemoved(sets); |
|
260 | emit barsetsRemoved(sets); | |
261 | emit countChanged(); |
|
261 | emit countChanged(); | |
262 | delete set; |
|
262 | delete set; | |
263 | set = 0; |
|
263 | set = 0; | |
264 | } |
|
264 | } | |
265 | return success; |
|
265 | return success; | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | /*! |
|
268 | /*! | |
269 | Takes a single \a set from the series. Does not delete the barset object. |
|
269 | Takes a single \a set from the series. Does not delete the barset object. | |
270 |
|
270 | |||
271 | NOTE: The series remains as the barset's parent object. You must set the |
|
271 | NOTE: The series remains as the barset's parent object. You must set the | |
272 | parent object to take full ownership. |
|
272 | parent object to take full ownership. | |
273 |
|
273 | |||
274 | Returns true if take was successful. |
|
274 | Returns true if take was successful. | |
275 | */ |
|
275 | */ | |
276 | bool QAbstractBarSeries::take(QBarSet *set) |
|
276 | bool QAbstractBarSeries::take(QBarSet *set) | |
277 | { |
|
277 | { | |
278 | Q_D(QAbstractBarSeries); |
|
278 | Q_D(QAbstractBarSeries); | |
279 | bool success = d->remove(set); |
|
279 | bool success = d->remove(set); | |
280 | if (success) { |
|
280 | if (success) { | |
281 | QList<QBarSet *> sets; |
|
281 | QList<QBarSet *> sets; | |
282 | sets.append(set); |
|
282 | sets.append(set); | |
283 | emit barsetsRemoved(sets); |
|
283 | emit barsetsRemoved(sets); | |
284 | emit countChanged(); |
|
284 | emit countChanged(); | |
285 | } |
|
285 | } | |
286 | return success; |
|
286 | return success; | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
290 | Adds a list of barsets to series. Takes ownership of \a sets. | |
291 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
291 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |
292 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
292 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
293 | and function returns false. |
|
293 | and function returns false. | |
294 | */ |
|
294 | */ | |
295 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) |
|
295 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) | |
296 | { |
|
296 | { | |
297 | Q_D(QAbstractBarSeries); |
|
297 | Q_D(QAbstractBarSeries); | |
298 | bool success = d->append(sets); |
|
298 | bool success = d->append(sets); | |
299 | if (success) { |
|
299 | if (success) { | |
300 | emit barsetsAdded(sets); |
|
300 | emit barsetsAdded(sets); | |
301 | emit countChanged(); |
|
301 | emit countChanged(); | |
302 | } |
|
302 | } | |
303 | return success; |
|
303 | return success; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
307 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
308 | Returns true, if inserting succeeded. |
|
308 | Returns true, if inserting succeeded. | |
309 |
|
309 | |||
310 | */ |
|
310 | */ | |
311 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
311 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
312 | { |
|
312 | { | |
313 | Q_D(QAbstractBarSeries); |
|
313 | Q_D(QAbstractBarSeries); | |
314 | bool success = d->insert(index, set); |
|
314 | bool success = d->insert(index, set); | |
315 | if (success) { |
|
315 | if (success) { | |
316 | QList<QBarSet *> sets; |
|
316 | QList<QBarSet *> sets; | |
317 | sets.append(set); |
|
317 | sets.append(set); | |
318 | emit barsetsAdded(sets); |
|
318 | emit barsetsAdded(sets); | |
319 | emit countChanged(); |
|
319 | emit countChanged(); | |
320 | } |
|
320 | } | |
321 | return success; |
|
321 | return success; | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Removes all barsets from the series. Deletes removed sets. |
|
325 | Removes all barsets from the series. Deletes removed sets. | |
326 | */ |
|
326 | */ | |
327 | void QAbstractBarSeries::clear() |
|
327 | void QAbstractBarSeries::clear() | |
328 | { |
|
328 | { | |
329 | Q_D(QAbstractBarSeries); |
|
329 | Q_D(QAbstractBarSeries); | |
330 | QList<QBarSet *> sets = barSets(); |
|
330 | QList<QBarSet *> sets = barSets(); | |
331 | bool success = d->remove(sets); |
|
331 | bool success = d->remove(sets); | |
332 | if (success) { |
|
332 | if (success) { | |
333 | emit barsetsRemoved(sets); |
|
333 | emit barsetsRemoved(sets); | |
334 | emit countChanged(); |
|
334 | emit countChanged(); | |
335 | foreach (QBarSet *set, sets) |
|
335 | foreach (QBarSet *set, sets) | |
336 | delete set; |
|
336 | delete set; | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Returns number of sets in series. |
|
341 | Returns number of sets in series. | |
342 | */ |
|
342 | */ | |
343 | int QAbstractBarSeries::count() const |
|
343 | int QAbstractBarSeries::count() const | |
344 | { |
|
344 | { | |
345 | Q_D(const QAbstractBarSeries); |
|
345 | Q_D(const QAbstractBarSeries); | |
346 | return d->m_barSets.count(); |
|
346 | return d->m_barSets.count(); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Returns a list of sets in series. Keeps ownership of sets. |
|
350 | Returns a list of sets in series. Keeps ownership of sets. | |
351 | */ |
|
351 | */ | |
352 | QList<QBarSet *> QAbstractBarSeries::barSets() const |
|
352 | QList<QBarSet *> QAbstractBarSeries::barSets() const | |
353 | { |
|
353 | { | |
354 | Q_D(const QAbstractBarSeries); |
|
354 | Q_D(const QAbstractBarSeries); | |
355 | return d->m_barSets; |
|
355 | return d->m_barSets; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | /*! |
|
358 | /*! | |
359 | Sets the visibility of labels in series to \a visible |
|
359 | Sets the visibility of labels in series to \a visible | |
360 | */ |
|
360 | */ | |
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
362 | { |
|
362 | { | |
363 | Q_D(QAbstractBarSeries); |
|
363 | Q_D(QAbstractBarSeries); | |
364 | if (d->m_labelsVisible != visible) { |
|
364 | if (d->m_labelsVisible != visible) { | |
365 | d->setLabelsVisible(visible); |
|
365 | d->setLabelsVisible(visible); | |
366 | emit labelsVisibleChanged(); |
|
366 | emit labelsVisibleChanged(); | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns the visibility of labels |
|
371 | Returns the visibility of labels | |
372 | */ |
|
372 | */ | |
373 | bool QAbstractBarSeries::isLabelsVisible() const |
|
373 | bool QAbstractBarSeries::isLabelsVisible() const | |
374 | { |
|
374 | { | |
375 | Q_D(const QAbstractBarSeries); |
|
375 | Q_D(const QAbstractBarSeries); | |
376 | return d->m_labelsVisible; |
|
376 | return d->m_labelsVisible; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
380 |
|
380 | |||
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
382 | QAbstractSeriesPrivate(q), |
|
382 | QAbstractSeriesPrivate(q), | |
383 | m_barWidth(0.5), // Default value is 50% of category width |
|
383 | m_barWidth(0.5), // Default value is 50% of category width | |
384 | m_labelsVisible(false), |
|
384 | m_labelsVisible(false), | |
385 | m_visible(true) |
|
385 | m_visible(true) | |
386 | { |
|
386 | { | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
389 | int QAbstractBarSeriesPrivate::categoryCount() const | |
390 | { |
|
390 | { | |
391 | // No categories defined. return count of longest set. |
|
391 | // No categories defined. return count of longest set. | |
392 | int count = 0; |
|
392 | int count = 0; | |
393 | for (int i = 0; i < m_barSets.count(); i++) { |
|
393 | for (int i = 0; i < m_barSets.count(); i++) { | |
394 | if (m_barSets.at(i)->count() > count) |
|
394 | if (m_barSets.at(i)->count() > count) | |
395 | count = m_barSets.at(i)->count(); |
|
395 | count = m_barSets.at(i)->count(); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | return count; |
|
398 | return count; | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
401 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
402 | { |
|
402 | { | |
403 | if (width < 0.0) |
|
403 | if (width < 0.0) | |
404 | width = 0.0; |
|
404 | width = 0.0; | |
405 | m_barWidth = width; |
|
405 | m_barWidth = width; | |
406 | emit updatedLayout(); |
|
406 | emit updatedLayout(); | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
409 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
410 | { |
|
410 | { | |
411 | return m_barWidth; |
|
411 | return m_barWidth; | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) |
|
414 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) | |
415 | { |
|
415 | { | |
416 | return m_barSets.at(index); |
|
416 | return m_barSets.at(index); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
419 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
420 | { |
|
420 | { | |
421 | m_visible = visible; |
|
421 | m_visible = visible; | |
422 | emit visibleChanged(); |
|
422 | emit visibleChanged(); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
425 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
426 | { |
|
426 | { | |
427 | m_labelsVisible = visible; |
|
427 | m_labelsVisible = visible; | |
428 | emit labelsVisibleChanged(visible); |
|
428 | emit labelsVisibleChanged(visible); | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | qreal QAbstractBarSeriesPrivate::min() |
|
431 | qreal QAbstractBarSeriesPrivate::min() | |
432 | { |
|
432 | { | |
433 | if (m_barSets.count() <= 0) |
|
433 | if (m_barSets.count() <= 0) | |
434 | return 0; |
|
434 | return 0; | |
435 |
|
435 | |||
436 | qreal min = INT_MAX; |
|
436 | qreal min = INT_MAX; | |
437 |
|
437 | |||
438 | for (int i = 0; i < m_barSets.count(); i++) { |
|
438 | for (int i = 0; i < m_barSets.count(); i++) { | |
439 | int categoryCount = m_barSets.at(i)->count(); |
|
439 | int categoryCount = m_barSets.at(i)->count(); | |
440 | for (int j = 0; j < categoryCount; j++) { |
|
440 | for (int j = 0; j < categoryCount; j++) { | |
441 | qreal temp = m_barSets.at(i)->at(j); |
|
441 | qreal temp = m_barSets.at(i)->at(j); | |
442 | if (temp < min) |
|
442 | if (temp < min) | |
443 | min = temp; |
|
443 | min = temp; | |
444 | } |
|
444 | } | |
445 | } |
|
445 | } | |
446 | return min; |
|
446 | return min; | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | qreal QAbstractBarSeriesPrivate::max() |
|
449 | qreal QAbstractBarSeriesPrivate::max() | |
450 | { |
|
450 | { | |
451 | if (m_barSets.count() <= 0) |
|
451 | if (m_barSets.count() <= 0) | |
452 | return 0; |
|
452 | return 0; | |
453 |
|
453 | |||
454 | qreal max = INT_MIN; |
|
454 | qreal max = INT_MIN; | |
455 |
|
455 | |||
456 | for (int i = 0; i < m_barSets.count(); i++) { |
|
456 | for (int i = 0; i < m_barSets.count(); i++) { | |
457 | int categoryCount = m_barSets.at(i)->count(); |
|
457 | int categoryCount = m_barSets.at(i)->count(); | |
458 | for (int j = 0; j < categoryCount; j++) { |
|
458 | for (int j = 0; j < categoryCount; j++) { | |
459 | qreal temp = m_barSets.at(i)->at(j); |
|
459 | qreal temp = m_barSets.at(i)->at(j); | |
460 | if (temp > max) |
|
460 | if (temp > max) | |
461 | max = temp; |
|
461 | max = temp; | |
462 | } |
|
462 | } | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | return max; |
|
465 | return max; | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
468 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
469 | { |
|
469 | { | |
470 | if ((set < 0) || (set >= m_barSets.count())) |
|
470 | if ((set < 0) || (set >= m_barSets.count())) | |
471 | return 0; // No set, no value. |
|
471 | return 0; // No set, no value. | |
472 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
472 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
473 | return 0; // No category, no value. |
|
473 | return 0; // No category, no value. | |
474 |
|
474 | |||
475 | return m_barSets.at(set)->at(category); |
|
475 | return m_barSets.at(set)->at(category); | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
478 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
479 | { |
|
479 | { | |
480 | if ((set < 0) || (set >= m_barSets.count())) |
|
480 | if ((set < 0) || (set >= m_barSets.count())) | |
481 | return 0; // No set, no value. |
|
481 | return 0; // No set, no value. | |
482 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
482 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
483 | return 0; // No category, no value. |
|
483 | return 0; // No category, no value. | |
484 |
|
484 | |||
485 | qreal value = m_barSets.at(set)->at(category); |
|
485 | qreal value = m_barSets.at(set)->at(category); | |
486 | qreal sum = categorySum(category); |
|
486 | qreal sum = categorySum(category); | |
487 | if (qFuzzyIsNull(sum)) |
|
487 | if (qFuzzyIsNull(sum)) | |
488 | return 0; |
|
488 | return 0; | |
489 |
|
489 | |||
490 | return value / sum; |
|
490 | return value / sum; | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
493 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
494 | { |
|
494 | { | |
495 | qreal sum(0); |
|
495 | qreal sum(0); | |
496 | int count = m_barSets.count(); // Count sets |
|
496 | int count = m_barSets.count(); // Count sets | |
497 | for (int set = 0; set < count; set++) { |
|
497 | for (int set = 0; set < count; set++) { | |
498 | if (category < m_barSets.at(set)->count()) |
|
498 | if (category < m_barSets.at(set)->count()) | |
499 | sum += m_barSets.at(set)->at(category); |
|
499 | sum += m_barSets.at(set)->at(category); | |
500 | } |
|
500 | } | |
501 | return sum; |
|
501 | return sum; | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
504 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
505 | { |
|
505 | { | |
506 | qreal sum(0); |
|
506 | qreal sum(0); | |
507 | int count = m_barSets.count(); // Count sets |
|
507 | int count = m_barSets.count(); // Count sets | |
508 | for (int set = 0; set < count; set++) { |
|
508 | for (int set = 0; set < count; set++) { | |
509 | if (category < m_barSets.at(set)->count()) |
|
509 | if (category < m_barSets.at(set)->count()) | |
510 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
510 | sum += qAbs(m_barSets.at(set)->at(category)); | |
511 | } |
|
511 | } | |
512 | return sum; |
|
512 | return sum; | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
515 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
516 | { |
|
516 | { | |
517 | qreal max = INT_MIN; |
|
517 | qreal max = INT_MIN; | |
518 | int count = categoryCount(); |
|
518 | int count = categoryCount(); | |
519 | for (int i = 0; i < count; i++) { |
|
519 | for (int i = 0; i < count; i++) { | |
520 | qreal sum = categorySum(i); |
|
520 | qreal sum = categorySum(i); | |
521 | if (sum > max) |
|
521 | if (sum > max) | |
522 | max = sum; |
|
522 | max = sum; | |
523 | } |
|
523 | } | |
524 | return max; |
|
524 | return max; | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | qreal QAbstractBarSeriesPrivate::minX() |
|
527 | qreal QAbstractBarSeriesPrivate::minX() | |
528 | { |
|
528 | { | |
529 | if (m_barSets.count() <= 0) |
|
529 | if (m_barSets.count() <= 0) | |
530 | return 0; |
|
530 | return 0; | |
531 |
|
531 | |||
532 | qreal min = INT_MAX; |
|
532 | qreal min = INT_MAX; | |
533 |
|
533 | |||
534 | for (int i = 0; i < m_barSets.count(); i++) { |
|
534 | for (int i = 0; i < m_barSets.count(); i++) { | |
535 | int categoryCount = m_barSets.at(i)->count(); |
|
535 | int categoryCount = m_barSets.at(i)->count(); | |
536 | for (int j = 0; j < categoryCount; j++) { |
|
536 | for (int j = 0; j < categoryCount; j++) { | |
537 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
537 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
538 | if (temp < min) |
|
538 | if (temp < min) | |
539 | min = temp; |
|
539 | min = temp; | |
540 | } |
|
540 | } | |
541 | } |
|
541 | } | |
542 | return min; |
|
542 | return min; | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | qreal QAbstractBarSeriesPrivate::maxX() |
|
545 | qreal QAbstractBarSeriesPrivate::maxX() | |
546 | { |
|
546 | { | |
547 | if (m_barSets.count() <= 0) |
|
547 | if (m_barSets.count() <= 0) | |
548 | return 0; |
|
548 | return 0; | |
549 |
|
549 | |||
550 | qreal max = INT_MIN; |
|
550 | qreal max = INT_MIN; | |
551 |
|
551 | |||
552 | for (int i = 0; i < m_barSets.count(); i++) { |
|
552 | for (int i = 0; i < m_barSets.count(); i++) { | |
553 | int categoryCount = m_barSets.at(i)->count(); |
|
553 | int categoryCount = m_barSets.at(i)->count(); | |
554 | for (int j = 0; j < categoryCount; j++) { |
|
554 | for (int j = 0; j < categoryCount; j++) { | |
555 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
555 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
556 | if (temp > max) |
|
556 | if (temp > max) | |
557 | max = temp; |
|
557 | max = temp; | |
558 | } |
|
558 | } | |
559 | } |
|
559 | } | |
560 |
|
560 | |||
561 | return max; |
|
561 | return max; | |
562 | } |
|
562 | } | |
563 |
|
563 | |||
564 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
564 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) | |
565 | { |
|
565 | { | |
566 | // Returns top (sum of all positive values) of category. |
|
566 | // Returns top (sum of all positive values) of category. | |
567 | // Returns 0, if all values are negative |
|
567 | // Returns 0, if all values are negative | |
568 | qreal top(0); |
|
568 | qreal top(0); | |
569 | int count = m_barSets.count(); |
|
569 | int count = m_barSets.count(); | |
570 | for (int set = 0; set < count; set++) { |
|
570 | for (int set = 0; set < count; set++) { | |
571 | if (category < m_barSets.at(set)->count()) { |
|
571 | if (category < m_barSets.at(set)->count()) { | |
572 | qreal temp = m_barSets.at(set)->at(category); |
|
572 | qreal temp = m_barSets.at(set)->at(category); | |
573 | if (temp > 0) { |
|
573 | if (temp > 0) { | |
574 | top += temp; |
|
574 | top += temp; | |
575 | } |
|
575 | } | |
576 | } |
|
576 | } | |
577 | } |
|
577 | } | |
578 | return top; |
|
578 | return top; | |
579 | } |
|
579 | } | |
580 |
|
580 | |||
581 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
581 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) | |
582 | { |
|
582 | { | |
583 | // Returns bottom (sum of all negative values) of category |
|
583 | // Returns bottom (sum of all negative values) of category | |
584 | // Returns 0, if all values are positive |
|
584 | // Returns 0, if all values are positive | |
585 | qreal bottom(0); |
|
585 | qreal bottom(0); | |
586 | int count = m_barSets.count(); |
|
586 | int count = m_barSets.count(); | |
587 | for (int set = 0; set < count; set++) { |
|
587 | for (int set = 0; set < count; set++) { | |
588 | if (category < m_barSets.at(set)->count()) { |
|
588 | if (category < m_barSets.at(set)->count()) { | |
589 | qreal temp = m_barSets.at(set)->at(category); |
|
589 | qreal temp = m_barSets.at(set)->at(category); | |
590 | if (temp < 0) { |
|
590 | if (temp < 0) { | |
591 | bottom += temp; |
|
591 | bottom += temp; | |
592 | } |
|
592 | } | |
593 | } |
|
593 | } | |
594 | } |
|
594 | } | |
595 | return bottom; |
|
595 | return bottom; | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | qreal QAbstractBarSeriesPrivate::top() |
|
598 | qreal QAbstractBarSeriesPrivate::top() | |
599 | { |
|
599 | { | |
600 | // Returns top of all categories |
|
600 | // Returns top of all categories | |
601 | qreal top(0); |
|
601 | qreal top(0); | |
602 | int count = categoryCount(); |
|
602 | int count = categoryCount(); | |
603 | for (int i = 0; i < count; i++) { |
|
603 | for (int i = 0; i < count; i++) { | |
604 | qreal temp = categoryTop(i); |
|
604 | qreal temp = categoryTop(i); | |
605 | if (temp > top) |
|
605 | if (temp > top) | |
606 | top = temp; |
|
606 | top = temp; | |
607 | } |
|
607 | } | |
608 | return top; |
|
608 | return top; | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | qreal QAbstractBarSeriesPrivate::bottom() |
|
611 | qreal QAbstractBarSeriesPrivate::bottom() | |
612 | { |
|
612 | { | |
613 | // Returns bottom of all categories |
|
613 | // Returns bottom of all categories | |
614 | qreal bottom(0); |
|
614 | qreal bottom(0); | |
615 | int count = categoryCount(); |
|
615 | int count = categoryCount(); | |
616 | for (int i = 0; i < count; i++) { |
|
616 | for (int i = 0; i < count; i++) { | |
617 | qreal temp = categoryBottom(i); |
|
617 | qreal temp = categoryBottom(i); | |
618 | if (temp < bottom) |
|
618 | if (temp < bottom) | |
619 | bottom = temp; |
|
619 | bottom = temp; | |
620 | } |
|
620 | } | |
621 | return bottom; |
|
621 | return bottom; | |
622 | } |
|
622 | } | |
623 |
|
623 | |||
624 |
|
624 | |||
625 | void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) |
|
625 | void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain) | |
626 | { |
|
626 | { | |
627 | qreal minX(domain.minX()); |
|
627 | qreal minX(domain.minX()); | |
628 | qreal minY(domain.minY()); |
|
628 | qreal minY(domain.minY()); | |
629 | qreal maxX(domain.maxX()); |
|
629 | qreal maxX(domain.maxX()); | |
630 | qreal maxY(domain.maxY()); |
|
630 | qreal maxY(domain.maxY()); | |
631 |
|
631 | |||
632 | qreal seriesMinX = this->minX(); |
|
632 | qreal seriesMinX = this->minX(); | |
633 | qreal seriesMaxX = this->maxX(); |
|
633 | qreal seriesMaxX = this->maxX(); | |
634 | qreal y = max(); |
|
634 | qreal y = max(); | |
635 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
635 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
636 | minY = qMin(minY, y); |
|
636 | minY = qMin(minY, y); | |
637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
637 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
638 | maxY = qMax(maxY, y); |
|
638 | maxY = qMax(maxY, y); | |
639 |
|
639 | |||
640 | domain.setRange(minX, maxX, minY, maxY); |
|
640 | domain.setRange(minX, maxX, minY, maxY); | |
641 | } |
|
641 | } | |
642 |
|
642 | |||
643 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
643 | ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
644 | { |
|
644 | { | |
645 | Q_UNUSED(presenter); |
|
645 | Q_UNUSED(presenter); | |
646 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
646 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
647 | return 0; |
|
647 | return 0; | |
648 | } |
|
648 | } | |
649 |
|
649 | |||
650 | QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend) |
|
650 | QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend) | |
651 | { |
|
651 | { | |
652 | Q_Q(QAbstractBarSeries); |
|
652 | Q_Q(QAbstractBarSeries); | |
653 | QList<LegendMarker *> markers; |
|
653 | QList<LegendMarker *> markers; | |
654 | foreach (QBarSet *set, q->barSets()) { |
|
654 | foreach (QBarSet *set, q->barSets()) { | |
655 | BarLegendMarker* marker = new BarLegendMarker(q, set, legend); |
|
655 | BarLegendMarker* marker = new BarLegendMarker(q, set, legend); | |
656 | markers << marker; |
|
656 | markers << marker; | |
657 | } |
|
657 | } | |
658 |
|
658 | |||
659 | return markers; |
|
659 | return markers; | |
660 | } |
|
660 | } | |
661 |
|
661 | |||
|
662 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
663 | { | |||
|
664 | Q_UNUSED(legend); | |||
|
665 | // Q_Q(QAbstractBarSeries); | |||
|
666 | QList<QLegendMarker*> markers; | |||
|
667 | // TODO: when QBarLegendMarker is implemented | |||
|
668 | /* | |||
|
669 | foreach(QBarSet* set, q->barSets()) { | |||
|
670 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |||
|
671 | markers << marker; | |||
|
672 | } | |||
|
673 | */ | |||
|
674 | return markers; | |||
|
675 | } | |||
|
676 | ||||
|
677 | ||||
662 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
678 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
663 | { |
|
679 | { | |
664 | if ((m_barSets.contains(set)) || (set == 0)) |
|
680 | if ((m_barSets.contains(set)) || (set == 0)) | |
665 | return false; // Fail if set is already in list or set is null. |
|
681 | return false; // Fail if set is already in list or set is null. | |
666 |
|
682 | |||
667 | m_barSets.append(set); |
|
683 | m_barSets.append(set); | |
668 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
684 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
669 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
685 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
670 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
686 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
671 |
|
687 | |||
672 | emit restructuredBars(); // this notifies barchartitem |
|
688 | emit restructuredBars(); // this notifies barchartitem | |
673 | return true; |
|
689 | return true; | |
674 | } |
|
690 | } | |
675 |
|
691 | |||
676 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
692 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
677 | { |
|
693 | { | |
678 | if (!m_barSets.contains(set)) |
|
694 | if (!m_barSets.contains(set)) | |
679 | return false; // Fail if set is not in list |
|
695 | return false; // Fail if set is not in list | |
680 |
|
696 | |||
681 | m_barSets.removeOne(set); |
|
697 | m_barSets.removeOne(set); | |
682 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
698 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
699 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
700 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
685 |
|
701 | |||
686 | emit restructuredBars(); // this notifies barchartitem |
|
702 | emit restructuredBars(); // this notifies barchartitem | |
687 | return true; |
|
703 | return true; | |
688 | } |
|
704 | } | |
689 |
|
705 | |||
690 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) |
|
706 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) | |
691 | { |
|
707 | { | |
692 | foreach (QBarSet *set, sets) { |
|
708 | foreach (QBarSet *set, sets) { | |
693 | if ((set == 0) || (m_barSets.contains(set))) |
|
709 | if ((set == 0) || (m_barSets.contains(set))) | |
694 | return false; // Fail if any of the sets is null or is already appended. |
|
710 | return false; // Fail if any of the sets is null or is already appended. | |
695 | if (sets.count(set) != 1) |
|
711 | if (sets.count(set) != 1) | |
696 | return false; // Also fail if same set is more than once in given list. |
|
712 | return false; // Also fail if same set is more than once in given list. | |
697 | } |
|
713 | } | |
698 |
|
714 | |||
699 | foreach (QBarSet *set, sets) { |
|
715 | foreach (QBarSet *set, sets) { | |
700 | m_barSets.append(set); |
|
716 | m_barSets.append(set); | |
701 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
717 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
718 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
719 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
704 | } |
|
720 | } | |
705 |
|
721 | |||
706 | emit restructuredBars(); // this notifies barchartitem |
|
722 | emit restructuredBars(); // this notifies barchartitem | |
707 | return true; |
|
723 | return true; | |
708 | } |
|
724 | } | |
709 |
|
725 | |||
710 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) |
|
726 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) | |
711 | { |
|
727 | { | |
712 | if (sets.count() == 0) |
|
728 | if (sets.count() == 0) | |
713 | return false; |
|
729 | return false; | |
714 |
|
730 | |||
715 | foreach (QBarSet *set, sets) { |
|
731 | foreach (QBarSet *set, sets) { | |
716 | if ((set == 0) || (!m_barSets.contains(set))) |
|
732 | if ((set == 0) || (!m_barSets.contains(set))) | |
717 | return false; // Fail if any of the sets is null or is not in series |
|
733 | return false; // Fail if any of the sets is null or is not in series | |
718 | if (sets.count(set) != 1) |
|
734 | if (sets.count(set) != 1) | |
719 | return false; // Also fail if same set is more than once in given list. |
|
735 | return false; // Also fail if same set is more than once in given list. | |
720 | } |
|
736 | } | |
721 |
|
737 | |||
722 | foreach (QBarSet *set, sets) { |
|
738 | foreach (QBarSet *set, sets) { | |
723 | m_barSets.removeOne(set); |
|
739 | m_barSets.removeOne(set); | |
724 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
740 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
725 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
741 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
726 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
742 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
727 | } |
|
743 | } | |
728 |
|
744 | |||
729 | emit restructuredBars(); // this notifies barchartitem |
|
745 | emit restructuredBars(); // this notifies barchartitem | |
730 | return true; |
|
746 | return true; | |
731 | } |
|
747 | } | |
732 |
|
748 | |||
733 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
749 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
734 | { |
|
750 | { | |
735 | if ((m_barSets.contains(set)) || (set == 0)) |
|
751 | if ((m_barSets.contains(set)) || (set == 0)) | |
736 | return false; // Fail if set is already in list or set is null. |
|
752 | return false; // Fail if set is already in list or set is null. | |
737 |
|
753 | |||
738 | m_barSets.insert(index, set); |
|
754 | m_barSets.insert(index, set); | |
739 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
755 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
740 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
756 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
741 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
757 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
742 |
|
758 | |||
743 | emit restructuredBars(); // this notifies barchartitem |
|
759 | emit restructuredBars(); // this notifies barchartitem | |
744 | return true; |
|
760 | return true; | |
745 | } |
|
761 | } | |
746 |
|
762 | |||
747 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
763 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
748 | { |
|
764 | { | |
749 | Q_Q(QAbstractBarSeries); |
|
765 | Q_Q(QAbstractBarSeries); | |
750 |
|
766 | |||
751 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
767 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
752 | switch (q->type()) { |
|
768 | switch (q->type()) { | |
753 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
769 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
754 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
770 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
755 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
771 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
756 | if (axis->orientation() == Qt::Vertical) |
|
772 | if (axis->orientation() == Qt::Vertical) | |
757 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
773 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
758 | break; |
|
774 | break; | |
759 | case QAbstractSeries::SeriesTypeBar: |
|
775 | case QAbstractSeries::SeriesTypeBar: | |
760 | case QAbstractSeries::SeriesTypePercentBar: |
|
776 | case QAbstractSeries::SeriesTypePercentBar: | |
761 | case QAbstractSeries::SeriesTypeStackedBar: |
|
777 | case QAbstractSeries::SeriesTypeStackedBar: | |
762 | if (axis->orientation() == Qt::Horizontal) |
|
778 | if (axis->orientation() == Qt::Horizontal) | |
763 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
779 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
764 | break; |
|
780 | break; | |
765 | default: |
|
781 | default: | |
766 | qWarning() << "Unexpected series type"; |
|
782 | qWarning() << "Unexpected series type"; | |
767 | break; |
|
783 | break; | |
768 | } |
|
784 | } | |
769 | } |
|
785 | } | |
770 | } |
|
786 | } | |
771 |
|
787 | |||
772 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
788 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
773 | { |
|
789 | { | |
774 | Q_Q(const QAbstractBarSeries); |
|
790 | Q_Q(const QAbstractBarSeries); | |
775 |
|
791 | |||
776 | switch (q->type()) { |
|
792 | switch (q->type()) { | |
777 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
793 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
778 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
794 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
779 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
795 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
780 | if (orientation == Qt::Vertical) |
|
796 | if (orientation == Qt::Vertical) | |
781 | return QAbstractAxis::AxisTypeBarCategory; |
|
797 | return QAbstractAxis::AxisTypeBarCategory; | |
782 | break; |
|
798 | break; | |
783 | case QAbstractSeries::SeriesTypeBar: |
|
799 | case QAbstractSeries::SeriesTypeBar: | |
784 | case QAbstractSeries::SeriesTypePercentBar: |
|
800 | case QAbstractSeries::SeriesTypePercentBar: | |
785 | case QAbstractSeries::SeriesTypeStackedBar: |
|
801 | case QAbstractSeries::SeriesTypeStackedBar: | |
786 | if (orientation == Qt::Horizontal) |
|
802 | if (orientation == Qt::Horizontal) | |
787 | return QAbstractAxis::AxisTypeBarCategory; |
|
803 | return QAbstractAxis::AxisTypeBarCategory; | |
788 | break; |
|
804 | break; | |
789 | default: |
|
805 | default: | |
790 | qWarning() << "Unexpected series type"; |
|
806 | qWarning() << "Unexpected series type"; | |
791 | break; |
|
807 | break; | |
792 | } |
|
808 | } | |
793 | return QAbstractAxis::AxisTypeValue; |
|
809 | return QAbstractAxis::AxisTypeValue; | |
794 |
|
810 | |||
795 | } |
|
811 | } | |
796 |
|
812 | |||
797 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
813 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |
798 | { |
|
814 | { | |
799 | QStringList categories; |
|
815 | QStringList categories; | |
800 | if (axis->categories().isEmpty()) { |
|
816 | if (axis->categories().isEmpty()) { | |
801 | for (int i(1); i < categoryCount() + 1; i++) |
|
817 | for (int i(1); i < categoryCount() + 1; i++) | |
802 | categories << QString::number(i); |
|
818 | categories << QString::number(i); | |
803 | axis->append(categories); |
|
819 | axis->append(categories); | |
804 | } |
|
820 | } | |
805 | } |
|
821 | } | |
806 |
|
822 | |||
807 | #include "moc_qabstractbarseries.cpp" |
|
823 | #include "moc_qabstractbarseries.cpp" | |
808 | #include "moc_qabstractbarseries_p.cpp" |
|
824 | #include "moc_qabstractbarseries_p.cpp" | |
809 |
|
825 | |||
810 | QTCOMMERCIALCHART_END_NAMESPACE |
|
826 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,109 +1,111 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTBARSERIES_P_H |
|
30 | #ifndef QABSTRACTBARSERIES_P_H | |
31 | #define QABSTRACTBARSERIES_P_H |
|
31 | #define QABSTRACTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include <QStringList> |
|
35 | #include <QStringList> | |
36 | #include <QAbstractSeries> |
|
36 | #include <QAbstractSeries> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 | class QBarCategoryAxis; |
|
41 | class QBarCategoryAxis; | |
|
42 | class QLegendMarker; | |||
42 |
|
43 | |||
43 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
44 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate | |
44 | { |
|
45 | { | |
45 | Q_OBJECT |
|
46 | Q_OBJECT | |
46 | public: |
|
47 | public: | |
47 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); |
|
48 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); | |
48 | int categoryCount() const; |
|
49 | int categoryCount() const; | |
49 |
|
50 | |||
50 | void setBarWidth(qreal width); |
|
51 | void setBarWidth(qreal width); | |
51 | qreal barWidth() const; |
|
52 | qreal barWidth() const; | |
52 |
|
53 | |||
53 | void setVisible(bool visible); |
|
54 | void setVisible(bool visible); | |
54 | void setLabelsVisible(bool visible); |
|
55 | void setLabelsVisible(bool visible); | |
55 |
|
56 | |||
56 | void scaleDomain(Domain &domain); |
|
57 | void scaleDomain(Domain &domain); | |
57 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
58 | ChartElement *createGraphics(ChartPresenter *presenter); | |
58 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
59 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
60 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
59 |
|
61 | |||
60 | void initializeAxis(QAbstractAxis *axis); |
|
62 | void initializeAxis(QAbstractAxis *axis); | |
61 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
63 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
62 |
|
64 | |||
63 | bool append(QBarSet *set); |
|
65 | bool append(QBarSet *set); | |
64 | bool remove(QBarSet *set); |
|
66 | bool remove(QBarSet *set); | |
65 | bool append(QList<QBarSet *> sets); |
|
67 | bool append(QList<QBarSet *> sets); | |
66 | bool remove(QList<QBarSet *> sets); |
|
68 | bool remove(QList<QBarSet *> sets); | |
67 | bool insert(int index, QBarSet *set); |
|
69 | bool insert(int index, QBarSet *set); | |
68 |
|
70 | |||
69 | QBarSet *barsetAt(int index); |
|
71 | QBarSet *barsetAt(int index); | |
70 | qreal min(); |
|
72 | qreal min(); | |
71 | qreal max(); |
|
73 | qreal max(); | |
72 | qreal valueAt(int set, int category); |
|
74 | qreal valueAt(int set, int category); | |
73 | qreal percentageAt(int set, int category); |
|
75 | qreal percentageAt(int set, int category); | |
74 | qreal categorySum(int category); |
|
76 | qreal categorySum(int category); | |
75 | qreal absoluteCategorySum(int category); |
|
77 | qreal absoluteCategorySum(int category); | |
76 | qreal maxCategorySum(); |
|
78 | qreal maxCategorySum(); | |
77 | qreal minX(); |
|
79 | qreal minX(); | |
78 | qreal maxX(); |
|
80 | qreal maxX(); | |
79 | qreal categoryTop(int category); |
|
81 | qreal categoryTop(int category); | |
80 | qreal categoryBottom(int category); |
|
82 | qreal categoryBottom(int category); | |
81 | qreal top(); |
|
83 | qreal top(); | |
82 | qreal bottom(); |
|
84 | qreal bottom(); | |
83 |
|
85 | |||
84 | Q_SIGNALS: |
|
86 | Q_SIGNALS: | |
85 | void clicked(int index, QBarSet *barset); |
|
87 | void clicked(int index, QBarSet *barset); | |
86 | void updatedBars(); |
|
88 | void updatedBars(); | |
87 | void updatedLayout(); |
|
89 | void updatedLayout(); | |
88 | void restructuredBars(); |
|
90 | void restructuredBars(); | |
89 | void labelsVisibleChanged(bool visible); |
|
91 | void labelsVisibleChanged(bool visible); | |
90 | void visibleChanged(); |
|
92 | void visibleChanged(); | |
91 |
|
93 | |||
92 | private: |
|
94 | private: | |
93 | void populateCategories(QBarCategoryAxis *axis); |
|
95 | void populateCategories(QBarCategoryAxis *axis); | |
94 |
|
96 | |||
95 | protected: |
|
97 | protected: | |
96 | QList<QBarSet *> m_barSets; |
|
98 | QList<QBarSet *> m_barSets; | |
97 | qreal m_barWidth; |
|
99 | qreal m_barWidth; | |
98 | bool m_labelsVisible; |
|
100 | bool m_labelsVisible; | |
99 | bool m_visible; |
|
101 | bool m_visible; | |
100 |
|
102 | |||
101 | private: |
|
103 | private: | |
102 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
104 | Q_DECLARE_PUBLIC(QAbstractBarSeries) | |
103 | friend class HorizontalBarChartItem; |
|
105 | friend class HorizontalBarChartItem; | |
104 | friend class BarChartItem; |
|
106 | friend class BarChartItem; | |
105 | }; |
|
107 | }; | |
106 |
|
108 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
109 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
110 | |||
109 | #endif // QABSTRACTBARSERIES_P_H |
|
111 | #endif // QABSTRACTBARSERIES_P_H |
@@ -1,21 +1,22 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/qlegend.cpp \ |
|
5 | $$PWD/qlegend.cpp \ | |
6 | $$PWD/legendmarker.cpp \ |
|
6 | $$PWD/legendmarker.cpp \ | |
7 | $$PWD/legendlayout.cpp \ |
|
7 | $$PWD/legendlayout.cpp \ | |
8 | $$PWD/qlegendmarker.cpp \ |
|
8 | $$PWD/qlegendmarker.cpp \ | |
9 | $$PWD/qpielegendmarker.cpp |
|
9 | $$PWD/qpielegendmarker.cpp | |
10 |
|
10 | |||
11 | PRIVATE_HEADERS += \ |
|
11 | PRIVATE_HEADERS += \ | |
12 | $$PWD/legendmarker_p.h \ |
|
12 | $$PWD/legendmarker_p.h \ | |
13 | $$PWD/legendscroller_p.h \ |
|
13 | $$PWD/legendscroller_p.h \ | |
14 | $$PWD/qlegend_p.h \ |
|
14 | $$PWD/qlegend_p.h \ | |
15 | $$PWD/legendlayout_p.h |
|
15 | $$PWD/legendlayout_p.h \ | |
|
16 | $$PWD/qlegendmarker_p.h | |||
16 |
|
17 | |||
17 |
|
18 | |||
18 | PUBLIC_HEADERS += \ |
|
19 | PUBLIC_HEADERS += \ | |
19 | $$PWD/qlegend.h \ |
|
20 | $$PWD/qlegend.h \ | |
20 | $$PWD/qlegendmarker.h \ |
|
21 | $$PWD/qlegendmarker.h \ | |
21 | $$PWD/qpielegendmarker.h |
|
22 | $$PWD/qpielegendmarker.h |
@@ -1,522 +1,561 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "legendlayout_p.h" |
|
26 | #include "legendlayout_p.h" | |
27 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qabstractbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include "chartlayout_p.h" |
|
41 | #include "chartlayout_p.h" | |
42 | #include <QPainter> |
|
42 | #include <QPainter> | |
43 | #include <QPen> |
|
43 | #include <QPen> | |
44 | #include <QTimer> |
|
44 | #include <QTimer> | |
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
|
47 | #include <QLegendMarker> | |||
|
48 | ||||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
49 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
50 | |||
49 | /*! |
|
51 | /*! | |
50 | \class QLegend |
|
52 | \class QLegend | |
51 | \brief Legend object |
|
53 | \brief Legend object | |
52 | \mainclass |
|
54 | \mainclass | |
53 |
|
55 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
56 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
57 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
58 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
59 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
60 | |||
59 | \image examples_percentbarchart_legend.png |
|
61 | \image examples_percentbarchart_legend.png | |
60 |
|
62 | |||
61 | \sa QChart |
|
63 | \sa QChart | |
62 | */ |
|
64 | */ | |
63 | /*! |
|
65 | /*! | |
64 | \qmlclass Legend QLegend |
|
66 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
67 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
68 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
69 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is used via ChartView class. For example: |
|
70 | series have been changed. Legend is used via ChartView class. For example: | |
69 | \code |
|
71 | \code | |
70 | ChartView { |
|
72 | ChartView { | |
71 | legend.visible: true |
|
73 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
74 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
75 | // Add a few series... | |
74 | } |
|
76 | } | |
75 | \endcode |
|
77 | \endcode | |
76 |
|
78 | |||
77 | \image examples_percentbarchart_legend.png |
|
79 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
80 | */ | |
79 |
|
81 | |||
80 | /*! |
|
82 | /*! | |
81 | \property QLegend::alignment |
|
83 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
84 | \brief The alignment of the legend. | |
83 |
|
85 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
86 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
87 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
88 | */ | |
87 | /*! |
|
89 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
90 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
91 | \brief The alignment of the legend. | |
90 |
|
92 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
93 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
94 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
95 | */ | |
94 |
|
96 | |||
95 | /*! |
|
97 | /*! | |
96 | \property QLegend::backgroundVisible |
|
98 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
99 | Whether the legend background is visible or not. | |
98 | */ |
|
100 | */ | |
99 | /*! |
|
101 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
102 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
103 | Whether the legend background is visible or not. | |
102 | */ |
|
104 | */ | |
103 |
|
105 | |||
104 | /*! |
|
106 | /*! | |
105 | \property QLegend::color |
|
107 | \property QLegend::color | |
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
108 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
109 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
108 | */ |
|
110 | */ | |
109 | /*! |
|
111 | /*! | |
110 | \qmlproperty color Legend::color |
|
112 | \qmlproperty color Legend::color | |
111 | The color of the legend, i.e. the background (brush) color. |
|
113 | The color of the legend, i.e. the background (brush) color. | |
112 | */ |
|
114 | */ | |
113 |
|
115 | |||
114 | /*! |
|
116 | /*! | |
115 | \property QLegend::borderColor |
|
117 | \property QLegend::borderColor | |
116 | The border color of the legend, i.e. the line color. |
|
118 | The border color of the legend, i.e. the line color. | |
117 | */ |
|
119 | */ | |
118 | /*! |
|
120 | /*! | |
119 | \qmlproperty color Legend::borderColor |
|
121 | \qmlproperty color Legend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
122 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
123 | */ | |
122 |
|
124 | |||
123 | /*! |
|
125 | /*! | |
124 | \property QLegend::font |
|
126 | \property QLegend::font | |
125 | The font of markers used by legend |
|
127 | The font of markers used by legend | |
126 | */ |
|
128 | */ | |
127 | /*! |
|
129 | /*! | |
128 | \qmlproperty Font Legend::font |
|
130 | \qmlproperty Font Legend::font | |
129 | The font of markers used by legend |
|
131 | The font of markers used by legend | |
130 | */ |
|
132 | */ | |
131 |
|
133 | |||
132 | /*! |
|
134 | /*! | |
133 | \property QLegend::labelColor |
|
135 | \property QLegend::labelColor | |
134 | The color of brush used to draw labels. |
|
136 | The color of brush used to draw labels. | |
135 | */ |
|
137 | */ | |
136 | /*! |
|
138 | /*! | |
137 | \qmlproperty color QLegend::labelColor |
|
139 | \qmlproperty color QLegend::labelColor | |
138 | The color of brush used to draw labels. |
|
140 | The color of brush used to draw labels. | |
139 | */ |
|
141 | */ | |
140 |
|
142 | |||
141 | /*! |
|
143 | /*! | |
142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
144 | \fn void QLegend::backgroundVisibleChanged(bool) | |
143 | The visibility of the legend background changed to \a visible. |
|
145 | The visibility of the legend background changed to \a visible. | |
144 | */ |
|
146 | */ | |
145 |
|
147 | |||
146 | /*! |
|
148 | /*! | |
147 | \fn void QLegend::colorChanged(QColor) |
|
149 | \fn void QLegend::colorChanged(QColor) | |
148 | The color of the legend background changed to \a color. |
|
150 | The color of the legend background changed to \a color. | |
149 | */ |
|
151 | */ | |
150 |
|
152 | |||
151 | /*! |
|
153 | /*! | |
152 | \fn void QLegend::borderColorChanged(QColor) |
|
154 | \fn void QLegend::borderColorChanged(QColor) | |
153 | The border color of the legend background changed to \a color. |
|
155 | The border color of the legend background changed to \a color. | |
154 | */ |
|
156 | */ | |
155 |
|
157 | |||
156 | /*! |
|
158 | /*! | |
157 | \fn void QLegend::fontChanged(QFont) |
|
159 | \fn void QLegend::fontChanged(QFont) | |
158 | The font of markers of the legend changed to \a font. |
|
160 | The font of markers of the legend changed to \a font. | |
159 | */ |
|
161 | */ | |
160 |
|
162 | |||
161 | /*! |
|
163 | /*! | |
162 | \fn void QLegend::labelColorChanged(QColor color) |
|
164 | \fn void QLegend::labelColorChanged(QColor color) | |
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
165 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
164 | */ |
|
166 | */ | |
165 |
|
167 | |||
166 | /*! |
|
168 | /*! | |
167 | Constructs the legend object and sets the parent to \a parent |
|
169 | Constructs the legend object and sets the parent to \a parent | |
168 | */ |
|
170 | */ | |
169 |
|
171 | |||
170 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
172 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
173 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
172 | { |
|
174 | { | |
173 | setZValue(ChartPresenter::LegendZValue); |
|
175 | setZValue(ChartPresenter::LegendZValue); | |
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
176 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
175 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
177 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
176 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
178 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
177 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
179 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
178 | setLayout(d_ptr->m_layout); |
|
180 | setLayout(d_ptr->m_layout); | |
179 | } |
|
181 | } | |
180 |
|
182 | |||
181 | /*! |
|
183 | /*! | |
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
184 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
183 | */ |
|
185 | */ | |
184 | QLegend::~QLegend() |
|
186 | QLegend::~QLegend() | |
185 | { |
|
187 | { | |
186 | } |
|
188 | } | |
187 |
|
189 | |||
188 | /*! |
|
190 | /*! | |
189 | \internal |
|
191 | \internal | |
190 | */ |
|
192 | */ | |
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
193 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
192 | { |
|
194 | { | |
193 | Q_UNUSED(option) |
|
195 | Q_UNUSED(option) | |
194 | Q_UNUSED(widget) |
|
196 | Q_UNUSED(widget) | |
195 |
|
197 | |||
196 | if (!d_ptr->m_backgroundVisible) |
|
198 | if (!d_ptr->m_backgroundVisible) | |
197 | return; |
|
199 | return; | |
198 |
|
200 | |||
199 | painter->setOpacity(opacity()); |
|
201 | painter->setOpacity(opacity()); | |
200 | painter->setPen(d_ptr->m_pen); |
|
202 | painter->setPen(d_ptr->m_pen); | |
201 | painter->setBrush(d_ptr->m_brush); |
|
203 | painter->setBrush(d_ptr->m_brush); | |
202 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
204 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
203 | } |
|
205 | } | |
204 |
|
206 | |||
205 |
|
207 | |||
206 | /*! |
|
208 | /*! | |
207 | Sets the \a brush of legend. Brush affects the background of legend. |
|
209 | Sets the \a brush of legend. Brush affects the background of legend. | |
208 | */ |
|
210 | */ | |
209 | void QLegend::setBrush(const QBrush &brush) |
|
211 | void QLegend::setBrush(const QBrush &brush) | |
210 | { |
|
212 | { | |
211 | if (d_ptr->m_brush != brush) { |
|
213 | if (d_ptr->m_brush != brush) { | |
212 | d_ptr->m_brush = brush; |
|
214 | d_ptr->m_brush = brush; | |
213 | update(); |
|
215 | update(); | |
214 | emit colorChanged(brush.color()); |
|
216 | emit colorChanged(brush.color()); | |
215 | } |
|
217 | } | |
216 | } |
|
218 | } | |
217 |
|
219 | |||
218 | /*! |
|
220 | /*! | |
219 | Returns the brush used by legend. |
|
221 | Returns the brush used by legend. | |
220 | */ |
|
222 | */ | |
221 | QBrush QLegend::brush() const |
|
223 | QBrush QLegend::brush() const | |
222 | { |
|
224 | { | |
223 | return d_ptr->m_brush; |
|
225 | return d_ptr->m_brush; | |
224 | } |
|
226 | } | |
225 |
|
227 | |||
226 | void QLegend::setColor(QColor color) |
|
228 | void QLegend::setColor(QColor color) | |
227 | { |
|
229 | { | |
228 | QBrush b = d_ptr->m_brush; |
|
230 | QBrush b = d_ptr->m_brush; | |
229 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
231 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
230 | b.setStyle(Qt::SolidPattern); |
|
232 | b.setStyle(Qt::SolidPattern); | |
231 | b.setColor(color); |
|
233 | b.setColor(color); | |
232 | setBrush(b); |
|
234 | setBrush(b); | |
233 | } |
|
235 | } | |
234 | } |
|
236 | } | |
235 |
|
237 | |||
236 | QColor QLegend::color() |
|
238 | QColor QLegend::color() | |
237 | { |
|
239 | { | |
238 | return d_ptr->m_brush.color(); |
|
240 | return d_ptr->m_brush.color(); | |
239 | } |
|
241 | } | |
240 |
|
242 | |||
241 | /*! |
|
243 | /*! | |
242 | Sets the \a pen of legend. Pen affects the legend borders. |
|
244 | Sets the \a pen of legend. Pen affects the legend borders. | |
243 | */ |
|
245 | */ | |
244 | void QLegend::setPen(const QPen &pen) |
|
246 | void QLegend::setPen(const QPen &pen) | |
245 | { |
|
247 | { | |
246 | if (d_ptr->m_pen != pen) { |
|
248 | if (d_ptr->m_pen != pen) { | |
247 | d_ptr->m_pen = pen; |
|
249 | d_ptr->m_pen = pen; | |
248 | update(); |
|
250 | update(); | |
249 | emit borderColorChanged(pen.color()); |
|
251 | emit borderColorChanged(pen.color()); | |
250 | } |
|
252 | } | |
251 | } |
|
253 | } | |
252 |
|
254 | |||
253 | /*! |
|
255 | /*! | |
254 | Returns the pen used by legend |
|
256 | Returns the pen used by legend | |
255 | */ |
|
257 | */ | |
256 |
|
258 | |||
257 | QPen QLegend::pen() const |
|
259 | QPen QLegend::pen() const | |
258 | { |
|
260 | { | |
259 | return d_ptr->m_pen; |
|
261 | return d_ptr->m_pen; | |
260 | } |
|
262 | } | |
261 |
|
263 | |||
262 | void QLegend::setFont(const QFont &font) |
|
264 | void QLegend::setFont(const QFont &font) | |
263 | { |
|
265 | { | |
264 | if (d_ptr->m_font != font) { |
|
266 | if (d_ptr->m_font != font) { | |
265 | d_ptr->m_font = font; |
|
267 | d_ptr->m_font = font; | |
266 | foreach (LegendMarker *marker, d_ptr->markers()) |
|
268 | foreach (LegendMarker *marker, d_ptr->markers()) | |
267 | marker->setFont(d_ptr->m_font); |
|
269 | marker->setFont(d_ptr->m_font); | |
268 | layout()->invalidate(); |
|
270 | layout()->invalidate(); | |
269 | emit fontChanged(font); |
|
271 | emit fontChanged(font); | |
270 | } |
|
272 | } | |
271 | } |
|
273 | } | |
272 |
|
274 | |||
273 | QFont QLegend::font() const |
|
275 | QFont QLegend::font() const | |
274 | { |
|
276 | { | |
275 | return d_ptr->m_font; |
|
277 | return d_ptr->m_font; | |
276 | } |
|
278 | } | |
277 |
|
279 | |||
278 | void QLegend::setBorderColor(QColor color) |
|
280 | void QLegend::setBorderColor(QColor color) | |
279 | { |
|
281 | { | |
280 | QPen p = d_ptr->m_pen; |
|
282 | QPen p = d_ptr->m_pen; | |
281 | if (p.color() != color) { |
|
283 | if (p.color() != color) { | |
282 | p.setColor(color); |
|
284 | p.setColor(color); | |
283 | setPen(p); |
|
285 | setPen(p); | |
284 | } |
|
286 | } | |
285 | } |
|
287 | } | |
286 |
|
288 | |||
287 | QColor QLegend::borderColor() |
|
289 | QColor QLegend::borderColor() | |
288 | { |
|
290 | { | |
289 | return d_ptr->m_pen.color(); |
|
291 | return d_ptr->m_pen.color(); | |
290 | } |
|
292 | } | |
291 |
|
293 | |||
292 | /*! |
|
294 | /*! | |
293 | Set brush used to draw labels to \a brush. |
|
295 | Set brush used to draw labels to \a brush. | |
294 | */ |
|
296 | */ | |
295 | void QLegend::setLabelBrush(const QBrush &brush) |
|
297 | void QLegend::setLabelBrush(const QBrush &brush) | |
296 | { |
|
298 | { | |
297 | if (d_ptr->m_labelBrush != brush) { |
|
299 | if (d_ptr->m_labelBrush != brush) { | |
298 | d_ptr->m_labelBrush = brush; |
|
300 | d_ptr->m_labelBrush = brush; | |
299 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
301 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
300 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
302 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
301 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
303 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
302 | // instead of mapping it from label brush color |
|
304 | // instead of mapping it from label brush color | |
303 | marker->setPen(brush.color()); |
|
305 | marker->setPen(brush.color()); | |
304 | } |
|
306 | } | |
305 | emit labelColorChanged(brush.color()); |
|
307 | emit labelColorChanged(brush.color()); | |
306 | } |
|
308 | } | |
307 | } |
|
309 | } | |
308 |
|
310 | |||
309 | /*! |
|
311 | /*! | |
310 | Brush used to draw labels. |
|
312 | Brush used to draw labels. | |
311 | */ |
|
313 | */ | |
312 | QBrush QLegend::labelBrush() const |
|
314 | QBrush QLegend::labelBrush() const | |
313 | { |
|
315 | { | |
314 | return d_ptr->m_labelBrush; |
|
316 | return d_ptr->m_labelBrush; | |
315 | } |
|
317 | } | |
316 |
|
318 | |||
317 | void QLegend::setLabelColor(QColor color) |
|
319 | void QLegend::setLabelColor(QColor color) | |
318 | { |
|
320 | { | |
319 | QBrush b = d_ptr->m_labelBrush; |
|
321 | QBrush b = d_ptr->m_labelBrush; | |
320 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
322 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
321 | b.setStyle(Qt::SolidPattern); |
|
323 | b.setStyle(Qt::SolidPattern); | |
322 | b.setColor(color); |
|
324 | b.setColor(color); | |
323 | setLabelBrush(b); |
|
325 | setLabelBrush(b); | |
324 | } |
|
326 | } | |
325 | } |
|
327 | } | |
326 |
|
328 | |||
327 | QColor QLegend::labelColor() const |
|
329 | QColor QLegend::labelColor() const | |
328 | { |
|
330 | { | |
329 | return d_ptr->m_labelBrush.color(); |
|
331 | return d_ptr->m_labelBrush.color(); | |
330 | } |
|
332 | } | |
331 |
|
333 | |||
332 |
|
334 | |||
333 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
335 | void QLegend::setAlignment(Qt::Alignment alignment) | |
334 | { |
|
336 | { | |
335 | if (d_ptr->m_alignment != alignment) { |
|
337 | if (d_ptr->m_alignment != alignment) { | |
336 | d_ptr->m_alignment = alignment; |
|
338 | d_ptr->m_alignment = alignment; | |
337 | layout()->invalidate(); |
|
339 | layout()->invalidate(); | |
338 | } |
|
340 | } | |
339 | } |
|
341 | } | |
340 |
|
342 | |||
341 | Qt::Alignment QLegend::alignment() const |
|
343 | Qt::Alignment QLegend::alignment() const | |
342 | { |
|
344 | { | |
343 | return d_ptr->m_alignment; |
|
345 | return d_ptr->m_alignment; | |
344 | } |
|
346 | } | |
345 |
|
347 | |||
346 | /*! |
|
348 | /*! | |
347 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
349 | Detaches the legend from chart. Chart won't change layout of the legend. | |
348 | */ |
|
350 | */ | |
349 | void QLegend::detachFromChart() |
|
351 | void QLegend::detachFromChart() | |
350 | { |
|
352 | { | |
351 | d_ptr->m_attachedToChart = false; |
|
353 | d_ptr->m_attachedToChart = false; | |
352 | layout()->invalidate(); |
|
354 | layout()->invalidate(); | |
353 | setParent(0); |
|
355 | setParent(0); | |
354 |
|
356 | |||
355 | } |
|
357 | } | |
356 |
|
358 | |||
357 | /*! |
|
359 | /*! | |
358 | Attaches the legend to chart. Chart may change layout of the legend. |
|
360 | Attaches the legend to chart. Chart may change layout of the legend. | |
359 | */ |
|
361 | */ | |
360 | void QLegend::attachToChart() |
|
362 | void QLegend::attachToChart() | |
361 | { |
|
363 | { | |
362 | d_ptr->m_attachedToChart = true; |
|
364 | d_ptr->m_attachedToChart = true; | |
363 | layout()->invalidate(); |
|
365 | layout()->invalidate(); | |
364 | setParent(d_ptr->m_chart); |
|
366 | setParent(d_ptr->m_chart); | |
365 | } |
|
367 | } | |
366 |
|
368 | |||
367 | /*! |
|
369 | /*! | |
368 | Returns true, if legend is attached to chart. |
|
370 | Returns true, if legend is attached to chart. | |
369 | */ |
|
371 | */ | |
370 | bool QLegend::isAttachedToChart() |
|
372 | bool QLegend::isAttachedToChart() | |
371 | { |
|
373 | { | |
372 | return d_ptr->m_attachedToChart; |
|
374 | return d_ptr->m_attachedToChart; | |
373 | } |
|
375 | } | |
374 |
|
376 | |||
375 | /*! |
|
377 | /*! | |
376 | Sets the visibility of legend background to \a visible |
|
378 | Sets the visibility of legend background to \a visible | |
377 | */ |
|
379 | */ | |
378 | void QLegend::setBackgroundVisible(bool visible) |
|
380 | void QLegend::setBackgroundVisible(bool visible) | |
379 | { |
|
381 | { | |
380 | if (d_ptr->m_backgroundVisible != visible) { |
|
382 | if (d_ptr->m_backgroundVisible != visible) { | |
381 | d_ptr->m_backgroundVisible = visible; |
|
383 | d_ptr->m_backgroundVisible = visible; | |
382 | update(); |
|
384 | update(); | |
383 | emit backgroundVisibleChanged(visible); |
|
385 | emit backgroundVisibleChanged(visible); | |
384 | } |
|
386 | } | |
385 | } |
|
387 | } | |
386 |
|
388 | |||
387 | /*! |
|
389 | /*! | |
388 | Returns the visibility of legend background |
|
390 | Returns the visibility of legend background | |
389 | */ |
|
391 | */ | |
390 | bool QLegend::isBackgroundVisible() const |
|
392 | bool QLegend::isBackgroundVisible() const | |
391 | { |
|
393 | { | |
392 | return d_ptr->m_backgroundVisible; |
|
394 | return d_ptr->m_backgroundVisible; | |
393 | } |
|
395 | } | |
394 |
|
396 | |||
395 |
|
397 | |||
396 | QList<QLegendMarker*> QLegend::markers() const |
|
398 | QList<QLegendMarker*> QLegend::markers() const | |
397 | { |
|
399 | { | |
398 | // TODO: name of PIMPL method will change. |
|
400 | // TODO: name of PIMPL method will change. | |
399 | return d_ptr->legendMarkers(); |
|
401 | return d_ptr->legendMarkers(); | |
400 | } |
|
402 | } | |
401 |
|
403 | |||
402 |
|
404 | |||
403 | /*! |
|
405 | /*! | |
404 | \internal \a event see QGraphicsWidget for details |
|
406 | \internal \a event see QGraphicsWidget for details | |
405 | */ |
|
407 | */ | |
406 | void QLegend::hideEvent(QHideEvent *event) |
|
408 | void QLegend::hideEvent(QHideEvent *event) | |
407 | { |
|
409 | { | |
408 | if (isAttachedToChart()) |
|
410 | if (isAttachedToChart()) | |
409 | d_ptr->m_presenter->layout()->invalidate(); |
|
411 | d_ptr->m_presenter->layout()->invalidate(); | |
410 | QGraphicsWidget::hideEvent(event); |
|
412 | QGraphicsWidget::hideEvent(event); | |
411 | } |
|
413 | } | |
412 | /*! |
|
414 | /*! | |
413 | \internal \a event see QGraphicsWidget for details |
|
415 | \internal \a event see QGraphicsWidget for details | |
414 | */ |
|
416 | */ | |
415 | void QLegend::showEvent(QShowEvent *event) |
|
417 | void QLegend::showEvent(QShowEvent *event) | |
416 | { |
|
418 | { | |
417 | if (isAttachedToChart()) { |
|
419 | if (isAttachedToChart()) { | |
418 | d_ptr->items()->setVisible(false); |
|
420 | d_ptr->items()->setVisible(false); | |
419 | layout()->invalidate(); |
|
421 | layout()->invalidate(); | |
420 | } |
|
422 | } | |
421 | QGraphicsWidget::showEvent(event); |
|
423 | QGraphicsWidget::showEvent(event); | |
422 | //layout activation will show the items |
|
424 | //layout activation will show the items | |
423 | } |
|
425 | } | |
424 |
|
426 | |||
425 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
427 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
426 |
|
428 | |||
427 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
429 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
428 | : q_ptr(q), |
|
430 | : q_ptr(q), | |
429 | m_presenter(presenter), |
|
431 | m_presenter(presenter), | |
430 | m_layout(new LegendLayout(q)), |
|
432 | m_layout(new LegendLayout(q)), | |
431 | m_chart(chart), |
|
433 | m_chart(chart), | |
432 | m_items(new QGraphicsItemGroup(q)), |
|
434 | m_items(new QGraphicsItemGroup(q)), | |
433 | m_alignment(Qt::AlignTop), |
|
435 | m_alignment(Qt::AlignTop), | |
434 | m_brush(QBrush()), |
|
436 | m_brush(QBrush()), | |
435 | m_pen(QPen()), |
|
437 | m_pen(QPen()), | |
436 | m_labelBrush(QBrush()), |
|
438 | m_labelBrush(QBrush()), | |
437 | m_diameter(5), |
|
439 | m_diameter(5), | |
438 | m_attachedToChart(true), |
|
440 | m_attachedToChart(true), | |
439 | m_backgroundVisible(false) |
|
441 | m_backgroundVisible(false) | |
440 | { |
|
442 | { | |
441 |
|
443 | |||
442 | } |
|
444 | } | |
443 |
|
445 | |||
444 | QLegendPrivate::~QLegendPrivate() |
|
446 | QLegendPrivate::~QLegendPrivate() | |
445 | { |
|
447 | { | |
446 |
|
448 | |||
447 | } |
|
449 | } | |
448 |
|
450 | |||
449 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
451 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
450 | { |
|
452 | { | |
451 | m_layout->setOffset(x, y); |
|
453 | m_layout->setOffset(x, y); | |
452 | } |
|
454 | } | |
453 |
|
455 | |||
454 | QPointF QLegendPrivate::offset() const |
|
456 | QPointF QLegendPrivate::offset() const | |
455 | { |
|
457 | { | |
456 | return m_layout->offset(); |
|
458 | return m_layout->offset(); | |
457 | } |
|
459 | } | |
458 |
|
460 | |||
459 | int QLegendPrivate::roundness(qreal size) |
|
461 | int QLegendPrivate::roundness(qreal size) | |
460 | { |
|
462 | { | |
461 | return 100 * m_diameter / int(size); |
|
463 | return 100 * m_diameter / int(size); | |
462 | } |
|
464 | } | |
463 |
|
465 | |||
464 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
466 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
465 | { |
|
467 | { | |
466 | Q_UNUSED(domain) |
|
468 | Q_UNUSED(domain) | |
467 |
|
469 | |||
468 | QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
470 | // New markers ---> | |
|
471 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |||
|
472 | foreach (QLegendMarker* marker, newMarkers) { | |||
|
473 | marker->setFont(m_font); | |||
|
474 | marker->setLabelBrush(m_labelBrush); | |||
|
475 | marker->setVisible(series->isVisible()); | |||
|
476 | // TODO: QLegendMarker has QGraphicsItem vs QLegendMarker is QGraphicsItem | |||
|
477 | // m_items->addToGroup(marker); | |||
|
478 | m_legendMarkers << marker; | |||
|
479 | } | |||
|
480 | ||||
|
481 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |||
|
482 | // <--- New markers | |||
|
483 | ||||
|
484 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |||
469 |
|
485 | |||
470 | foreach (LegendMarker *marker, markers) { |
|
486 | foreach (LegendMarker *marker, markers) { | |
471 | marker->setFont(m_font); |
|
487 | marker->setFont(m_font); | |
472 | marker->setLabelBrush(m_labelBrush); |
|
488 | marker->setLabelBrush(m_labelBrush); | |
473 | marker->setVisible(series->isVisible()); |
|
489 | marker->setVisible(series->isVisible()); | |
474 | m_items->addToGroup(marker); |
|
490 | m_items->addToGroup(marker); | |
475 | m_markers << marker; |
|
491 | m_markers << marker; | |
476 | } |
|
492 | } | |
477 |
|
493 | |||
478 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
494 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
479 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
495 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
480 |
|
496 | |||
481 | m_items->setVisible(false); |
|
497 | m_items->setVisible(false); | |
482 | m_layout->invalidate(); |
|
498 | m_layout->invalidate(); | |
483 | } |
|
499 | } | |
484 |
|
500 | |||
485 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
501 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
486 | { |
|
502 | { | |
|
503 | // New markers ---> | |||
|
504 | foreach (QLegendMarker *marker, m_legendMarkers) { | |||
|
505 | if (marker->series() == series) { | |||
|
506 | delete marker; | |||
|
507 | m_legendMarkers.removeAll(marker); | |||
|
508 | } | |||
|
509 | } | |||
|
510 | ||||
|
511 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |||
|
512 | // <--- New markers | |||
|
513 | ||||
487 | foreach (LegendMarker *marker, m_markers) { |
|
514 | foreach (LegendMarker *marker, m_markers) { | |
488 | if (marker->series() == series) { |
|
515 | if (marker->series() == series) { | |
489 | delete marker; |
|
516 | delete marker; | |
490 | m_markers.removeAll(marker); |
|
517 | m_markers.removeAll(marker); | |
491 | } |
|
518 | } | |
492 | } |
|
519 | } | |
493 |
|
520 | |||
494 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
521 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
495 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
522 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
496 | m_layout->invalidate(); |
|
523 | m_layout->invalidate(); | |
497 | } |
|
524 | } | |
498 |
|
525 | |||
499 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
526 | void QLegendPrivate::handleSeriesVisibleChanged() | |
500 | { |
|
527 | { | |
501 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
528 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
502 | Q_ASSERT(series); |
|
529 | Q_ASSERT(series); | |
503 |
|
530 | |||
504 | foreach (LegendMarker *marker, m_markers) { |
|
531 | // New markers ---> | |
505 | if (marker->series() == series) |
|
532 | foreach (QLegendMarker* marker, m_legendMarkers) { | |
|
533 | if (marker->series() == series) { | |||
|
534 | marker->setVisible(series->isVisible()); | |||
|
535 | } | |||
|
536 | } | |||
|
537 | ||||
|
538 | // <--- New markers | |||
|
539 | ||||
|
540 | foreach (LegendMarker* marker, m_markers) { | |||
|
541 | if (marker->series() == series) { | |||
506 | marker->setVisible(series->isVisible()); |
|
542 | marker->setVisible(series->isVisible()); | |
507 | } |
|
543 | } | |
508 | m_layout->invalidate(); |
|
544 | m_layout->invalidate(); | |
509 | } |
|
545 | } | |
510 |
|
546 | |||
511 | void QLegendPrivate::handleCountChanged() |
|
547 | void QLegendPrivate::handleCountChanged() | |
512 | { |
|
548 | { | |
513 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
549 | // With new markers, the series shoud notify markers directly? | |
514 | Q_ASSERT(series); |
|
550 | ||
515 | handleSeriesRemoved(series->q_ptr); |
|
551 | // Handle new or removed markers | |
516 | handleSeriesAdded(series->q_ptr, 0); |
|
552 | // Handle changes of marker pen/brush/label. every property that legend is interested | |
|
553 | handleSeriesRemoved(series); | |||
|
554 | Domain domain; | |||
|
555 | handleSeriesAdded(series, &domain); | |||
517 | } |
|
556 | } | |
518 |
|
557 | |||
519 | #include "moc_qlegend.cpp" |
|
558 | #include "moc_qlegend.cpp" | |
520 | #include "moc_qlegend_p.cpp" |
|
559 | #include "moc_qlegend_p.cpp" | |
521 |
|
560 | |||
522 | QTCOMMERCIALCHART_END_NAMESPACE |
|
561 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,86 +1,185 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegendmarker.h" |
|
21 | #include "qlegendmarker.h" | |
22 |
|
|
22 | #include "qlegendmarker_p.h" | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
|
24 | #include <QFontMetrics> | |||
24 |
|
25 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
27 | |||
27 | QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) : |
|
28 | QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) : | |
28 | QObject(parent), |
|
29 | QObject(parent), | |
29 | m_series(series) |
|
30 | d_ptr(new QLegendMarkerPrivate(series, this)) | |
30 | // d_ptr(new QLegendMarkerPrivate(this)) |
|
|||
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QLegendMarker::~QLegendMarker() |
|
34 | QLegendMarker::~QLegendMarker() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QString QLegendMarker::label() const |
|
38 | QString QLegendMarker::label() const | |
39 | { |
|
39 | { | |
40 | return m_label; |
|
40 | return d_ptr->m_label; | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | void QLegendMarker::setLabel(const QString &label) |
|
43 | void QLegendMarker::setLabel(const QString &label) | |
44 | { |
|
44 | { | |
45 | m_label = label; |
|
45 | d_ptr->m_label = label; | |
|
46 | } | |||
|
47 | ||||
|
48 | QBrush QLegendMarker::labelBrush() const | |||
|
49 | { | |||
|
50 | return d_ptr->m_labelBrush; | |||
|
51 | } | |||
|
52 | ||||
|
53 | void QLegendMarker::setLabelBrush(const QBrush &brush) | |||
|
54 | { | |||
|
55 | d_ptr->m_labelBrush = brush; | |||
|
56 | } | |||
|
57 | ||||
|
58 | QFont QLegendMarker::font() const | |||
|
59 | { | |||
|
60 | return d_ptr->m_font; | |||
|
61 | } | |||
|
62 | ||||
|
63 | void QLegendMarker::setFont(const QFont &font) | |||
|
64 | { | |||
|
65 | d_ptr->m_font = font; | |||
46 | } |
|
66 | } | |
47 |
|
67 | |||
48 | QPen QLegendMarker::pen() const |
|
68 | QPen QLegendMarker::pen() const | |
49 | { |
|
69 | { | |
50 | return m_pen; |
|
70 | return d_ptr->m_pen; | |
51 | } |
|
71 | } | |
52 |
|
72 | |||
53 | void QLegendMarker::setPen(const QPen &pen) |
|
73 | void QLegendMarker::setPen(const QPen &pen) | |
54 | { |
|
74 | { | |
55 | m_pen = pen; |
|
75 | d_ptr->m_pen = pen; | |
56 | } |
|
76 | } | |
57 |
|
77 | |||
58 | QBrush QLegendMarker::brush() const |
|
78 | QBrush QLegendMarker::brush() const | |
59 | { |
|
79 | { | |
60 | return m_brush; |
|
80 | return d_ptr->m_brush; | |
61 | } |
|
81 | } | |
62 |
|
82 | |||
63 | void QLegendMarker::setBrush(const QBrush &brush) |
|
83 | void QLegendMarker::setBrush(const QBrush &brush) | |
64 | { |
|
84 | { | |
65 | m_brush = brush; |
|
85 | d_ptr->m_brush = brush; | |
66 | } |
|
86 | } | |
67 |
|
87 | |||
68 | bool QLegendMarker::isVisible() const |
|
88 | bool QLegendMarker::isVisible() const | |
69 | { |
|
89 | { | |
70 | return m_visible; |
|
90 | return d_ptr->m_visible; | |
71 | } |
|
91 | } | |
72 |
|
92 | |||
73 | void QLegendMarker::setVisible(bool visible) |
|
93 | void QLegendMarker::setVisible(bool visible) | |
74 | { |
|
94 | { | |
75 | m_visible = visible; |
|
95 | d_ptr->m_visible = visible; | |
76 | } |
|
96 | } | |
77 |
|
97 | |||
78 | void QLegendMarker::markersUpdated() |
|
98 | QAbstractSeries* QLegendMarker::series() | |
79 | { |
|
99 | { | |
80 | // TODO: |
|
100 | return d_ptr->m_series; | |
81 | } |
|
101 | } | |
82 |
|
102 | |||
|
103 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
104 | ||||
|
105 | QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q) : | |||
|
106 | q_ptr(q), | |||
|
107 | m_series(series) | |||
|
108 | { | |||
|
109 | ||||
|
110 | } | |||
|
111 | ||||
|
112 | void QLegendMarkerPrivate::setGeometry(const QRectF& rect) | |||
|
113 | { | |||
|
114 | QFontMetrics fn (m_font); | |||
|
115 | ||||
|
116 | ||||
|
117 | int width = rect.width(); | |||
|
118 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; | |||
|
119 | qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); | |||
|
120 | ||||
|
121 | if (fn.boundingRect(m_label).width() + x > width) | |||
|
122 | { | |||
|
123 | QString string = m_label + "..."; | |||
|
124 | while(fn.boundingRect(string).width() + x > width && string.length() > 3) | |||
|
125 | string.remove(string.length() - 4, 1); | |||
|
126 | m_textItem->setText(string); | |||
|
127 | } | |||
|
128 | else | |||
|
129 | m_textItem->setText(m_label); | |||
|
130 | ||||
|
131 | const QRectF& textRect = m_textItem->boundingRect(); | |||
|
132 | ||||
|
133 | ||||
|
134 | m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); | |||
|
135 | m_rectItem->setRect(m_markerRect); | |||
|
136 | m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); | |||
|
137 | ||||
|
138 | prepareGeometryChange(); | |||
|
139 | m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); | |||
|
140 | } | |||
|
141 | ||||
|
142 | QRectF QLegendMarkerPrivate::boundingRect() const | |||
|
143 | { | |||
|
144 | return m_boundingRect; | |||
|
145 | } | |||
|
146 | ||||
|
147 | void QLegendMarkerPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |||
|
148 | { | |||
|
149 | Q_UNUSED(option) | |||
|
150 | Q_UNUSED(widget) | |||
|
151 | Q_UNUSED(painter) | |||
|
152 | } | |||
|
153 | ||||
|
154 | QSizeF QLegendMarkerPrivate::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |||
|
155 | { | |||
|
156 | Q_UNUSED(constraint) | |||
|
157 | ||||
|
158 | QFontMetrics fn(m_textItem->font()); | |||
|
159 | QSizeF sh; | |||
|
160 | ||||
|
161 | switch (which) { | |||
|
162 | case Qt::MinimumSize: | |||
|
163 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |||
|
164 | break; | |||
|
165 | case Qt::PreferredSize: | |||
|
166 | sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |||
|
167 | break; | |||
|
168 | default: | |||
|
169 | break; | |||
|
170 | } | |||
|
171 | ||||
|
172 | return sh; | |||
|
173 | } | |||
|
174 | ||||
|
175 | void QLegendMarkerPrivate::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
|
176 | { | |||
|
177 | QGraphicsObject::mousePressEvent(event); | |||
|
178 | //TODO: selected signal removed for now | |||
|
179 | } | |||
|
180 | ||||
|
181 | ||||
83 | #include "moc_qlegendmarker.cpp" |
|
182 | #include "moc_qlegendmarker.cpp" | |
84 |
|
|
183 | #include "moc_qlegendmarker_p.cpp" | |
85 |
|
184 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
185 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,87 +1,86 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QLEGENDMARKER_H |
|
21 | #ifndef QLEGENDMARKER_H | |
22 | #define QLEGENDMARKER_H |
|
22 | #define QLEGENDMARKER_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
|
28 | #include <QFont> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | // TODO: |
|
32 | class QLegendMarkerPrivate; | |
32 | //class QLegendMarkerPrivate; |
|
|||
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 |
|
34 | |||
35 |
// TODO: should this be |
|
35 | // TODO: should this be QAbstractLegendMarker? | |
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject |
|
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 |
|
39 | |||
40 | // TODO: need for these? |
|
40 | // TODO: need for these? | |
41 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); |
|
41 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); | |
42 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); |
|
42 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); | |
43 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); |
|
43 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0); |
|
46 | explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0); | |
47 | virtual ~QLegendMarker(); |
|
47 | virtual ~QLegendMarker(); | |
48 |
|
48 | |||
49 | QString label() const; |
|
49 | QString label() const; | |
50 | void setLabel(const QString &label); |
|
50 | void setLabel(const QString &label); | |
51 |
|
51 | |||
|
52 | QBrush labelBrush() const; | |||
|
53 | void setLabelBrush(const QBrush &brush); | |||
|
54 | ||||
|
55 | QFont font() const; | |||
|
56 | void setFont(const QFont &font); | |||
|
57 | ||||
52 | QPen pen() const; |
|
58 | QPen pen() const; | |
53 | void setPen(const QPen &pen); |
|
59 | void setPen(const QPen &pen); | |
54 |
|
60 | |||
55 | QBrush brush() const; |
|
61 | QBrush brush() const; | |
56 | void setBrush(const QBrush &brush); |
|
62 | void setBrush(const QBrush &brush); | |
57 |
|
63 | |||
58 | bool isVisible() const; |
|
64 | bool isVisible() const; | |
59 | void setVisible(bool visible); |
|
65 | void setVisible(bool visible); | |
60 |
|
66 | |||
61 | // virtual QAbstractSeries::SeriesType type() = 0; |
|
67 | // virtual QAbstractSeries::SeriesType type() = 0; | |
62 |
virtual QAbstractSeries* series() |
|
68 | virtual QAbstractSeries* series(); | |
63 | virtual QObject* peerObject() = 0; |
|
69 | virtual QObject* peerObject() = 0; | |
64 |
|
70 | |||
65 | Q_SIGNALS: |
|
71 | Q_SIGNALS: | |
66 | void clicked(); |
|
72 | void clicked(); | |
67 | void hovered(bool status); |
|
73 | void hovered(bool status); | |
68 |
|
74 | |||
69 | public Q_SLOTS: |
|
75 | public Q_SLOTS: | |
70 |
void |
|
76 | virtual void updated() = 0; // TODO: private. Idea is that series signals, when some property has changed | |
71 |
|
77 | |||
72 | public: |
|
78 | public: | |
73 | // TODO: |
|
79 | QScopedPointer<QLegendMarkerPrivate> d_ptr; | |
74 | // QScopedPointer<QLegendMarkerPrivate> d_ptr; |
|
|||
75 | Q_DISABLE_COPY(QLegendMarker) |
|
80 | Q_DISABLE_COPY(QLegendMarker) | |
76 |
|
81 | |||
77 | // TODO: move to PIMPL |
|
|||
78 | QAbstractSeries* m_series; |
|
|||
79 | QString m_label; |
|
|||
80 | QPen m_pen; |
|
|||
81 | QBrush m_brush; |
|
|||
82 | bool m_visible; |
|
|||
83 | }; |
|
82 | }; | |
84 |
|
83 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
85 | |||
87 | #endif // QLEGENDMARKER_H |
|
86 | #endif // QLEGENDMARKER_H |
@@ -1,36 +1,45 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpielegendmarker.h" |
|
21 | #include "qpielegendmarker.h" | |
22 | #include <QPieSeries> |
|
22 | #include <QPieSeries> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) : |
|
26 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent) : | |
27 | QLegendMarker(series, parent), |
|
27 | QLegendMarker(series, parent), | |
28 | m_slice(slice) |
|
28 | m_slice(slice) | |
29 | { |
|
29 | { | |
|
30 | QObject::connect(slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |||
|
31 | QObject::connect(slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |||
|
32 | updated(); | |||
30 | } |
|
33 | } | |
31 |
|
34 | |||
|
35 | void QPieLegendMarker::updated() | |||
|
36 | { | |||
|
37 | // TODO: to PIMPL. | |||
|
38 | setBrush(m_slice->brush()); | |||
|
39 | setLabel(m_slice->label()); | |||
|
40 | } | |||
32 |
|
41 | |||
33 | #include "moc_qpielegendmarker.cpp" |
|
42 | #include "moc_qpielegendmarker.cpp" | |
34 | //#include "moc_qpielegendmarker_p.cpp" |
|
43 | //#include "moc_qpielegendmarker_p.cpp" | |
35 |
|
44 | |||
36 | QTCOMMERCIALCHART_END_NAMESPACE |
|
45 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,53 +1,56 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QPIELEGENDMARKER_H |
|
21 | #ifndef QPIELEGENDMARKER_H | |
22 | #define QPIELEGENDMARKER_H |
|
22 | #define QPIELEGENDMARKER_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QLegendMarker> |
|
25 | #include <QLegendMarker> | |
26 | #include <QPieSlice> |
|
26 | #include <QPieSlice> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker |
|
30 | class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent = 0); |
|
35 | explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent = 0); | |
36 |
|
36 | |||
37 | virtual QPieSlice* peerObject() { return m_slice; } |
|
37 | virtual QPieSlice* peerObject() { return m_slice; } | |
38 |
|
38 | |||
|
39 | // TODO: to pimp. | |||
|
40 | void updated(); | |||
|
41 | ||||
39 | //Q_SIGNALS: |
|
42 | //Q_SIGNALS: | |
40 |
|
43 | |||
41 | //public Q_SLOTS: |
|
44 | //public Q_SLOTS: | |
42 |
|
45 | |||
43 | private: |
|
46 | private: | |
44 | // TODO: |
|
47 | // TODO: | |
45 | // QScopedPointer<QPieLegendMarkerPrivate> d_ptr; |
|
48 | // QScopedPointer<QPieLegendMarkerPrivate> d_ptr; | |
46 | Q_DISABLE_COPY(QPieLegendMarker) |
|
49 | Q_DISABLE_COPY(QPieLegendMarker) | |
47 |
|
50 | |||
48 | QPieSlice* m_slice; |
|
51 | QPieSlice* m_slice; | |
49 |
|
52 | |||
50 | }; |
|
53 | }; | |
51 |
|
54 | |||
52 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
53 | #endif // QPIELEGENDMARKER_H |
|
56 | #endif // QPIELEGENDMARKER_H |
@@ -1,878 +1,891 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "legendmarker_p.h" |
|
28 | #include "legendmarker_p.h" | |
29 | #include "qabstractaxis.h" |
|
29 | #include "qabstractaxis.h" | |
30 | #include "pieanimation_p.h" |
|
30 | #include "pieanimation_p.h" | |
31 |
|
31 | |||
|
32 | #include "qpielegendmarker.h" | |||
|
33 | ||||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
35 | |||
34 | /*! |
|
36 | /*! | |
35 | \class QPieSeries |
|
37 | \class QPieSeries | |
36 | \brief Pie series API for QtCommercial Charts |
|
38 | \brief Pie series API for QtCommercial Charts | |
37 |
|
39 | |||
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
40 | The actual slice size is determined by that relative value. |
|
42 | The actual slice size is determined by that relative value. | |
41 |
|
43 | |||
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
43 | These relate to the actual chart rectangle. |
|
45 | These relate to the actual chart rectangle. | |
44 |
|
46 | |||
45 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
47 | By default the pie is defined as a full pie but it can also be a partial pie. | |
46 | This can be done by setting a starting angle and angle span to the series. |
|
48 | This can be done by setting a starting angle and angle span to the series. | |
47 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
49 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
48 |
|
50 | |||
49 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. | |
50 | \table 100% |
|
52 | \table 100% | |
51 | \row |
|
53 | \row | |
52 | \o \image examples_piechart.png |
|
54 | \o \image examples_piechart.png | |
53 | \o \image examples_donut.png |
|
55 | \o \image examples_donut.png | |
54 | \endtable |
|
56 | \endtable | |
55 | */ |
|
57 | */ | |
56 | /*! |
|
58 | /*! | |
57 | \qmlclass PieSeries QPieSeries |
|
59 | \qmlclass PieSeries QPieSeries | |
58 | \inherits AbstractSeries |
|
60 | \inherits AbstractSeries | |
59 |
|
61 | |||
60 | The following QML shows how to create a simple pie chart. |
|
62 | The following QML shows how to create a simple pie chart. | |
61 |
|
63 | |||
62 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
63 |
|
65 | |||
64 | \beginfloatleft |
|
66 | \beginfloatleft | |
65 | \image demos_qmlchart1.png |
|
67 | \image demos_qmlchart1.png | |
66 | \endfloat |
|
68 | \endfloat | |
67 | \clearfloat |
|
69 | \clearfloat | |
68 | */ |
|
70 | */ | |
69 |
|
71 | |||
70 | /*! |
|
72 | /*! | |
71 | \property QPieSeries::horizontalPosition |
|
73 | \property QPieSeries::horizontalPosition | |
72 | \brief Defines the horizontal position of the pie. |
|
74 | \brief Defines the horizontal position of the pie. | |
73 |
|
75 | |||
74 | The value is a relative value to the chart rectangle where: |
|
76 | The value is a relative value to the chart rectangle where: | |
75 |
|
77 | |||
76 | \list |
|
78 | \list | |
77 | \o 0.0 is the absolute left. |
|
79 | \o 0.0 is the absolute left. | |
78 | \o 1.0 is the absolute right. |
|
80 | \o 1.0 is the absolute right. | |
79 | \endlist |
|
81 | \endlist | |
80 | Default value is 0.5 (center). |
|
82 | Default value is 0.5 (center). | |
81 | \sa verticalPosition |
|
83 | \sa verticalPosition | |
82 | */ |
|
84 | */ | |
83 |
|
85 | |||
84 | /*! |
|
86 | /*! | |
85 | \qmlproperty real PieSeries::horizontalPosition |
|
87 | \qmlproperty real PieSeries::horizontalPosition | |
86 |
|
88 | |||
87 | Defines the horizontal position of the pie. |
|
89 | Defines the horizontal position of the pie. | |
88 |
|
90 | |||
89 | The value is a relative value to the chart rectangle where: |
|
91 | The value is a relative value to the chart rectangle where: | |
90 |
|
92 | |||
91 | \list |
|
93 | \list | |
92 | \o 0.0 is the absolute left. |
|
94 | \o 0.0 is the absolute left. | |
93 | \o 1.0 is the absolute right. |
|
95 | \o 1.0 is the absolute right. | |
94 | \endlist |
|
96 | \endlist | |
95 | Default value is 0.5 (center). |
|
97 | Default value is 0.5 (center). | |
96 | \sa verticalPosition |
|
98 | \sa verticalPosition | |
97 | */ |
|
99 | */ | |
98 |
|
100 | |||
99 | /*! |
|
101 | /*! | |
100 | \property QPieSeries::verticalPosition |
|
102 | \property QPieSeries::verticalPosition | |
101 | \brief Defines the vertical position of the pie. |
|
103 | \brief Defines the vertical position of the pie. | |
102 |
|
104 | |||
103 | The value is a relative value to the chart rectangle where: |
|
105 | The value is a relative value to the chart rectangle where: | |
104 |
|
106 | |||
105 | \list |
|
107 | \list | |
106 | \o 0.0 is the absolute top. |
|
108 | \o 0.0 is the absolute top. | |
107 | \o 1.0 is the absolute bottom. |
|
109 | \o 1.0 is the absolute bottom. | |
108 | \endlist |
|
110 | \endlist | |
109 | Default value is 0.5 (center). |
|
111 | Default value is 0.5 (center). | |
110 | \sa horizontalPosition |
|
112 | \sa horizontalPosition | |
111 | */ |
|
113 | */ | |
112 |
|
114 | |||
113 | /*! |
|
115 | /*! | |
114 | \qmlproperty real PieSeries::verticalPosition |
|
116 | \qmlproperty real PieSeries::verticalPosition | |
115 |
|
117 | |||
116 | Defines the vertical position of the pie. |
|
118 | Defines the vertical position of the pie. | |
117 |
|
119 | |||
118 | The value is a relative value to the chart rectangle where: |
|
120 | The value is a relative value to the chart rectangle where: | |
119 |
|
121 | |||
120 | \list |
|
122 | \list | |
121 | \o 0.0 is the absolute top. |
|
123 | \o 0.0 is the absolute top. | |
122 | \o 1.0 is the absolute bottom. |
|
124 | \o 1.0 is the absolute bottom. | |
123 | \endlist |
|
125 | \endlist | |
124 | Default value is 0.5 (center). |
|
126 | Default value is 0.5 (center). | |
125 | \sa horizontalPosition |
|
127 | \sa horizontalPosition | |
126 | */ |
|
128 | */ | |
127 |
|
129 | |||
128 | /*! |
|
130 | /*! | |
129 | \property QPieSeries::size |
|
131 | \property QPieSeries::size | |
130 | \brief Defines the pie size. |
|
132 | \brief Defines the pie size. | |
131 |
|
133 | |||
132 | The value is a relative value to the chart rectangle where: |
|
134 | The value is a relative value to the chart rectangle where: | |
133 |
|
135 | |||
134 | \list |
|
136 | \list | |
135 | \o 0.0 is the minimum size (pie not drawn). |
|
137 | \o 0.0 is the minimum size (pie not drawn). | |
136 | \o 1.0 is the maximum size that can fit the chart. |
|
138 | \o 1.0 is the maximum size that can fit the chart. | |
137 | \endlist |
|
139 | \endlist | |
138 |
|
140 | |||
139 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. | |
140 |
|
142 | |||
141 | Default value is 0.7. |
|
143 | Default value is 0.7. | |
142 | */ |
|
144 | */ | |
143 |
|
145 | |||
144 | /*! |
|
146 | /*! | |
145 | \qmlproperty real PieSeries::size |
|
147 | \qmlproperty real PieSeries::size | |
146 |
|
148 | |||
147 | Defines the pie size. |
|
149 | Defines the pie size. | |
148 |
|
150 | |||
149 | The value is a relative value to the chart rectangle where: |
|
151 | The value is a relative value to the chart rectangle where: | |
150 |
|
152 | |||
151 | \list |
|
153 | \list | |
152 | \o 0.0 is the minimum size (pie not drawn). |
|
154 | \o 0.0 is the minimum size (pie not drawn). | |
153 | \o 1.0 is the maximum size that can fit the chart. |
|
155 | \o 1.0 is the maximum size that can fit the chart. | |
154 | \endlist |
|
156 | \endlist | |
155 |
|
157 | |||
156 | Default value is 0.7. |
|
158 | Default value is 0.7. | |
157 | */ |
|
159 | */ | |
158 |
|
160 | |||
159 | /*! |
|
161 | /*! | |
160 | \property QPieSeries::holeSize |
|
162 | \property QPieSeries::holeSize | |
161 | \brief Defines the donut hole size. |
|
163 | \brief Defines the donut hole size. | |
162 |
|
164 | |||
163 | The value is a relative value to the chart rectangle where: |
|
165 | The value is a relative value to the chart rectangle where: | |
164 |
|
166 | |||
165 | \list |
|
167 | \list | |
166 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
167 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
168 | \endlist |
|
170 | \endlist | |
169 |
|
171 | |||
170 | The value is never greater then size property. |
|
172 | The value is never greater then size property. | |
171 | Default value is 0.0. |
|
173 | Default value is 0.0. | |
172 | */ |
|
174 | */ | |
173 |
|
175 | |||
174 | /*! |
|
176 | /*! | |
175 | \qmlproperty real PieSeries::holeSize |
|
177 | \qmlproperty real PieSeries::holeSize | |
176 |
|
178 | |||
177 | Defines the donut hole size. |
|
179 | Defines the donut hole size. | |
178 |
|
180 | |||
179 | The value is a relative value to the chart rectangle where: |
|
181 | The value is a relative value to the chart rectangle where: | |
180 |
|
182 | |||
181 | \list |
|
183 | \list | |
182 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
183 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
184 | \endlist |
|
186 | \endlist | |
185 |
|
187 | |||
186 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. | |
187 |
|
189 | |||
188 | Default value is 0.0. |
|
190 | Default value is 0.0. | |
189 | */ |
|
191 | */ | |
190 |
|
192 | |||
191 | /*! |
|
193 | /*! | |
192 | \property QPieSeries::startAngle |
|
194 | \property QPieSeries::startAngle | |
193 | \brief Defines the starting angle of the pie. |
|
195 | \brief Defines the starting angle of the pie. | |
194 |
|
196 | |||
195 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
196 |
|
198 | |||
197 | Default is value is 0. |
|
199 | Default is value is 0. | |
198 | */ |
|
200 | */ | |
199 |
|
201 | |||
200 | /*! |
|
202 | /*! | |
201 | \qmlproperty real PieSeries::startAngle |
|
203 | \qmlproperty real PieSeries::startAngle | |
202 |
|
204 | |||
203 | Defines the starting angle of the pie. |
|
205 | Defines the starting angle of the pie. | |
204 |
|
206 | |||
205 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
206 |
|
208 | |||
207 | Default is value is 0. |
|
209 | Default is value is 0. | |
208 | */ |
|
210 | */ | |
209 |
|
211 | |||
210 | /*! |
|
212 | /*! | |
211 | \property QPieSeries::endAngle |
|
213 | \property QPieSeries::endAngle | |
212 | \brief Defines the ending angle of the pie. |
|
214 | \brief Defines the ending angle of the pie. | |
213 |
|
215 | |||
214 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
215 |
|
217 | |||
216 | Default is value is 360. |
|
218 | Default is value is 360. | |
217 | */ |
|
219 | */ | |
218 |
|
220 | |||
219 | /*! |
|
221 | /*! | |
220 | \qmlproperty real PieSeries::endAngle |
|
222 | \qmlproperty real PieSeries::endAngle | |
221 |
|
223 | |||
222 | Defines the ending angle of the pie. |
|
224 | Defines the ending angle of the pie. | |
223 |
|
225 | |||
224 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
225 |
|
227 | |||
226 | Default is value is 360. |
|
228 | Default is value is 360. | |
227 | */ |
|
229 | */ | |
228 |
|
230 | |||
229 | /*! |
|
231 | /*! | |
230 | \property QPieSeries::count |
|
232 | \property QPieSeries::count | |
231 |
|
233 | |||
232 | Number of slices in the series. |
|
234 | Number of slices in the series. | |
233 | */ |
|
235 | */ | |
234 |
|
236 | |||
235 | /*! |
|
237 | /*! | |
236 | \qmlproperty int PieSeries::count |
|
238 | \qmlproperty int PieSeries::count | |
237 |
|
239 | |||
238 | Number of slices in the series. |
|
240 | Number of slices in the series. | |
239 | */ |
|
241 | */ | |
240 |
|
242 | |||
241 | /*! |
|
243 | /*! | |
242 | \fn void QPieSeries::countChanged() |
|
244 | \fn void QPieSeries::countChanged() | |
243 | Emitted when the slice count has changed. |
|
245 | Emitted when the slice count has changed. | |
244 | \sa count |
|
246 | \sa count | |
245 | */ |
|
247 | */ | |
246 | /*! |
|
248 | /*! | |
247 | \qmlsignal PieSeries::onCountChanged() |
|
249 | \qmlsignal PieSeries::onCountChanged() | |
248 | Emitted when the slice count has changed. |
|
250 | Emitted when the slice count has changed. | |
249 | */ |
|
251 | */ | |
250 |
|
252 | |||
251 | /*! |
|
253 | /*! | |
252 | \property QPieSeries::sum |
|
254 | \property QPieSeries::sum | |
253 |
|
255 | |||
254 | Sum of all slices. |
|
256 | Sum of all slices. | |
255 |
|
257 | |||
256 | The series keeps track of the sum of all slices it holds. |
|
258 | The series keeps track of the sum of all slices it holds. | |
257 | */ |
|
259 | */ | |
258 |
|
260 | |||
259 | /*! |
|
261 | /*! | |
260 | \qmlproperty real PieSeries::sum |
|
262 | \qmlproperty real PieSeries::sum | |
261 |
|
263 | |||
262 | Sum of all slices. |
|
264 | Sum of all slices. | |
263 |
|
265 | |||
264 | The series keeps track of the sum of all slices it holds. |
|
266 | The series keeps track of the sum of all slices it holds. | |
265 | */ |
|
267 | */ | |
266 |
|
268 | |||
267 | /*! |
|
269 | /*! | |
268 | \fn void QPieSeries::sumChanged() |
|
270 | \fn void QPieSeries::sumChanged() | |
269 | Emitted when the sum of all slices has changed. |
|
271 | Emitted when the sum of all slices has changed. | |
270 | \sa sum |
|
272 | \sa sum | |
271 | */ |
|
273 | */ | |
272 | /*! |
|
274 | /*! | |
273 | \qmlsignal PieSeries::onSumChanged() |
|
275 | \qmlsignal PieSeries::onSumChanged() | |
274 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
275 | change value of a slice. |
|
277 | change value of a slice. | |
276 | */ |
|
278 | */ | |
277 |
|
279 | |||
278 | /*! |
|
280 | /*! | |
279 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
280 |
|
282 | |||
281 | This signal is emitted when \a slices have been added to the series. |
|
283 | This signal is emitted when \a slices have been added to the series. | |
282 |
|
284 | |||
283 | \sa append(), insert() |
|
285 | \sa append(), insert() | |
284 | */ |
|
286 | */ | |
285 | /*! |
|
287 | /*! | |
286 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
288 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
287 | Emitted when \a slice has been added to the series. |
|
289 | Emitted when \a slice has been added to the series. | |
288 | */ |
|
290 | */ | |
289 |
|
291 | |||
290 | /*! |
|
292 | /*! | |
291 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
292 | This signal is emitted when \a slices have been removed from the series. |
|
294 | This signal is emitted when \a slices have been removed from the series. | |
293 | \sa remove() |
|
295 | \sa remove() | |
294 | */ |
|
296 | */ | |
295 | /*! |
|
297 | /*! | |
296 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
297 | Emitted when \a slice has been removed from the series. |
|
299 | Emitted when \a slice has been removed from the series. | |
298 | */ |
|
300 | */ | |
299 |
|
301 | |||
300 | /*! |
|
302 | /*! | |
301 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
303 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
302 | This signal is emitted when a \a slice has been clicked. |
|
304 | This signal is emitted when a \a slice has been clicked. | |
303 | \sa QPieSlice::clicked() |
|
305 | \sa QPieSlice::clicked() | |
304 | */ |
|
306 | */ | |
305 | /*! |
|
307 | /*! | |
306 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
308 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
307 | This signal is emitted when a \a slice has been clicked. |
|
309 | This signal is emitted when a \a slice has been clicked. | |
308 | */ |
|
310 | */ | |
309 |
|
311 | |||
310 | /*! |
|
312 | /*! | |
311 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
312 | This signal is emitted when user has hovered over or away from the \a slice. |
|
314 | This signal is emitted when user has hovered over or away from the \a slice. | |
313 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
314 | \sa QPieSlice::hovered() |
|
316 | \sa QPieSlice::hovered() | |
315 | */ |
|
317 | */ | |
316 | /*! |
|
318 | /*! | |
317 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
318 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
319 | over the slice and false when hover has moved away from the slice. |
|
321 | over the slice and false when hover has moved away from the slice. | |
320 | */ |
|
322 | */ | |
321 |
|
323 | |||
322 | /*! |
|
324 | /*! | |
323 | \qmlmethod PieSlice PieSeries::at(int index) |
|
325 | \qmlmethod PieSlice PieSeries::at(int index) | |
324 | Returns slice at \a index. Returns null if the index is not valid. |
|
326 | Returns slice at \a index. Returns null if the index is not valid. | |
325 | */ |
|
327 | */ | |
326 |
|
328 | |||
327 | /*! |
|
329 | /*! | |
328 | \qmlmethod PieSlice PieSeries::find(string label) |
|
330 | \qmlmethod PieSlice PieSeries::find(string label) | |
329 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
331 | Returns the first slice with \a label. Returns null if the index is not valid. | |
330 | */ |
|
332 | */ | |
331 |
|
333 | |||
332 | /*! |
|
334 | /*! | |
333 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
335 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
334 | Adds a new slice with \a label and \a value to the pie. |
|
336 | Adds a new slice with \a label and \a value to the pie. | |
335 | */ |
|
337 | */ | |
336 |
|
338 | |||
337 | /*! |
|
339 | /*! | |
338 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
340 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
339 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. | |
340 | */ |
|
342 | */ | |
341 |
|
343 | |||
342 | /*! |
|
344 | /*! | |
343 | \qmlmethod PieSeries::clear() |
|
345 | \qmlmethod PieSeries::clear() | |
344 | Removes all slices from the pie. |
|
346 | Removes all slices from the pie. | |
345 | */ |
|
347 | */ | |
346 |
|
348 | |||
347 | /*! |
|
349 | /*! | |
348 | Constructs a series object which is a child of \a parent. |
|
350 | Constructs a series object which is a child of \a parent. | |
349 | */ |
|
351 | */ | |
350 | QPieSeries::QPieSeries(QObject *parent) |
|
352 | QPieSeries::QPieSeries(QObject *parent) | |
351 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) | |
352 | { |
|
354 | { | |
353 | Q_D(QPieSeries); |
|
355 | Q_D(QPieSeries); | |
354 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
355 | } |
|
357 | } | |
356 |
|
358 | |||
357 | /*! |
|
359 | /*! | |
358 | Destroys the series and its slices. |
|
360 | Destroys the series and its slices. | |
359 | */ |
|
361 | */ | |
360 | QPieSeries::~QPieSeries() |
|
362 | QPieSeries::~QPieSeries() | |
361 | { |
|
363 | { | |
362 | // NOTE: d_prt destroyed by QObject |
|
364 | // NOTE: d_prt destroyed by QObject | |
363 | } |
|
365 | } | |
364 |
|
366 | |||
365 | /*! |
|
367 | /*! | |
366 | Returns QChartSeries::SeriesTypePie. |
|
368 | Returns QChartSeries::SeriesTypePie. | |
367 | */ |
|
369 | */ | |
368 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
370 | QAbstractSeries::SeriesType QPieSeries::type() const | |
369 | { |
|
371 | { | |
370 | return QAbstractSeries::SeriesTypePie; |
|
372 | return QAbstractSeries::SeriesTypePie; | |
371 | } |
|
373 | } | |
372 |
|
374 | |||
373 | /*! |
|
375 | /*! | |
374 | Appends a single \a slice to the series. |
|
376 | Appends a single \a slice to the series. | |
375 | Slice ownership is passed to the series. |
|
377 | Slice ownership is passed to the series. | |
376 |
|
378 | |||
377 | Returns true if append was succesfull. |
|
379 | Returns true if append was succesfull. | |
378 | */ |
|
380 | */ | |
379 | bool QPieSeries::append(QPieSlice *slice) |
|
381 | bool QPieSeries::append(QPieSlice *slice) | |
380 | { |
|
382 | { | |
381 | return append(QList<QPieSlice *>() << slice); |
|
383 | return append(QList<QPieSlice *>() << slice); | |
382 | } |
|
384 | } | |
383 |
|
385 | |||
384 | /*! |
|
386 | /*! | |
385 | Appends an array of \a slices to the series. |
|
387 | Appends an array of \a slices to the series. | |
386 | Slice ownership is passed to the series. |
|
388 | Slice ownership is passed to the series. | |
387 |
|
389 | |||
388 | Returns true if append was successful. |
|
390 | Returns true if append was successful. | |
389 | */ |
|
391 | */ | |
390 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
392 | bool QPieSeries::append(QList<QPieSlice *> slices) | |
391 | { |
|
393 | { | |
392 | Q_D(QPieSeries); |
|
394 | Q_D(QPieSeries); | |
393 |
|
395 | |||
394 | if (slices.count() == 0) |
|
396 | if (slices.count() == 0) | |
395 | return false; |
|
397 | return false; | |
396 |
|
398 | |||
397 | foreach (QPieSlice *s, slices) { |
|
399 | foreach (QPieSlice *s, slices) { | |
398 | if (!s || d->m_slices.contains(s)) |
|
400 | if (!s || d->m_slices.contains(s)) | |
399 | return false; |
|
401 | return false; | |
400 | if (s->series()) // already added to some series |
|
402 | if (s->series()) // already added to some series | |
401 | return false; |
|
403 | return false; | |
402 | } |
|
404 | } | |
403 |
|
405 | |||
404 | foreach (QPieSlice *s, slices) { |
|
406 | foreach (QPieSlice *s, slices) { | |
405 | s->setParent(this); |
|
407 | s->setParent(this); | |
406 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
408 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
407 | d->m_slices << s; |
|
409 | d->m_slices << s; | |
408 | } |
|
410 | } | |
409 |
|
411 | |||
410 | d->updateDerivativeData(); |
|
412 | d->updateDerivativeData(); | |
411 |
|
413 | |||
412 | foreach(QPieSlice * s, slices) { |
|
414 | foreach(QPieSlice * s, slices) { | |
413 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
415 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
414 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
416 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
415 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
417 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
416 | } |
|
418 | } | |
417 |
|
419 | |||
418 | emit added(slices); |
|
420 | emit added(slices); | |
419 | emit countChanged(); |
|
421 | emit countChanged(); | |
420 |
|
422 | |||
421 | return true; |
|
423 | return true; | |
422 | } |
|
424 | } | |
423 |
|
425 | |||
424 | /*! |
|
426 | /*! | |
425 | Appends a single \a slice to the series and returns a reference to the series. |
|
427 | Appends a single \a slice to the series and returns a reference to the series. | |
426 | Slice ownership is passed to the series. |
|
428 | Slice ownership is passed to the series. | |
427 | */ |
|
429 | */ | |
428 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
430 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |
429 | { |
|
431 | { | |
430 | append(slice); |
|
432 | append(slice); | |
431 | return *this; |
|
433 | return *this; | |
432 | } |
|
434 | } | |
433 |
|
435 | |||
434 |
|
436 | |||
435 | /*! |
|
437 | /*! | |
436 | Appends a single slice to the series with give \a value and \a label. |
|
438 | Appends a single slice to the series with give \a value and \a label. | |
437 | Slice ownership is passed to the series. |
|
439 | Slice ownership is passed to the series. | |
438 | */ |
|
440 | */ | |
439 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
441 | QPieSlice *QPieSeries::append(QString label, qreal value) | |
440 | { |
|
442 | { | |
441 | QPieSlice *slice = new QPieSlice(label, value); |
|
443 | QPieSlice *slice = new QPieSlice(label, value); | |
442 | append(slice); |
|
444 | append(slice); | |
443 | return slice; |
|
445 | return slice; | |
444 | } |
|
446 | } | |
445 |
|
447 | |||
446 | /*! |
|
448 | /*! | |
447 | Inserts a single \a slice to the series before the slice at \a index position. |
|
449 | Inserts a single \a slice to the series before the slice at \a index position. | |
448 | Slice ownership is passed to the series. |
|
450 | Slice ownership is passed to the series. | |
449 |
|
451 | |||
450 | Returns true if insert was successful. |
|
452 | Returns true if insert was successful. | |
451 | */ |
|
453 | */ | |
452 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
454 | bool QPieSeries::insert(int index, QPieSlice *slice) | |
453 | { |
|
455 | { | |
454 | Q_D(QPieSeries); |
|
456 | Q_D(QPieSeries); | |
455 |
|
457 | |||
456 | if (index < 0 || index > d->m_slices.count()) |
|
458 | if (index < 0 || index > d->m_slices.count()) | |
457 | return false; |
|
459 | return false; | |
458 |
|
460 | |||
459 | if (!slice || d->m_slices.contains(slice)) |
|
461 | if (!slice || d->m_slices.contains(slice)) | |
460 | return false; |
|
462 | return false; | |
461 |
|
463 | |||
462 | if (slice->series()) // already added to some series |
|
464 | if (slice->series()) // already added to some series | |
463 | return false; |
|
465 | return false; | |
464 |
|
466 | |||
465 | slice->setParent(this); |
|
467 | slice->setParent(this); | |
466 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
468 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
467 | d->m_slices.insert(index, slice); |
|
469 | d->m_slices.insert(index, slice); | |
468 |
|
470 | |||
469 | d->updateDerivativeData(); |
|
471 | d->updateDerivativeData(); | |
470 |
|
472 | |||
471 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
473 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
472 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
474 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
473 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
475 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
474 |
|
476 | |||
475 |
|
477 | |||
476 | emit added(QList<QPieSlice *>() << slice); |
|
478 | emit added(QList<QPieSlice *>() << slice); | |
477 | emit countChanged(); |
|
479 | emit countChanged(); | |
478 |
|
480 | |||
479 | return true; |
|
481 | return true; | |
480 | } |
|
482 | } | |
481 |
|
483 | |||
482 | /*! |
|
484 | /*! | |
483 | Removes a single \a slice from the series and deletes the slice. |
|
485 | Removes a single \a slice from the series and deletes the slice. | |
484 |
|
486 | |||
485 | Do not reference the pointer after this call. |
|
487 | Do not reference the pointer after this call. | |
486 |
|
488 | |||
487 | Returns true if remove was successful. |
|
489 | Returns true if remove was successful. | |
488 | */ |
|
490 | */ | |
489 | bool QPieSeries::remove(QPieSlice *slice) |
|
491 | bool QPieSeries::remove(QPieSlice *slice) | |
490 | { |
|
492 | { | |
491 | Q_D(QPieSeries); |
|
493 | Q_D(QPieSeries); | |
492 |
|
494 | |||
493 | if (!d->m_slices.removeOne(slice)) |
|
495 | if (!d->m_slices.removeOne(slice)) | |
494 | return false; |
|
496 | return false; | |
495 |
|
497 | |||
496 | d->updateDerivativeData(); |
|
498 | d->updateDerivativeData(); | |
497 |
|
499 | |||
498 | emit removed(QList<QPieSlice *>() << slice); |
|
500 | emit removed(QList<QPieSlice *>() << slice); | |
499 | emit countChanged(); |
|
501 | emit countChanged(); | |
500 |
|
502 | |||
501 | delete slice; |
|
503 | delete slice; | |
502 | slice = 0; |
|
504 | slice = 0; | |
503 |
|
505 | |||
504 | return true; |
|
506 | return true; | |
505 | } |
|
507 | } | |
506 |
|
508 | |||
507 | /*! |
|
509 | /*! | |
508 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
510 | Takes a single \a slice from the series. Does not destroy the slice object. | |
509 |
|
511 | |||
510 | NOTE: The series remains as the slice's parent object. You must set the |
|
512 | NOTE: The series remains as the slice's parent object. You must set the | |
511 | parent object to take full ownership. |
|
513 | parent object to take full ownership. | |
512 |
|
514 | |||
513 | Returns true if take was successful. |
|
515 | Returns true if take was successful. | |
514 | */ |
|
516 | */ | |
515 | bool QPieSeries::take(QPieSlice *slice) |
|
517 | bool QPieSeries::take(QPieSlice *slice) | |
516 | { |
|
518 | { | |
517 | Q_D(QPieSeries); |
|
519 | Q_D(QPieSeries); | |
518 |
|
520 | |||
519 | if (!d->m_slices.removeOne(slice)) |
|
521 | if (!d->m_slices.removeOne(slice)) | |
520 | return false; |
|
522 | return false; | |
521 |
|
523 | |||
522 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
524 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |
523 | slice->disconnect(d); |
|
525 | slice->disconnect(d); | |
524 |
|
526 | |||
525 | d->updateDerivativeData(); |
|
527 | d->updateDerivativeData(); | |
526 |
|
528 | |||
527 | emit removed(QList<QPieSlice *>() << slice); |
|
529 | emit removed(QList<QPieSlice *>() << slice); | |
528 | emit countChanged(); |
|
530 | emit countChanged(); | |
529 |
|
531 | |||
530 | return true; |
|
532 | return true; | |
531 | } |
|
533 | } | |
532 |
|
534 | |||
533 | /*! |
|
535 | /*! | |
534 | Clears all slices from the series. |
|
536 | Clears all slices from the series. | |
535 | */ |
|
537 | */ | |
536 | void QPieSeries::clear() |
|
538 | void QPieSeries::clear() | |
537 | { |
|
539 | { | |
538 | Q_D(QPieSeries); |
|
540 | Q_D(QPieSeries); | |
539 | if (d->m_slices.count() == 0) |
|
541 | if (d->m_slices.count() == 0) | |
540 | return; |
|
542 | return; | |
541 |
|
543 | |||
542 | QList<QPieSlice *> slices = d->m_slices; |
|
544 | QList<QPieSlice *> slices = d->m_slices; | |
543 | foreach (QPieSlice *s, d->m_slices) |
|
545 | foreach (QPieSlice *s, d->m_slices) | |
544 | d->m_slices.removeOne(s); |
|
546 | d->m_slices.removeOne(s); | |
545 |
|
547 | |||
546 | d->updateDerivativeData(); |
|
548 | d->updateDerivativeData(); | |
547 |
|
549 | |||
548 | emit removed(slices); |
|
550 | emit removed(slices); | |
549 | emit countChanged(); |
|
551 | emit countChanged(); | |
550 |
|
552 | |||
551 | foreach (QPieSlice *s, slices) |
|
553 | foreach (QPieSlice *s, slices) | |
552 | delete s; |
|
554 | delete s; | |
553 | } |
|
555 | } | |
554 |
|
556 | |||
555 | /*! |
|
557 | /*! | |
556 | Returns a list of slices that belong to this series. |
|
558 | Returns a list of slices that belong to this series. | |
557 | */ |
|
559 | */ | |
558 | QList<QPieSlice *> QPieSeries::slices() const |
|
560 | QList<QPieSlice *> QPieSeries::slices() const | |
559 | { |
|
561 | { | |
560 | Q_D(const QPieSeries); |
|
562 | Q_D(const QPieSeries); | |
561 | return d->m_slices; |
|
563 | return d->m_slices; | |
562 | } |
|
564 | } | |
563 |
|
565 | |||
564 | /*! |
|
566 | /*! | |
565 | returns the number of the slices in this series. |
|
567 | returns the number of the slices in this series. | |
566 | */ |
|
568 | */ | |
567 | int QPieSeries::count() const |
|
569 | int QPieSeries::count() const | |
568 | { |
|
570 | { | |
569 | Q_D(const QPieSeries); |
|
571 | Q_D(const QPieSeries); | |
570 | return d->m_slices.count(); |
|
572 | return d->m_slices.count(); | |
571 | } |
|
573 | } | |
572 |
|
574 | |||
573 | /*! |
|
575 | /*! | |
574 | Returns true is the series is empty. |
|
576 | Returns true is the series is empty. | |
575 | */ |
|
577 | */ | |
576 | bool QPieSeries::isEmpty() const |
|
578 | bool QPieSeries::isEmpty() const | |
577 | { |
|
579 | { | |
578 | Q_D(const QPieSeries); |
|
580 | Q_D(const QPieSeries); | |
579 | return d->m_slices.isEmpty(); |
|
581 | return d->m_slices.isEmpty(); | |
580 | } |
|
582 | } | |
581 |
|
583 | |||
582 | /*! |
|
584 | /*! | |
583 | Returns the sum of all slice values in this series. |
|
585 | Returns the sum of all slice values in this series. | |
584 |
|
586 | |||
585 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
587 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
586 | */ |
|
588 | */ | |
587 | qreal QPieSeries::sum() const |
|
589 | qreal QPieSeries::sum() const | |
588 | { |
|
590 | { | |
589 | Q_D(const QPieSeries); |
|
591 | Q_D(const QPieSeries); | |
590 | return d->m_sum; |
|
592 | return d->m_sum; | |
591 | } |
|
593 | } | |
592 |
|
594 | |||
593 | void QPieSeries::setHoleSize(qreal holeSize) |
|
595 | void QPieSeries::setHoleSize(qreal holeSize) | |
594 | { |
|
596 | { | |
595 | Q_D(QPieSeries); |
|
597 | Q_D(QPieSeries); | |
596 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
598 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); | |
597 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
599 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); | |
598 | } |
|
600 | } | |
599 |
|
601 | |||
600 | qreal QPieSeries::holeSize() const |
|
602 | qreal QPieSeries::holeSize() const | |
601 | { |
|
603 | { | |
602 | Q_D(const QPieSeries); |
|
604 | Q_D(const QPieSeries); | |
603 | return d->m_holeRelativeSize; |
|
605 | return d->m_holeRelativeSize; | |
604 | } |
|
606 | } | |
605 |
|
607 | |||
606 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
608 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
607 | { |
|
609 | { | |
608 | Q_D(QPieSeries); |
|
610 | Q_D(QPieSeries); | |
609 |
|
611 | |||
610 | if (relativePosition < 0.0) |
|
612 | if (relativePosition < 0.0) | |
611 | relativePosition = 0.0; |
|
613 | relativePosition = 0.0; | |
612 | if (relativePosition > 1.0) |
|
614 | if (relativePosition > 1.0) | |
613 | relativePosition = 1.0; |
|
615 | relativePosition = 1.0; | |
614 |
|
616 | |||
615 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
617 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
616 | d->m_pieRelativeHorPos = relativePosition; |
|
618 | d->m_pieRelativeHorPos = relativePosition; | |
617 | emit d->horizontalPositionChanged(); |
|
619 | emit d->horizontalPositionChanged(); | |
618 | } |
|
620 | } | |
619 | } |
|
621 | } | |
620 |
|
622 | |||
621 | qreal QPieSeries::horizontalPosition() const |
|
623 | qreal QPieSeries::horizontalPosition() const | |
622 | { |
|
624 | { | |
623 | Q_D(const QPieSeries); |
|
625 | Q_D(const QPieSeries); | |
624 | return d->m_pieRelativeHorPos; |
|
626 | return d->m_pieRelativeHorPos; | |
625 | } |
|
627 | } | |
626 |
|
628 | |||
627 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
629 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
628 | { |
|
630 | { | |
629 | Q_D(QPieSeries); |
|
631 | Q_D(QPieSeries); | |
630 |
|
632 | |||
631 | if (relativePosition < 0.0) |
|
633 | if (relativePosition < 0.0) | |
632 | relativePosition = 0.0; |
|
634 | relativePosition = 0.0; | |
633 | if (relativePosition > 1.0) |
|
635 | if (relativePosition > 1.0) | |
634 | relativePosition = 1.0; |
|
636 | relativePosition = 1.0; | |
635 |
|
637 | |||
636 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
638 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
637 | d->m_pieRelativeVerPos = relativePosition; |
|
639 | d->m_pieRelativeVerPos = relativePosition; | |
638 | emit d->verticalPositionChanged(); |
|
640 | emit d->verticalPositionChanged(); | |
639 | } |
|
641 | } | |
640 | } |
|
642 | } | |
641 |
|
643 | |||
642 | qreal QPieSeries::verticalPosition() const |
|
644 | qreal QPieSeries::verticalPosition() const | |
643 | { |
|
645 | { | |
644 | Q_D(const QPieSeries); |
|
646 | Q_D(const QPieSeries); | |
645 | return d->m_pieRelativeVerPos; |
|
647 | return d->m_pieRelativeVerPos; | |
646 | } |
|
648 | } | |
647 |
|
649 | |||
648 | void QPieSeries::setPieSize(qreal relativeSize) |
|
650 | void QPieSeries::setPieSize(qreal relativeSize) | |
649 | { |
|
651 | { | |
650 | Q_D(QPieSeries); |
|
652 | Q_D(QPieSeries); | |
651 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
653 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
652 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
654 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); | |
653 |
|
655 | |||
654 | } |
|
656 | } | |
655 |
|
657 | |||
656 | qreal QPieSeries::pieSize() const |
|
658 | qreal QPieSeries::pieSize() const | |
657 | { |
|
659 | { | |
658 | Q_D(const QPieSeries); |
|
660 | Q_D(const QPieSeries); | |
659 | return d->m_pieRelativeSize; |
|
661 | return d->m_pieRelativeSize; | |
660 | } |
|
662 | } | |
661 |
|
663 | |||
662 |
|
664 | |||
663 | void QPieSeries::setPieStartAngle(qreal angle) |
|
665 | void QPieSeries::setPieStartAngle(qreal angle) | |
664 | { |
|
666 | { | |
665 | Q_D(QPieSeries); |
|
667 | Q_D(QPieSeries); | |
666 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
668 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
667 | return; |
|
669 | return; | |
668 | d->m_pieStartAngle = angle; |
|
670 | d->m_pieStartAngle = angle; | |
669 | d->updateDerivativeData(); |
|
671 | d->updateDerivativeData(); | |
670 | emit d->pieStartAngleChanged(); |
|
672 | emit d->pieStartAngleChanged(); | |
671 | } |
|
673 | } | |
672 |
|
674 | |||
673 | qreal QPieSeries::pieStartAngle() const |
|
675 | qreal QPieSeries::pieStartAngle() const | |
674 | { |
|
676 | { | |
675 | Q_D(const QPieSeries); |
|
677 | Q_D(const QPieSeries); | |
676 | return d->m_pieStartAngle; |
|
678 | return d->m_pieStartAngle; | |
677 | } |
|
679 | } | |
678 |
|
680 | |||
679 | /*! |
|
681 | /*! | |
680 | Sets the end angle of the pie. |
|
682 | Sets the end angle of the pie. | |
681 |
|
683 | |||
682 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
684 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
683 |
|
685 | |||
684 | \a angle must be greater than start angle. |
|
686 | \a angle must be greater than start angle. | |
685 |
|
687 | |||
686 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
688 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
687 | */ |
|
689 | */ | |
688 | void QPieSeries::setPieEndAngle(qreal angle) |
|
690 | void QPieSeries::setPieEndAngle(qreal angle) | |
689 | { |
|
691 | { | |
690 | Q_D(QPieSeries); |
|
692 | Q_D(QPieSeries); | |
691 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
693 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
692 | return; |
|
694 | return; | |
693 | d->m_pieEndAngle = angle; |
|
695 | d->m_pieEndAngle = angle; | |
694 | d->updateDerivativeData(); |
|
696 | d->updateDerivativeData(); | |
695 | emit d->pieEndAngleChanged(); |
|
697 | emit d->pieEndAngleChanged(); | |
696 | } |
|
698 | } | |
697 |
|
699 | |||
698 | /*! |
|
700 | /*! | |
699 | Returns the end angle of the pie. |
|
701 | Returns the end angle of the pie. | |
700 |
|
702 | |||
701 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
703 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
702 |
|
704 | |||
703 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
705 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
704 | */ |
|
706 | */ | |
705 | qreal QPieSeries::pieEndAngle() const |
|
707 | qreal QPieSeries::pieEndAngle() const | |
706 | { |
|
708 | { | |
707 | Q_D(const QPieSeries); |
|
709 | Q_D(const QPieSeries); | |
708 | return d->m_pieEndAngle; |
|
710 | return d->m_pieEndAngle; | |
709 | } |
|
711 | } | |
710 |
|
712 | |||
711 | /*! |
|
713 | /*! | |
712 | Sets the all the slice labels \a visible or invisible. |
|
714 | Sets the all the slice labels \a visible or invisible. | |
713 |
|
715 | |||
714 | Note that this affects only the current slices in the series. |
|
716 | Note that this affects only the current slices in the series. | |
715 | If user adds a new slice the default label visibility is false. |
|
717 | If user adds a new slice the default label visibility is false. | |
716 |
|
718 | |||
717 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
719 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
718 | */ |
|
720 | */ | |
719 | void QPieSeries::setLabelsVisible(bool visible) |
|
721 | void QPieSeries::setLabelsVisible(bool visible) | |
720 | { |
|
722 | { | |
721 | Q_D(QPieSeries); |
|
723 | Q_D(QPieSeries); | |
722 | foreach (QPieSlice *s, d->m_slices) |
|
724 | foreach (QPieSlice *s, d->m_slices) | |
723 | s->setLabelVisible(visible); |
|
725 | s->setLabelVisible(visible); | |
724 | } |
|
726 | } | |
725 |
|
727 | |||
726 | /*! |
|
728 | /*! | |
727 | Sets the all the slice labels \a position |
|
729 | Sets the all the slice labels \a position | |
728 |
|
730 | |||
729 | Note that this affects only the current slices in the series. |
|
731 | Note that this affects only the current slices in the series. | |
730 | If user adds a new slice the default label position is LabelOutside |
|
732 | If user adds a new slice the default label position is LabelOutside | |
731 |
|
733 | |||
732 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
734 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
733 | */ |
|
735 | */ | |
734 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
736 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
735 | { |
|
737 | { | |
736 | Q_D(QPieSeries); |
|
738 | Q_D(QPieSeries); | |
737 | foreach (QPieSlice *s, d->m_slices) |
|
739 | foreach (QPieSlice *s, d->m_slices) | |
738 | s->setLabelPosition(position); |
|
740 | s->setLabelPosition(position); | |
739 | } |
|
741 | } | |
740 |
|
742 | |||
741 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
743 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
742 |
|
744 | |||
743 |
|
745 | |||
744 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
746 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
745 | QAbstractSeriesPrivate(parent), |
|
747 | QAbstractSeriesPrivate(parent), | |
746 | m_pieRelativeHorPos(0.5), |
|
748 | m_pieRelativeHorPos(0.5), | |
747 | m_pieRelativeVerPos(0.5), |
|
749 | m_pieRelativeVerPos(0.5), | |
748 | m_pieRelativeSize(0.7), |
|
750 | m_pieRelativeSize(0.7), | |
749 | m_pieStartAngle(0), |
|
751 | m_pieStartAngle(0), | |
750 | m_pieEndAngle(360), |
|
752 | m_pieEndAngle(360), | |
751 | m_sum(0), |
|
753 | m_sum(0), | |
752 | m_holeRelativeSize(0.0) |
|
754 | m_holeRelativeSize(0.0) | |
753 | { |
|
755 | { | |
754 | } |
|
756 | } | |
755 |
|
757 | |||
756 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
758 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
757 | { |
|
759 | { | |
758 | } |
|
760 | } | |
759 |
|
761 | |||
760 | void QPieSeriesPrivate::updateDerivativeData() |
|
762 | void QPieSeriesPrivate::updateDerivativeData() | |
761 | { |
|
763 | { | |
762 | // calculate sum of all slices |
|
764 | // calculate sum of all slices | |
763 | qreal sum = 0; |
|
765 | qreal sum = 0; | |
764 | foreach (QPieSlice *s, m_slices) |
|
766 | foreach (QPieSlice *s, m_slices) | |
765 | sum += s->value(); |
|
767 | sum += s->value(); | |
766 |
|
768 | |||
767 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
769 | if (!qFuzzyIsNull(m_sum - sum)) { | |
768 | m_sum = sum; |
|
770 | m_sum = sum; | |
769 | emit q_func()->sumChanged(); |
|
771 | emit q_func()->sumChanged(); | |
770 | } |
|
772 | } | |
771 |
|
773 | |||
772 | // nothing to show.. |
|
774 | // nothing to show.. | |
773 | if (qFuzzyIsNull(m_sum)) |
|
775 | if (qFuzzyIsNull(m_sum)) | |
774 | return; |
|
776 | return; | |
775 |
|
777 | |||
776 | // update slice attributes |
|
778 | // update slice attributes | |
777 | qreal sliceAngle = m_pieStartAngle; |
|
779 | qreal sliceAngle = m_pieStartAngle; | |
778 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
780 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
779 | QVector<QPieSlice *> changed; |
|
781 | QVector<QPieSlice *> changed; | |
780 | foreach (QPieSlice *s, m_slices) { |
|
782 | foreach (QPieSlice *s, m_slices) { | |
781 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
783 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
782 | d->setPercentage(s->value() / m_sum); |
|
784 | d->setPercentage(s->value() / m_sum); | |
783 | d->setStartAngle(sliceAngle); |
|
785 | d->setStartAngle(sliceAngle); | |
784 | d->setAngleSpan(pieSpan * s->percentage()); |
|
786 | d->setAngleSpan(pieSpan * s->percentage()); | |
785 | sliceAngle += s->angleSpan(); |
|
787 | sliceAngle += s->angleSpan(); | |
786 | } |
|
788 | } | |
787 |
|
789 | |||
788 |
|
790 | |||
789 | emit calculatedDataChanged(); |
|
791 | emit calculatedDataChanged(); | |
790 | } |
|
792 | } | |
791 |
|
793 | |||
792 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
794 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
793 | { |
|
795 | { | |
794 | bool changed = false; |
|
796 | bool changed = false; | |
795 |
|
797 | |||
796 | if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) { |
|
798 | if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) { | |
797 | m_holeRelativeSize = innerSize; |
|
799 | m_holeRelativeSize = innerSize; | |
798 | changed = true; |
|
800 | changed = true; | |
799 | } |
|
801 | } | |
800 |
|
802 | |||
801 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { |
|
803 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { | |
802 | m_pieRelativeSize = outerSize; |
|
804 | m_pieRelativeSize = outerSize; | |
803 | changed = true; |
|
805 | changed = true; | |
804 | } |
|
806 | } | |
805 |
|
807 | |||
806 | if (changed) |
|
808 | if (changed) | |
807 | emit pieSizeChanged(); |
|
809 | emit pieSizeChanged(); | |
808 | } |
|
810 | } | |
809 |
|
811 | |||
810 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
812 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
811 | { |
|
813 | { | |
812 | return series->d_func(); |
|
814 | return series->d_func(); | |
813 | } |
|
815 | } | |
814 |
|
816 | |||
815 | void QPieSeriesPrivate::sliceValueChanged() |
|
817 | void QPieSeriesPrivate::sliceValueChanged() | |
816 | { |
|
818 | { | |
817 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
819 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
818 | updateDerivativeData(); |
|
820 | updateDerivativeData(); | |
819 | } |
|
821 | } | |
820 |
|
822 | |||
821 | void QPieSeriesPrivate::sliceClicked() |
|
823 | void QPieSeriesPrivate::sliceClicked() | |
822 | { |
|
824 | { | |
823 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
825 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
824 | Q_ASSERT(m_slices.contains(slice)); |
|
826 | Q_ASSERT(m_slices.contains(slice)); | |
825 | Q_Q(QPieSeries); |
|
827 | Q_Q(QPieSeries); | |
826 | emit q->clicked(slice); |
|
828 | emit q->clicked(slice); | |
827 | } |
|
829 | } | |
828 |
|
830 | |||
829 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
831 | void QPieSeriesPrivate::sliceHovered(bool state) | |
830 | { |
|
832 | { | |
831 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
833 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
832 | Q_ASSERT(m_slices.contains(slice)); |
|
834 | Q_ASSERT(m_slices.contains(slice)); | |
833 | Q_Q(QPieSeries); |
|
835 | Q_Q(QPieSeries); | |
834 | emit q->hovered(slice, state); |
|
836 | emit q->hovered(slice, state); | |
835 | } |
|
837 | } | |
836 |
|
838 | |||
837 | void QPieSeriesPrivate::scaleDomain(Domain &domain) |
|
839 | void QPieSeriesPrivate::scaleDomain(Domain &domain) | |
838 | { |
|
840 | { | |
839 | Q_UNUSED(domain); |
|
841 | Q_UNUSED(domain); | |
840 | // does not apply to pie |
|
842 | // does not apply to pie | |
841 | } |
|
843 | } | |
842 |
|
844 | |||
843 | ChartElement *QPieSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
845 | ChartElement *QPieSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
844 | { |
|
846 | { | |
845 | Q_Q(QPieSeries); |
|
847 | Q_Q(QPieSeries); | |
846 | PieChartItem *pie = new PieChartItem(q, presenter); |
|
848 | PieChartItem *pie = new PieChartItem(q, presenter); | |
847 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
849 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) | |
848 | pie->setAnimation(new PieAnimation(pie)); |
|
850 | pie->setAnimation(new PieAnimation(pie)); | |
849 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
851 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
850 | return pie; |
|
852 | return pie; | |
851 | } |
|
853 | } | |
852 |
|
854 | |||
853 | QList<LegendMarker *> QPieSeriesPrivate::createLegendMarker(QLegend *legend) |
|
855 | QList<LegendMarker *> QPieSeriesPrivate::createLegendMarker(QLegend *legend) | |
854 | { |
|
856 | { | |
855 | Q_Q(QPieSeries); |
|
857 | Q_Q(QPieSeries); | |
856 | QList<LegendMarker *> markers; |
|
858 | QList<LegendMarker *> markers; | |
857 | foreach (QPieSlice *slice, q->slices()) { |
|
859 | foreach (QPieSlice *slice, q->slices()) { | |
858 | PieLegendMarker* marker = new PieLegendMarker(q, slice, legend); |
|
860 | PieLegendMarker* marker = new PieLegendMarker(q, slice, legend); | |
859 | markers << marker; |
|
861 | markers << marker; | |
860 | } |
|
862 | } | |
861 | return markers; |
|
863 | return markers; | |
862 | } |
|
864 | } | |
863 |
|
865 | |||
|
866 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
867 | { | |||
|
868 | Q_Q(QPieSeries); | |||
|
869 | QList<QLegendMarker*> markers; | |||
|
870 | foreach(QPieSlice* slice, q->slices()) { | |||
|
871 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); | |||
|
872 | markers << marker; | |||
|
873 | } | |||
|
874 | return markers; | |||
|
875 | } | |||
|
876 | ||||
864 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
877 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
865 | { |
|
878 | { | |
866 | Q_UNUSED(axis); |
|
879 | Q_UNUSED(axis); | |
867 | } |
|
880 | } | |
868 |
|
881 | |||
869 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
882 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
870 | { |
|
883 | { | |
871 | Q_UNUSED(orientation); |
|
884 | Q_UNUSED(orientation); | |
872 | return QAbstractAxis::AxisTypeNoAxis; |
|
885 | return QAbstractAxis::AxisTypeNoAxis; | |
873 | } |
|
886 | } | |
874 |
|
887 | |||
875 | #include "moc_qpieseries.cpp" |
|
888 | #include "moc_qpieseries.cpp" | |
876 | #include "moc_qpieseries_p.cpp" |
|
889 | #include "moc_qpieseries_p.cpp" | |
877 |
|
890 | |||
878 | QTCOMMERCIALCHART_END_NAMESPACE |
|
891 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QPIESERIES_P_H |
|
30 | #ifndef QPIESERIES_P_H | |
31 | #define QPIESERIES_P_H |
|
31 | #define QPIESERIES_P_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 | class QLegendPrivate; |
|
37 | class QLegendPrivate; | |
38 |
|
38 | |||
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QPieSeriesPrivate(QPieSeries *parent); |
|
44 | QPieSeriesPrivate(QPieSeries *parent); | |
45 | ~QPieSeriesPrivate(); |
|
45 | ~QPieSeriesPrivate(); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain &domain); |
|
47 | void scaleDomain(Domain &domain); | |
48 | ChartElement *createGraphics(ChartPresenter *presenter); |
|
48 | ChartElement *createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
50 | QList<QLegendMarker *> createLegendMarkers(QLegend *legend); | |||
50 | void initializeAxis(QAbstractAxis *axis); |
|
51 | void initializeAxis(QAbstractAxis *axis); | |
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
52 |
|
53 | |||
53 | void updateDerivativeData(); |
|
54 | void updateDerivativeData(); | |
54 | void setSizes(qreal innerSize, qreal outerSize); |
|
55 | void setSizes(qreal innerSize, qreal outerSize); | |
55 |
|
56 | |||
56 | static QPieSeriesPrivate *fromSeries(QPieSeries *series); |
|
57 | static QPieSeriesPrivate *fromSeries(QPieSeries *series); | |
57 |
|
58 | |||
58 | signals: |
|
59 | signals: | |
59 | void calculatedDataChanged(); |
|
60 | void calculatedDataChanged(); | |
60 | void pieSizeChanged(); |
|
61 | void pieSizeChanged(); | |
61 | void pieStartAngleChanged(); |
|
62 | void pieStartAngleChanged(); | |
62 | void pieEndAngleChanged(); |
|
63 | void pieEndAngleChanged(); | |
63 | void horizontalPositionChanged(); |
|
64 | void horizontalPositionChanged(); | |
64 | void verticalPositionChanged(); |
|
65 | void verticalPositionChanged(); | |
65 |
|
66 | |||
66 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
67 | void sliceValueChanged(); |
|
68 | void sliceValueChanged(); | |
68 | void sliceClicked(); |
|
69 | void sliceClicked(); | |
69 | void sliceHovered(bool state); |
|
70 | void sliceHovered(bool state); | |
70 |
|
71 | |||
71 | private: |
|
72 | private: | |
72 | QList<QPieSlice *> m_slices; |
|
73 | QList<QPieSlice *> m_slices; | |
73 | qreal m_pieRelativeHorPos; |
|
74 | qreal m_pieRelativeHorPos; | |
74 | qreal m_pieRelativeVerPos; |
|
75 | qreal m_pieRelativeVerPos; | |
75 | qreal m_pieRelativeSize; |
|
76 | qreal m_pieRelativeSize; | |
76 | qreal m_pieStartAngle; |
|
77 | qreal m_pieStartAngle; | |
77 | qreal m_pieEndAngle; |
|
78 | qreal m_pieEndAngle; | |
78 | qreal m_sum; |
|
79 | qreal m_sum; | |
79 | qreal m_holeRelativeSize; |
|
80 | qreal m_holeRelativeSize; | |
80 |
|
81 | |||
81 | private: |
|
82 | private: | |
82 | friend class QLegendPrivate; |
|
83 | friend class QLegendPrivate; | |
83 | Q_DECLARE_PUBLIC(QPieSeries) |
|
84 | Q_DECLARE_PUBLIC(QPieSeries) | |
84 | }; |
|
85 | }; | |
85 |
|
86 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
88 | |||
88 | #endif // QPIESERIES_P_H |
|
89 | #endif // QPIESERIES_P_H |
@@ -1,76 +1,78 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTSERIES_P_H |
|
30 | #ifndef QABSTRACTSERIES_P_H | |
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class Domain; |
|
37 | class Domain; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class ChartElement; |
|
39 | class ChartElement; | |
40 | class LegendMarker; |
|
40 | class LegendMarker; | |
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
|
44 | class QLegendMarker; | |||
44 |
|
45 | |||
45 | class QAbstractSeriesPrivate : public QObject |
|
46 | class QAbstractSeriesPrivate : public QObject | |
46 | { |
|
47 | { | |
47 | Q_OBJECT |
|
48 | Q_OBJECT | |
48 | public: |
|
49 | public: | |
49 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
50 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
50 | ~QAbstractSeriesPrivate(); |
|
51 | ~QAbstractSeriesPrivate(); | |
51 |
|
52 | |||
52 | virtual void scaleDomain(Domain &domain) = 0; |
|
53 | virtual void scaleDomain(Domain &domain) = 0; | |
53 | virtual ChartElement *createGraphics(ChartPresenter *presenter) = 0; |
|
54 | virtual ChartElement *createGraphics(ChartPresenter *presenter) = 0; | |
54 | virtual QList<LegendMarker *> createLegendMarker(QLegend *legend) = 0; |
|
55 | virtual QList<LegendMarker *> createLegendMarker(QLegend *legend) = 0; | |
|
56 | virtual QList<QLegendMarker*> createLegendMarkers(QLegend* legend) = 0; | |||
55 | virtual void initializeAxis(QAbstractAxis *axis) = 0; |
|
57 | virtual void initializeAxis(QAbstractAxis *axis) = 0; | |
56 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; |
|
58 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; | |
57 |
|
59 | |||
58 | Q_SIGNALS: |
|
60 | Q_SIGNALS: | |
59 | void countChanged(); |
|
61 | void countChanged(); | |
60 |
|
62 | |||
61 | protected: |
|
63 | protected: | |
62 | QAbstractSeries *q_ptr; |
|
64 | QAbstractSeries *q_ptr; | |
63 | QChart *m_chart; |
|
65 | QChart *m_chart; | |
64 | ChartDataSet *m_dataset; |
|
66 | ChartDataSet *m_dataset; | |
65 | QString m_name; |
|
67 | QString m_name; | |
66 | bool m_visible; |
|
68 | bool m_visible; | |
67 | qreal m_opacity; |
|
69 | qreal m_opacity; | |
68 |
|
70 | |||
69 | friend class QAbstractSeries; |
|
71 | friend class QAbstractSeries; | |
70 | friend class ChartDataSet; |
|
72 | friend class ChartDataSet; | |
71 | friend class QLegendPrivate; |
|
73 | friend class QLegendPrivate; | |
72 | }; |
|
74 | }; | |
73 |
|
75 | |||
74 | QTCOMMERCIALCHART_END_NAMESPACE |
|
76 | QTCOMMERCIALCHART_END_NAMESPACE | |
75 |
|
77 | |||
76 | #endif |
|
78 | #endif |
@@ -1,471 +1,481 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "qvalueaxis.h" |
|
25 | #include "qvalueaxis.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QXYSeries |
|
30 | \class QXYSeries | |
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
32 | */ |
|
32 | */ | |
33 | /*! |
|
33 | /*! | |
34 | \qmlclass XYSeries |
|
34 | \qmlclass XYSeries | |
35 | \inherits AbstractSeries |
|
35 | \inherits AbstractSeries | |
36 | The XYSeries class is a base class for line, spline and scatter series. |
|
36 | The XYSeries class is a base class for line, spline and scatter series. | |
37 |
|
37 | |||
38 | The class cannot be instantiated directly. |
|
38 | The class cannot be instantiated directly. | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \property QXYSeries::pointsVisible |
|
42 | \property QXYSeries::pointsVisible | |
43 | Controls if the data points are visible and should be drawn. |
|
43 | Controls if the data points are visible and should be drawn. | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlproperty bool XYSeries::pointsVisible |
|
46 | \qmlproperty bool XYSeries::pointsVisible | |
47 | Controls if the data points are visible and should be drawn. |
|
47 | Controls if the data points are visible and should be drawn. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn QPen QXYSeries::pen() const |
|
51 | \fn QPen QXYSeries::pen() const | |
52 | \brief Returns pen used to draw points for series. |
|
52 | \brief Returns pen used to draw points for series. | |
53 | \sa setPen() |
|
53 | \sa setPen() | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn QBrush QXYSeries::brush() const |
|
57 | \fn QBrush QXYSeries::brush() const | |
58 | \brief Returns brush used to draw points for series. |
|
58 | \brief Returns brush used to draw points for series. | |
59 | \sa setBrush() |
|
59 | \sa setBrush() | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QXYSeries::color |
|
63 | \property QXYSeries::color | |
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
66 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
66 | \sa QXYSeries::pen(), QXYSeries::brush() | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty color XYSeries::color |
|
69 | \qmlproperty color XYSeries::color | |
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
71 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
71 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn void QXYSeries::clicked(const QPointF& point) |
|
75 | \fn void QXYSeries::clicked(const QPointF& point) | |
76 | \brief Signal is emitted when user clicks the \a point on chart. |
|
76 | \brief Signal is emitted when user clicks the \a point on chart. | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
79 | \qmlsignal XYSeries::onClicked(QPointF point) | |
80 | Signal is emitted when user clicks the \a point on chart. For example: |
|
80 | Signal is emitted when user clicks the \a point on chart. For example: | |
81 | \code |
|
81 | \code | |
82 | LineSeries { |
|
82 | LineSeries { | |
83 | XYPoint { x: 0; y: 0 } |
|
83 | XYPoint { x: 0; y: 0 } | |
84 | XYPoint { x: 1.1; y: 2.1 } |
|
84 | XYPoint { x: 1.1; y: 2.1 } | |
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
86 | } |
|
86 | } | |
87 | \endcode |
|
87 | \endcode | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \fn void QXYSeries::pointReplaced(int index) |
|
91 | \fn void QXYSeries::pointReplaced(int index) | |
92 | Signal is emitted when a point has been replaced at \a index. |
|
92 | Signal is emitted when a point has been replaced at \a index. | |
93 | \sa replace() |
|
93 | \sa replace() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
96 | \qmlsignal XYSeries::onPointReplaced(int index) | |
97 | Signal is emitted when a point has been replaced at \a index. |
|
97 | Signal is emitted when a point has been replaced at \a index. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QXYSeries::pointsReplaced() |
|
101 | \fn void QXYSeries::pointsReplaced() | |
102 | Signal is emitted when all points have been replaced with another points. |
|
102 | Signal is emitted when all points have been replaced with another points. | |
103 | \sa replace() |
|
103 | \sa replace() | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlsignal XYSeries::onPointsReplaced() |
|
106 | \qmlsignal XYSeries::onPointsReplaced() | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \fn void QXYSeries::pointAdded(int index) |
|
110 | \fn void QXYSeries::pointAdded(int index) | |
111 | Signal is emitted when a point has been added at \a index. |
|
111 | Signal is emitted when a point has been added at \a index. | |
112 | \sa append(), insert() |
|
112 | \sa append(), insert() | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal XYSeries::onPointAdded(int index) |
|
115 | \qmlsignal XYSeries::onPointAdded(int index) | |
116 | Signal is emitted when a point has been added at \a index. |
|
116 | Signal is emitted when a point has been added at \a index. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QXYSeries::pointRemoved(int index) |
|
120 | \fn void QXYSeries::pointRemoved(int index) | |
121 | Signal is emitted when a point has been removed from \a index. |
|
121 | Signal is emitted when a point has been removed from \a index. | |
122 | \sa remove() |
|
122 | \sa remove() | |
123 | */ |
|
123 | */ | |
124 | /*! |
|
124 | /*! | |
125 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
125 | \qmlsignal XYSeries::onPointRemoved(int index) | |
126 | Signal is emitted when a point has been removed from \a index. |
|
126 | Signal is emitted when a point has been removed from \a index. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QXYSeries::colorChanged(QColor color) |
|
130 | \fn void QXYSeries::colorChanged(QColor color) | |
131 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
131 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
132 | */ |
|
132 | */ | |
133 | /*! |
|
133 | /*! | |
134 | \qmlsignal XYSeries::onColorChanged(color color) |
|
134 | \qmlsignal XYSeries::onColorChanged(color color) | |
135 | Signal is emitted when the line (pen) color has changed to \a color. |
|
135 | Signal is emitted when the line (pen) color has changed to \a color. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QXYSeriesPrivate::updated() |
|
139 | \fn void QXYSeriesPrivate::updated() | |
140 | \brief \internal |
|
140 | \brief \internal | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \qmlmethod XYSeries::append(real x, real y) |
|
144 | \qmlmethod XYSeries::append(real x, real y) | |
145 | Append point (\a x, \a y) to the series |
|
145 | Append point (\a x, \a y) to the series | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
149 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
150 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
150 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
151 | exist. |
|
151 | exist. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \qmlmethod XYSeries::remove(real x, real y) |
|
155 | \qmlmethod XYSeries::remove(real x, real y) | |
156 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
156 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
160 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
161 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
161 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
162 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
162 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \qmlmethod QPointF XYSeries::at(int index) |
|
166 | \qmlmethod QPointF XYSeries::at(int index) | |
167 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
167 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \internal |
|
171 | \internal | |
172 |
|
172 | |||
173 | Constructs empty series object which is a child of \a parent. |
|
173 | Constructs empty series object which is a child of \a parent. | |
174 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
174 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
175 | */ |
|
175 | */ | |
176 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
176 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) | |
177 | : QAbstractSeries(d, parent) |
|
177 | : QAbstractSeries(d, parent) | |
178 | { |
|
178 | { | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
182 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
183 | and are deleted when mentioned object are destroyed. |
|
183 | and are deleted when mentioned object are destroyed. | |
184 | */ |
|
184 | */ | |
185 | QXYSeries::~QXYSeries() |
|
185 | QXYSeries::~QXYSeries() | |
186 | { |
|
186 | { | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
190 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
191 | */ |
|
191 | */ | |
192 | void QXYSeries::append(qreal x, qreal y) |
|
192 | void QXYSeries::append(qreal x, qreal y) | |
193 | { |
|
193 | { | |
194 | append(QPointF(x, y)); |
|
194 | append(QPointF(x, y)); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | This is an overloaded function. |
|
198 | This is an overloaded function. | |
199 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
199 | Adds data \a point to the series. Points are connected with lines on the chart. | |
200 | */ |
|
200 | */ | |
201 | void QXYSeries::append(const QPointF &point) |
|
201 | void QXYSeries::append(const QPointF &point) | |
202 | { |
|
202 | { | |
203 | Q_D(QXYSeries); |
|
203 | Q_D(QXYSeries); | |
204 | d->m_points << point; |
|
204 | d->m_points << point; | |
205 | emit pointAdded(d->m_points.count() - 1); |
|
205 | emit pointAdded(d->m_points.count() - 1); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | This is an overloaded function. |
|
209 | This is an overloaded function. | |
210 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
210 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
211 | */ |
|
211 | */ | |
212 | void QXYSeries::append(const QList<QPointF> &points) |
|
212 | void QXYSeries::append(const QList<QPointF> &points) | |
213 | { |
|
213 | { | |
214 | foreach (const QPointF &point , points) |
|
214 | foreach (const QPointF &point , points) | |
215 | append(point); |
|
215 | append(point); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
219 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. | |
220 | \sa QXYSeries::pointReplaced() |
|
220 | \sa QXYSeries::pointReplaced() | |
221 | */ |
|
221 | */ | |
222 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
222 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) | |
223 | { |
|
223 | { | |
224 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
224 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Replaces \a oldPoint with \a newPoint. |
|
228 | Replaces \a oldPoint with \a newPoint. | |
229 | \sa QXYSeries::pointReplaced() |
|
229 | \sa QXYSeries::pointReplaced() | |
230 | */ |
|
230 | */ | |
231 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
231 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) | |
232 | { |
|
232 | { | |
233 | Q_D(QXYSeries); |
|
233 | Q_D(QXYSeries); | |
234 | int index = d->m_points.indexOf(oldPoint); |
|
234 | int index = d->m_points.indexOf(oldPoint); | |
235 | if (index == -1) |
|
235 | if (index == -1) | |
236 | return; |
|
236 | return; | |
237 | d->m_points[index] = newPoint; |
|
237 | d->m_points[index] = newPoint; | |
238 | emit pointReplaced(index); |
|
238 | emit pointReplaced(index); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Replaces the current points with \a points. This is faster than replacing data points one by one, |
|
242 | Replaces the current points with \a points. This is faster than replacing data points one by one, | |
243 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
243 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() | |
244 | when the points have been replaced. |
|
244 | when the points have been replaced. | |
245 | \sa QXYSeries::pointsReplaced() |
|
245 | \sa QXYSeries::pointsReplaced() | |
246 | */ |
|
246 | */ | |
247 | void QXYSeries::replace(QList<QPointF> points) |
|
247 | void QXYSeries::replace(QList<QPointF> points) | |
248 | { |
|
248 | { | |
249 | Q_D(QXYSeries); |
|
249 | Q_D(QXYSeries); | |
250 | d->m_points = points.toVector(); |
|
250 | d->m_points = points.toVector(); | |
251 | emit pointsReplaced(); |
|
251 | emit pointsReplaced(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Removes current \a x and \a y value. |
|
255 | Removes current \a x and \a y value. | |
256 | */ |
|
256 | */ | |
257 | void QXYSeries::remove(qreal x, qreal y) |
|
257 | void QXYSeries::remove(qreal x, qreal y) | |
258 | { |
|
258 | { | |
259 | remove(QPointF(x, y)); |
|
259 | remove(QPointF(x, y)); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | Removes current \a point x value. |
|
263 | Removes current \a point x value. | |
264 |
|
264 | |||
265 | Note: point y value is ignored. |
|
265 | Note: point y value is ignored. | |
266 | */ |
|
266 | */ | |
267 | void QXYSeries::remove(const QPointF &point) |
|
267 | void QXYSeries::remove(const QPointF &point) | |
268 | { |
|
268 | { | |
269 | Q_D(QXYSeries); |
|
269 | Q_D(QXYSeries); | |
270 | int index = d->m_points.indexOf(point); |
|
270 | int index = d->m_points.indexOf(point); | |
271 | if (index == -1) |
|
271 | if (index == -1) | |
272 | return; |
|
272 | return; | |
273 | d->m_points.remove(index); |
|
273 | d->m_points.remove(index); | |
274 | emit pointRemoved(index); |
|
274 | emit pointRemoved(index); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | Inserts a \a point in the series at \a index position. |
|
278 | Inserts a \a point in the series at \a index position. | |
279 | */ |
|
279 | */ | |
280 | void QXYSeries::insert(int index, const QPointF &point) |
|
280 | void QXYSeries::insert(int index, const QPointF &point) | |
281 | { |
|
281 | { | |
282 | Q_D(QXYSeries); |
|
282 | Q_D(QXYSeries); | |
283 | d->m_points.insert(index, point); |
|
283 | d->m_points.insert(index, point); | |
284 | emit pointAdded(index); |
|
284 | emit pointAdded(index); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Removes all points from the series. |
|
288 | Removes all points from the series. | |
289 | */ |
|
289 | */ | |
290 | void QXYSeries::clear() |
|
290 | void QXYSeries::clear() | |
291 | { |
|
291 | { | |
292 | Q_D(QXYSeries); |
|
292 | Q_D(QXYSeries); | |
293 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
293 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
294 | remove(d->m_points.at(i)); |
|
294 | remove(d->m_points.at(i)); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | /*! |
|
297 | /*! | |
298 | Returns list of points in the series. |
|
298 | Returns list of points in the series. | |
299 | */ |
|
299 | */ | |
300 | QList<QPointF> QXYSeries::points() const |
|
300 | QList<QPointF> QXYSeries::points() const | |
301 | { |
|
301 | { | |
302 | Q_D(const QXYSeries); |
|
302 | Q_D(const QXYSeries); | |
303 | return d->m_points.toList(); |
|
303 | return d->m_points.toList(); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 | Returns number of data points within series. |
|
307 | Returns number of data points within series. | |
308 | */ |
|
308 | */ | |
309 | int QXYSeries::count() const |
|
309 | int QXYSeries::count() const | |
310 | { |
|
310 | { | |
311 | Q_D(const QXYSeries); |
|
311 | Q_D(const QXYSeries); | |
312 | return d->m_points.count(); |
|
312 | return d->m_points.count(); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 |
|
315 | |||
316 | /*! |
|
316 | /*! | |
317 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
317 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
318 | pen from chart theme is used. |
|
318 | pen from chart theme is used. | |
319 | \sa QChart::setTheme() |
|
319 | \sa QChart::setTheme() | |
320 | */ |
|
320 | */ | |
321 | void QXYSeries::setPen(const QPen &pen) |
|
321 | void QXYSeries::setPen(const QPen &pen) | |
322 | { |
|
322 | { | |
323 | Q_D(QXYSeries); |
|
323 | Q_D(QXYSeries); | |
324 | if (d->m_pen != pen) { |
|
324 | if (d->m_pen != pen) { | |
325 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
325 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
326 | d->m_pen = pen; |
|
326 | d->m_pen = pen; | |
327 | emit d->updated(); |
|
327 | emit d->updated(); | |
328 | if (emitColorChanged) |
|
328 | if (emitColorChanged) | |
329 | emit colorChanged(pen.color()); |
|
329 | emit colorChanged(pen.color()); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | QPen QXYSeries::pen() const |
|
333 | QPen QXYSeries::pen() const | |
334 | { |
|
334 | { | |
335 | Q_D(const QXYSeries); |
|
335 | Q_D(const QXYSeries); | |
336 | return d->m_pen; |
|
336 | return d->m_pen; | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | /*! |
|
339 | /*! | |
340 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
340 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
341 | from chart theme setting is used. |
|
341 | from chart theme setting is used. | |
342 | \sa QChart::setTheme() |
|
342 | \sa QChart::setTheme() | |
343 | */ |
|
343 | */ | |
344 | void QXYSeries::setBrush(const QBrush &brush) |
|
344 | void QXYSeries::setBrush(const QBrush &brush) | |
345 | { |
|
345 | { | |
346 | Q_D(QXYSeries); |
|
346 | Q_D(QXYSeries); | |
347 | if (d->m_brush != brush) { |
|
347 | if (d->m_brush != brush) { | |
348 | d->m_brush = brush; |
|
348 | d->m_brush = brush; | |
349 | emit d->updated(); |
|
349 | emit d->updated(); | |
350 | } |
|
350 | } | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | QBrush QXYSeries::brush() const |
|
353 | QBrush QXYSeries::brush() const | |
354 | { |
|
354 | { | |
355 | Q_D(const QXYSeries); |
|
355 | Q_D(const QXYSeries); | |
356 | return d->m_brush; |
|
356 | return d->m_brush; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | void QXYSeries::setColor(const QColor &color) |
|
359 | void QXYSeries::setColor(const QColor &color) | |
360 | { |
|
360 | { | |
361 | QPen p = pen(); |
|
361 | QPen p = pen(); | |
362 | if (p.color() != color) { |
|
362 | if (p.color() != color) { | |
363 | p.setColor(color); |
|
363 | p.setColor(color); | |
364 | setPen(p); |
|
364 | setPen(p); | |
365 | } |
|
365 | } | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | QColor QXYSeries::color() const |
|
368 | QColor QXYSeries::color() const | |
369 | { |
|
369 | { | |
370 | return pen().color(); |
|
370 | return pen().color(); | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | void QXYSeries::setPointsVisible(bool visible) |
|
373 | void QXYSeries::setPointsVisible(bool visible) | |
374 | { |
|
374 | { | |
375 | Q_D(QXYSeries); |
|
375 | Q_D(QXYSeries); | |
376 | if (d->m_pointsVisible != visible) { |
|
376 | if (d->m_pointsVisible != visible) { | |
377 | d->m_pointsVisible = visible; |
|
377 | d->m_pointsVisible = visible; | |
378 | emit d->updated(); |
|
378 | emit d->updated(); | |
379 | } |
|
379 | } | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | bool QXYSeries::pointsVisible() const |
|
382 | bool QXYSeries::pointsVisible() const | |
383 | { |
|
383 | { | |
384 | Q_D(const QXYSeries); |
|
384 | Q_D(const QXYSeries); | |
385 | return d->m_pointsVisible; |
|
385 | return d->m_pointsVisible; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 |
|
388 | |||
389 | /*! |
|
389 | /*! | |
390 | Stream operator for adding a data \a point to the series. |
|
390 | Stream operator for adding a data \a point to the series. | |
391 | \sa append() |
|
391 | \sa append() | |
392 | */ |
|
392 | */ | |
393 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
393 | QXYSeries &QXYSeries::operator<< (const QPointF &point) | |
394 | { |
|
394 | { | |
395 | append(point); |
|
395 | append(point); | |
396 | return *this; |
|
396 | return *this; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Stream operator for adding a list of \a points to the series. |
|
401 | Stream operator for adding a list of \a points to the series. | |
402 | \sa append() |
|
402 | \sa append() | |
403 | */ |
|
403 | */ | |
404 |
|
404 | |||
405 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
405 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) | |
406 | { |
|
406 | { | |
407 | append(points); |
|
407 | append(points); | |
408 | return *this; |
|
408 | return *this; | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
411 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
412 |
|
412 | |||
413 |
|
413 | |||
414 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
414 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) | |
415 | : QAbstractSeriesPrivate(q), |
|
415 | : QAbstractSeriesPrivate(q), | |
416 | m_pointsVisible(false) |
|
416 | m_pointsVisible(false) | |
417 | { |
|
417 | { | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | void QXYSeriesPrivate::scaleDomain(Domain &domain) |
|
420 | void QXYSeriesPrivate::scaleDomain(Domain &domain) | |
421 | { |
|
421 | { | |
422 | qreal minX(0); |
|
422 | qreal minX(0); | |
423 | qreal minY(0); |
|
423 | qreal minY(0); | |
424 | qreal maxX(1); |
|
424 | qreal maxX(1); | |
425 | qreal maxY(1); |
|
425 | qreal maxY(1); | |
426 |
|
426 | |||
427 | Q_Q(QXYSeries); |
|
427 | Q_Q(QXYSeries); | |
428 |
|
428 | |||
429 | const QList<QPointF>& points = q->points(); |
|
429 | const QList<QPointF>& points = q->points(); | |
430 |
|
430 | |||
431 | if (!points.isEmpty()) { |
|
431 | if (!points.isEmpty()) { | |
432 | minX = points[0].x(); |
|
432 | minX = points[0].x(); | |
433 | minY = points[0].y(); |
|
433 | minY = points[0].y(); | |
434 | maxX = minX; |
|
434 | maxX = minX; | |
435 | maxY = minY; |
|
435 | maxY = minY; | |
436 |
|
436 | |||
437 | for (int i = 0; i < points.count(); i++) { |
|
437 | for (int i = 0; i < points.count(); i++) { | |
438 | qreal x = points[i].x(); |
|
438 | qreal x = points[i].x(); | |
439 | qreal y = points[i].y(); |
|
439 | qreal y = points[i].y(); | |
440 | minX = qMin(minX, x); |
|
440 | minX = qMin(minX, x); | |
441 | minY = qMin(minY, y); |
|
441 | minY = qMin(minY, y); | |
442 | maxX = qMax(maxX, x); |
|
442 | maxX = qMax(maxX, x); | |
443 | maxY = qMax(maxY, y); |
|
443 | maxY = qMax(maxY, y); | |
444 | } |
|
444 | } | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | domain.setRange(minX, maxX, minY, maxY); |
|
447 | domain.setRange(minX, maxX, minY, maxY); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | QList<LegendMarker *> QXYSeriesPrivate::createLegendMarker(QLegend *legend) |
|
450 | QList<LegendMarker *> QXYSeriesPrivate::createLegendMarker(QLegend *legend) | |
451 | { |
|
451 | { | |
452 | Q_Q(QXYSeries); |
|
452 | Q_Q(QXYSeries); | |
453 | QList<LegendMarker *> list; |
|
453 | QList<LegendMarker *> list; | |
454 | return list << new XYLegendMarker(q, legend); |
|
454 | return list << new XYLegendMarker(q, legend); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
|
457 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |||
|
458 | { | |||
|
459 | Q_UNUSED(legend); | |||
|
460 | // Q_Q(QXYSeries); | |||
|
461 | QList<QLegendMarker*> list; | |||
|
462 | // TODO: | |||
|
463 | // return list << new QXYLegendMarker(q,legend); | |||
|
464 | return list; | |||
|
465 | } | |||
|
466 | ||||
457 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
467 | void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
458 | { |
|
468 | { | |
459 | Q_UNUSED(axis); |
|
469 | Q_UNUSED(axis); | |
460 | } |
|
470 | } | |
461 |
|
471 | |||
462 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
472 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
463 | { |
|
473 | { | |
464 | Q_UNUSED(orientation); |
|
474 | Q_UNUSED(orientation); | |
465 | return QAbstractAxis::AxisTypeValue; |
|
475 | return QAbstractAxis::AxisTypeValue; | |
466 | } |
|
476 | } | |
467 |
|
477 | |||
468 | #include "moc_qxyseries.cpp" |
|
478 | #include "moc_qxyseries.cpp" | |
469 | #include "moc_qxyseries_p.cpp" |
|
479 | #include "moc_qxyseries_p.cpp" | |
470 |
|
480 | |||
471 | QTCOMMERCIALCHART_END_NAMESPACE |
|
481 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,73 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QXYSERIES_P_H |
|
30 | #ifndef QXYSERIES_P_H | |
31 | #define QXYSERIES_P_H |
|
31 | #define QXYSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QXYSeries; |
|
37 | class QXYSeries; | |
38 | class QAbstractAxis; |
|
38 | class QAbstractAxis; | |
39 |
|
39 | |||
40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QXYSeriesPrivate(QXYSeries *q); |
|
45 | QXYSeriesPrivate(QXYSeries *q); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain &domain); |
|
47 | void scaleDomain(Domain &domain); | |
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); |
|
48 | QList<LegendMarker *> createLegendMarker(QLegend *legend); | |
|
49 | QList<QLegendMarker*> createLegendMarkers(QLegend* legend); | |||
49 |
|
50 | |||
50 | void initializeAxis(QAbstractAxis *axis); |
|
51 | void initializeAxis(QAbstractAxis *axis); | |
51 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; |
|
52 | QAbstractAxis::AxisType defaultAxisType(Qt::Orientation orientation) const; | |
52 |
|
53 | |||
53 | Q_SIGNALS: |
|
54 | Q_SIGNALS: | |
54 | void updated(); |
|
55 | void updated(); | |
55 | // void pointReplaced(int index); |
|
56 | // void pointReplaced(int index); | |
56 | // void pointRemoved(int index); |
|
57 | // void pointRemoved(int index); | |
57 | // void pointAdded(int index); |
|
58 | // void pointAdded(int index); | |
58 |
|
59 | |||
59 | protected: |
|
60 | protected: | |
60 | QVector<QPointF> m_points; |
|
61 | QVector<QPointF> m_points; | |
61 | QPen m_pen; |
|
62 | QPen m_pen; | |
62 | QBrush m_brush; |
|
63 | QBrush m_brush; | |
63 | bool m_pointsVisible; |
|
64 | bool m_pointsVisible; | |
64 |
|
65 | |||
65 | private: |
|
66 | private: | |
66 | Q_DECLARE_PUBLIC(QXYSeries) |
|
67 | Q_DECLARE_PUBLIC(QXYSeries) | |
67 | friend class QScatterSeries; |
|
68 | friend class QScatterSeries; | |
68 | }; |
|
69 | }; | |
69 |
|
70 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
72 | |||
72 | #endif |
|
73 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now