##// END OF EJS Templates
Adding more controls to piechartcustomization demo
Jani Honkonen -
r511:6c936a9996d6
parent child
Show More
@@ -11,6 +11,8
11 #include <QCheckBox>
11 #include <QCheckBox>
12 #include <QGroupBox>
12 #include <QGroupBox>
13 #include <QLabel>
13 #include <QLabel>
14 #include <QPushButton>
15 #include <QColorDialog>
14
16
15 QTCOMMERCIALCHART_USE_NAMESPACE
17 QTCOMMERCIALCHART_USE_NAMESPACE
16
18
@@ -25,6 +27,12 public:
25 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
27 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
26 }
28 }
27
29
30 public:
31 QBrush originalBrush()
32 {
33 return m_originalBrush;
34 }
35
28 public Q_SLOTS:
36 public Q_SLOTS:
29
37
30 void handleHoverEnter()
38 void handleHoverEnter()
@@ -53,11 +61,11 public:
53 :QWidget(parent),
61 :QWidget(parent),
54 m_slice(0)
62 m_slice(0)
55 {
63 {
64 // create chart
56 m_chartView = new QChartView();
65 m_chartView = new QChartView();
57 m_chartView->setChartTitle("Piechart customization");
66 m_chartView->setChartTitle("Piechart customization");
58 m_chartView->setRenderHint(QPainter::Antialiasing);
59 m_chartView->setChartTheme(QChart::ChartThemeIcy);
60
67
68 // create series
61 m_series = new QPieSeries();
69 m_series = new QPieSeries();
62 *m_series << new CustomSlice(10.0, "Slice 1");
70 *m_series << new CustomSlice(10.0, "Slice 1");
63 *m_series << new CustomSlice(20.0, "Slice 2");
71 *m_series << new CustomSlice(20.0, "Slice 2");
@@ -66,6 +74,28 public:
66 *m_series << new CustomSlice(50.0, "Slice 5");
74 *m_series << new CustomSlice(50.0, "Slice 5");
67 m_chartView->addSeries(m_series);
75 m_chartView->addSeries(m_series);
68
76
77 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
78
79 // chart settings
80 m_themeComboBox = new QComboBox();
81 m_themeComboBox->addItem("Default", QChart::ChartThemeDefault);
82 m_themeComboBox->addItem("Vanilla", QChart::ChartThemeVanilla);
83 m_themeComboBox->addItem("Icy", QChart::ChartThemeIcy);
84 m_themeComboBox->addItem("Grayscale", QChart::ChartThemeGrayscale);
85 m_themeComboBox->addItem("Scientific", QChart::ChartThemeScientific);
86
87 m_aaCheckBox = new QCheckBox();
88
89 QFormLayout* chartSettingsLayout = new QFormLayout();
90 chartSettingsLayout->addRow("Theme", m_themeComboBox);
91 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
92 QGroupBox* chartSettings = new QGroupBox("Chart");
93 chartSettings->setLayout(chartSettingsLayout);
94
95 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
96 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
97
98 // series settings
69 m_hPosition = new QDoubleSpinBox();
99 m_hPosition = new QDoubleSpinBox();
70 m_hPosition->setMinimum(0.0);
100 m_hPosition->setMinimum(0.0);
71 m_hPosition->setMaximum(1.0);
101 m_hPosition->setMaximum(1.0);
@@ -105,6 +135,13 public:
105 QGroupBox* seriesSettings = new QGroupBox("Series");
135 QGroupBox* seriesSettings = new QGroupBox("Series");
106 seriesSettings->setLayout(seriesSettingsLayout);
136 seriesSettings->setLayout(seriesSettingsLayout);
107
137
138 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
139 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
140 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
141 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
142 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
143
144 // slice settings
108 m_sliceName = new QLabel("<click a slice>");
145 m_sliceName = new QLabel("<click a slice>");
109 m_sliceValue = new QDoubleSpinBox();
146 m_sliceValue = new QDoubleSpinBox();
110 m_sliceValue->setMaximum(1000);
147 m_sliceValue->setMaximum(1000);
@@ -114,43 +151,58 public:
114 m_sliceExploded = new QCheckBox();
151 m_sliceExploded = new QCheckBox();
115 m_sliceExplodedFactor = new QDoubleSpinBox();
152 m_sliceExplodedFactor = new QDoubleSpinBox();
116 m_sliceExplodedFactor->setSingleStep(0.01);
153 m_sliceExplodedFactor->setSingleStep(0.01);
154 m_penWidth = new QDoubleSpinBox();
155 m_penColor = new QPushButton();
156 m_brushColor = new QPushButton();
117
157
118 QFormLayout* sliceSettingsLayout = new QFormLayout();
158 QFormLayout* sliceSettingsLayout = new QFormLayout();
119 sliceSettingsLayout->addRow("Selected", m_sliceName);
159 sliceSettingsLayout->addRow("Selected", m_sliceName);
120 sliceSettingsLayout->addRow("Value", m_sliceValue);
160 sliceSettingsLayout->addRow("Value", m_sliceValue);
161 sliceSettingsLayout->addRow("Pen color", m_penColor);
162 sliceSettingsLayout->addRow("Pen width", m_penWidth);
163 sliceSettingsLayout->addRow("Brush color", m_brushColor);
121 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
164 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
122 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
165 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
123 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
166 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
124 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
167 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
125
168
169
126 QGroupBox* sliceSettings = new QGroupBox("Slice");
170 QGroupBox* sliceSettings = new QGroupBox("Slice");
127 sliceSettings->setLayout(sliceSettingsLayout);
171 sliceSettings->setLayout(sliceSettingsLayout);
128
172
129 QGridLayout* baseLayout = new QGridLayout();
130 baseLayout->addWidget(seriesSettings, 0, 0);
131 baseLayout->addWidget(sliceSettings, 1, 0);
132 baseLayout->addWidget(m_chartView, 0, 1, 2, 1);
133 setLayout(baseLayout);
134
135 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
138 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
139 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
140
141 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
173 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
174 connect(m_penColor, SIGNAL(clicked()), this, SLOT(showPenColorDialog()));
175 connect(m_penWidth, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
176 connect(m_brushColor, SIGNAL(clicked()), this, SLOT(showBrushColorDialog()));
142 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
177 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
143 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
178 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
144 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
179 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
145 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
180 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
146
181
147 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
182 // create main layout
183 QVBoxLayout *settingsLayout = new QVBoxLayout();
184 settingsLayout->addWidget(chartSettings);
185 settingsLayout->addWidget(seriesSettings);
186 settingsLayout->addWidget(sliceSettings);
187 settingsLayout->addStretch();
188
189 QGridLayout* baseLayout = new QGridLayout();
190 baseLayout->addLayout(settingsLayout, 0, 0);
191 baseLayout->addWidget(m_chartView, 0, 1);
192 setLayout(baseLayout);
148
193
149 updateSerieSettings();
194 updateSerieSettings();
150 }
195 }
151
196
152 public Q_SLOTS:
197 public Q_SLOTS:
153
198
199 void updateChartSettings()
200 {
201 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
202 m_chartView->setChartTheme(theme);
203 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
204 }
205
154 void updateSerieSettings()
206 void updateSerieSettings()
155 {
207 {
156 m_series->setPiePosition(m_vPosition->value(), m_hPosition->value());
208 m_series->setPiePosition(m_vPosition->value(), m_hPosition->value());
@@ -165,21 +217,36 public Q_SLOTS:
165 return;
217 return;
166
218
167 m_slice->setValue(m_sliceValue->value());
219 m_slice->setValue(m_sliceValue->value());
220
221 QPen pen = m_slice->slicePen();
222 pen.setWidthF(m_penWidth->value());
223 m_slice->setSlicePen(pen);
224
168 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
225 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
169 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
226 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
227
170 m_slice->setExploded(m_sliceExploded->isChecked());
228 m_slice->setExploded(m_sliceExploded->isChecked());
171 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
229 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
172 }
230 }
173
231
174 void handleSliceClicked(QPieSlice* slice)
232 void handleSliceClicked(QPieSlice* slice)
175 {
233 {
176 m_slice = slice;
234 m_slice = static_cast<CustomSlice*>(slice);
235
177 m_sliceName->setText(slice->label());
236 m_sliceName->setText(slice->label());
178
237
179 m_sliceValue->blockSignals(true);
238 m_sliceValue->blockSignals(true);
180 m_sliceValue->setValue(slice->value());
239 m_sliceValue->setValue(slice->value());
181 m_sliceValue->blockSignals(false);
240 m_sliceValue->blockSignals(false);
182
241
242 m_penColor->setText(m_slice->slicePen().color().name());
243
244 m_sliceValue->blockSignals(true);
245 m_penWidth->setValue(slice->slicePen().widthF());
246 m_sliceValue->blockSignals(false);
247
248 m_brushColor->setText(m_slice->originalBrush().color().name());
249
183 m_sliceLabelVisible->blockSignals(true);
250 m_sliceLabelVisible->blockSignals(true);
184 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
251 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
185 m_sliceLabelVisible->blockSignals(false);
252 m_sliceLabelVisible->blockSignals(false);
@@ -197,10 +264,45 public Q_SLOTS:
197 m_sliceExplodedFactor->blockSignals(false);
264 m_sliceExplodedFactor->blockSignals(false);
198 }
265 }
199
266
267 void showBrushColorDialog()
268 {
269 if (!m_slice)
270 return;
271
272 QColorDialog dialog(m_slice->originalBrush().color());
273 dialog.show();
274 dialog.exec();
275
276 QBrush brush = m_slice->originalBrush();
277 brush.setColor(dialog.currentColor());
278 m_slice->setSliceBrush(brush);
279
280 m_brushColor->setText(dialog.currentColor().name());
281 }
282
283 void showPenColorDialog()
284 {
285 if (!m_slice)
286 return;
287
288 QColorDialog dialog(m_slice->slicePen().color());
289 dialog.show();
290 dialog.exec();
291
292 QPen pen = m_slice->slicePen();
293 pen.setColor(dialog.currentColor());
294 m_slice->setSlicePen(pen);
295
296 m_penColor->setText(dialog.currentColor().name());
297 }
298
200 private:
299 private:
300 QComboBox *m_themeComboBox;
301 QCheckBox *m_aaCheckBox;
302
201 QChartView* m_chartView;
303 QChartView* m_chartView;
202 QPieSeries* m_series;
304 QPieSeries* m_series;
203 QPieSlice* m_slice;
305 CustomSlice* m_slice;
204
306
205 QDoubleSpinBox* m_hPosition;
307 QDoubleSpinBox* m_hPosition;
206 QDoubleSpinBox* m_vPosition;
308 QDoubleSpinBox* m_vPosition;
@@ -214,6 +316,9 private:
214 QDoubleSpinBox* m_sliceLabelArmFactor;
316 QDoubleSpinBox* m_sliceLabelArmFactor;
215 QCheckBox* m_sliceExploded;
317 QCheckBox* m_sliceExploded;
216 QDoubleSpinBox* m_sliceExplodedFactor;
318 QDoubleSpinBox* m_sliceExplodedFactor;
319 QPushButton *m_brushColor;
320 QPushButton *m_penColor;
321 QDoubleSpinBox* m_penWidth;
217 };
322 };
218
323
219 int main(int argc, char *argv[])
324 int main(int argc, char *argv[])
General Comments 0
You need to be logged in to leave comments. Login now