##// END OF EJS Templates
class QValuesAxis renamed to QValueAxis
class QValuesAxis renamed to QValueAxis

File last commit:

r1759:dc4b31cf5c38
r1804:82dd686825b5
Show More
mainwidget.cpp
363 lines | 14.2 KiB | text/x-c | CppLexer
Jani Honkonen
Split piechartcustomization to different files
r844 /****************************************************************************
**
** Copyright (C) 2012 Digia Plc
** All rights reserved.
** For any questions to Digia, please use contact form at http://qt.digia.com
**
** This file is part of the Qt Commercial Charts Add-on.
**
** $QT_BEGIN_LICENSE$
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.
**
** If you have questions regarding the use of this file, please use
** contact form at http://qt.digia.com
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mainwidget.h"
#include "customslice.h"
#include "pentool.h"
#include "brushtool.h"
#include <QPushButton>
#include <QComboBox>
#include <QCheckBox>
Jani Honkonen
Tinkering with piechartcustomization
r1486 #include <QLineEdit>
Jani Honkonen
Split piechartcustomization to different files
r844 #include <QGroupBox>
#include <QDoubleSpinBox>
#include <QFormLayout>
#include <QFontDialog>
#include <QChartView>
#include <QPieSeries>
QTCOMMERCIALCHART_USE_NAMESPACE
MainWidget::MainWidget(QWidget* parent)
:QWidget(parent),
m_slice(0)
{
// create chart
QChart *chart = new QChart;
chart->setTitle("Piechart customization");
chart->setAnimationOptions(QChart::AllAnimations);
// create series
m_series = new QPieSeries();
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 *m_series << new CustomSlice("Slice 1", 10.0);
*m_series << new CustomSlice("Slice 2", 20.0);
*m_series << new CustomSlice("Slice 3", 30.0);
*m_series << new CustomSlice("Slice 4", 40.0);
*m_series << new CustomSlice("Slice 5", 50.0);
Jani Honkonen
Split piechartcustomization to different files
r844 m_series->setLabelsVisible();
chart->addSeries(m_series);
Jani Honkonen
API review changes for pie
r1009 connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*)));
Jani Honkonen
Split piechartcustomization to different files
r844
// chart settings
m_themeComboBox = new QComboBox();
m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
m_aaCheckBox = new QCheckBox();
m_animationsCheckBox = new QCheckBox();
m_animationsCheckBox->setCheckState(Qt::Checked);
Jani Honkonen
API review changes for pie
r1009 m_legendCheckBox = new QCheckBox();
Jani Honkonen
Split piechartcustomization to different files
r844 QFormLayout* chartSettingsLayout = new QFormLayout();
chartSettingsLayout->addRow("Theme", m_themeComboBox);
chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
Jani Honkonen
API review changes for pie
r1009 chartSettingsLayout->addRow("Legend", m_legendCheckBox);
Jani Honkonen
Split piechartcustomization to different files
r844 QGroupBox* chartSettings = new QGroupBox("Chart");
chartSettings->setLayout(chartSettingsLayout);
connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
Jani Honkonen
API review changes for pie
r1009 connect(m_legendCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
Jani Honkonen
Split piechartcustomization to different files
r844
// series settings
m_hPosition = new QDoubleSpinBox();
m_hPosition->setMinimum(0.0);
m_hPosition->setMaximum(1.0);
m_hPosition->setSingleStep(0.1);
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 m_hPosition->setValue(m_series->horizontalPosition());
Jani Honkonen
Split piechartcustomization to different files
r844
m_vPosition = new QDoubleSpinBox();
m_vPosition->setMinimum(0.0);
m_vPosition->setMaximum(1.0);
m_vPosition->setSingleStep(0.1);
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 m_vPosition->setValue(m_series->verticalPosition());
Jani Honkonen
Split piechartcustomization to different files
r844
m_sizeFactor = new QDoubleSpinBox();
m_sizeFactor->setMinimum(0.0);
m_sizeFactor->setMaximum(1.0);
m_sizeFactor->setSingleStep(0.1);
m_sizeFactor->setValue(m_series->pieSize());
m_startAngle = new QDoubleSpinBox();
Jani Honkonen
Bugfix: remove restrictions from pie start & end angles...
r1207 m_startAngle->setMinimum(-720);
m_startAngle->setMaximum(720);
Jani Honkonen
Split piechartcustomization to different files
r844 m_startAngle->setValue(m_series->pieStartAngle());
m_startAngle->setSingleStep(1);
m_endAngle = new QDoubleSpinBox();
Jani Honkonen
Bugfix: remove restrictions from pie start & end angles...
r1207 m_endAngle->setMinimum(-720);
m_endAngle->setMaximum(720);
Jani Honkonen
Split piechartcustomization to different files
r844 m_endAngle->setValue(m_series->pieEndAngle());
m_endAngle->setSingleStep(1);
Jani Honkonen
pie: finetuning donut animations...
r1758 m_isDonut = new QCheckBox();
m_donutInnerSize = new QDoubleSpinBox();
m_donutInnerSize->setMinimum(0.0);
m_donutInnerSize->setMaximum(1.0);
m_donutInnerSize->setSingleStep(0.1);
m_donutInnerSize->setValue(m_series->donutInnerSize());
Jani Honkonen
Improving pie examples
r892 QPushButton *appendSlice = new QPushButton("Append slice");
Jani Honkonen
Split piechartcustomization to different files
r844 QPushButton *insertSlice = new QPushButton("Insert slice");
Jani Honkonen
Tinkering with piechartcustomization
r1486 QPushButton *removeSlice = new QPushButton("Remove selected slice");
Jani Honkonen
Split piechartcustomization to different files
r844
QFormLayout* seriesSettingsLayout = new QFormLayout();
seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
seriesSettingsLayout->addRow("Vertical position", m_vPosition);
seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
seriesSettingsLayout->addRow("Start angle", m_startAngle);
seriesSettingsLayout->addRow("End angle", m_endAngle);
Jani Honkonen
pie: finetuning donut animations...
r1758 seriesSettingsLayout->addRow("Is donut", m_isDonut);
seriesSettingsLayout->addRow("Donut inner size", m_donutInnerSize);
Jani Honkonen
Improving pie examples
r892 seriesSettingsLayout->addRow(appendSlice);
Jani Honkonen
Split piechartcustomization to different files
r844 seriesSettingsLayout->addRow(insertSlice);
Jani Honkonen
Tinkering with piechartcustomization
r1486 seriesSettingsLayout->addRow(removeSlice);
Jani Honkonen
Split piechartcustomization to different files
r844 QGroupBox* seriesSettings = new QGroupBox("Series");
seriesSettings->setLayout(seriesSettingsLayout);
connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
Jani Honkonen
pie: finetuning donut animations...
r1758 connect(m_isDonut, SIGNAL(toggled(bool)), this, SLOT(updateSerieSettings()));
connect(m_donutInnerSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
Jani Honkonen
Improving pie examples
r892 connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice()));
Jani Honkonen
Split piechartcustomization to different files
r844 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
Jani Honkonen
Tinkering with piechartcustomization
r1486 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
Jani Honkonen
Split piechartcustomization to different files
r844
// slice settings
Jani Honkonen
Tinkering with piechartcustomization
r1486 m_sliceName = new QLineEdit("<click a slice>");
m_sliceName->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
Jani Honkonen
Split piechartcustomization to different files
r844 m_sliceValue = new QDoubleSpinBox();
m_sliceValue->setMaximum(1000);
m_sliceLabelVisible = new QCheckBox();
m_sliceLabelArmFactor = new QDoubleSpinBox();
m_sliceLabelArmFactor->setSingleStep(0.01);
m_sliceExploded = new QCheckBox();
m_sliceExplodedFactor = new QDoubleSpinBox();
m_sliceExplodedFactor->setSingleStep(0.01);
m_pen = new QPushButton();
m_penTool = new PenTool("Slice pen", this);
m_brush = new QPushButton();
m_brushTool = new BrushTool("Slice brush", this);
m_font = new QPushButton();
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 m_labelBrush = new QPushButton();
m_labelBrushTool = new BrushTool("Label brush", this);
Jani Honkonen
pie: add label position to slice
r1450 m_labelPosition = new QComboBox(this);
m_labelPosition->addItem("Outside", QPieSlice::LabelOutside);
Jani Honkonen
QPieSlice::LabelInside -> LabelInsideHorizontal
r1759 m_labelPosition->addItem("Inside horizontal", QPieSlice::LabelInsideHorizontal);
Marek Rosa
Added one more type of label placing on Pie chart
r1712 m_labelPosition->addItem("Inside tangential", QPieSlice::LabelInsideTangential);
m_labelPosition->addItem("Inside normal", QPieSlice::LabelInsideNormal);
Jani Honkonen
Split piechartcustomization to different files
r844
QFormLayout* sliceSettingsLayout = new QFormLayout();
Jani Honkonen
Tinkering with piechartcustomization
r1486 sliceSettingsLayout->addRow("Label", m_sliceName);
Jani Honkonen
Split piechartcustomization to different files
r844 sliceSettingsLayout->addRow("Value", m_sliceValue);
sliceSettingsLayout->addRow("Pen", m_pen);
sliceSettingsLayout->addRow("Brush", m_brush);
sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
sliceSettingsLayout->addRow("Label font", m_font);
Jani Honkonen
pie: add label position to slice
r1450 sliceSettingsLayout->addRow("Label brush", m_labelBrush);
sliceSettingsLayout->addRow("Label position", m_labelPosition);
Jani Honkonen
Split piechartcustomization to different files
r844 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
Jani Honkonen
Tinkering with piechartcustomization
r1486 QGroupBox* sliceSettings = new QGroupBox("Selected slice");
Jani Honkonen
Split piechartcustomization to different files
r844 sliceSettings->setLayout(sliceSettingsLayout);
Jani Honkonen
Tinkering with piechartcustomization
r1486 connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings()));
Jani Honkonen
Split piechartcustomization to different files
r844 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show()));
connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
Jani Honkonen
Split piechartcustomization to different files
r844 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
Jani Honkonen
pie: add label position to slice
r1450 connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings()));
Jani Honkonen
Split piechartcustomization to different files
r844
// create chart view
m_chartView = new QChartView(chart);
// create main layout
QVBoxLayout *settingsLayout = new QVBoxLayout();
settingsLayout->addWidget(chartSettings);
settingsLayout->addWidget(seriesSettings);
settingsLayout->addWidget(sliceSettings);
settingsLayout->addStretch();
QGridLayout* baseLayout = new QGridLayout();
baseLayout->addLayout(settingsLayout, 0, 0);
baseLayout->addWidget(m_chartView, 0, 1);
setLayout(baseLayout);
updateSerieSettings();
Michal Klocek
Fix piechartcustomization example
r1644 updateChartSettings();
Jani Honkonen
Split piechartcustomization to different files
r844 }
void MainWidget::updateChartSettings()
{
QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
m_chartView->chart()->setTheme(theme);
m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
if (m_animationsCheckBox->checkState() == Qt::Checked)
m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
else
m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
Jani Honkonen
API review changes for pie
r1009
if (m_legendCheckBox->checkState() == Qt::Checked)
m_chartView->chart()->legend()->show();
else
m_chartView->chart()->legend()->hide();
Jani Honkonen
Split piechartcustomization to different files
r844 }
void MainWidget::updateSerieSettings()
{
Tero Ahola
QSeries name and QPieSeries properties to QML api
r884 m_series->setHorizontalPosition(m_hPosition->value());
m_series->setVerticalPosition(m_vPosition->value());
Jani Honkonen
Split piechartcustomization to different files
r844 m_series->setPieSize(m_sizeFactor->value());
m_series->setPieStartAngle(m_startAngle->value());
m_series->setPieEndAngle(m_endAngle->value());
Jani Honkonen
pie: finetuning donut animations...
r1758 m_series->setDonut(m_isDonut->isChecked());
m_series->setDonutInnerSize(m_donutInnerSize->value());
Jani Honkonen
Split piechartcustomization to different files
r844 }
void MainWidget::updateSliceSettings()
{
if (!m_slice)
return;
Jani Honkonen
Tinkering with piechartcustomization
r1486 m_slice->setLabel(m_sliceName->text());
Jani Honkonen
Split piechartcustomization to different files
r844 m_slice->setValue(m_sliceValue->value());
m_slice->setPen(m_penTool->pen());
m_slice->setBrush(m_brushTool->brush());
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 m_slice->setLabelBrush(m_labelBrushTool->brush());
Jani Honkonen
Split piechartcustomization to different files
r844 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
Jani Honkonen
pie: add label position to slice
r1450 m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum
Jani Honkonen
Split piechartcustomization to different files
r844
m_slice->setExploded(m_sliceExploded->isChecked());
m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
}
Jani Honkonen
API review changes for pie
r1009 void MainWidget::handleSliceClicked(QPieSlice* slice)
Jani Honkonen
Split piechartcustomization to different files
r844 {
m_slice = static_cast<CustomSlice*>(slice);
// name
Jani Honkonen
Tinkering with piechartcustomization
r1486 m_sliceName->blockSignals(true);
Jani Honkonen
Split piechartcustomization to different files
r844 m_sliceName->setText(slice->label());
Jani Honkonen
Tinkering with piechartcustomization
r1486 m_sliceName->blockSignals(false);
Jani Honkonen
Split piechartcustomization to different files
r844
// value
m_sliceValue->blockSignals(true);
m_sliceValue->setValue(slice->value());
m_sliceValue->blockSignals(false);
// pen
m_pen->setText(PenTool::name(m_slice->pen()));
m_penTool->setPen(m_slice->pen());
// brush
m_brush->setText(m_slice->originalBrush().color().name());
m_brushTool->setBrush(m_slice->originalBrush());
// label
Tero Ahola
Use labelBrush instead of labelPen for text labels
r1307 m_labelBrush->setText(BrushTool::name(m_slice->labelBrush()));
m_labelBrushTool->setBrush(m_slice->labelBrush());
Jani Honkonen
Split piechartcustomization to different files
r844 m_font->setText(slice->labelFont().toString());
m_sliceLabelVisible->blockSignals(true);
m_sliceLabelVisible->setChecked(slice->isLabelVisible());
m_sliceLabelVisible->blockSignals(false);
m_sliceLabelArmFactor->blockSignals(true);
m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
m_sliceLabelArmFactor->blockSignals(false);
Jani Honkonen
pie: add label position to slice
r1450 m_labelPosition->blockSignals(true);
m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum
m_labelPosition->blockSignals(false);
Jani Honkonen
Split piechartcustomization to different files
r844
// exploded
m_sliceExploded->blockSignals(true);
m_sliceExploded->setChecked(slice->isExploded());
m_sliceExploded->blockSignals(false);
m_sliceExplodedFactor->blockSignals(true);
m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
m_sliceExplodedFactor->blockSignals(false);
}
void MainWidget::showFontDialog()
{
if (!m_slice)
return;
QFontDialog dialog(m_slice->labelFont());
dialog.show();
dialog.exec();
m_slice->setLabelFont(dialog.currentFont());
m_font->setText(dialog.currentFont().toString());
}
Jani Honkonen
Improving pie examples
r892 void MainWidget::appendSlice()
Jani Honkonen
Split piechartcustomization to different files
r844 {
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 *m_series << new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0);
Jani Honkonen
Split piechartcustomization to different files
r844 }
void MainWidget::insertSlice()
{
if (!m_slice)
return;
int i = m_series->slices().indexOf(m_slice);
Jani Honkonen
pie: change the order of parameters when creating slices to be more intuitive
r1206 m_series->insert(i, new CustomSlice("Slice " + QString::number(m_series->count()+1), 10.0));
Jani Honkonen
Split piechartcustomization to different files
r844 }
void MainWidget::removeSlice()
{
if (!m_slice)
return;
Jani Honkonen
Improving pie examples
r892 m_sliceName->setText("<click a slice>");
Jani Honkonen
Split piechartcustomization to different files
r844 m_series->remove(m_slice);
m_slice = 0;
}
#include "moc_mainwidget.cpp"