diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2017-08-01 16:45:50 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2017-08-03 07:54:28 +0000 |
commit | ebc5bc3d8b2d7ea135a430d5cbc77f9f97cb78b0 (patch) | |
tree | 3b872b582ddeab668e0cc4b809640a53b114c282 | |
parent | eedb1c76538cac3c11e7ac57eaa571d6ce07a632 (diff) |
Minor coding style fixes to examples
Task-number: QTBUG-60662
Change-Id: I0edd88328b403d09faa27d30b89ac91c802121dc
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
19 files changed, 158 insertions, 97 deletions
diff --git a/examples/charts/callout/view.cpp b/examples/charts/callout/view.cpp index 9c1eca69..bdec4e67 100644 --- a/examples/charts/callout/view.cpp +++ b/examples/charts/callout/view.cpp @@ -82,11 +82,11 @@ View::View(QWidget *parent) m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height()); m_coordY->setText("Y: "); - connect(series, SIGNAL(clicked(QPointF)), this, SLOT(keepCallout())); - connect(series, SIGNAL(hovered(QPointF, bool)), this, SLOT(tooltip(QPointF,bool))); + connect(series, &QLineSeries::clicked, this, &View::keepCallout); + connect(series, &QLineSeries::hovered, this, &View::tooltip); - connect(series2, SIGNAL(clicked(QPointF)), this, SLOT(keepCallout())); - connect(series2, SIGNAL(hovered(QPointF, bool)), this, SLOT(tooltip(QPointF,bool))); + connect(series2, &QSplineSeries::clicked, this, &View::keepCallout); + connect(series2, &QSplineSeries::hovered, this, &View::tooltip); this->setMouseTracking(true); } diff --git a/examples/charts/chartinteractions/main.cpp b/examples/charts/chartinteractions/main.cpp index 41b1fd91..5b8bac5b 100644 --- a/examples/charts/chartinteractions/main.cpp +++ b/examples/charts/chartinteractions/main.cpp @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) chart->setAxisY(axisY, series); axisY->setRange(0, 13); - QObject::connect(series, SIGNAL(pressed(QPointF)), chart, SLOT(clickPoint(QPointF))); + QObject::connect(series, &QLineSeries::pressed, chart, &Chart::clickPoint); ChartView *chartView = new ChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); diff --git a/examples/charts/chartthemes/themewidget.cpp b/examples/charts/chartthemes/themewidget.cpp index 9739dde1..32779bb9 100644 --- a/examples/charts/chartthemes/themewidget.cpp +++ b/examples/charts/chartthemes/themewidget.cpp @@ -94,7 +94,8 @@ ThemeWidget::ThemeWidget(QWidget *parent) : m_charts << chartView; chartView = new QChartView(createPieChart()); - chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... + // Funny things happen if the pie slice labels do not fit the screen, so we ignore size policy + chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); baseLayout->addWidget(chartView, 2, 0); m_charts << chartView; @@ -119,10 +120,16 @@ ThemeWidget::~ThemeWidget() void ThemeWidget::connectSignals() { - connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); - connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); - connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); - connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); + connect(m_themeComboBox, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &ThemeWidget::updateUI); + connect(m_antialiasCheckBox, &QCheckBox::toggled, this, &ThemeWidget::updateUI); + connect(m_animatedComboBox, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &ThemeWidget::updateUI); + connect(m_legendComboBox, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &ThemeWidget::updateUI); } DataTable ThemeWidget::generateRandomData(int listCount, int valueMax, int valueCount) const @@ -321,7 +328,8 @@ QChart *ThemeWidget::createScatterChart() const void ThemeWidget::updateUI() { - QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); + QChart::ChartTheme theme = static_cast<QChart::ChartTheme>( + m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt()); if (m_charts.at(0)->chart()->theme() != theme) { foreach (QChartView *chartView, m_charts) @@ -360,7 +368,8 @@ void ThemeWidget::updateUI() foreach (QChartView *chart, m_charts) chart->setRenderHint(QPainter::Antialiasing, checked); - QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); + QChart::AnimationOptions options( + m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); if (m_charts.at(0)->chart()->animationOptions() != options) { foreach (QChartView *chartView, m_charts) chartView->chart()->setAnimationOptions(options); diff --git a/examples/charts/donutbreakdown/mainslice.cpp b/examples/charts/donutbreakdown/mainslice.cpp index 31541270..49746de0 100644 --- a/examples/charts/donutbreakdown/mainslice.cpp +++ b/examples/charts/donutbreakdown/mainslice.cpp @@ -36,7 +36,7 @@ MainSlice::MainSlice(QPieSeries *breakdownSeries, QObject *parent) : QPieSlice(parent), m_breakdownSeries(breakdownSeries) { - connect(this, SIGNAL(percentageChanged()), this, SLOT(updateLabel())); + connect(this, &MainSlice::percentageChanged, this, &MainSlice::updateLabel); } //![1] diff --git a/examples/charts/dynamicspline/chart.cpp b/examples/charts/dynamicspline/chart.cpp index 264f2460..21985998 100644 --- a/examples/charts/dynamicspline/chart.cpp +++ b/examples/charts/dynamicspline/chart.cpp @@ -44,7 +44,7 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): { qsrand((uint) QTime::currentTime().msec()); - QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); + QObject::connect(&m_timer, &QTimer::timeout, this, &Chart::handleTimeout); m_timer.setInterval(1000); m_series = new QSplineSeries(this); diff --git a/examples/charts/legend/mainwidget.cpp b/examples/charts/legend/mainwidget.cpp index 1d9a3b00..047526a8 100644 --- a/examples/charts/legend/mainwidget.cpp +++ b/examples/charts/legend/mainwidget.cpp @@ -46,26 +46,26 @@ MainWidget::MainWidget(QWidget *parent) : // Create buttons for ui m_buttonLayout = new QGridLayout(); QPushButton *detachLegendButton = new QPushButton("Toggle attached"); - connect(detachLegendButton, SIGNAL(clicked()), this, SLOT(toggleAttached())); + connect(detachLegendButton, &QPushButton::clicked, this, &MainWidget::toggleAttached); m_buttonLayout->addWidget(detachLegendButton, 0, 0); QPushButton *addSetButton = new QPushButton("add barset"); - connect(addSetButton, SIGNAL(clicked()), this, SLOT(addBarset())); + connect(addSetButton, &QPushButton::clicked, this, &MainWidget::addBarset); m_buttonLayout->addWidget(addSetButton, 2, 0); QPushButton *removeBarsetButton = new QPushButton("remove barset"); - connect(removeBarsetButton, SIGNAL(clicked()), this, SLOT(removeBarset())); + connect(removeBarsetButton, &QPushButton::clicked, this, &MainWidget::removeBarset); m_buttonLayout->addWidget(removeBarsetButton, 3, 0); QPushButton *alignButton = new QPushButton("Align (Bottom)"); - connect(alignButton, SIGNAL(clicked()), this, SLOT(setLegendAlignment())); + connect(alignButton, &QPushButton::clicked, this, &MainWidget::setLegendAlignment); m_buttonLayout->addWidget(alignButton, 4, 0); QPushButton *boldButton = new QPushButton("Toggle bold"); - connect(boldButton, SIGNAL(clicked()), this, SLOT(toggleBold())); + connect(boldButton, &QPushButton::clicked, this, &MainWidget::toggleBold); m_buttonLayout->addWidget(boldButton, 8, 0); QPushButton *italicButton = new QPushButton("Toggle italic"); - connect(italicButton, SIGNAL(clicked()), this, SLOT(toggleItalic())); + connect(italicButton, &QPushButton::clicked, this, &MainWidget::toggleItalic); m_buttonLayout->addWidget(italicButton, 9, 0); m_legendPosX = new QDoubleSpinBox(); @@ -73,10 +73,18 @@ MainWidget::MainWidget(QWidget *parent) : m_legendWidth = new QDoubleSpinBox(); m_legendHeight = new QDoubleSpinBox(); - connect(m_legendPosX, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); - connect(m_legendPosY, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); - connect(m_legendWidth, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); - connect(m_legendHeight, SIGNAL(valueChanged(double)), this, SLOT(updateLegendLayout())); + connect(m_legendPosX, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateLegendLayout); + connect(m_legendPosY, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateLegendLayout); + connect(m_legendWidth, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateLegendLayout); + connect(m_legendHeight, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateLegendLayout); QFormLayout *legendLayout = new QFormLayout(); legendLayout->addRow("HPos", m_legendPosX); @@ -95,7 +103,9 @@ MainWidget::MainWidget(QWidget *parent) : // Create spinbox to modify font size m_fontSize = new QDoubleSpinBox(); m_fontSize->setValue(m_chart->legend()->font().pointSizeF()); - connect(m_fontSize, SIGNAL(valueChanged(double)), this, SLOT(fontSizeChanged())); + connect(m_fontSize, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::fontSizeChanged); QFormLayout *fontLayout = new QFormLayout(); fontLayout->addRow("Legend font size", m_fontSize); diff --git a/examples/charts/legendmarkers/mainwidget.cpp b/examples/charts/legendmarkers/mainwidget.cpp index 78f8bc74..4222b960 100644 --- a/examples/charts/legendmarkers/mainwidget.cpp +++ b/examples/charts/legendmarkers/mainwidget.cpp @@ -88,9 +88,8 @@ void MainWidget::addSeries() series->append(data); m_chart->addSeries(series); - if (m_series.count() == 1) { + if (m_series.count() == 1) m_chart->createDefaultAxes(); - } } void MainWidget::removeSeries() @@ -110,8 +109,9 @@ void MainWidget::connectMarkers() // Connect all markers to handler foreach (QLegendMarker* marker, m_chart->legend()->markers()) { // Disconnect possible existing connection to avoid multiple connections - QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); - QObject::connect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); + QObject::disconnect(marker, &QLegendMarker::clicked, + this, &MainWidget::handleMarkerClicked); + QObject::connect(marker, &QLegendMarker::clicked, this, &MainWidget::handleMarkerClicked); } //![1] } @@ -120,7 +120,8 @@ void MainWidget::disconnectMarkers() { //![2] foreach (QLegendMarker* marker, m_chart->legend()->markers()) { - QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); + QObject::disconnect(marker, &QLegendMarker::clicked, + this, &MainWidget::handleMarkerClicked); } //![2] } @@ -151,9 +152,8 @@ void MainWidget::handleMarkerClicked() // Dim the marker, if series is not visible qreal alpha = 1.0; - if (!marker->series()->isVisible()) { + if (!marker->series()->isVisible()) alpha = 0.5; - } QColor color; QBrush brush = marker->labelBrush(); diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp index 35860a01..3d2292c8 100644 --- a/examples/charts/nesteddonuts/widget.cpp +++ b/examples/charts/nesteddonuts/widget.cpp @@ -69,7 +69,7 @@ Widget::Widget(QWidget *parent) slice->setLabelVisible(true); slice->setLabelColor(Qt::white); slice->setLabelPosition(QPieSlice::LabelInsideTangential); - connect(slice, SIGNAL(hovered(bool)), this, SLOT(explodeSlice(bool))); + connect(slice, &QPieSlice::hovered, this, &Widget::explodeSlice); donut->append(slice); donut->setHoleSize(minSize + i * (maxSize - minSize) / donutCount); donut->setPieSize(minSize + (i + 1) * (maxSize - minSize) / donutCount); @@ -88,7 +88,7 @@ Widget::Widget(QWidget *parent) //! [5] updateTimer = new QTimer(this); - connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateRotation())); + connect(updateTimer, &QTimer::timeout, this, &Widget::updateRotation); updateTimer->start(1250); //! [5] } diff --git a/examples/charts/piechartcustomization/brushtool.cpp b/examples/charts/piechartcustomization/brushtool.cpp index 6f46fe26..d4c1785b 100644 --- a/examples/charts/piechartcustomization/brushtool.cpp +++ b/examples/charts/piechartcustomization/brushtool.cpp @@ -61,8 +61,9 @@ BrushTool::BrushTool(QString title, QWidget *parent) layout->addRow("Style", m_styleCombo); setLayout(layout); - connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); - connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); + connect(m_colorButton, &QPushButton::clicked, this, &BrushTool::showColorDialog); + connect(m_styleCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &BrushTool::updateStyle); } void BrushTool::setBrush(QBrush brush) diff --git a/examples/charts/piechartcustomization/customslice.cpp b/examples/charts/piechartcustomization/customslice.cpp index ac46410b..12402d60 100644 --- a/examples/charts/piechartcustomization/customslice.cpp +++ b/examples/charts/piechartcustomization/customslice.cpp @@ -34,7 +34,7 @@ QT_CHARTS_USE_NAMESPACE CustomSlice::CustomSlice(QString label, qreal value) : QPieSlice(label, value) { - connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); + connect(this, &CustomSlice::hovered, this, &CustomSlice::showHighlight); } QBrush CustomSlice::originalBrush() diff --git a/examples/charts/piechartcustomization/mainwidget.cpp b/examples/charts/piechartcustomization/mainwidget.cpp index 71de08d9..7c3648a2 100644 --- a/examples/charts/piechartcustomization/mainwidget.cpp +++ b/examples/charts/piechartcustomization/mainwidget.cpp @@ -62,7 +62,7 @@ MainWidget::MainWidget(QWidget *parent) m_series->setLabelsVisible(); chart->addSeries(m_series); - connect(m_series, SIGNAL(clicked(QPieSlice*)), this, SLOT(handleSliceClicked(QPieSlice*))); + connect(m_series, &QPieSeries::clicked, this, &MainWidget::handleSliceClicked); // chart settings m_themeComboBox = new QComboBox(); @@ -89,10 +89,11 @@ MainWidget::MainWidget(QWidget *parent) 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())); - connect(m_legendCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateChartSettings())); + connect(m_themeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &MainWidget::updateChartSettings); + connect(m_aaCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); + connect(m_animationsCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); + connect(m_legendCheckBox, &QCheckBox::toggled, this, &MainWidget::updateChartSettings); // series settings m_hPosition = new QDoubleSpinBox(); @@ -148,15 +149,27 @@ MainWidget::MainWidget(QWidget *parent) 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())); - connect(m_holeSize, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); - connect(appendSlice, SIGNAL(clicked()), this, SLOT(appendSlice())); - connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); - connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); + connect(m_vPosition, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(m_hPosition, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(m_sizeFactor, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(m_startAngle, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(m_endAngle, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(m_holeSize, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSerieSettings); + connect(appendSlice, &QPushButton::clicked, this, &MainWidget::appendSlice); + connect(insertSlice, &QPushButton::clicked, this, &MainWidget::insertSlice); + connect(removeSlice, &QPushButton::clicked, this, &MainWidget::removeSlice); // slice settings m_sliceName = new QLineEdit("<click a slice>"); @@ -197,21 +210,29 @@ MainWidget::MainWidget(QWidget *parent) QGroupBox *sliceSettings = new QGroupBox("Selected slice"); sliceSettings->setLayout(sliceSettingsLayout); - connect(m_sliceName, SIGNAL(textChanged(QString)), this, SLOT(updateSliceSettings())); - 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())); - connect(m_labelBrush, SIGNAL(clicked()), m_labelBrushTool, SLOT(show())); - connect(m_labelBrushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); - 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())); - connect(m_labelPosition, SIGNAL(currentIndexChanged(int)), this, SLOT(updateSliceSettings())); + connect(m_sliceName, &QLineEdit::textChanged, this, &MainWidget::updateSliceSettings); + connect(m_sliceValue, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSliceSettings); + connect(m_pen, &QPushButton::clicked, m_penTool, &PenTool::show); + connect(m_penTool, &PenTool::changed, this, &MainWidget::updateSliceSettings); + connect(m_brush, &QPushButton::clicked, m_brushTool, &BrushTool::show); + connect(m_brushTool, &BrushTool::changed, this, &MainWidget::updateSliceSettings); + connect(m_font, &QPushButton::clicked, this, &MainWidget::showFontDialog); + connect(m_labelBrush, &QPushButton::clicked, m_labelBrushTool, &BrushTool::show); + connect(m_labelBrushTool, &BrushTool::changed, this, &MainWidget::updateSliceSettings); + connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); + connect(m_sliceLabelVisible, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); + connect(m_sliceLabelArmFactor, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSliceSettings); + connect(m_sliceExploded, &QCheckBox::toggled, this, &MainWidget::updateSliceSettings); + connect(m_sliceExplodedFactor, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &MainWidget::updateSliceSettings); + connect(m_labelPosition, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &MainWidget::updateSliceSettings); // create chart view m_chartView = new QChartView(chart); @@ -235,7 +256,8 @@ MainWidget::MainWidget(QWidget *parent) void MainWidget::updateChartSettings() { - QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); + QChart::ChartTheme theme = static_cast<QChart::ChartTheme>(m_themeComboBox->itemData( + m_themeComboBox->currentIndex()).toInt()); m_chartView->chart()->setTheme(theme); m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); @@ -276,7 +298,8 @@ void MainWidget::updateSliceSettings() m_slice->setLabelBrush(m_labelBrushTool->brush()); m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); - m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); // assumes that index is in sync with the enum + // We assume that label position index is in sync with the enum + m_slice->setLabelPosition((QPieSlice::LabelPosition)m_labelPosition->currentIndex()); m_slice->setExploded(m_sliceExploded->isChecked()); m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); @@ -315,7 +338,8 @@ void MainWidget::handleSliceClicked(QPieSlice *slice) m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); m_sliceLabelArmFactor->blockSignals(false); m_labelPosition->blockSignals(true); - m_labelPosition->setCurrentIndex(slice->labelPosition()); // assumes that index is in sync with the enum + // We assume that label position index is in sync with the enum + m_labelPosition->setCurrentIndex(slice->labelPosition()); m_labelPosition->blockSignals(false); // exploded diff --git a/examples/charts/piechartcustomization/pentool.cpp b/examples/charts/piechartcustomization/pentool.cpp index f39d8661..3b160859 100644 --- a/examples/charts/piechartcustomization/pentool.cpp +++ b/examples/charts/piechartcustomization/pentool.cpp @@ -71,11 +71,20 @@ PenTool::PenTool(QString title, QWidget *parent) layout->addRow("Join style", m_joinStyleCombo); setLayout(layout); - connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); - connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); - connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); - connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); - connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); + // Use old style connect on some signals because the signal is overloaded + connect(m_colorButton, &QPushButton::clicked, this, &PenTool::showColorDialog); + connect(m_widthSpinBox, + static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), + this, &PenTool::updateWidth); + connect(m_styleCombo, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &PenTool::updateStyle); + connect(m_capStyleCombo, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &PenTool::updateCapStyle); + connect(m_joinStyleCombo, + static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), + this, &PenTool::updateJoinStyle); } void PenTool::setPen(const QPen &pen) diff --git a/examples/charts/piechartdrilldown/drilldownslice.cpp b/examples/charts/piechartdrilldown/drilldownslice.cpp index 5f83d006..1fc6bd81 100644 --- a/examples/charts/piechartdrilldown/drilldownslice.cpp +++ b/examples/charts/piechartdrilldown/drilldownslice.cpp @@ -38,8 +38,8 @@ DrilldownSlice::DrilldownSlice(qreal value, QString prefix, QAbstractSeries *dri setValue(value); updateLabel(); setLabelFont(QFont("Arial", 8)); - connect(this, SIGNAL(percentageChanged()), this, SLOT(updateLabel())); - connect(this, SIGNAL(hovered(bool)), this, SLOT(showHighlight(bool))); + connect(this, &DrilldownSlice::percentageChanged, this, &DrilldownSlice::updateLabel); + connect(this, &DrilldownSlice::hovered, this, &DrilldownSlice::showHighlight); } DrilldownSlice::~DrilldownSlice() diff --git a/examples/charts/piechartdrilldown/main.cpp b/examples/charts/piechartdrilldown/main.cpp index 69f87158..3fd6ad65 100644 --- a/examples/charts/piechartdrilldown/main.cpp +++ b/examples/charts/piechartdrilldown/main.cpp @@ -55,24 +55,26 @@ int main(int argc, char *argv[]) QPieSeries *yearSeries = new QPieSeries(&window); yearSeries->setName("Sales by year - All"); - QList<QString> months; - months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; - QList<QString> names; - names << "Jane" << "John" << "Axel" << "Mary" << "Susan" << "Bob"; + const QStringList months = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + const QStringList names = { + "Jane", "John", "Axel", "Mary", "Susan", "Bob" + }; foreach (QString name, names) { QPieSeries *series = new QPieSeries(&window); series->setName("Sales by month - " + name); foreach (QString month, months) - *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); + *series << new DrilldownSlice(qrand() % 1000, month, yearSeries); - QObject::connect(series, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*))); + QObject::connect(series, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked); *yearSeries << new DrilldownSlice(series->sum(), name, series); } - QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), chart, SLOT(handleSliceClicked(QPieSlice*))); + QObject::connect(yearSeries, &QPieSeries::clicked, chart, &DrilldownChart::handleSliceClicked); chart->changeSeries(yearSeries); diff --git a/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml b/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml index 5d7a96ae..c52722f0 100644 --- a/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml +++ b/examples/charts/qmlf1legends/qml/qmlf1legends/main.qml @@ -70,10 +70,12 @@ Item { onTriggered: { currentIndex++; if (currentIndex < speedsXml.count) { - // Check if there is a series for the data already (we are using driver name to identify series) + // Check if there is a series for the data already + // (we are using driver name to identify series) var lineSeries = chartView.series(speedsXml.get(currentIndex).driver); if (!lineSeries) { - lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, speedsXml.get(currentIndex).driver); + lineSeries = chartView.createSeries(ChartView.SeriesTypeLine, + speedsXml.get(currentIndex).driver); chartView.axisY().min = 0; chartView.axisY().max = 250; chartView.axisY().tickCount = 6; @@ -81,7 +83,8 @@ Item { chartView.axisX().titleText = "speed trap"; chartView.axisX().labelFormat = "%.0f"; } - lineSeries.append(speedsXml.get(currentIndex).speedTrap, speedsXml.get(currentIndex).speed); + lineSeries.append(speedsXml.get(currentIndex).speedTrap, + speedsXml.get(currentIndex).speed); if (speedsXml.get(currentIndex).speedTrap > 3) { chartView.axisX().max = Number(speedsXml.get(currentIndex).speedTrap) + 1; diff --git a/examples/charts/scatterinteractions/chartview.cpp b/examples/charts/scatterinteractions/chartview.cpp index 25432786..fb4a81d2 100644 --- a/examples/charts/scatterinteractions/chartview.cpp +++ b/examples/charts/scatterinteractions/chartview.cpp @@ -45,9 +45,8 @@ ChartView::ChartView(QWidget *parent) m_scatter = new QScatterSeries(); m_scatter->setName("scatter1"); for (qreal x(0.5); x <= 4.0; x += 0.5) { - for (qreal y(0.5); y <= 4.0; y += 0.5) { + for (qreal y(0.5); y <= 4.0; y += 0.5) *m_scatter << QPointF(x, y); - } } m_scatter2 = new QScatterSeries(); m_scatter2->setName("scatter2"); @@ -58,7 +57,7 @@ ChartView::ChartView(QWidget *parent) chart()->axisX()->setRange(0, 4.5); chart()->axisY()->setRange(0, 4.5); - connect(m_scatter, SIGNAL(clicked(QPointF)), this, SLOT(handleClickedPoint(QPointF))); + connect(m_scatter, &QScatterSeries::clicked, this, &ChartView::handleClickedPoint); } ChartView::~ChartView() diff --git a/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp b/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp index 652300c1..2af737d2 100644 --- a/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp +++ b/examples/charts/stackedbarchartdrilldown/drilldownchart.cpp @@ -40,9 +40,8 @@ DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) void DrilldownChart::changeSeries(DrilldownBarSeries *series) { - if (m_currentSeries) { + if (m_currentSeries) removeSeries(m_currentSeries); - } m_currentSeries = series; diff --git a/examples/charts/stackedbarchartdrilldown/main.cpp b/examples/charts/stackedbarchartdrilldown/main.cpp index c3e03505..63043dfe 100644 --- a/examples/charts/stackedbarchartdrilldown/main.cpp +++ b/examples/charts/stackedbarchartdrilldown/main.cpp @@ -76,11 +76,13 @@ int main(int argc, char *argv[]) } // Use clicked signal to implement drilldown - QObject::connect(weeklySeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*))); + QObject::connect(weeklySeries, &DrilldownBarSeries::clicked, + drilldownChart, &DrilldownChart::handleClicked); } // Enable drilldown from season series using clicked signal - QObject::connect(seasonSeries, SIGNAL(clicked(int,QBarSet*)), drilldownChart, SLOT(handleClicked(int,QBarSet*))); + QObject::connect(seasonSeries, &DrilldownBarSeries::clicked, + drilldownChart, &DrilldownChart::handleClicked); //! [3] //! [4] diff --git a/examples/charts/temperaturerecords/main.cpp b/examples/charts/temperaturerecords/main.cpp index a41724ba..b521dee7 100644 --- a/examples/charts/temperaturerecords/main.cpp +++ b/examples/charts/temperaturerecords/main.cpp @@ -46,8 +46,10 @@ int main(int argc, char *argv[]) QBarSet *low = new QBarSet("Min"); QBarSet *high = new QBarSet("Max"); - *low << -52 << -50 << -45.3 << -37.0 << -25.6 << -8.0 << -6.0 << -11.8 << -19.7 << -32.8 << -43.0 << -48.0; - *high << 11.9 << 12.8 << 18.5 << 26.5 << 32.0 << 34.8 << 38.2 << 34.8 << 29.8 << 20.4 << 15.1 << 11.8; + *low << -52 << -50 << -45.3 << -37.0 << -25.6 << -8.0 + << -6.0 << -11.8 << -19.7 << -32.8 << -43.0 << -48.0; + *high << 11.9 << 12.8 << 18.5 << 26.5 << 32.0 << 34.8 + << 38.2 << 34.8 << 29.8 << 20.4 << 15.1 << 11.8; //![1] //![2] @@ -64,8 +66,9 @@ int main(int argc, char *argv[]) //![3] //![4] - QStringList categories; - categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec"; + QStringList categories = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; QBarCategoryAxis *axis = new QBarCategoryAxis(); axis->append(categories); |