@@ -1,315 +1,312 | |||||
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 | #include <QLegendMarker> | |
|
32 | #include <QPieLegendMarker> | |||
32 |
|
33 | |||
33 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
34 | QTCOMMERCIALCHART_USE_NAMESPACE | |
34 |
|
35 | |||
35 | MainWidget::MainWidget(QWidget *parent) : |
|
36 | MainWidget::MainWidget(QWidget *parent) : | |
36 | QWidget(parent) |
|
37 | QWidget(parent) | |
37 | { |
|
38 | { | |
38 | // Create buttons for ui |
|
39 | // Create buttons for ui | |
39 | m_buttonLayout = new QGridLayout(); |
|
40 | m_buttonLayout = new QGridLayout(); | |
40 | QPushButton *detachLegendButton = new QPushButton("Toggle attached"); |
|
41 | QPushButton *detachLegendButton = new QPushButton("Toggle attached"); | |
41 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); |
|
42 | connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); | |
42 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); |
|
43 | m_buttonLayout->addWidget(detachLegendButton, 0, 0); | |
43 |
|
44 | |||
44 | QPushButton *addSliceButton = new QPushButton("add slice"); |
|
45 | QPushButton *addSliceButton = new QPushButton("add slice"); | |
45 | connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSlice())); |
|
46 | connect(addSliceButton, SIGNAL(clicked()), this, SLOT(addSlice())); | |
46 | m_buttonLayout->addWidget(addSliceButton, 2, 0); |
|
47 | m_buttonLayout->addWidget(addSliceButton, 2, 0); | |
47 | QPushButton *removeSliceButton = new QPushButton("remove slice"); |
|
48 | QPushButton *removeSliceButton = new QPushButton("remove slice"); | |
48 | connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
49 | connect(removeSliceButton, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
49 | m_buttonLayout->addWidget(removeSliceButton, 3, 0); |
|
50 | m_buttonLayout->addWidget(removeSliceButton, 3, 0); | |
50 |
|
51 | |||
51 | QPushButton *alignButton = new QPushButton("Align (Bottom)"); |
|
52 | QPushButton *alignButton = new QPushButton("Align (Bottom)"); | |
52 | connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); |
|
53 | connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); | |
53 | m_buttonLayout->addWidget(alignButton, 4, 0); |
|
54 | m_buttonLayout->addWidget(alignButton, 4, 0); | |
54 |
|
55 | |||
55 | QPushButton *boldButton = new QPushButton("Toggle bold"); |
|
56 | QPushButton *boldButton = new QPushButton("Toggle bold"); | |
56 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); |
|
57 | connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); | |
57 | m_buttonLayout->addWidget(boldButton, 5, 0); |
|
58 | m_buttonLayout->addWidget(boldButton, 5, 0); | |
58 |
|
59 | |||
59 | QPushButton *italicButton = new QPushButton("Toggle italic"); |
|
60 | QPushButton *italicButton = new QPushButton("Toggle italic"); | |
60 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); |
|
61 | connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); | |
61 | m_buttonLayout->addWidget(italicButton, 6, 0); |
|
62 | m_buttonLayout->addWidget(italicButton, 6, 0); | |
62 |
|
63 | |||
63 | QPushButton *infoButton = new QPushButton("Debug info"); |
|
64 | QPushButton *infoButton = new QPushButton("Debug info"); | |
64 | connect(infoButton, SIGNAL(clicked()), this, SLOT(showDebugInfo())); |
|
65 | connect(infoButton, SIGNAL(clicked()), this, SLOT(showDebugInfo())); | |
65 | m_buttonLayout->addWidget(infoButton, 7, 0); |
|
66 | m_buttonLayout->addWidget(infoButton, 7, 0); | |
66 |
|
67 | |||
67 | QPushButton *connectButton = new QPushButton("Connect markers"); |
|
68 | QPushButton *connectButton = new QPushButton("Connect markers"); | |
68 | connect(connectButton, SIGNAL(clicked()), this, SLOT(connectMarkers())); |
|
69 | connect(connectButton, SIGNAL(clicked()), this, SLOT(connectMarkers())); | |
69 | m_buttonLayout->addWidget(connectButton, 8, 0); |
|
70 | m_buttonLayout->addWidget(connectButton, 8, 0); | |
70 |
|
71 | |||
71 | QPushButton *disConnectButton = new QPushButton("Disconnect markers"); |
|
72 | QPushButton *disConnectButton = new QPushButton("Disconnect markers"); | |
72 | connect(disConnectButton, SIGNAL(clicked()), this, SLOT(disconnectMarkers())); |
|
73 | connect(disConnectButton, SIGNAL(clicked()), this, SLOT(disconnectMarkers())); | |
73 | m_buttonLayout->addWidget(disConnectButton, 9, 0); |
|
74 | m_buttonLayout->addWidget(disConnectButton, 9, 0); | |
74 |
|
75 | |||
75 |
|
76 | |||
76 | m_legendPosX = new QDoubleSpinBox(); |
|
77 | m_legendPosX = new QDoubleSpinBox(); | |
77 | m_legendPosY = new QDoubleSpinBox(); |
|
78 | m_legendPosY = new QDoubleSpinBox(); | |
78 | m_legendWidth = new QDoubleSpinBox(); |
|
79 | m_legendWidth = new QDoubleSpinBox(); | |
79 | m_legendHeight = new QDoubleSpinBox(); |
|
80 | m_legendHeight = new QDoubleSpinBox(); | |
80 |
|
81 | |||
81 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
82 | connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
82 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
83 | connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
83 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
84 | connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
84 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); |
|
85 | connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); | |
85 |
|
86 | |||
86 | QFormLayout* legendLayout = new QFormLayout(); |
|
87 | QFormLayout* legendLayout = new QFormLayout(); | |
87 | legendLayout->addRow("HPos", m_legendPosX); |
|
88 | legendLayout->addRow("HPos", m_legendPosX); | |
88 | legendLayout->addRow("VPos", m_legendPosY); |
|
89 | legendLayout->addRow("VPos", m_legendPosY); | |
89 | legendLayout->addRow("Width", m_legendWidth); |
|
90 | legendLayout->addRow("Width", m_legendWidth); | |
90 | legendLayout->addRow("Height", m_legendHeight); |
|
91 | legendLayout->addRow("Height", m_legendHeight); | |
91 | m_legendSettings = new QGroupBox("Detached legend"); |
|
92 | m_legendSettings = new QGroupBox("Detached legend"); | |
92 | m_legendSettings->setLayout(legendLayout); |
|
93 | m_legendSettings->setLayout(legendLayout); | |
93 | m_buttonLayout->addWidget(m_legendSettings); |
|
94 | m_buttonLayout->addWidget(m_legendSettings); | |
94 | m_legendSettings->setVisible(false); |
|
95 | m_legendSettings->setVisible(false); | |
95 |
|
96 | |||
96 | // Create chart view with the chart |
|
97 | // Create chart view with the chart | |
97 | m_chart = new QChart(); |
|
98 | m_chart = new QChart(); | |
98 | m_chartView = new QChartView(m_chart, this); |
|
99 | m_chartView = new QChartView(m_chart, this); | |
99 |
|
100 | |||
100 | // Create spinbox to modify font size |
|
101 | // Create spinbox to modify font size | |
101 | m_fontSize = new QDoubleSpinBox(); |
|
102 | m_fontSize = new QDoubleSpinBox(); | |
102 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); |
|
103 | m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); | |
103 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); |
|
104 | connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); | |
104 |
|
105 | |||
105 | QFormLayout* fontLayout = new QFormLayout(); |
|
106 | QFormLayout* fontLayout = new QFormLayout(); | |
106 | fontLayout->addRow("Legend font size", m_fontSize); |
|
107 | fontLayout->addRow("Legend font size", m_fontSize); | |
107 |
|
108 | |||
108 | // Create layout for grid and detached legend |
|
109 | // Create layout for grid and detached legend | |
109 | m_mainLayout = new QGridLayout(); |
|
110 | m_mainLayout = new QGridLayout(); | |
110 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); |
|
111 | m_mainLayout->addLayout(m_buttonLayout, 0, 0); | |
111 | m_mainLayout->addLayout(fontLayout,1,0); |
|
112 | m_mainLayout->addLayout(fontLayout,1,0); | |
112 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
113 | m_mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
113 | setLayout(m_mainLayout); |
|
114 | setLayout(m_mainLayout); | |
114 |
|
115 | |||
115 | createSeries(); |
|
116 | createSeries(); | |
116 | } |
|
117 | } | |
117 |
|
118 | |||
118 | void MainWidget::createSeries() |
|
119 | void MainWidget::createSeries() | |
119 | { |
|
120 | { | |
120 | m_series = new QPieSeries(); |
|
121 | m_series = new QPieSeries(); | |
121 | addSlice(); |
|
122 | addSlice(); | |
122 | addSlice(); |
|
123 | addSlice(); | |
123 | addSlice(); |
|
124 | addSlice(); | |
124 | addSlice(); |
|
125 | addSlice(); | |
125 |
|
126 | |||
126 | m_chart->addSeries(m_series); |
|
127 | m_chart->addSeries(m_series); | |
127 | m_chart->setTitle("Legend detach example"); |
|
128 | m_chart->setTitle("Legend detach example"); | |
128 | m_chart->createDefaultAxes(); |
|
129 | m_chart->createDefaultAxes(); | |
129 | //![1] |
|
130 | //![1] | |
130 | m_chart->legend()->setVisible(true); |
|
131 | m_chart->legend()->setVisible(true); | |
131 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
132 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
132 | //![1] |
|
133 | //![1] | |
133 |
|
134 | |||
134 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
135 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
135 | } |
|
136 | } | |
136 |
|
137 | |||
137 | void MainWidget::showLegendSpinbox() |
|
138 | void MainWidget::showLegendSpinbox() | |
138 | { |
|
139 | { | |
139 | m_legendSettings->setVisible(true); |
|
140 | m_legendSettings->setVisible(true); | |
140 | QRectF chartViewRect = m_chartView->rect(); |
|
141 | QRectF chartViewRect = m_chartView->rect(); | |
141 |
|
142 | |||
142 | m_legendPosX->setMinimum(0); |
|
143 | m_legendPosX->setMinimum(0); | |
143 | m_legendPosX->setMaximum(chartViewRect.width()); |
|
144 | m_legendPosX->setMaximum(chartViewRect.width()); | |
144 | m_legendPosX->setValue(150); |
|
145 | m_legendPosX->setValue(150); | |
145 |
|
146 | |||
146 | m_legendPosY->setMinimum(0); |
|
147 | m_legendPosY->setMinimum(0); | |
147 | m_legendPosY->setMaximum(chartViewRect.height()); |
|
148 | m_legendPosY->setMaximum(chartViewRect.height()); | |
148 | m_legendPosY->setValue(150); |
|
149 | m_legendPosY->setValue(150); | |
149 |
|
150 | |||
150 | m_legendWidth->setMinimum(0); |
|
151 | m_legendWidth->setMinimum(0); | |
151 | m_legendWidth->setMaximum(chartViewRect.width()); |
|
152 | m_legendWidth->setMaximum(chartViewRect.width()); | |
152 | m_legendWidth->setValue(150); |
|
153 | m_legendWidth->setValue(150); | |
153 |
|
154 | |||
154 | m_legendHeight->setMinimum(0); |
|
155 | m_legendHeight->setMinimum(0); | |
155 | m_legendHeight->setMaximum(chartViewRect.height()); |
|
156 | m_legendHeight->setMaximum(chartViewRect.height()); | |
156 | m_legendHeight->setValue(75); |
|
157 | m_legendHeight->setValue(75); | |
157 | } |
|
158 | } | |
158 |
|
159 | |||
159 | void MainWidget::hideLegendSpinbox() |
|
160 | void MainWidget::hideLegendSpinbox() | |
160 | { |
|
161 | { | |
161 | m_legendSettings->setVisible(false); |
|
162 | m_legendSettings->setVisible(false); | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 |
|
165 | |||
165 | void MainWidget::toggleAttached() |
|
166 | void MainWidget::toggleAttached() | |
166 | { |
|
167 | { | |
167 | QLegend *legend = m_chart->legend(); |
|
168 | QLegend *legend = m_chart->legend(); | |
168 | if (legend->isAttachedToChart()) { |
|
169 | if (legend->isAttachedToChart()) { | |
169 | //![2] |
|
170 | //![2] | |
170 | legend->detachFromChart(); |
|
171 | legend->detachFromChart(); | |
171 | m_chart->legend()->setBackgroundVisible(true); |
|
172 | m_chart->legend()->setBackgroundVisible(true); | |
172 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); |
|
173 | m_chart->legend()->setBrush(QBrush(QColor(128,128,128,128))); | |
173 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); |
|
174 | m_chart->legend()->setPen(QPen(QColor(192,192,192,192))); | |
174 | //![2] |
|
175 | //![2] | |
175 | showLegendSpinbox(); |
|
176 | showLegendSpinbox(); | |
176 | updateLegendLayout(); |
|
177 | updateLegendLayout(); | |
177 | } else { |
|
178 | } else { | |
178 | //![3] |
|
179 | //![3] | |
179 | legend->attachToChart(); |
|
180 | legend->attachToChart(); | |
180 | legend->setBackgroundVisible(false); |
|
181 | legend->setBackgroundVisible(false); | |
181 | //![3] |
|
182 | //![3] | |
182 | hideLegendSpinbox(); |
|
183 | hideLegendSpinbox(); | |
183 | } |
|
184 | } | |
184 | update(); |
|
185 | update(); | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | void MainWidget::addSlice() |
|
188 | void MainWidget::addSlice() | |
188 | { |
|
189 | { | |
189 | QPieSlice* slice = new QPieSlice(QString("slice " + QString::number(m_series->count())), m_series->count()+1); |
|
190 | QPieSlice* slice = new QPieSlice(QString("slice " + QString::number(m_series->count())), m_series->count()+1); | |
190 | m_series->append(slice); |
|
191 | m_series->append(slice); | |
191 | } |
|
192 | } | |
192 |
|
193 | |||
193 | void MainWidget::removeSlice() |
|
194 | void MainWidget::removeSlice() | |
194 | { |
|
195 | { | |
195 | QList<QPieSlice*> slices = m_series->slices(); |
|
196 | QList<QPieSlice*> slices = m_series->slices(); | |
196 | if (slices.count() > 0) { |
|
197 | if (slices.count() > 0) { | |
197 | m_series->remove(slices.at(slices.count()-1)); |
|
198 | m_series->remove(slices.at(slices.count()-1)); | |
198 | } |
|
199 | } | |
199 | } |
|
200 | } | |
200 |
|
201 | |||
201 | void MainWidget::connectMarkers() |
|
202 | void MainWidget::connectMarkers() | |
202 | { |
|
203 | { | |
203 | // Example use case. |
|
204 | // Example use case. | |
204 | // Explode slice via marker. |
|
205 | // Explode slice via marker. | |
205 | // Should be doable via public api. |
|
206 | // Should be doable via public api. | |
206 |
|
207 | |||
207 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { |
|
208 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { | |
208 | // Disconnect possible existing connection to avoid multiple connections |
|
209 | // Disconnect possible existing connection to avoid multiple connections | |
209 | QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); |
|
210 | QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); | |
210 | QObject::connect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); |
|
211 | QObject::connect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); | |
211 | } |
|
212 | } | |
212 | } |
|
213 | } | |
213 |
|
214 | |||
214 | void MainWidget::disconnectMarkers() |
|
215 | void MainWidget::disconnectMarkers() | |
215 | { |
|
216 | { | |
216 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { |
|
217 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { | |
217 | QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); |
|
218 | QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); | |
218 | } |
|
219 | } | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | void MainWidget::setLegendAlignment() |
|
222 | void MainWidget::setLegendAlignment() | |
222 | { |
|
223 | { | |
223 | QPushButton *button = qobject_cast<QPushButton *>(sender()); |
|
224 | QPushButton *button = qobject_cast<QPushButton *>(sender()); | |
224 |
|
225 | |||
225 | switch (m_chart->legend()->alignment()) { |
|
226 | switch (m_chart->legend()->alignment()) { | |
226 | case Qt::AlignTop: |
|
227 | case Qt::AlignTop: | |
227 | m_chart->legend()->setAlignment(Qt::AlignLeft); |
|
228 | m_chart->legend()->setAlignment(Qt::AlignLeft); | |
228 | if (button) |
|
229 | if (button) | |
229 | button->setText("Align (Left)"); |
|
230 | button->setText("Align (Left)"); | |
230 | break; |
|
231 | break; | |
231 | case Qt::AlignLeft: |
|
232 | case Qt::AlignLeft: | |
232 | m_chart->legend()->setAlignment(Qt::AlignBottom); |
|
233 | m_chart->legend()->setAlignment(Qt::AlignBottom); | |
233 | if (button) |
|
234 | if (button) | |
234 | button->setText("Align (Bottom)"); |
|
235 | button->setText("Align (Bottom)"); | |
235 | break; |
|
236 | break; | |
236 | case Qt::AlignBottom: |
|
237 | case Qt::AlignBottom: | |
237 | m_chart->legend()->setAlignment(Qt::AlignRight); |
|
238 | m_chart->legend()->setAlignment(Qt::AlignRight); | |
238 | if (button) |
|
239 | if (button) | |
239 | button->setText("Align (Right)"); |
|
240 | button->setText("Align (Right)"); | |
240 | break; |
|
241 | break; | |
241 | default: |
|
242 | default: | |
242 | if (button) |
|
243 | if (button) | |
243 | button->setText("Align (Top)"); |
|
244 | button->setText("Align (Top)"); | |
244 | m_chart->legend()->setAlignment(Qt::AlignTop); |
|
245 | m_chart->legend()->setAlignment(Qt::AlignTop); | |
245 | break; |
|
246 | break; | |
246 | } |
|
247 | } | |
247 | } |
|
248 | } | |
248 |
|
249 | |||
249 | void MainWidget::toggleBold() |
|
250 | void MainWidget::toggleBold() | |
250 | { |
|
251 | { | |
251 | QFont font = m_chart->legend()->font(); |
|
252 | QFont font = m_chart->legend()->font(); | |
252 | font.setBold(!font.bold()); |
|
253 | font.setBold(!font.bold()); | |
253 | m_chart->legend()->setFont(font); |
|
254 | m_chart->legend()->setFont(font); | |
254 | } |
|
255 | } | |
255 |
|
256 | |||
256 | void MainWidget::toggleItalic() |
|
257 | void MainWidget::toggleItalic() | |
257 | { |
|
258 | { | |
258 | QFont font = m_chart->legend()->font(); |
|
259 | QFont font = m_chart->legend()->font(); | |
259 | font.setItalic(!font.italic()); |
|
260 | font.setItalic(!font.italic()); | |
260 | m_chart->legend()->setFont(font); |
|
261 | m_chart->legend()->setFont(font); | |
261 | } |
|
262 | } | |
262 |
|
263 | |||
263 | void MainWidget::showDebugInfo() |
|
264 | void MainWidget::showDebugInfo() | |
264 | { |
|
265 | { | |
265 | qDebug() << "marker count:" << m_chart->legend()->markers().count(); |
|
266 | qDebug() << "marker count:" << m_chart->legend()->markers().count(); | |
266 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { |
|
267 | foreach (QLegendMarker* marker, m_chart->legend()->markers()) { | |
267 |
qDebug() << "marker |
|
268 | qDebug() << "marker type:" << marker->type(); | |
268 |
qDebug() << " |
|
269 | qDebug() << "related series:" << marker->series(); | |
269 | qDebug() << "label:" << marker->label(); |
|
|||
270 | } |
|
270 | } | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void MainWidget::fontSizeChanged() |
|
273 | void MainWidget::fontSizeChanged() | |
274 | { |
|
274 | { | |
275 | QFont font = m_chart->legend()->font(); |
|
275 | QFont font = m_chart->legend()->font(); | |
276 | font.setPointSizeF(m_fontSize->value()); |
|
276 | font.setPointSizeF(m_fontSize->value()); | |
277 | m_chart->legend()->setFont(font); |
|
277 | m_chart->legend()->setFont(font); | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | void MainWidget::updateLegendLayout() |
|
280 | void MainWidget::updateLegendLayout() | |
281 | { |
|
281 | { | |
282 | //![4] |
|
282 | //![4] | |
283 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() |
|
283 | m_chart->legend()->setGeometry(QRectF(m_legendPosX->value() | |
284 | ,m_legendPosY->value() |
|
284 | ,m_legendPosY->value() | |
285 | ,m_legendWidth->value() |
|
285 | ,m_legendWidth->value() | |
286 | ,m_legendHeight->value())); |
|
286 | ,m_legendHeight->value())); | |
287 | m_chart->legend()->update(); |
|
287 | m_chart->legend()->update(); | |
288 | //![4] |
|
288 | //![4] | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void MainWidget::handleMarkerClicked() |
|
291 | void MainWidget::handleMarkerClicked() | |
292 | { |
|
292 | { | |
293 | QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender()); |
|
293 | QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender()); | |
|
294 | Q_ASSERT(marker); | |||
294 |
|
295 | |||
295 | qDebug() << "marker clicked:" << marker; |
|
296 | switch (marker->type()) | |
296 |
|
||||
297 | switch (marker->series()->type()) |
|
|||
298 | { |
|
297 | { | |
299 |
case Q |
|
298 | case QLegendMarker::LegendMarkerTypePie: | |
300 | { |
|
299 | { | |
301 | // Series type is pie. |
|
300 | QPieLegendMarker *pieMarker = qobject_cast<QPieLegendMarker *> (marker); | |
302 | // The peer object is QPieSlice |
|
301 | QPieSlice* slice = pieMarker->slice(); | |
303 | QPieSlice* slice = qobject_cast<QPieSlice*> (marker->peerObject()); |
|
|||
304 | Q_ASSERT(slice); |
|
|||
305 | slice->setExploded(!slice->isExploded()); |
|
302 | slice->setExploded(!slice->isExploded()); | |
306 | break; |
|
303 | break; | |
307 | } |
|
304 | } | |
308 | default: |
|
305 | default: | |
309 | { |
|
306 | { | |
310 |
qDebug() << "Unknown |
|
307 | qDebug() << "Unknown marker type"; | |
311 | break; |
|
308 | break; | |
312 | } |
|
309 | } | |
313 | } |
|
310 | } | |
314 |
|
311 | |||
315 | } |
|
312 | } |
@@ -1,85 +1,79 | |||||
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 "qarealegendmarker.h" |
|
21 | #include "qarealegendmarker.h" | |
22 | #include "qarealegendmarker_p.h" |
|
22 | #include "qarealegendmarker_p.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include <QAreaSeries> |
|
24 | #include <QAreaSeries> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QAreaLegendMarker::~QAreaLegendMarker() |
|
34 | QAreaLegendMarker::~QAreaLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting Area marker" << this; |
|
36 | // qDebug() << "deleting Area marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAreaSeries* QAreaLegendMarker::series() |
|
47 | QAreaSeries* QAreaLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QAreaLegendMarker); |
|
49 | Q_D(QAreaLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QAreaSeries* QAreaLegendMarker::peerObject() |
|
|||
54 | { |
|
|||
55 | Q_D(QAreaLegendMarker); |
|
|||
56 | return d->m_series; |
|
|||
57 | } |
|
|||
58 |
|
||||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
54 | |||
61 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
|
55 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series) |
|
57 | m_series(series) | |
64 | { |
|
58 | { | |
65 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
66 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
67 | updated(); |
|
61 | updated(); | |
68 | } |
|
62 | } | |
69 |
|
63 | |||
70 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
|
64 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() | |
71 | { |
|
65 | { | |
72 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
66 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
73 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
74 | } |
|
68 | } | |
75 |
|
69 | |||
76 | void QAreaLegendMarkerPrivate::updated() |
|
70 | void QAreaLegendMarkerPrivate::updated() | |
77 | { |
|
71 | { | |
78 | m_item->setBrush(m_series->brush()); |
|
72 | m_item->setBrush(m_series->brush()); | |
79 | m_item->setLabel(m_series->name()); |
|
73 | m_item->setLabel(m_series->name()); | |
80 | } |
|
74 | } | |
81 |
|
75 | |||
82 | #include "moc_qarealegendmarker.cpp" |
|
76 | #include "moc_qarealegendmarker.cpp" | |
83 | #include "moc_qarealegendmarker_p.cpp" |
|
77 | #include "moc_qarealegendmarker_p.cpp" | |
84 |
|
78 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
79 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,57 | |||||
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 QAREALEGENDMARKER_H |
|
21 | #ifndef QAREALEGENDMARKER_H | |
22 | #define QAREALEGENDMARKER_H |
|
22 | #define QAREALEGENDMARKER_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QLegendMarker> |
|
25 | #include <QLegendMarker> | |
26 | #include <QAreaSeries> |
|
26 | #include <QAreaSeries> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QAreaLegendMarkerPrivate; |
|
30 | class QAreaLegendMarkerPrivate; | |
31 |
|
31 | |||
32 | // TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?) |
|
32 | // TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?) | |
33 | class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker |
|
33 | class QTCOMMERCIALCHART_EXPORT QAreaLegendMarker : public QLegendMarker | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 |
|
36 | |||
37 | public: |
|
37 | public: | |
38 | explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0); |
|
38 | explicit QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent = 0); | |
39 | virtual ~QAreaLegendMarker(); |
|
39 | virtual ~QAreaLegendMarker(); | |
40 |
|
40 | |||
41 | virtual QAreaSeries* series(); |
|
41 | virtual LegendMarkerType type() { return LegendMarkerTypeArea; } | |
42 | virtual QAreaSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class? |
|
42 | ||
|
43 | // Related series | |||
|
44 | QAreaSeries* series(); | |||
43 |
|
45 | |||
44 | protected: |
|
46 | protected: | |
45 | QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0); |
|
47 | QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent = 0); | |
46 |
|
48 | |||
47 | //Q_SIGNALS: |
|
|||
48 |
|
||||
49 | //public Q_SLOTS: |
|
|||
50 |
|
||||
51 | private: |
|
49 | private: | |
52 | Q_DECLARE_PRIVATE(QAreaLegendMarker) |
|
50 | Q_DECLARE_PRIVATE(QAreaLegendMarker) | |
53 | Q_DISABLE_COPY(QAreaLegendMarker) |
|
51 | Q_DISABLE_COPY(QAreaLegendMarker) | |
54 |
|
52 | |||
55 | }; |
|
53 | }; | |
56 |
|
54 | |||
57 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
58 |
|
56 | |||
59 | #endif // QAREALEGENDMARKER_H |
|
57 | #endif // QAREALEGENDMARKER_H |
@@ -1,90 +1,90 | |||||
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 "qbarlegendmarker.h" |
|
21 | #include "qbarlegendmarker.h" | |
22 | #include "qbarlegendmarker_p.h" |
|
22 | #include "qbarlegendmarker_p.h" | |
23 | #include <QAbstractBarSeries> |
|
23 | #include <QAbstractBarSeries> | |
24 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : |
|
29 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) |
|
30 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QBarLegendMarker::~QBarLegendMarker() |
|
34 | QBarLegendMarker::~QBarLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting bar marker" << this; |
|
36 | // qDebug() << "deleting bar marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAbstractBarSeries *QBarLegendMarker::series() |
|
47 | QAbstractBarSeries *QBarLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QBarLegendMarker); |
|
49 | Q_D(QBarLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
QBarSet* QBarLegendMarker:: |
|
53 | QBarSet* QBarLegendMarker::barset() | |
54 | { |
|
54 | { | |
55 | Q_D(QBarLegendMarker); |
|
55 | Q_D(QBarLegendMarker); | |
56 | return d->m_barset; |
|
56 | return d->m_barset; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : |
|
61 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_barset(barset) |
|
64 | m_barset(barset) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() |
|
72 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
74 | QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); | |
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
75 | QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); | |
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); |
|
76 | QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void QBarLegendMarkerPrivate::updated() |
|
79 | void QBarLegendMarkerPrivate::updated() | |
80 | { |
|
80 | { | |
81 | m_item->setPen(m_barset->pen()); |
|
81 | m_item->setPen(m_barset->pen()); | |
82 | m_item->setBrush(m_barset->brush()); |
|
82 | m_item->setBrush(m_barset->brush()); | |
83 | m_item->setLabel(m_barset->label()); |
|
83 | m_item->setLabel(m_barset->label()); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | #include "moc_qbarlegendmarker.cpp" |
|
86 | #include "moc_qbarlegendmarker.cpp" | |
87 | #include "moc_qbarlegendmarker_p.cpp" |
|
87 | #include "moc_qbarlegendmarker_p.cpp" | |
88 |
|
88 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
90 |
@@ -1,58 +1,57 | |||||
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 | #ifndef QBARLEGENDMARKER_H |
|
20 | #ifndef QBARLEGENDMARKER_H | |
21 | #define QBARLEGENDMARKER_H |
|
21 | #define QBARLEGENDMARKER_H | |
22 |
|
22 | |||
23 | #include <QChartGlobal> |
|
23 | #include <QChartGlobal> | |
24 | #include <QLegendMarker> |
|
24 | #include <QLegendMarker> | |
25 | #include <QAbstractBarSeries> |
|
25 | #include <QAbstractBarSeries> | |
26 | #include <QBarSet> |
|
26 | #include <QBarSet> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QLegend; |
|
30 | class QLegend; | |
31 | class QBarLegendMarkerPrivate; |
|
31 | class QBarLegendMarkerPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker |
|
33 | class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | public: |
|
36 | public: | |
37 | explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0); |
|
37 | explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0); | |
38 | virtual ~QBarLegendMarker(); |
|
38 | virtual ~QBarLegendMarker(); | |
39 |
|
39 | |||
40 | virtual QAbstractBarSeries* series(); |
|
40 | virtual LegendMarkerType type() { return LegendMarkerTypeBar; } | |
41 | virtual QBarSet* peerObject(); // TODO: rename to slice and remove these virtuals from base class? |
|
41 | ||
|
42 | // Related series and barset | |||
|
43 | QAbstractBarSeries* series(); | |||
|
44 | QBarSet* barset(); | |||
42 |
|
45 | |||
43 | protected: |
|
46 | protected: | |
44 | QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0); |
|
47 | QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0); | |
45 |
|
48 | |||
46 | //Q_SIGNALS: |
|
|||
47 |
|
||||
48 | //public Q_SLOTS: |
|
|||
49 |
|
||||
50 | private: |
|
49 | private: | |
51 | Q_DECLARE_PRIVATE(QBarLegendMarker) |
|
50 | Q_DECLARE_PRIVATE(QBarLegendMarker) | |
52 | Q_DISABLE_COPY(QBarLegendMarker) |
|
51 | Q_DISABLE_COPY(QBarLegendMarker) | |
53 |
|
52 | |||
54 | }; |
|
53 | }; | |
55 |
|
54 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
57 |
|
56 | |||
58 | #endif // QBARLEGENDMARKER_H |
|
57 | #endif // QBARLEGENDMARKER_H |
@@ -1,89 +1,91 | |||||
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 | #include <QFont> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QLegendMarkerPrivate; |
|
32 | class QLegendMarkerPrivate; | |
33 | class QAbstractSeries; |
|
33 | class QAbstractSeries; | |
34 | class QLegend; |
|
34 | class QLegend; | |
35 |
|
35 | |||
36 | // TODO: should this be QAbstractLegendMarker? |
|
|||
37 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject |
|
36 | class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject | |
38 | { |
|
37 | { | |
39 | Q_OBJECT |
|
38 | Q_OBJECT | |
40 |
|
39 | |||
41 | // TODO: need for these? |
|
40 | enum LegendMarkerType { | |
|
41 | LegendMarkerTypeArea, | |||
|
42 | LegendMarkerTypeBar, | |||
|
43 | LegendMarkerTypePie, | |||
|
44 | LegendMarkerTypeXY | |||
|
45 | }; | |||
|
46 | ||||
|
47 | // TODO: | |||
42 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); |
|
48 | // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); | |
43 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); |
|
49 | // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); | |
44 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); |
|
50 | // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); | |
45 |
|
51 | |||
46 | public: |
|
52 | public: | |
47 | // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0); |
|
|||
48 | virtual ~QLegendMarker(); |
|
53 | virtual ~QLegendMarker(); | |
|
54 | virtual LegendMarkerType type() = 0; | |||
49 |
|
55 | |||
50 | QString label() const; |
|
56 | QString label() const; | |
51 | void setLabel(const QString &label); |
|
57 | void setLabel(const QString &label); | |
52 |
|
58 | |||
53 | QBrush labelBrush() const; |
|
59 | QBrush labelBrush() const; | |
54 | void setLabelBrush(const QBrush &brush); |
|
60 | void setLabelBrush(const QBrush &brush); | |
55 |
|
61 | |||
56 | QFont font() const; |
|
62 | QFont font() const; | |
57 | void setFont(const QFont &font); |
|
63 | void setFont(const QFont &font); | |
58 |
|
64 | |||
59 | QPen pen() const; |
|
65 | QPen pen() const; | |
60 | void setPen(const QPen &pen); |
|
66 | void setPen(const QPen &pen); | |
61 |
|
67 | |||
62 | QBrush brush() const; |
|
68 | QBrush brush() const; | |
63 | void setBrush(const QBrush &brush); |
|
69 | void setBrush(const QBrush &brush); | |
64 |
|
70 | |||
65 | bool isVisible() const; |
|
71 | bool isVisible() const; | |
66 | void setVisible(bool visible); |
|
72 | void setVisible(bool visible); | |
67 |
|
73 | |||
68 | // virtual QAbstractSeries::SeriesType type() = 0; // TODO? Or use LegendMarker type enum? |
|
|||
69 | virtual QAbstractSeries* series() = 0; // TODO: remove these and use specialised functions on derived classes? |
|
|||
70 | virtual QObject* peerObject() = 0; |
|
|||
71 |
|
||||
72 | protected: |
|
74 | protected: | |
73 | explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0); |
|
75 | explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0); | |
74 |
|
76 | |||
75 | Q_SIGNALS: |
|
77 | Q_SIGNALS: | |
76 | void clicked(); |
|
78 | void clicked(); | |
77 | void hovered(bool status); |
|
79 | void hovered(bool status); | |
78 |
|
80 | |||
79 | protected: |
|
81 | protected: | |
80 | QScopedPointer<QLegendMarkerPrivate> d_ptr; |
|
82 | QScopedPointer<QLegendMarkerPrivate> d_ptr; | |
81 | Q_DISABLE_COPY(QLegendMarker) |
|
83 | Q_DISABLE_COPY(QLegendMarker) | |
82 | friend class QLegendPrivate; |
|
84 | friend class QLegendPrivate; | |
83 | friend class QLegendMarkerPrivate; |
|
85 | friend class QLegendMarkerPrivate; | |
84 | friend class LegendLayout; |
|
86 | friend class LegendLayout; | |
85 | }; |
|
87 | }; | |
86 |
|
88 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE | |
88 |
|
90 | |||
89 | #endif // QLEGENDMARKER_H |
|
91 | #endif // QLEGENDMARKER_H |
@@ -1,89 +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 | #include "qpielegendmarker.h" |
|
21 | #include "qpielegendmarker.h" | |
22 | #include "qpielegendmarker_p.h" |
|
22 | #include "qpielegendmarker_p.h" | |
23 | #include <QPieSeries> |
|
23 | #include <QPieSeries> | |
24 | #include <QPieSlice> |
|
24 | #include <QPieSlice> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : |
|
29 | QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) |
|
30 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QPieLegendMarker::~QPieLegendMarker() |
|
34 | QPieLegendMarker::~QPieLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting pie marker" << this; |
|
36 | // qDebug() << "deleting pie marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QPieSeries* QPieLegendMarker::series() |
|
47 | QPieSeries* QPieLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QPieLegendMarker); |
|
49 | Q_D(QPieLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 |
QPieSlice* QPieLegendMarker:: |
|
53 | QPieSlice* QPieLegendMarker::slice() | |
54 | { |
|
54 | { | |
55 | Q_D(QPieLegendMarker); |
|
55 | Q_D(QPieLegendMarker); | |
56 | return d->m_slice; |
|
56 | return d->m_slice; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : |
|
61 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series), |
|
63 | m_series(series), | |
64 | m_slice(slice) |
|
64 | m_slice(slice) | |
65 | { |
|
65 | { | |
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
66 | QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
68 | QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
69 | updated(); |
|
69 | updated(); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() |
|
72 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() | |
73 | { |
|
73 | { | |
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
74 | QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
75 | QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); |
|
76 | QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void QPieLegendMarkerPrivate::updated() |
|
79 | void QPieLegendMarkerPrivate::updated() | |
80 | { |
|
80 | { | |
81 | m_item->setPen(m_slice->pen()); |
|
81 | m_item->setPen(m_slice->pen()); | |
82 | m_item->setBrush(m_slice->brush()); |
|
82 | m_item->setBrush(m_slice->brush()); | |
83 | m_item->setLabel(m_slice->label()); |
|
83 | m_item->setLabel(m_slice->label()); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | #include "moc_qpielegendmarker.cpp" |
|
86 | #include "moc_qpielegendmarker.cpp" | |
87 | #include "moc_qpielegendmarker_p.cpp" |
|
87 | #include "moc_qpielegendmarker_p.cpp" | |
88 |
|
88 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
89 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,59 +1,58 | |||||
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 <QPieSeries> |
|
26 | #include <QPieSeries> | |
27 | #include <QPieSlice> |
|
27 | #include <QPieSlice> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QPieLegendMarkerPrivate; |
|
31 | class QPieLegendMarkerPrivate; | |
32 |
|
32 | |||
33 | // TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?) |
|
33 | // TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?) | |
34 | class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker |
|
34 | class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0); |
|
39 | explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0); | |
40 | virtual ~QPieLegendMarker(); |
|
40 | virtual ~QPieLegendMarker(); | |
41 |
|
41 | |||
42 | virtual QPieSeries* series(); |
|
42 | virtual LegendMarkerType type() { return LegendMarkerTypePie; } | |
43 | virtual QPieSlice* peerObject(); // TODO: rename to slice and remove these virtuals from base class? |
|
43 | ||
|
44 | // Related series and slice | |||
|
45 | QPieSeries* series(); | |||
|
46 | QPieSlice* slice(); | |||
44 |
|
47 | |||
45 | protected: |
|
48 | protected: | |
46 | QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0); |
|
49 | QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0); | |
47 |
|
50 | |||
48 | //Q_SIGNALS: |
|
|||
49 |
|
||||
50 | //public Q_SLOTS: |
|
|||
51 |
|
||||
52 | private: |
|
51 | private: | |
53 | Q_DECLARE_PRIVATE(QPieLegendMarker) |
|
52 | Q_DECLARE_PRIVATE(QPieLegendMarker) | |
54 | Q_DISABLE_COPY(QPieLegendMarker) |
|
53 | Q_DISABLE_COPY(QPieLegendMarker) | |
55 |
|
54 | |||
56 | }; |
|
55 | }; | |
57 |
|
56 | |||
58 | QTCOMMERCIALCHART_END_NAMESPACE |
|
57 | QTCOMMERCIALCHART_END_NAMESPACE | |
59 | #endif // QPIELEGENDMARKER_H |
|
58 | #endif // QPIELEGENDMARKER_H |
@@ -1,91 +1,85 | |||||
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 "qxylegendmarker.h" |
|
21 | #include "qxylegendmarker.h" | |
22 | #include "qxylegendmarker_p.h" |
|
22 | #include "qxylegendmarker_p.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include <QXYSeries> |
|
24 | #include <QXYSeries> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QXYLegendMarker::~QXYLegendMarker() |
|
34 | QXYLegendMarker::~QXYLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting xy marker" << this; |
|
36 | // qDebug() << "deleting xy marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QXYSeries* QXYLegendMarker::series() |
|
47 | QXYSeries* QXYLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QXYLegendMarker); |
|
49 | Q_D(QXYLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QXYSeries* QXYLegendMarker::peerObject() |
|
|||
54 | { |
|
|||
55 | Q_D(QXYLegendMarker); |
|
|||
56 | return d->m_series; |
|
|||
57 | } |
|
|||
58 |
|
||||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
54 | |||
61 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : |
|
55 | QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
56 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series) |
|
57 | m_series(series) | |
64 | { |
|
58 | { | |
65 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
59 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
66 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
60 | QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
67 | updated(); |
|
61 | updated(); | |
68 | } |
|
62 | } | |
69 |
|
63 | |||
70 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() |
|
64 | QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() | |
71 | { |
|
65 | { | |
72 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); |
|
66 | QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); | |
73 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
67 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
74 | } |
|
68 | } | |
75 |
|
69 | |||
76 | void QXYLegendMarkerPrivate::updated() |
|
70 | void QXYLegendMarkerPrivate::updated() | |
77 | { |
|
71 | { | |
78 | m_item->setLabel(m_series->name()); |
|
72 | m_item->setLabel(m_series->name()); | |
79 |
|
73 | |||
80 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { |
|
74 | if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { | |
81 | m_item->setBrush(m_series->brush()); |
|
75 | m_item->setBrush(m_series->brush()); | |
82 | } else { |
|
76 | } else { | |
83 | m_item->setBrush(QBrush(m_series->pen().color())); |
|
77 | m_item->setBrush(QBrush(m_series->pen().color())); | |
84 | } |
|
78 | } | |
85 | } |
|
79 | } | |
86 |
|
80 | |||
87 | #include "moc_qxylegendmarker.cpp" |
|
81 | #include "moc_qxylegendmarker.cpp" | |
88 | #include "moc_qxylegendmarker_p.cpp" |
|
82 | #include "moc_qxylegendmarker_p.cpp" | |
89 |
|
83 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
85 |
@@ -1,57 +1,55 | |||||
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 QXYLEGENDMARKER_H |
|
21 | #ifndef QXYLEGENDMARKER_H | |
22 | #define QXYLEGENDMARKER_H |
|
22 | #define QXYLEGENDMARKER_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QLegendMarker> |
|
25 | #include <QLegendMarker> | |
26 | #include <QXYSeries> |
|
26 | #include <QXYSeries> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | class QXYLegendMarkerPrivate; |
|
30 | class QXYLegendMarkerPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker |
|
32 | class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0); |
|
36 | explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0); | |
37 | virtual ~QXYLegendMarker(); |
|
37 | virtual ~QXYLegendMarker(); | |
38 |
|
38 | |||
39 | virtual QXYSeries* series(); |
|
39 | virtual LegendMarkerType type() { return LegendMarkerTypeXY; } | |
40 | virtual QXYSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class? |
|
40 | ||
|
41 | // Related series | |||
|
42 | QXYSeries* series(); | |||
41 |
|
43 | |||
42 | protected: |
|
44 | protected: | |
43 | QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0); |
|
45 | QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0); | |
44 |
|
46 | |||
45 | //Q_SIGNALS: |
|
|||
46 |
|
||||
47 | //public Q_SLOTS: |
|
|||
48 |
|
||||
49 | private: |
|
47 | private: | |
50 | Q_DECLARE_PRIVATE(QXYLegendMarker) |
|
48 | Q_DECLARE_PRIVATE(QXYLegendMarker) | |
51 | Q_DISABLE_COPY(QXYLegendMarker) |
|
49 | Q_DISABLE_COPY(QXYLegendMarker) | |
52 |
|
50 | |||
53 | }; |
|
51 | }; | |
54 |
|
52 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
54 | |||
57 | #endif // QXYLEGENDMARKER_H |
|
55 | #endif // QXYLEGENDMARKER_H |
General Comments 0
You need to be logged in to leave comments.
Login now