##// END OF EJS Templates
Tinkering with piechartcustomization
Jani Honkonen -
r1486:0f0d41a23707
parent child
Show More
@@ -1,340 +1,346
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 #include "mainwidget.h"
20 #include "mainwidget.h"
21 #include "customslice.h"
21 #include "customslice.h"
22 #include "pentool.h"
22 #include "pentool.h"
23 #include "brushtool.h"
23 #include "brushtool.h"
24 #include <QPushButton>
24 #include <QPushButton>
25 #include <QComboBox>
25 #include <QComboBox>
26 #include <QCheckBox>
26 #include <QCheckBox>
27 #include <QLabel>
27 #include <QLineEdit>
28 #include <QGroupBox>
28 #include <QGroupBox>
29 #include <QDoubleSpinBox>
29 #include <QDoubleSpinBox>
30 #include <QFormLayout>
30 #include <QFormLayout>
31 #include <QFontDialog>
31 #include <QFontDialog>
32 #include <QChartView>
32 #include <QChartView>
33 #include <QPieSeries>
33 #include <QPieSeries>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 MainWidget::MainWidget(QWidget* parent)
37 MainWidget::MainWidget(QWidget* parent)
38 :QWidget(parent),
38 :QWidget(parent),
39 m_slice(0)
39 m_slice(0)
40 {
40 {
41 // create chart
41 // create chart
42 QChart *chart = new QChart;
42 QChart *chart = new QChart;
43 chart->setTitle("Piechart customization");
43 chart->setTitle("Piechart customization");
44 chart->setAnimationOptions(QChart::AllAnimations);
44 chart->setAnimationOptions(QChart::AllAnimations);
45
45
46 // create series
46 // create series
47 m_series = new QPieSeries();
47 m_series = new QPieSeries();
48 *m_series << new CustomSlice("Slice 1", 10.0);
48 *m_series << new CustomSlice("Slice 1", 10.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
49 *m_series << new CustomSlice("Slice 2", 20.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
50 *m_series << new CustomSlice("Slice 3", 30.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
51 *m_series << new CustomSlice("Slice 4", 40.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
52 *m_series << new CustomSlice("Slice 5", 50.0);
53 m_series->setLabelsVisible();
53 m_series->setLabelsVisible();
54 chart->addSeries(m_series);
54 chart->addSeries(m_series);
55
55
56 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
56 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
57
57
58 // chart settings
58 // chart settings
59 m_themeComboBox = new QComboBox();
59 m_themeComboBox = new QComboBox();
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
60 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
61 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
62 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
63 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
64 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
65 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
66 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
67
67
68 m_aaCheckBox = new QCheckBox();
68 m_aaCheckBox = new QCheckBox();
69 m_animationsCheckBox = new QCheckBox();
69 m_animationsCheckBox = new QCheckBox();
70 m_animationsCheckBox->setCheckState(Qt::Checked);
70 m_animationsCheckBox->setCheckState(Qt::Checked);
71
71
72 m_legendCheckBox = new QCheckBox();
72 m_legendCheckBox = new QCheckBox();
73
73
74 QFormLayout* chartSettingsLayout = new QFormLayout();
74 QFormLayout* chartSettingsLayout = new QFormLayout();
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
75 chartSettingsLayout->addRow("Theme", m_themeComboBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
76 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
77 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
78 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
79 QGroupBox* chartSettings = new QGroupBox("Chart");
79 QGroupBox* chartSettings = new QGroupBox("Chart");
80 chartSettings->setLayout(chartSettingsLayout);
80 chartSettings->setLayout(chartSettingsLayout);
81
81
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
82 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
83 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
84 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
84 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
85 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
86
86
87 // series settings
87 // series settings
88 m_hPosition = new QDoubleSpinBox();
88 m_hPosition = new QDoubleSpinBox();
89 m_hPosition->setMinimum(0.0);
89 m_hPosition->setMinimum(0.0);
90 m_hPosition->setMaximum(1.0);
90 m_hPosition->setMaximum(1.0);
91 m_hPosition->setSingleStep(0.1);
91 m_hPosition->setSingleStep(0.1);
92 m_hPosition->setValue(m_series->horizontalPosition());
92 m_hPosition->setValue(m_series->horizontalPosition());
93
93
94 m_vPosition = new QDoubleSpinBox();
94 m_vPosition = new QDoubleSpinBox();
95 m_vPosition->setMinimum(0.0);
95 m_vPosition->setMinimum(0.0);
96 m_vPosition->setMaximum(1.0);
96 m_vPosition->setMaximum(1.0);
97 m_vPosition->setSingleStep(0.1);
97 m_vPosition->setSingleStep(0.1);
98 m_vPosition->setValue(m_series->verticalPosition());
98 m_vPosition->setValue(m_series->verticalPosition());
99
99
100 m_sizeFactor = new QDoubleSpinBox();
100 m_sizeFactor = new QDoubleSpinBox();
101 m_sizeFactor->setMinimum(0.0);
101 m_sizeFactor->setMinimum(0.0);
102 m_sizeFactor->setMaximum(1.0);
102 m_sizeFactor->setMaximum(1.0);
103 m_sizeFactor->setSingleStep(0.1);
103 m_sizeFactor->setSingleStep(0.1);
104 m_sizeFactor->setValue(m_series->pieSize());
104 m_sizeFactor->setValue(m_series->pieSize());
105
105
106 m_startAngle = new QDoubleSpinBox();
106 m_startAngle = new QDoubleSpinBox();
107 m_startAngle->setMinimum(-720);
107 m_startAngle->setMinimum(-720);
108 m_startAngle->setMaximum(720);
108 m_startAngle->setMaximum(720);
109 m_startAngle->setValue(m_series->pieStartAngle());
109 m_startAngle->setValue(m_series->pieStartAngle());
110 m_startAngle->setSingleStep(1);
110 m_startAngle->setSingleStep(1);
111
111
112 m_endAngle = new QDoubleSpinBox();
112 m_endAngle = new QDoubleSpinBox();
113 m_endAngle->setMinimum(-720);
113 m_endAngle->setMinimum(-720);
114 m_endAngle->setMaximum(720);
114 m_endAngle->setMaximum(720);
115 m_endAngle->setValue(m_series->pieEndAngle());
115 m_endAngle->setValue(m_series->pieEndAngle());
116 m_endAngle->setSingleStep(1);
116 m_endAngle->setSingleStep(1);
117
117
118 QPushButton *appendSlice = new QPushButton("Append slice");
118 QPushButton *appendSlice = new QPushButton("Append slice");
119 QPushButton *insertSlice = new QPushButton("Insert slice");
119 QPushButton *insertSlice = new QPushButton("Insert slice");
120 QPushButton *removeSlice = new QPushButton("Remove selected slice");
120
121
121 QFormLayout* seriesSettingsLayout = new QFormLayout();
122 QFormLayout* seriesSettingsLayout = new QFormLayout();
122 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
123 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
123 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
124 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
124 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
125 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
125 seriesSettingsLayout->addRow("Start angle", m_startAngle);
126 seriesSettingsLayout->addRow("Start angle", m_startAngle);
126 seriesSettingsLayout->addRow("End angle", m_endAngle);
127 seriesSettingsLayout->addRow("End angle", m_endAngle);
127 seriesSettingsLayout->addRow(appendSlice);
128 seriesSettingsLayout->addRow(appendSlice);
128 seriesSettingsLayout->addRow(insertSlice);
129 seriesSettingsLayout->addRow(insertSlice);
130 seriesSettingsLayout->addRow(removeSlice);
129 QGroupBox* seriesSettings = new QGroupBox("Series");
131 QGroupBox* seriesSettings = new QGroupBox("Series");
130 seriesSettings->setLayout(seriesSettingsLayout);
132 seriesSettings->setLayout(seriesSettingsLayout);
131
133
132 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
134 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
133 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
135 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
134 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
135 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
136 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
138 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
137 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
139 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
138 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
140 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
141 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
139
142
140 // slice settings
143 // slice settings
141 m_sliceName = new QLabel("<click a slice>");
144 m_sliceName = new QLineEdit("<click a slice>");
145 m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
142 m_sliceValue = new QDoubleSpinBox();
146 m_sliceValue = new QDoubleSpinBox();
143 m_sliceValue->setMaximum(1000);
147 m_sliceValue->setMaximum(1000);
144 m_sliceLabelVisible = new QCheckBox();
148 m_sliceLabelVisible = new QCheckBox();
145 m_sliceLabelArmFactor = new QDoubleSpinBox();
149 m_sliceLabelArmFactor = new QDoubleSpinBox();
146 m_sliceLabelArmFactor->setSingleStep(0.01);
150 m_sliceLabelArmFactor->setSingleStep(0.01);
147 m_sliceExploded = new QCheckBox();
151 m_sliceExploded = new QCheckBox();
148 m_sliceExplodedFactor = new QDoubleSpinBox();
152 m_sliceExplodedFactor = new QDoubleSpinBox();
149 m_sliceExplodedFactor->setSingleStep(0.01);
153 m_sliceExplodedFactor->setSingleStep(0.01);
150 m_pen = new QPushButton();
154 m_pen = new QPushButton();
151 m_penTool = new PenTool("Slice pen", this);
155 m_penTool = new PenTool("Slice pen", this);
152 m_brush = new QPushButton();
156 m_brush = new QPushButton();
153 m_brushTool = new BrushTool("Slice brush", this);
157 m_brushTool = new BrushTool("Slice brush", this);
154 m_font = new QPushButton();
158 m_font = new QPushButton();
155 m_labelBrush = new QPushButton();
159 m_labelBrush = new QPushButton();
156 m_labelBrushTool = new BrushTool("Label brush", this);
160 m_labelBrushTool = new BrushTool("Label brush", this);
157 m_labelPosition = new QComboBox(this);
161 m_labelPosition = new QComboBox(this);
158 m_labelPosition->addItem("Outside", QPieSlice::LabelOutside);
162 m_labelPosition->addItem("Outside", QPieSlice::LabelOutside);
159 m_labelPosition->addItem("Inside", QPieSlice::LabelInside);
163 m_labelPosition->addItem("Inside", QPieSlice::LabelInside);
160 QPushButton *removeSlice = new QPushButton("Remove slice");
161
164
162 QFormLayout* sliceSettingsLayout = new QFormLayout();
165 QFormLayout* sliceSettingsLayout = new QFormLayout();
163 sliceSettingsLayout->addRow("Selected", m_sliceName);
166 sliceSettingsLayout->addRow("Label", m_sliceName);
164 sliceSettingsLayout->addRow("Value", m_sliceValue);
167 sliceSettingsLayout->addRow("Value", m_sliceValue);
165 sliceSettingsLayout->addRow("Pen", m_pen);
168 sliceSettingsLayout->addRow("Pen", m_pen);
166 sliceSettingsLayout->addRow("Brush", m_brush);
169 sliceSettingsLayout->addRow("Brush", m_brush);
167 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
170 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
168 sliceSettingsLayout->addRow("Label font", m_font);
171 sliceSettingsLayout->addRow("Label font", m_font);
169 sliceSettingsLayout->addRow("Label brush", m_labelBrush);
172 sliceSettingsLayout->addRow("Label brush", m_labelBrush);
170 sliceSettingsLayout->addRow("Label position", m_labelPosition);
173 sliceSettingsLayout->addRow("Label position", m_labelPosition);
171 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
174 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
172 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
175 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
173 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
176 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
174 sliceSettingsLayout->addRow(removeSlice);
177 QGroupBox* sliceSettings = new QGroupBox("Selected slice");
175 QGroupBox* sliceSettings = new QGroupBox("Slice");
176 sliceSettings->setLayout(sliceSettingsLayout);
178 sliceSettings->setLayout(sliceSettingsLayout);
177
179
180 connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings()));
178 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
181 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
179 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
182 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
180 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
183 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
181 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
184 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
182 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
185 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
183 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
186 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
184 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
187 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
185 connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
188 connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
186 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
189 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
187 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
190 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
188 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
191 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
189 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
192 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
190 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
193 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
191 connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings()));
194 connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings()));
192 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
193
195
194 // create chart view
196 // create chart view
195 m_chartView = new QChartView(chart);
197 m_chartView = new QChartView(chart);
196
198
197 // create main layout
199 // create main layout
198 QVBoxLayout *settingsLayout = new QVBoxLayout();
200 QVBoxLayout *settingsLayout = new QVBoxLayout();
199 settingsLayout->addWidget(chartSettings);
201 settingsLayout->addWidget(chartSettings);
200 settingsLayout->addWidget(seriesSettings);
202 settingsLayout->addWidget(seriesSettings);
201 settingsLayout->addWidget(sliceSettings);
203 settingsLayout->addWidget(sliceSettings);
202 settingsLayout->addStretch();
204 settingsLayout->addStretch();
203
205
204 QGridLayout* baseLayout = new QGridLayout();
206 QGridLayout* baseLayout = new QGridLayout();
205 baseLayout->addLayout(settingsLayout, 0, 0);
207 baseLayout->addLayout(settingsLayout, 0, 0);
206 baseLayout->addWidget(m_chartView, 0, 1);
208 baseLayout->addWidget(m_chartView, 0, 1);
207 setLayout(baseLayout);
209 setLayout(baseLayout);
208
210
209 updateSerieSettings();
211 updateSerieSettings();
210 }
212 }
211
213
212
214
213 void MainWidget::updateChartSettings()
215 void MainWidget::updateChartSettings()
214 {
216 {
215 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
217 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
216 m_chartView->chart()->setTheme(theme);
218 m_chartView->chart()->setTheme(theme);
217 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
219 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
218
220
219 if (m_animationsCheckBox->checkState() == Qt::Checked)
221 if (m_animationsCheckBox->checkState() == Qt::Checked)
220 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
222 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
221 else
223 else
222 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
224 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
223
225
224 if (m_legendCheckBox->checkState() == Qt::Checked)
226 if (m_legendCheckBox->checkState() == Qt::Checked)
225 m_chartView->chart()->legend()->show();
227 m_chartView->chart()->legend()->show();
226 else
228 else
227 m_chartView->chart()->legend()->hide();
229 m_chartView->chart()->legend()->hide();
228 }
230 }
229
231
230 void MainWidget::updateSerieSettings()
232 void MainWidget::updateSerieSettings()
231 {
233 {
232 m_series->setHorizontalPosition(m_hPosition->value());
234 m_series->setHorizontalPosition(m_hPosition->value());
233 m_series->setVerticalPosition(m_vPosition->value());
235 m_series->setVerticalPosition(m_vPosition->value());
234 m_series->setPieSize(m_sizeFactor->value());
236 m_series->setPieSize(m_sizeFactor->value());
235 m_series->setPieStartAngle(m_startAngle->value());
237 m_series->setPieStartAngle(m_startAngle->value());
236 m_series->setPieEndAngle(m_endAngle->value());
238 m_series->setPieEndAngle(m_endAngle->value());
237 }
239 }
238
240
239 void MainWidget::updateSliceSettings()
241 void MainWidget::updateSliceSettings()
240 {
242 {
241 if (!m_slice)
243 if (!m_slice)
242 return;
244 return;
243
245
246 m_slice->setLabel(m_sliceName->text());
247
244 m_slice->setValue(m_sliceValue->value());
248 m_slice->setValue(m_sliceValue->value());
245
249
246 m_slice->setPen(m_penTool->pen());
250 m_slice->setPen(m_penTool->pen());
247 m_slice->setBrush(m_brushTool->brush());
251 m_slice->setBrush(m_brushTool->brush());
248
252
249 m_slice->setLabelBrush(m_labelBrushTool->brush());
253 m_slice->setLabelBrush(m_labelBrushTool->brush());
250 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
254 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
251 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
255 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
252 m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum
256 m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum
253
257
254 m_slice->setExploded(m_sliceExploded->isChecked());
258 m_slice->setExploded(m_sliceExploded->isChecked());
255 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
259 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
256 }
260 }
257
261
258 void MainWidget::handleSliceClicked(QPieSlice* slice)
262 void MainWidget::handleSliceClicked(QPieSlice* slice)
259 {
263 {
260 m_slice = static_cast<CustomSlice*>(slice);
264 m_slice = static_cast<CustomSlice*>(slice);
261
265
262 // name
266 // name
267 m_sliceName->blockSignals(true);
263 m_sliceName->setText(slice->label());
268 m_sliceName->setText(slice->label());
269 m_sliceName->blockSignals(false);
264
270
265 // value
271 // value
266 m_sliceValue->blockSignals(true);
272 m_sliceValue->blockSignals(true);
267 m_sliceValue->setValue(slice->value());
273 m_sliceValue->setValue(slice->value());
268 m_sliceValue->blockSignals(false);
274 m_sliceValue->blockSignals(false);
269
275
270 // pen
276 // pen
271 m_pen->setText(PenTool::name(m_slice->pen()));
277 m_pen->setText(PenTool::name(m_slice->pen()));
272 m_penTool->setPen(m_slice->pen());
278 m_penTool->setPen(m_slice->pen());
273
279
274 // brush
280 // brush
275 m_brush->setText(m_slice->originalBrush().color().name());
281 m_brush->setText(m_slice->originalBrush().color().name());
276 m_brushTool->setBrush(m_slice->originalBrush());
282 m_brushTool->setBrush(m_slice->originalBrush());
277
283
278 // label
284 // label
279 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
285 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
280 m_labelBrushTool->setBrush(m_slice->labelBrush());
286 m_labelBrushTool->setBrush(m_slice->labelBrush());
281 m_font->setText(slice->labelFont().toString());
287 m_font->setText(slice->labelFont().toString());
282 m_sliceLabelVisible->blockSignals(true);
288 m_sliceLabelVisible->blockSignals(true);
283 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
289 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
284 m_sliceLabelVisible->blockSignals(false);
290 m_sliceLabelVisible->blockSignals(false);
285 m_sliceLabelArmFactor->blockSignals(true);
291 m_sliceLabelArmFactor->blockSignals(true);
286 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
292 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
287 m_sliceLabelArmFactor->blockSignals(false);
293 m_sliceLabelArmFactor->blockSignals(false);
288 m_labelPosition->blockSignals(true);
294 m_labelPosition->blockSignals(true);
289 m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum
295 m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum
290 m_labelPosition->blockSignals(false);
296 m_labelPosition->blockSignals(false);
291
297
292 // exploded
298 // exploded
293 m_sliceExploded->blockSignals(true);
299 m_sliceExploded->blockSignals(true);
294 m_sliceExploded->setChecked(slice->isExploded());
300 m_sliceExploded->setChecked(slice->isExploded());
295 m_sliceExploded->blockSignals(false);
301 m_sliceExploded->blockSignals(false);
296 m_sliceExplodedFactor->blockSignals(true);
302 m_sliceExplodedFactor->blockSignals(true);
297 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
303 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
298 m_sliceExplodedFactor->blockSignals(false);
304 m_sliceExplodedFactor->blockSignals(false);
299 }
305 }
300
306
301 void MainWidget::showFontDialog()
307 void MainWidget::showFontDialog()
302 {
308 {
303 if (!m_slice)
309 if (!m_slice)
304 return;
310 return;
305
311
306 QFontDialog dialog(m_slice->labelFont());
312 QFontDialog dialog(m_slice->labelFont());
307 dialog.show();
313 dialog.show();
308 dialog.exec();
314 dialog.exec();
309
315
310 m_slice->setLabelFont(dialog.currentFont());
316 m_slice->setLabelFont(dialog.currentFont());
311 m_font->setText(dialog.currentFont().toString());
317 m_font->setText(dialog.currentFont().toString());
312 }
318 }
313
319
314 void MainWidget::appendSlice()
320 void MainWidget::appendSlice()
315 {
321 {
316 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
322 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
317 }
323 }
318
324
319 void MainWidget::insertSlice()
325 void MainWidget::insertSlice()
320 {
326 {
321 if (!m_slice)
327 if (!m_slice)
322 return;
328 return;
323
329
324 int i = m_series->slices().indexOf(m_slice);
330 int i = m_series->slices().indexOf(m_slice);
325
331
326 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
332 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
327 }
333 }
328
334
329 void MainWidget::removeSlice()
335 void MainWidget::removeSlice()
330 {
336 {
331 if (!m_slice)
337 if (!m_slice)
332 return;
338 return;
333
339
334 m_sliceName->setText("<click a slice>");
340 m_sliceName->setText("<click a slice>");
335
341
336 m_series->remove(m_slice);
342 m_series->remove(m_slice);
337 m_slice = 0;
343 m_slice = 0;
338 }
344 }
339
345
340 #include "moc_mainwidget.cpp"
346 #include "moc_mainwidget.cpp"
@@ -1,92 +1,92
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 MAINWIDGET_H
20 #ifndef MAINWIDGET_H
21 #define MAINWIDGET_H
21 #define MAINWIDGET_H
22
22
23 #include <QWidget>
23 #include <QWidget>
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25
25
26 class QLabel;
26 class QLineEdit;
27 class QPushButton;
27 class QPushButton;
28 class QCheckBox;
28 class QCheckBox;
29 class QComboBox;
29 class QComboBox;
30 class QDoubleSpinBox;
30 class QDoubleSpinBox;
31 class PenTool;
31 class PenTool;
32 class BrushTool;
32 class BrushTool;
33 class CustomSlice;
33 class CustomSlice;
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 class QChartView;
36 class QChartView;
37 class QPieSeries;
37 class QPieSeries;
38 class QPieSlice;
38 class QPieSlice;
39 QTCOMMERCIALCHART_END_NAMESPACE
39 QTCOMMERCIALCHART_END_NAMESPACE
40
40
41 QTCOMMERCIALCHART_USE_NAMESPACE
41 QTCOMMERCIALCHART_USE_NAMESPACE
42
42
43 class MainWidget : public QWidget
43 class MainWidget : public QWidget
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46
46
47 public:
47 public:
48 explicit MainWidget(QWidget* parent = 0);
48 explicit MainWidget(QWidget* parent = 0);
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void updateChartSettings();
51 void updateChartSettings();
52 void updateSerieSettings();
52 void updateSerieSettings();
53 void updateSliceSettings();
53 void updateSliceSettings();
54 void handleSliceClicked(QPieSlice* slice);
54 void handleSliceClicked(QPieSlice* slice);
55 void showFontDialog();
55 void showFontDialog();
56 void appendSlice();
56 void appendSlice();
57 void insertSlice();
57 void insertSlice();
58 void removeSlice();
58 void removeSlice();
59
59
60 private:
60 private:
61 QComboBox *m_themeComboBox;
61 QComboBox *m_themeComboBox;
62 QCheckBox *m_aaCheckBox;
62 QCheckBox *m_aaCheckBox;
63 QCheckBox *m_animationsCheckBox;
63 QCheckBox *m_animationsCheckBox;
64 QCheckBox *m_legendCheckBox;
64 QCheckBox *m_legendCheckBox;
65
65
66 QChartView* m_chartView;
66 QChartView* m_chartView;
67 QPieSeries* m_series;
67 QPieSeries* m_series;
68 CustomSlice* m_slice;
68 CustomSlice* m_slice;
69
69
70 QDoubleSpinBox* m_hPosition;
70 QDoubleSpinBox* m_hPosition;
71 QDoubleSpinBox* m_vPosition;
71 QDoubleSpinBox* m_vPosition;
72 QDoubleSpinBox* m_sizeFactor;
72 QDoubleSpinBox* m_sizeFactor;
73 QDoubleSpinBox* m_startAngle;
73 QDoubleSpinBox* m_startAngle;
74 QDoubleSpinBox* m_endAngle;
74 QDoubleSpinBox* m_endAngle;
75
75
76 QLabel* m_sliceName;
76 QLineEdit* m_sliceName;
77 QDoubleSpinBox* m_sliceValue;
77 QDoubleSpinBox* m_sliceValue;
78 QCheckBox* m_sliceLabelVisible;
78 QCheckBox* m_sliceLabelVisible;
79 QDoubleSpinBox* m_sliceLabelArmFactor;
79 QDoubleSpinBox* m_sliceLabelArmFactor;
80 QCheckBox* m_sliceExploded;
80 QCheckBox* m_sliceExploded;
81 QDoubleSpinBox* m_sliceExplodedFactor;
81 QDoubleSpinBox* m_sliceExplodedFactor;
82 QPushButton *m_brush;
82 QPushButton *m_brush;
83 BrushTool *m_brushTool;
83 BrushTool *m_brushTool;
84 QPushButton *m_pen;
84 QPushButton *m_pen;
85 PenTool *m_penTool;
85 PenTool *m_penTool;
86 QPushButton *m_font;
86 QPushButton *m_font;
87 QPushButton *m_labelBrush;
87 QPushButton *m_labelBrush;
88 QComboBox *m_labelPosition;
88 QComboBox *m_labelPosition;
89 BrushTool *m_labelBrushTool;
89 BrushTool *m_labelBrushTool;
90 };
90 };
91
91
92 #endif // MAINWIDGET_H
92 #endif // MAINWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now