diff options
author | Liang Qi <liang.qi@qt.io> | 2017-08-15 12:22:16 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-08-15 13:06:48 +0200 |
commit | 0168fe1f95d56850734447b118cdcf1847da1c51 (patch) | |
tree | 55763c374af875fc7228dc8d1f3771ef74c083cb | |
parent | ac79bf382a9fabed940b8f9be20feeb58ac205aa (diff) | |
parent | 1f47b1a7ae58702dccc57a9ccbaa905441f4fecb (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
.qmake.conf
examples/charts/dynamicspline/chart.cpp
examples/charts/piechartdrilldown/main.cpp
Change-Id: I839e97bf377c7823f2f464c097656d58f279ed77
32 files changed, 321 insertions, 193 deletions
@@ -40,6 +40,7 @@ pcviewer.cfg core .qmake.cache .qmake.vars +.qmake.stash *.prl tags .DS_Store @@ -265,3 +266,8 @@ qtc-qmldbg *.map work +# Generated by qtPrepareTool() +wrapper.sh +wrapper.bat +*_wrapper.sh +*_wrapper.bat diff --git a/dist/changes-5.9.1 b/dist/changes-5.9.1 new file mode 100644 index 00000000..326ea171 --- /dev/null +++ b/dist/changes-5.9.1 @@ -0,0 +1,26 @@ +Qt 5.9.1 is a bug-fix release. It maintains both forward and backward +compatibility (source and binary) with Qt 5.9.0. + +For more details, refer to the online documentation included in this +distribution. The documentation is also available online: + +http://doc.qt.io/qt-5/index.html + +The Qt version 5.9 series is binary compatible with the 5.8.x series. +Applications compiled for 5.8 will continue to run with 5.9. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + +https://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Qt 5.9.1 Changes * +**************************************************************************** + +Fixed issues +------------ +- Fixed QXYModelMapper sync issues diff --git a/examples/charts/barmodelmapper/customtablemodel.cpp b/examples/charts/barmodelmapper/customtablemodel.cpp index 2caef9b5..71165dff 100644 --- a/examples/charts/barmodelmapper/customtablemodel.cpp +++ b/examples/charts/barmodelmapper/customtablemodel.cpp @@ -88,10 +88,10 @@ QVariant CustomTableModel::data(const QModelIndex &index, int role) const } else if (role == Qt::EditRole) { return m_data[index.row()]->at(index.column()); } else if (role == Qt::BackgroundRole) { - QRect rect; - foreach (rect, m_mapping) - if (rect.contains(index.column(), index.row())) - return QColor(m_mapping.key(rect)); + for (const QRect &rect : m_mapping) { + if (rect.contains(index.column(), index.row())) + return QColor(m_mapping.key(rect)); + } // cell not mapped return white color return QColor(Qt::white); diff --git a/examples/charts/callout/view.cpp b/examples/charts/callout/view.cpp index 9c1eca69..5936befd 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); } @@ -98,7 +98,8 @@ void View::resizeEvent(QResizeEvent *event) m_chart->resize(event->size()); m_coordX->setPos(m_chart->size().width()/2 - 50, m_chart->size().height() - 20); m_coordY->setPos(m_chart->size().width()/2 + 50, m_chart->size().height() - 20); - foreach (Callout *callout, m_callouts) + const auto callouts = m_callouts; + for (Callout *callout : callouts) callout->updateGeometry(); } QGraphicsView::resizeEvent(event); diff --git a/examples/charts/chartinteractions/chart.cpp b/examples/charts/chartinteractions/chart.cpp index a178dffc..ca63a3de 100644 --- a/examples/charts/chartinteractions/chart.cpp +++ b/examples/charts/chartinteractions/chart.cpp @@ -44,10 +44,11 @@ Chart::~Chart() void Chart::clickPoint(const QPointF &point) { - // Find the closes data point + // Find the closest data point m_movingPoint = QPoint(); m_clicked = false; - foreach (QPointF p, m_series->points()) { + const auto points = m_series->points(); + for (QPointF p : points) { if (distance(p, point) < distance(m_movingPoint, point)) { m_movingPoint = p; m_clicked = 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 6f408c75..f1f28af4 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 @@ -223,7 +230,7 @@ QChart *ThemeWidget::createBarChart(int valueCount) const QStackedBarSeries *series = new QStackedBarSeries(chart); for (int i(0); i < m_dataTable.count(); i++) { QBarSet *set = new QBarSet("Bar set " + QString::number(i)); - foreach (Data data, m_dataTable[i]) + for (const Data &data : m_dataTable[i]) *set << data.first.y(); series->append(set); } @@ -240,9 +247,9 @@ QChart *ThemeWidget::createLineChart() const QString name("Series "); int nameIndex = 0; - foreach (DataList list, m_dataTable) { + for (const DataList &list : m_dataTable) { QLineSeries *series = new QLineSeries(chart); - foreach (Data data, list) + for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); nameIndex++; @@ -261,7 +268,7 @@ QChart *ThemeWidget::createPieChart() const qreal pieSize = 1.0 / m_dataTable.count(); for (int i = 0; i < m_dataTable.count(); i++) { QPieSeries *series = new QPieSeries(chart); - foreach (Data data, m_dataTable[i]) { + for (const Data &data : m_dataTable[i]) { QPieSlice *slice = series->append(data.second, data.first.y()); if (data == m_dataTable[i].first()) { slice->setLabelVisible(); @@ -285,9 +292,9 @@ QChart *ThemeWidget::createSplineChart() const chart->setTitle("Spline chart"); QString name("Series "); int nameIndex = 0; - foreach (DataList list, m_dataTable) { + for (const DataList &list : m_dataTable) { QSplineSeries *series = new QSplineSeries(chart); - foreach (Data data, list) + for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); nameIndex++; @@ -304,9 +311,9 @@ QChart *ThemeWidget::createScatterChart() const chart->setTitle("Scatter chart"); QString name("Series "); int nameIndex = 0; - foreach (DataList list, m_dataTable) { + for (const DataList &list : m_dataTable) { QScatterSeries *series = new QScatterSeries(chart); - foreach (Data data, list) + for (const Data &data : list) series->append(data.first); series->setName(name + QString::number(nameIndex)); nameIndex++; @@ -318,10 +325,12 @@ 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()); + const auto charts = m_charts; if (m_charts.at(0)->chart()->theme() != theme) { - foreach (QChartView *chartView, m_charts) + for (QChartView *chartView : charts) chartView->chart()->setTheme(theme); QPalette pal = window()->palette(); @@ -354,22 +363,23 @@ void ThemeWidget::updateUI() } bool checked = m_antialiasCheckBox->isChecked(); - foreach (QChartView *chart, m_charts) + for (QChartView *chart : 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) + for (QChartView *chartView : charts) chartView->chart()->setAnimationOptions(options); } Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); if (!alignment) { - foreach (QChartView *chartView, m_charts) + for (QChartView *chartView : charts) chartView->chart()->legend()->hide(); } else { - foreach (QChartView *chartView, m_charts) { + for (QChartView *chartView : charts) { chartView->chart()->legend()->setAlignment(alignment); chartView->chart()->legend()->show(); } diff --git a/examples/charts/donutbreakdown/donutbreakdownchart.cpp b/examples/charts/donutbreakdown/donutbreakdownchart.cpp index cf04edeb..9bf7f71a 100644 --- a/examples/charts/donutbreakdown/donutbreakdownchart.cpp +++ b/examples/charts/donutbreakdown/donutbreakdownchart.cpp @@ -66,7 +66,8 @@ void DonutBreakdownChart::addBreakdownSeries(QPieSeries *breakdownSeries, QColor breakdownSeries->setPieSize(0.8); breakdownSeries->setHoleSize(0.7); breakdownSeries->setLabelsVisible(); - foreach (QPieSlice *slice, breakdownSeries->slices()) { + const auto slices = breakdownSeries->slices(); + for (QPieSlice *slice : slices) { color = color.lighter(115); slice->setBrush(color); slice->setLabelFont(font); @@ -87,7 +88,8 @@ void DonutBreakdownChart::addBreakdownSeries(QPieSeries *breakdownSeries, QColor void DonutBreakdownChart::recalculateAngles() { qreal angle = 0; - foreach (QPieSlice *slice, m_mainSeries->slices()) { + const auto slices = m_mainSeries->slices(); + for (QPieSlice *slice : slices) { QPieSeries *breakdownSeries = qobject_cast<MainSlice *>(slice)->breakdownSeries(); breakdownSeries->setPieStartAngle(angle); angle += slice->percentage() * 360.0; // full pie is 360.0 @@ -100,8 +102,10 @@ void DonutBreakdownChart::recalculateAngles() void DonutBreakdownChart::updateLegendMarkers() { // go through all markers - foreach (QAbstractSeries *series, series()) { - foreach (QLegendMarker *marker, legend()->markers(series)) { + const auto allseries = series(); + for (QAbstractSeries *series : allseries) { + const auto markers = legend()->markers(series); + for (QLegendMarker *marker : markers) { QPieLegendMarker *pieMarker = qobject_cast<QPieLegendMarker *>(marker); if (series == m_mainSeries) { // hide markers from main series 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 9f33423c..ee7061d2 100644 --- a/examples/charts/dynamicspline/chart.cpp +++ b/examples/charts/dynamicspline/chart.cpp @@ -42,7 +42,7 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags): m_x(5), m_y(1) { - 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 2cfe570e..a48a6384 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() @@ -108,10 +107,12 @@ void MainWidget::connectMarkers() { //![1] // Connect all markers to handler - foreach (QLegendMarker* marker, m_chart->legend()->markers()) { + const auto markers = m_chart->legend()->markers(); + for (QLegendMarker *marker : 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] } @@ -119,8 +120,10 @@ void MainWidget::connectMarkers() void MainWidget::disconnectMarkers() { //![2] - foreach (QLegendMarker* marker, m_chart->legend()->markers()) { - QObject::disconnect(marker, SIGNAL(clicked()), this, SLOT(handleMarkerClicked())); + const auto markers = m_chart->legend()->markers(); + for (QLegendMarker *marker : markers) { + QObject::disconnect(marker, &QLegendMarker::clicked, + this, &MainWidget::handleMarkerClicked); } //![2] } @@ -151,9 +154,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/modeldata/customtablemodel.cpp b/examples/charts/modeldata/customtablemodel.cpp index 98cd8c8c..e36a5d3d 100644 --- a/examples/charts/modeldata/customtablemodel.cpp +++ b/examples/charts/modeldata/customtablemodel.cpp @@ -86,7 +86,7 @@ QVariant CustomTableModel::data(const QModelIndex &index, int role) const } else if (role == Qt::EditRole) { return m_data[index.row()]->at(index.column()); } else if (role == Qt::BackgroundRole) { - foreach (QRect rect, m_mapping) { + for (const QRect &rect : m_mapping) { if (rect.contains(index.column(), index.row())) return QColor(m_mapping.key(rect)); } diff --git a/examples/charts/nesteddonuts/widget.cpp b/examples/charts/nesteddonuts/widget.cpp index 533b8969..f8090455 100644 --- a/examples/charts/nesteddonuts/widget.cpp +++ b/examples/charts/nesteddonuts/widget.cpp @@ -68,7 +68,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); @@ -87,7 +87,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/openglseries/datasource.cpp b/examples/charts/openglseries/datasource.cpp index 1448e54e..b5992214 100644 --- a/examples/charts/openglseries/datasource.cpp +++ b/examples/charts/openglseries/datasource.cpp @@ -96,12 +96,6 @@ void DataSource::startUpdates(const QList<QXYSeries *> &seriesList, QLabel *fpsL void DataSource::generateData(int seriesCount, int rowCount, int colCount) { - // Remove previous data - foreach (QVector<QVector<QPointF> > seriesData, m_data) { - foreach (QVector<QPointF> row, seriesData) - row.clear(); - } - m_data.clear(); qreal xAdjustment = 20.0 / (colCount * rowCount); 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 bea7fb3c..1fed557a 100644 --- a/examples/charts/piechartdrilldown/main.cpp +++ b/examples/charts/piechartdrilldown/main.cpp @@ -53,24 +53,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) { + for (const QString &name : names) { QPieSeries *series = new QPieSeries(&window); series->setName("Sales by month - " + name); - foreach (QString month, months) - *series << new DrilldownSlice(QRandomGenerator::bounded(1000), month, yearSeries); + for (const QString &month : months) + *series << new DrilldownSlice(QRandomGenerator::bounded(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/polarchart/chartview.cpp b/examples/charts/polarchart/chartview.cpp index 0a3ff9ad..1dc5cc00 100644 --- a/examples/charts/polarchart/chartview.cpp +++ b/examples/charts/polarchart/chartview.cpp @@ -84,31 +84,31 @@ void ChartView::switchChartType() newChart = new QChart(); // Move series and axes from old chart to new one - QList<QAbstractSeries *> seriesList = oldChart->series(); - QList<QAbstractAxis *> axisList = oldChart->axes(); + const QList<QAbstractSeries *> seriesList = oldChart->series(); + const QList<QAbstractAxis *> axisList = oldChart->axes(); QList<QPair<qreal, qreal> > axisRanges; - foreach (QAbstractAxis *axis, axisList) { + for (QAbstractAxis *axis : axisList) { QValueAxis *valueAxis = static_cast<QValueAxis *>(axis); axisRanges.append(QPair<qreal, qreal>(valueAxis->min(), valueAxis->max())); } - foreach (QAbstractSeries *series, seriesList) + for (QAbstractSeries *series : seriesList) oldChart->removeSeries(series); - foreach (QAbstractAxis *axis, axisList) { + for (QAbstractAxis *axis : axisList) { oldChart->removeAxis(axis); newChart->addAxis(axis, axis->alignment()); } - foreach (QAbstractSeries *series, seriesList) { + for (QAbstractSeries *series : seriesList) { newChart->addSeries(series); - foreach (QAbstractAxis *axis, axisList) + for (QAbstractAxis *axis : axisList) series->attachAxis(axis); } int count = 0; - foreach (QAbstractAxis *axis, axisList) { + for (QAbstractAxis *axis : axisList) { axis->setRange(axisRanges[count].first, axisRanges[count].second); count++; } 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/qmloscilloscope/datasource.cpp b/examples/charts/qmloscilloscope/datasource.cpp index 1f6c7272..dddee543 100644 --- a/examples/charts/qmloscilloscope/datasource.cpp +++ b/examples/charts/qmloscilloscope/datasource.cpp @@ -69,8 +69,6 @@ void DataSource::update(QAbstractSeries *series) void DataSource::generateData(int type, int rowCount, int colCount) { // Remove previous data - foreach (QVector<QPointF> row, m_data) - row.clear(); m_data.clear(); // Append the new data depending on the type diff --git a/examples/charts/scatterinteractions/chartview.cpp b/examples/charts/scatterinteractions/chartview.cpp index 25432786..9c2e8da3 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() @@ -71,7 +70,8 @@ void ChartView::handleClickedPoint(const QPointF &point) // Find the closest point from series 1 QPointF closest(INT_MAX, INT_MAX); qreal distance(INT_MAX); - foreach (QPointF currentPoint, m_scatter->points()) { + const auto points = m_scatter->points(); + for (const QPointF ¤tPoint : points) { qreal currentDistance = qSqrt((currentPoint.x() - clickedPoint.x()) * (currentPoint.x() - clickedPoint.x()) + (currentPoint.y() - clickedPoint.y()) 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 f4bbc3f0..46d00190 100644 --- a/examples/charts/stackedbarchartdrilldown/main.cpp +++ b/examples/charts/stackedbarchartdrilldown/main.cpp @@ -50,12 +50,15 @@ int main(int argc, char *argv[]) //! [2] // Define categories - QStringList months; - months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; - QStringList weeks; - weeks << "week 1" << "week 2" << "week 3" << "week 4"; - QStringList plants; - plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; + const QStringList months = { + "May", "Jun", "Jul", "Aug", "Sep" + }; + const QStringList weeks = { + "week 1", "week 2", "week 3", "week 4" + }; + const QStringList plants = { + "Habanero", "Lemon Drop", "Starfish", "Aji Amarillo" + }; //! [2] //! [3] @@ -77,16 +80,18 @@ 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] // Fill monthly and weekly series with data - foreach (QString plant, plants) { + for (const QString &plant : plants) { QBarSet *monthlyCrop = new QBarSet(plant); for (int month = 0; month < months.count(); month++) { QBarSet *weeklyCrop = new QBarSet(plant); 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); diff --git a/src/charts/axis/linearrowitem_p.h b/src/charts/axis/linearrowitem_p.h index 2e785716..521444aa 100644 --- a/src/charts/axis/linearrowitem_p.h +++ b/src/charts/axis/linearrowitem_p.h @@ -58,8 +58,8 @@ public: protected: void mousePressEvent(QGraphicsSceneMouseEvent *event) { - Q_UNUSED(event) m_axis->axisSelected(); + QGraphicsLineItem::mousePressEvent(event); } QRectF boundingRect() const diff --git a/src/charts/barchart/abstractbarchartitem.cpp b/src/charts/barchart/abstractbarchartitem.cpp index f62c0ef7..910066b5 100644 --- a/src/charts/barchart/abstractbarchartitem.cpp +++ b/src/charts/barchart/abstractbarchartitem.cpp @@ -500,6 +500,7 @@ void AbstractBarChartItem::createLabelItems() QGraphicsTextItem *label = bars.at(j)->labelItem(); if (!label) { QGraphicsTextItem *newLabel = new QGraphicsTextItem(this); + newLabel->setAcceptHoverEvents(false); newLabel->document()->setDocumentMargin(ChartPresenter::textMargin()); bars.at(j)->setLabelItem(newLabel); } diff --git a/tests/auto/qbarseries/BLACKLIST b/tests/auto/qbarseries/BLACKLIST new file mode 100644 index 00000000..ea01d313 --- /dev/null +++ b/tests/auto/qbarseries/BLACKLIST @@ -0,0 +1,2 @@ +[mousehovered] +ci diff --git a/tests/auto/qbarseries/tst_qbarseries.cpp b/tests/auto/qbarseries/tst_qbarseries.cpp index 8922af25..5fe2808c 100644 --- a/tests/auto/qbarseries/tst_qbarseries.cpp +++ b/tests/auto/qbarseries/tst_qbarseries.cpp @@ -621,16 +621,24 @@ void tst_QBarSeries::mouseclicked() void tst_QBarSeries::mousehovered_data() { - + QTest::addColumn<uint>("labelsPosition"); + QTest::addColumn<bool>("labelsVisible"); + + QTest::newRow("labelsCenter") << (uint)QAbstractBarSeries::LabelsCenter << true; + QTest::newRow("labelsInsideEnd") << (uint)QAbstractBarSeries::LabelsInsideEnd << true; + QTest::newRow("labelsInsideBase") << (uint)QAbstractBarSeries::LabelsInsideBase << true; + QTest::newRow("labelsOutsideEnd") << (uint)QAbstractBarSeries::LabelsOutsideEnd << true; + QTest::newRow("noLabelsCenter") << (uint)QAbstractBarSeries::LabelsCenter << false; } void tst_QBarSeries::mousehovered() { - SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); - SKIP_IF_FLAKY_MOUSE_MOVE(); + QFETCH(uint, labelsPosition); + QFETCH(bool, labelsVisible); QBarSeries* series = new QBarSeries(); - + series->setLabelsVisible(labelsVisible); + series->setLabelsPosition(static_cast<QAbstractBarSeries::LabelsPosition>(labelsPosition)); QBarSet* set1 = new QBarSet(QString("set 1")); *set1 << 10 << 10 << 10; series->append(set1); @@ -683,21 +691,24 @@ void tst_QBarSeries::mousehovered() layout.append(rect); } } + // In order to make it feel like a normal user moving the mouse, we hover across from the edge. + // If we go right to the center, we can hit a label which does not emit hovered then, but that + // would not be a normal use case. //======================================================================= // move mouse to left border QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y())); - QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); - TRY_COMPARE(seriesIndexSpy.count(), 0); - TRY_COMPARE(setIndexSpy1.count(), 0); - TRY_COMPARE(setIndexSpy2.count(), 0); + QTest::qWait(5000); + QCOMPARE(seriesIndexSpy.count(), 0); + QCOMPARE(setIndexSpy1.count(), 0); + QCOMPARE(setIndexSpy2.count(), 0); //======================================================================= -// move mouse on top of set1 - QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint()); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 0); +// move mouse to just inside left border to account for labels + QTest::mouseMove(view.viewport(), QPoint(layout.at(0).x() + 1, layout.at(0).y() + 1)); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 0); QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst(); QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); @@ -709,11 +720,27 @@ void tst_QBarSeries::mousehovered() QVERIFY(setIndexSpyArg.at(0).toBool() == true); //======================================================================= +// move mouse to center of set1 + QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint()); + QTest::qWait(5000); + QCOMPARE(seriesIndexSpy.count(), 0); + QCOMPARE(setIndexSpy1.count(), 0); + QCOMPARE(setIndexSpy2.count(), 0); + +//======================================================================= +// move mouse to bottom of set1 + QTest::mouseMove(view.viewport(), QPoint(layout.at(0).center().x(), layout.at(0).bottom())); + QTest::qWait(5000); + QCOMPARE(seriesIndexSpy.count(), 0); + QCOMPARE(setIndexSpy1.count(), 0); + QCOMPARE(setIndexSpy2.count(), 0); + +//======================================================================= // move mouse from top of set1 to top of set2 - QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint()); - TRY_COMPARE(seriesIndexSpy.count(), 2); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTest::mouseMove(view.viewport(), QPoint(layout.at(1).x() + 1, layout.at(1).y() + 1)); + QTRY_COMPARE(seriesIndexSpy.count(), 2); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should leave set1 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -738,9 +765,9 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse from top of set2 to background QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0)); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 0); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 0); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should leave set2 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -754,11 +781,11 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse on top of set1, bar0 to check the index (hover into set1) - QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint()); + QTest::mouseMove(view.viewport(), QPoint(layout.at(0).x() + 1, layout.at(0).y() + 1)); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 0); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 0); //should enter set1, bar0 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -777,11 +804,11 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse on top of set2, bar0 to check the index (hover out set1, // hover in set1) - QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint()); + QTest::mouseMove(view.viewport(), QPoint(layout.at(1).x() + 1, layout.at(1).y() + 1)); - TRY_COMPARE(seriesIndexSpy.count(), 2); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTRY_COMPARE(seriesIndexSpy.count(), 2); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should leave set1, bar0 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -814,11 +841,11 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse on top of set1, bar1 to check the index (hover out set 2, // hover in set1) - QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint()); + QTest::mouseMove(view.viewport(), QPoint(layout.at(2).x() + 1, layout.at(2).y() + 1)); - TRY_COMPARE(seriesIndexSpy.count(), 2); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTRY_COMPARE(seriesIndexSpy.count(), 2); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should leave set2, bar0 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -853,9 +880,9 @@ void tst_QBarSeries::mousehovered() // (hover out set1) QTest::mouseMove(view.viewport(), QPoint((layout.at(2).right() + layout.at(3).left()) / 2, 0)); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 1); - TRY_COMPARE(setIndexSpy2.count(), 0); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 1); + QTRY_COMPARE(setIndexSpy2.count(), 0); // should leave set1, bar1 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -873,11 +900,11 @@ void tst_QBarSeries::mousehovered() //======================================================================= // move mouse on top of set2, bar1 to check the index (hover in set2) - QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint()); + QTest::mouseMove(view.viewport(), QPoint(layout.at(3).x() + 1, layout.at(3).y() + 1)); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 0); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 0); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should enter set2, bar1 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); @@ -898,9 +925,9 @@ void tst_QBarSeries::mousehovered() //(hover out set2) QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(3).left()) / 2, 0)); - TRY_COMPARE(seriesIndexSpy.count(), 1); - TRY_COMPARE(setIndexSpy1.count(), 0); - TRY_COMPARE(setIndexSpy2.count(), 1); + QTRY_COMPARE(seriesIndexSpy.count(), 1); + QTRY_COMPARE(setIndexSpy1.count(), 0); + QTRY_COMPARE(setIndexSpy2.count(), 1); // should leave set2, bar1 seriesIndexSpyArg = seriesIndexSpy.takeFirst(); |