@@ -1,346 +1,347 | |||||
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 <QLineEdit> |
|
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 | QPushButton *removeSlice = new QPushButton("Remove selected slice"); | |
121 |
|
121 | |||
122 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
122 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | |
123 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
123 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | |
124 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
124 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | |
125 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
125 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
126 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
126 | seriesSettingsLayout->addRow("Start angle", m_startAngle); | |
127 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
127 | seriesSettingsLayout->addRow("End angle", m_endAngle); | |
128 | seriesSettingsLayout->addRow(appendSlice); |
|
128 | seriesSettingsLayout->addRow(appendSlice); | |
129 | seriesSettingsLayout->addRow(insertSlice); |
|
129 | seriesSettingsLayout->addRow(insertSlice); | |
130 | seriesSettingsLayout->addRow(removeSlice); |
|
130 | seriesSettingsLayout->addRow(removeSlice); | |
131 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
131 | QGroupBox* seriesSettings = new QGroupBox("Series"); | |
132 | seriesSettings->setLayout(seriesSettingsLayout); |
|
132 | seriesSettings->setLayout(seriesSettingsLayout); | |
133 |
|
133 | |||
134 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
134 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
135 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
135 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
136 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
136 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
137 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
137 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
138 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
138 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
139 | connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); |
|
139 | connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); | |
140 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); |
|
140 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | |
141 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
141 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
142 |
|
142 | |||
143 | // slice settings |
|
143 | // slice settings | |
144 | m_sliceName = new QLineEdit("<click a slice>"); |
|
144 | m_sliceName = new QLineEdit("<click a slice>"); | |
145 | m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
145 | m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
146 | m_sliceValue = new QDoubleSpinBox(); |
|
146 | m_sliceValue = new QDoubleSpinBox(); | |
147 | m_sliceValue->setMaximum(1000); |
|
147 | m_sliceValue->setMaximum(1000); | |
148 | m_sliceLabelVisible = new QCheckBox(); |
|
148 | m_sliceLabelVisible = new QCheckBox(); | |
149 | m_sliceLabelArmFactor = new QDoubleSpinBox(); |
|
149 | m_sliceLabelArmFactor = new QDoubleSpinBox(); | |
150 | m_sliceLabelArmFactor->setSingleStep(0.01); |
|
150 | m_sliceLabelArmFactor->setSingleStep(0.01); | |
151 | m_sliceExploded = new QCheckBox(); |
|
151 | m_sliceExploded = new QCheckBox(); | |
152 | m_sliceExplodedFactor = new QDoubleSpinBox(); |
|
152 | m_sliceExplodedFactor = new QDoubleSpinBox(); | |
153 | m_sliceExplodedFactor->setSingleStep(0.01); |
|
153 | m_sliceExplodedFactor->setSingleStep(0.01); | |
154 | m_pen = new QPushButton(); |
|
154 | m_pen = new QPushButton(); | |
155 | m_penTool = new PenTool("Slice pen", this); |
|
155 | m_penTool = new PenTool("Slice pen", this); | |
156 | m_brush = new QPushButton(); |
|
156 | m_brush = new QPushButton(); | |
157 | m_brushTool = new BrushTool("Slice brush", this); |
|
157 | m_brushTool = new BrushTool("Slice brush", this); | |
158 | m_font = new QPushButton(); |
|
158 | m_font = new QPushButton(); | |
159 | m_labelBrush = new QPushButton(); |
|
159 | m_labelBrush = new QPushButton(); | |
160 | m_labelBrushTool = new BrushTool("Label brush", this); |
|
160 | m_labelBrushTool = new BrushTool("Label brush", this); | |
161 | m_labelPosition = new QComboBox(this); |
|
161 | m_labelPosition = new QComboBox(this); | |
162 | m_labelPosition->addItem("Outside", QPieSlice::LabelOutside); |
|
162 | m_labelPosition->addItem("Outside", QPieSlice::LabelOutside); | |
163 | m_labelPosition->addItem("Inside", QPieSlice::LabelInside); |
|
163 | m_labelPosition->addItem("Inside", QPieSlice::LabelInside); | |
164 |
|
164 | |||
165 | QFormLayout* sliceSettingsLayout = new QFormLayout(); |
|
165 | QFormLayout* sliceSettingsLayout = new QFormLayout(); | |
166 | sliceSettingsLayout->addRow("Label", m_sliceName); |
|
166 | sliceSettingsLayout->addRow("Label", m_sliceName); | |
167 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
167 | sliceSettingsLayout->addRow("Value", m_sliceValue); | |
168 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
168 | sliceSettingsLayout->addRow("Pen", m_pen); | |
169 | sliceSettingsLayout->addRow("Brush", m_brush); |
|
169 | sliceSettingsLayout->addRow("Brush", m_brush); | |
170 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); |
|
170 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); | |
171 | sliceSettingsLayout->addRow("Label font", m_font); |
|
171 | sliceSettingsLayout->addRow("Label font", m_font); | |
172 | sliceSettingsLayout->addRow("Label brush", m_labelBrush); |
|
172 | sliceSettingsLayout->addRow("Label brush", m_labelBrush); | |
173 | sliceSettingsLayout->addRow("Label position", m_labelPosition); |
|
173 | sliceSettingsLayout->addRow("Label position", m_labelPosition); | |
174 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
174 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | |
175 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
175 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | |
176 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
176 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | |
177 | QGroupBox* sliceSettings = new QGroupBox("Selected slice"); |
|
177 | QGroupBox* sliceSettings = new QGroupBox("Selected slice"); | |
178 | sliceSettings->setLayout(sliceSettingsLayout); |
|
178 | sliceSettings->setLayout(sliceSettingsLayout); | |
179 |
|
179 | |||
180 | connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); |
|
180 | connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); | |
181 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
181 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
182 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
182 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); | |
183 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
183 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
184 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); |
|
184 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); | |
185 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
185 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
186 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); |
|
186 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); | |
187 | connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show())); |
|
187 | connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show())); | |
188 | connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
188 | connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
189 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
189 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
190 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
190 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
191 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
191 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
192 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
192 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
193 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
193 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
194 | connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings())); |
|
194 | connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings())); | |
195 |
|
195 | |||
196 | // create chart view |
|
196 | // create chart view | |
197 | m_chartView = new QChartView(chart); |
|
197 | m_chartView = new QChartView(chart); | |
198 |
|
198 | |||
199 | // create main layout |
|
199 | // create main layout | |
200 | QVBoxLayout *settingsLayout = new QVBoxLayout(); |
|
200 | QVBoxLayout *settingsLayout = new QVBoxLayout(); | |
201 | settingsLayout->addWidget(chartSettings); |
|
201 | settingsLayout->addWidget(chartSettings); | |
202 | settingsLayout->addWidget(seriesSettings); |
|
202 | settingsLayout->addWidget(seriesSettings); | |
203 | settingsLayout->addWidget(sliceSettings); |
|
203 | settingsLayout->addWidget(sliceSettings); | |
204 | settingsLayout->addStretch(); |
|
204 | settingsLayout->addStretch(); | |
205 |
|
205 | |||
206 | QGridLayout* baseLayout = new QGridLayout(); |
|
206 | QGridLayout* baseLayout = new QGridLayout(); | |
207 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
207 | baseLayout->addLayout(settingsLayout, 0, 0); | |
208 | baseLayout->addWidget(m_chartView, 0, 1); |
|
208 | baseLayout->addWidget(m_chartView, 0, 1); | |
209 | setLayout(baseLayout); |
|
209 | setLayout(baseLayout); | |
210 |
|
210 | |||
211 | updateSerieSettings(); |
|
211 | updateSerieSettings(); | |
|
212 | updateChartSettings(); | |||
212 | } |
|
213 | } | |
213 |
|
214 | |||
214 |
|
215 | |||
215 | void MainWidget::updateChartSettings() |
|
216 | void MainWidget::updateChartSettings() | |
216 | { |
|
217 | { | |
217 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
218 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
218 | m_chartView->chart()->setTheme(theme); |
|
219 | m_chartView->chart()->setTheme(theme); | |
219 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); |
|
220 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); | |
220 |
|
221 | |||
221 | if (m_animationsCheckBox->checkState() == Qt::Checked) |
|
222 | if (m_animationsCheckBox->checkState() == Qt::Checked) | |
222 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); |
|
223 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); | |
223 | else |
|
224 | else | |
224 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); |
|
225 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); | |
225 |
|
226 | |||
226 | if (m_legendCheckBox->checkState() == Qt::Checked) |
|
227 | if (m_legendCheckBox->checkState() == Qt::Checked) | |
227 | m_chartView->chart()->legend()->show(); |
|
228 | m_chartView->chart()->legend()->show(); | |
228 | else |
|
229 | else | |
229 | m_chartView->chart()->legend()->hide(); |
|
230 | m_chartView->chart()->legend()->hide(); | |
230 | } |
|
231 | } | |
231 |
|
232 | |||
232 | void MainWidget::updateSerieSettings() |
|
233 | void MainWidget::updateSerieSettings() | |
233 | { |
|
234 | { | |
234 | m_series->setHorizontalPosition(m_hPosition->value()); |
|
235 | m_series->setHorizontalPosition(m_hPosition->value()); | |
235 | m_series->setVerticalPosition(m_vPosition->value()); |
|
236 | m_series->setVerticalPosition(m_vPosition->value()); | |
236 | m_series->setPieSize(m_sizeFactor->value()); |
|
237 | m_series->setPieSize(m_sizeFactor->value()); | |
237 | m_series->setPieStartAngle(m_startAngle->value()); |
|
238 | m_series->setPieStartAngle(m_startAngle->value()); | |
238 | m_series->setPieEndAngle(m_endAngle->value()); |
|
239 | m_series->setPieEndAngle(m_endAngle->value()); | |
239 | } |
|
240 | } | |
240 |
|
241 | |||
241 | void MainWidget::updateSliceSettings() |
|
242 | void MainWidget::updateSliceSettings() | |
242 | { |
|
243 | { | |
243 | if (!m_slice) |
|
244 | if (!m_slice) | |
244 | return; |
|
245 | return; | |
245 |
|
246 | |||
246 | m_slice->setLabel(m_sliceName->text()); |
|
247 | m_slice->setLabel(m_sliceName->text()); | |
247 |
|
248 | |||
248 | m_slice->setValue(m_sliceValue->value()); |
|
249 | m_slice->setValue(m_sliceValue->value()); | |
249 |
|
250 | |||
250 | m_slice->setPen(m_penTool->pen()); |
|
251 | m_slice->setPen(m_penTool->pen()); | |
251 | m_slice->setBrush(m_brushTool->brush()); |
|
252 | m_slice->setBrush(m_brushTool->brush()); | |
252 |
|
253 | |||
253 | m_slice->setLabelBrush(m_labelBrushTool->brush()); |
|
254 | m_slice->setLabelBrush(m_labelBrushTool->brush()); | |
254 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); |
|
255 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); | |
255 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); |
|
256 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); | |
256 | m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum |
|
257 | m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum | |
257 |
|
258 | |||
258 | m_slice->setExploded(m_sliceExploded->isChecked()); |
|
259 | m_slice->setExploded(m_sliceExploded->isChecked()); | |
259 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
260 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | |
260 | } |
|
261 | } | |
261 |
|
262 | |||
262 | void MainWidget::handleSliceClicked(QPieSlice* slice) |
|
263 | void MainWidget::handleSliceClicked(QPieSlice* slice) | |
263 | { |
|
264 | { | |
264 | m_slice = static_cast<CustomSlice*>(slice); |
|
265 | m_slice = static_cast<CustomSlice*>(slice); | |
265 |
|
266 | |||
266 | // name |
|
267 | // name | |
267 | m_sliceName->blockSignals(true); |
|
268 | m_sliceName->blockSignals(true); | |
268 | m_sliceName->setText(slice->label()); |
|
269 | m_sliceName->setText(slice->label()); | |
269 | m_sliceName->blockSignals(false); |
|
270 | m_sliceName->blockSignals(false); | |
270 |
|
271 | |||
271 | // value |
|
272 | // value | |
272 | m_sliceValue->blockSignals(true); |
|
273 | m_sliceValue->blockSignals(true); | |
273 | m_sliceValue->setValue(slice->value()); |
|
274 | m_sliceValue->setValue(slice->value()); | |
274 | m_sliceValue->blockSignals(false); |
|
275 | m_sliceValue->blockSignals(false); | |
275 |
|
276 | |||
276 | // pen |
|
277 | // pen | |
277 | m_pen->setText(PenTool::name(m_slice->pen())); |
|
278 | m_pen->setText(PenTool::name(m_slice->pen())); | |
278 | m_penTool->setPen(m_slice->pen()); |
|
279 | m_penTool->setPen(m_slice->pen()); | |
279 |
|
280 | |||
280 | // brush |
|
281 | // brush | |
281 | m_brush->setText(m_slice->originalBrush().color().name()); |
|
282 | m_brush->setText(m_slice->originalBrush().color().name()); | |
282 | m_brushTool->setBrush(m_slice->originalBrush()); |
|
283 | m_brushTool->setBrush(m_slice->originalBrush()); | |
283 |
|
284 | |||
284 | // label |
|
285 | // label | |
285 | m_labelBrush->setText(BrushTool::name(m_slice->labelBrush())); |
|
286 | m_labelBrush->setText(BrushTool::name(m_slice->labelBrush())); | |
286 | m_labelBrushTool->setBrush(m_slice->labelBrush()); |
|
287 | m_labelBrushTool->setBrush(m_slice->labelBrush()); | |
287 | m_font->setText(slice->labelFont().toString()); |
|
288 | m_font->setText(slice->labelFont().toString()); | |
288 | m_sliceLabelVisible->blockSignals(true); |
|
289 | m_sliceLabelVisible->blockSignals(true); | |
289 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); |
|
290 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); | |
290 | m_sliceLabelVisible->blockSignals(false); |
|
291 | m_sliceLabelVisible->blockSignals(false); | |
291 | m_sliceLabelArmFactor->blockSignals(true); |
|
292 | m_sliceLabelArmFactor->blockSignals(true); | |
292 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); |
|
293 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); | |
293 | m_sliceLabelArmFactor->blockSignals(false); |
|
294 | m_sliceLabelArmFactor->blockSignals(false); | |
294 | m_labelPosition->blockSignals(true); |
|
295 | m_labelPosition->blockSignals(true); | |
295 | m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum |
|
296 | m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum | |
296 | m_labelPosition->blockSignals(false); |
|
297 | m_labelPosition->blockSignals(false); | |
297 |
|
298 | |||
298 | // exploded |
|
299 | // exploded | |
299 | m_sliceExploded->blockSignals(true); |
|
300 | m_sliceExploded->blockSignals(true); | |
300 | m_sliceExploded->setChecked(slice->isExploded()); |
|
301 | m_sliceExploded->setChecked(slice->isExploded()); | |
301 | m_sliceExploded->blockSignals(false); |
|
302 | m_sliceExploded->blockSignals(false); | |
302 | m_sliceExplodedFactor->blockSignals(true); |
|
303 | m_sliceExplodedFactor->blockSignals(true); | |
303 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); |
|
304 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); | |
304 | m_sliceExplodedFactor->blockSignals(false); |
|
305 | m_sliceExplodedFactor->blockSignals(false); | |
305 | } |
|
306 | } | |
306 |
|
307 | |||
307 | void MainWidget::showFontDialog() |
|
308 | void MainWidget::showFontDialog() | |
308 | { |
|
309 | { | |
309 | if (!m_slice) |
|
310 | if (!m_slice) | |
310 | return; |
|
311 | return; | |
311 |
|
312 | |||
312 | QFontDialog dialog(m_slice->labelFont()); |
|
313 | QFontDialog dialog(m_slice->labelFont()); | |
313 | dialog.show(); |
|
314 | dialog.show(); | |
314 | dialog.exec(); |
|
315 | dialog.exec(); | |
315 |
|
316 | |||
316 | m_slice->setLabelFont(dialog.currentFont()); |
|
317 | m_slice->setLabelFont(dialog.currentFont()); | |
317 | m_font->setText(dialog.currentFont().toString()); |
|
318 | m_font->setText(dialog.currentFont().toString()); | |
318 | } |
|
319 | } | |
319 |
|
320 | |||
320 | void MainWidget::appendSlice() |
|
321 | void MainWidget::appendSlice() | |
321 | { |
|
322 | { | |
322 | *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0); |
|
323 | *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0); | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 | void MainWidget::insertSlice() |
|
326 | void MainWidget::insertSlice() | |
326 | { |
|
327 | { | |
327 | if (!m_slice) |
|
328 | if (!m_slice) | |
328 | return; |
|
329 | return; | |
329 |
|
330 | |||
330 | int i = m_series->slices().indexOf(m_slice); |
|
331 | int i = m_series->slices().indexOf(m_slice); | |
331 |
|
332 | |||
332 | m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0)); |
|
333 | m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0)); | |
333 | } |
|
334 | } | |
334 |
|
335 | |||
335 | void MainWidget::removeSlice() |
|
336 | void MainWidget::removeSlice() | |
336 | { |
|
337 | { | |
337 | if (!m_slice) |
|
338 | if (!m_slice) | |
338 | return; |
|
339 | return; | |
339 |
|
340 | |||
340 | m_sliceName->setText("<click a slice>"); |
|
341 | m_sliceName->setText("<click a slice>"); | |
341 |
|
342 | |||
342 | m_series->remove(m_slice); |
|
343 | m_series->remove(m_slice); | |
343 | m_slice = 0; |
|
344 | m_slice = 0; | |
344 | } |
|
345 | } | |
345 |
|
346 | |||
346 | #include "moc_mainwidget.cpp" |
|
347 | #include "moc_mainwidget.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now