diff --git a/CHANGES b/CHANGES index e645377d..cd9c843c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ Release Highlights ================== +Version 3.1.0 (unreleased): +-------------------------- + * Bug fix: Fix model about to be reset + Version 3.0.1 (unreleased): --------------------------- * Add WebAssembly demo-example diff --git a/CMakeLists.txt b/CMakeLists.txt index f6c20535..0ed72615 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,8 +65,8 @@ project( ) set(${PROJECT_NAME}_VERSION_MAJOR 3) -set(${PROJECT_NAME}_VERSION_MINOR 0) -set(${PROJECT_NAME}_VERSION_PATCH 1) +set(${PROJECT_NAME}_VERSION_MINOR 1) +set(${PROJECT_NAME}_VERSION_PATCH 0) set(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH} ) diff --git a/conan/conanfile.py b/conan/conanfile.py index ac6851a1..3750cd21 100644 --- a/conan/conanfile.py +++ b/conan/conanfile.py @@ -10,7 +10,7 @@ class KdchartConan(ConanFile): name = "KDChart" - version = "3.0.1" + version = "3.1.0" license = ("https://raw.githubusercontent.com/KDAB/KDChart/master/LICENSES/MIT.txt") author = "Klaralvdalens Datakonsult AB (KDAB) info@kdab.com" url = "https://github.com/KDAB/KDChart.git" diff --git a/examples/Axis/Labels/mainwindow.cpp b/examples/Axis/Labels/mainwindow.cpp index 435ae6fb..88422039 100644 --- a/examples/Axis/Labels/mainwindow.cpp +++ b/examples/Axis/Labels/mainwindow.cpp @@ -94,8 +94,8 @@ MainWindow::MainWindow(QWidget *parent) m_legend->setAlignment(Qt::AlignTop); m_chart->addLegend(m_legend); - connect(m_annotations, SIGNAL(toggled(bool)), SLOT(annotationsToggled(bool))); - connect(m_linesOnAnnotations, SIGNAL(toggled(bool)), SLOT(gridLinesOnAnnotationsToggled(bool))); + connect(m_annotations, &QCheckBox::toggled, this, &MainWindow::annotationsToggled); + connect(m_linesOnAnnotations, &QCheckBox::toggled, this, &MainWindow::gridLinesOnAnnotationsToggled); } void MainWindow::annotationsToggled(bool showAnnotations) diff --git a/examples/DrawIntoPainter/framewidget.cpp b/examples/DrawIntoPainter/framewidget.cpp index 31089bd6..7a697b9a 100644 --- a/examples/DrawIntoPainter/framewidget.cpp +++ b/examples/DrawIntoPainter/framewidget.cpp @@ -26,7 +26,7 @@ void FrameWidget::setChart(KDChart::Chart *chart) mChart = chart; // This is necessary because Chart can't automatically schedule somebody else (this object) to // call its custom paint method. - connect(mChart, SIGNAL(propertiesChanged()), SLOT(update())); + connect(mChart, &KDChart::Chart::propertiesChanged, this, QOverload<>::of(&FrameWidget::update)); } void FrameWidget::paintEvent(QPaintEvent *e) diff --git a/examples/DrawIntoPainter/mainwindow.cpp b/examples/DrawIntoPainter/mainwindow.cpp index aee6c9b3..9b1bd31f 100644 --- a/examples/DrawIntoPainter/mainwindow.cpp +++ b/examples/DrawIntoPainter/mainwindow.cpp @@ -82,8 +82,8 @@ MainWindow::MainWindow(QWidget *parent) #ifdef USE_FRAME_WIDGET chartFrameWidget->setChart(m_chart); // make sure, we re-draw after changing one of the chart's properties - connect(m_chart, SIGNAL(propertiesChanged()), - chartFrameWidget, SLOT(update())); + connect(m_chart, &KDChart::Chart::propertiesChanged, + chartFrameWidget, QOverload<>::of(&FrameWidget::update)); #else chartLayout->addWidget(m_chart); #endif diff --git a/examples/Gantt/legend_example/entrydialog.cpp b/examples/Gantt/legend_example/entrydialog.cpp index acb72138..6baa2e22 100644 --- a/examples/Gantt/legend_example/entrydialog.cpp +++ b/examples/Gantt/legend_example/entrydialog.cpp @@ -40,9 +40,10 @@ void EntryDialog::init() for (int row = 0; row < model->rowCount(); ++row) addDependItem(model, model->index(row, 0)); - connect(ui->startDate, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(updateEndDate(const QDateTime &))); - connect(ui->readOnly, SIGNAL(toggled(bool)), this, SLOT(disableEditing(bool))); - connect(ui->type, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); + connect(ui->startDate, &QDateTimeEdit::dateTimeChanged, + this, &EntryDialog::updateEndDate); + connect(ui->readOnly, &QCheckBox::toggled, this, &EntryDialog::disableEditing); + connect(ui->type, QOverload::of(&QComboBox::currentIndexChanged), this, &EntryDialog::typeChanged); ui->startDate->setDateTime(QDateTime::currentDateTime()); typeChanged(0); diff --git a/examples/Gantt/legend_example/mainwindow.cpp b/examples/Gantt/legend_example/mainwindow.cpp index 2031a4ee..b724016e 100644 --- a/examples/Gantt/legend_example/mainwindow.cpp +++ b/examples/Gantt/legend_example/mainwindow.cpp @@ -64,10 +64,10 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) leftView->setColumnHidden(5, true); leftView->header()->setStretchLastSection(true); - connect(ui->ganttView->leftView(), SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(showContextMenu(const QPoint &))); - connect(ui->ganttView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - this, SLOT(enableActions(const QItemSelection &))); + connect(ui->ganttView->leftView(), &QAbstractItemView::customContextMenuRequested, + this, &MainWindow::showContextMenu); + connect(ui->ganttView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &MainWindow::enableActions); } MainWindow::~MainWindow() @@ -128,22 +128,22 @@ void MainWindow::initActions() { newEntryAction = new QAction(tr("New entry"), this); newEntryAction->setShortcut(QKeySequence::New); - connect(newEntryAction, SIGNAL(triggered()), this, SLOT(addNewEntry())); + connect(newEntryAction, &QAction::triggered, this, &MainWindow::addNewEntry); removeEntryAction = new QAction(tr("Remove entry"), this); removeEntryAction->setShortcut(QKeySequence::Delete); - connect(removeEntryAction, SIGNAL(triggered()), this, SLOT(removeEntry())); + connect(removeEntryAction, &QAction::triggered, this, &MainWindow::removeEntry); zoomInAction = new QAction(tr("Zoom In"), this); zoomInAction->setShortcut(QKeySequence::ZoomIn); - connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn())); + connect(zoomInAction, &QAction::triggered, this, &MainWindow::zoomIn); zoomOutAction = new QAction(tr("Zoom Out"), this); zoomOutAction->setShortcut(QKeySequence::ZoomOut); - connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut())); + connect(zoomOutAction, &QAction::triggered, this, &MainWindow::zoomOut); zoomFitAction = new QAction(tr("Zoom to Fit"), this); - connect(zoomFitAction, SIGNAL(triggered()), this, SLOT(zoomFit())); + connect(zoomFitAction, &QAction::triggered, this, &MainWindow::zoomFit); ui->ganttView->leftView()->setContextMenuPolicy(Qt::CustomContextMenu); ui->ganttView->leftView()->addAction(newEntryAction); @@ -160,11 +160,11 @@ void MainWindow::initActions() QMenu *scaleMenu = menuBar()->addMenu(tr("Scale")); - scaleMenu->addAction(tr("Auto"), this, SLOT(scaleAuto())); - scaleMenu->addAction(tr("Hour"), this, SLOT(scaleHour())); - scaleMenu->addAction(tr("Day"), this, SLOT(scaleDay())); - scaleMenu->addAction(tr("Week"), this, SLOT(scaleWeek())); - scaleMenu->addAction(tr("Month"), this, SLOT(scaleMonth())); + scaleMenu->addAction(tr("Auto"), this, &MainWindow::scaleAuto); + scaleMenu->addAction(tr("Hour"), this, &MainWindow::scaleHour); + scaleMenu->addAction(tr("Day"), this, &MainWindow::scaleDay); + scaleMenu->addAction(tr("Week"), this, &MainWindow::scaleWeek); + scaleMenu->addAction(tr("Month"), this, &MainWindow::scaleMonth); enableActions(QItemSelection()); } @@ -314,14 +314,14 @@ void MainWindow::zoomOut() void MainWindow::zoomFit() { - QModelIndexList selectedIndexes = ui->ganttView->selectionModel()->selectedIndexes(); + const QModelIndexList selectedIndexes = ui->ganttView->selectionModel()->selectedIndexes(); if (selectedIndexes.isEmpty()) { return; } KDGantt::Span span; - Q_FOREACH (QModelIndex idx, selectedIndexes) { + for (QModelIndex idx : selectedIndexes) { const KDGantt::Span s = grid->mapToChart(grid->model()->index(idx.row(), 0)); if (span.isValid()) { span = span.expandedTo(s); diff --git a/examples/Gantt/project/mainwindow.cpp b/examples/Gantt/project/mainwindow.cpp index a768d7f6..b245b983 100644 --- a/examples/Gantt/project/mainwindow.cpp +++ b/examples/Gantt/project/mainwindow.cpp @@ -275,28 +275,28 @@ MainWindow::MainWindow(QWidget *parent) auto *fileMenu = new QMenu(tr("&File")); #ifndef QT_NO_PRINTER - fileMenu->addAction(tr("&Save as PDF..."), this, SLOT(slotFileSavePdf())); - fileMenu->addAction(tr("&Print..."), this, SLOT(slotFilePrint())); + fileMenu->addAction(tr("&Save as PDF..."), this, &MainWindow::slotFileSavePdf); + fileMenu->addAction(tr("&Print..."), this, &MainWindow::slotFilePrint); #endif fileMenu->addSeparator(); - fileMenu->addAction(tr("&Quit"), this, SLOT(slotFileQuit())); + fileMenu->addAction(tr("&Quit"), this, &MainWindow::slotFileQuit); mb->addMenu(fileMenu); auto *toolsMenu = new QMenu(tr("&Tools")); - toolsMenu->addAction(tr("&New Item"), this, SLOT(slotToolsNewItem())); - toolsMenu->addAction(tr("&Add Item"), this, SLOT(slotToolsAppendItem())); + toolsMenu->addAction(tr("&New Item"), this, &MainWindow::slotToolsNewItem); + toolsMenu->addAction(tr("&Add Item"), this, &MainWindow::slotToolsAppendItem); toolsMenu->addSeparator(); QMenu *alignMenu = toolsMenu->addMenu(tr("Ali&gn")); - alignMenu->addAction(tr("&Left"), this, SLOT(slotAlignLeft())); - alignMenu->addAction(tr("&Center"), this, SLOT(slotAlignCenter())); - alignMenu->addAction(tr("&Right"), this, SLOT(slotAlignRight())); - alignMenu->addAction(tr("&Hidden"), this, SLOT(slotAlignHidden())); + alignMenu->addAction(tr("&Left"), this, &MainWindow::slotAlignLeft); + alignMenu->addAction(tr("&Center"), this, &MainWindow::slotAlignCenter); + alignMenu->addAction(tr("&Right"), this, &MainWindow::slotAlignRight); + alignMenu->addAction(tr("&Hidden"), this, &MainWindow::slotAlignHidden); toolsMenu->addSeparator(); - toolsMenu->addAction(tr("&Collapse All"), this, SLOT(slotCollapseAll())); - toolsMenu->addAction(tr("&Expand All"), this, SLOT(slotExpandAll())); + toolsMenu->addAction(tr("&Collapse All"), this, &MainWindow::slotCollapseAll); + toolsMenu->addAction(tr("&Expand All"), this, &MainWindow::slotExpandAll); mb->addMenu(toolsMenu); @@ -331,7 +331,7 @@ SavePdfDialog::SavePdfDialog(QWidget *parent) m_fileEdit->setText(QFileInfo(QDir::homePath(), "gantt.pdf").absoluteFilePath()); fileLayout->addWidget(m_fileEdit); auto *m_fileButton = new QPushButton("...", this); - connect(m_fileButton, SIGNAL(clicked()), this, SLOT(fileButtonClicked())); + connect(m_fileButton, &QPushButton::clicked, this, &SavePdfDialog::fileButtonClicked); fileLayout->addWidget(m_fileButton); m_rowLabels = new QCheckBox(tr("Row Header"), this); @@ -344,8 +344,8 @@ SavePdfDialog::SavePdfDialog(QWidget *parent) auto *btnBox = new QDialogButtonBox(this); btnBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel); - connect(btnBox, SIGNAL(accepted()), this, SLOT(accept())); - connect(btnBox, SIGNAL(rejected()), this, SLOT(reject())); + connect(btnBox, &QDialogButtonBox::accepted, this, &SavePdfDialog::accept); + connect(btnBox, &QDialogButtonBox::rejected, this, &SavePdfDialog::reject); l->addWidget(btnBox); resize(QSize(400, 100).expandedTo(minimumSizeHint())); diff --git a/examples/LeveyJennings/Simple/main.cpp b/examples/LeveyJennings/Simple/main.cpp index ba8733f1..68e6b3d2 100644 --- a/examples/LeveyJennings/Simple/main.cpp +++ b/examples/LeveyJennings/Simple/main.cpp @@ -31,7 +31,7 @@ class SelectionAnimator : public QObject , view(view) { auto *const t = new QTimer(this); - connect(t, SIGNAL(timeout()), this, SLOT(animate())); + connect(t, &QTimer::timeout, this, &SelectionAnimator::animate); t->start(1000); } diff --git a/examples/Lines/Advanced/mainwindow.cpp b/examples/Lines/Advanced/mainwindow.cpp index 90561c0b..8db1dde0 100644 --- a/examples/Lines/Advanced/mainwindow.cpp +++ b/examples/Lines/Advanced/mainwindow.cpp @@ -50,7 +50,7 @@ MainWindow::MainWindow(QWidget *parent) m_chart->setGlobalLeading(20, 20, 20, 20); // Instantiate the timer auto *timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(slot_timerFired())); + connect(timer, &QTimer::timeout, this, &MainWindow::slot_timerFired); timer->start(30); // Change the cursor to IBeamCursor inside Chart widget. diff --git a/examples/ModelView/TableView/mainwindow.cpp b/examples/ModelView/TableView/mainwindow.cpp index 40168a40..fc30bae8 100644 --- a/examples/ModelView/TableView/mainwindow.cpp +++ b/examples/ModelView/TableView/mainwindow.cpp @@ -43,14 +43,16 @@ MainWindow::MainWindow() initializeData(); setupViews(); - connect(openAction, SIGNAL(triggered()), this, SLOT(openFile())); - connect(saveAction, SIGNAL(triggered()), this, SLOT(saveFile())); - connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); + connect(openAction, &QAction::triggered, this, [this] { + openFile(); + }); + connect(saveAction, &QAction::triggered, this, &MainWindow::saveFile); + connect(quitAction, &QAction::triggered, qApp, &QApplication::quit); - connect(m_selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - this, SLOT(selectionChanged(const QItemSelection &, const QItemSelection &))); + connect(m_selectionModel, &QItemSelectionModel::selectionChanged, + this, &MainWindow::selectionChanged); - connect(m_diagramView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); + connect(m_diagramView, &BarDiagram::clicked, this, &MainWindow::itemClicked); menuBar()->addMenu(fileMenu); statusBar(); diff --git a/examples/Pie/Advanced/mainwindow.cpp b/examples/Pie/Advanced/mainwindow.cpp index 945e922f..199d530a 100644 --- a/examples/Pie/Advanced/mainwindow.cpp +++ b/examples/Pie/Advanced/mainwindow.cpp @@ -42,7 +42,7 @@ MainWindow::MainWindow(QWidget *parent) m_chart->coordinatePlane()->replaceDiagram(m_pie); m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(slotNextFrame())); + connect(m_timer, &QTimer::timeout, this, &MainWindow::slotNextFrame); } void MainWindow::on_startPositionSB_valueChanged(double pos) diff --git a/examples/Plotter/BigDataset/MainWidget.cpp b/examples/Plotter/BigDataset/MainWidget.cpp index 2526270c..7822160d 100644 --- a/examples/Plotter/BigDataset/MainWidget.cpp +++ b/examples/Plotter/BigDataset/MainWidget.cpp @@ -55,17 +55,17 @@ MainWidget::MainWidget() m_functionSelector << m_controls.sineRadio << m_controls.triangleRadio << m_controls.squareRadio << m_controls.noiseRadio << m_controls.oneDivSineRadio << m_controls.sineOneDivRadio; - foreach (QRadioButton *r, m_functionSelector) { - connect(r, SIGNAL(toggled(bool)), SLOT(functionToggled(bool))); + for (QRadioButton *r : qAsConst(m_functionSelector)) { + connect(r, &QRadioButton::toggled, this, &MainWidget::functionToggled); } - connect(m_controls.runButton, SIGNAL(toggled(bool)), - &m_model, SLOT(setRunning(bool))); + connect(m_controls.runButton, &QPushButton::toggled, + &m_model, &Model::setRunning); // order matters again m_addPointsButtons << m_controls.add1kButton << m_controls.add10kButton << m_controls.add100kButton; - foreach (QPushButton *b, m_addPointsButtons) { - connect(b, SIGNAL(clicked(bool)), SLOT(addPointsButtonClicked())); + for (QPushButton *b : qAsConst(m_addPointsButtons)) { + connect(b, &QPushButton::clicked, this, &MainWidget::addPointsButtonClicked); } } diff --git a/examples/Plotter/BigDataset/Model.cpp b/examples/Plotter/BigDataset/Model.cpp index 30086417..3cb0f990 100644 --- a/examples/Plotter/BigDataset/Model.cpp +++ b/examples/Plotter/BigDataset/Model.cpp @@ -26,7 +26,7 @@ static const qreal s_stepWidth = 0.1; Model::Model() { m_appendTimer.setInterval(3); - connect(&m_appendTimer, SIGNAL(timeout()), SLOT(appendPoint())); + connect(&m_appendTimer, &QTimer::timeout, this, &Model::appendPoint); // pre-fill some values appendPoints(100); } diff --git a/examples/Plotter/BubbleChart/mainwindow.cpp b/examples/Plotter/BubbleChart/mainwindow.cpp index ca0b8159..f1cffb9f 100644 --- a/examples/Plotter/BubbleChart/mainwindow.cpp +++ b/examples/Plotter/BubbleChart/mainwindow.cpp @@ -78,7 +78,7 @@ MainWindow::MainWindow(QWidget *parent) m_plotter->addAxis(xAxis2); m_plotter->addAxis(yAxis); m_plotter->addAxis(yAxis2); - connect(threeDEnabled, SIGNAL(toggled(bool)), this, SLOT(setMarkerAttributes())); + connect(threeDEnabled, &QCheckBox::toggled, this, &MainWindow::setMarkerAttributes); m_chart->coordinatePlane()->replaceDiagram(m_plotter); m_chart->setGlobalLeading(20, 20, 20, 20); diff --git a/examples/Plotter/Timeline/main.cpp b/examples/Plotter/Timeline/main.cpp index dd90e3f4..ec6dc0a1 100644 --- a/examples/Plotter/Timeline/main.cpp +++ b/examples/Plotter/Timeline/main.cpp @@ -43,7 +43,7 @@ class ChartWidget : public QWidget auto *button = new QPushButton("Animate", leftWidget); leftLayout->addWidget(button); button->setCheckable(true); - connect(button, SIGNAL(toggled(bool)), this, SLOT(buttonToggled(bool))); + connect(button, &QPushButton::toggled, this, &ChartWidget::buttonToggled); auto *tv = new QTreeView(leftWidget); leftLayout->addWidget(tv); @@ -74,17 +74,19 @@ class ChartWidget : public QWidget plotter->setModel(proxy); - connect(proxy, SIGNAL(rowsInserted(QModelIndex, int, int)), - m_chart->coordinatePlane(), SLOT(adjustRangesToData())); - connect(proxy, SIGNAL(rowsRemoved(QModelIndex, int, int)), - m_chart->coordinatePlane(), SLOT(adjustRangesToData())); + auto coordinatePlane = qobject_cast(m_chart->coordinatePlane()); + connect(proxy, &TimeChartModel::rowsInserted, + coordinatePlane, &KDChart::CartesianCoordinatePlane::adjustRangesToData); + connect(proxy, &TimeChartModel::rowsRemoved, + coordinatePlane, &KDChart::CartesianCoordinatePlane::adjustRangesToData); proxy->setVisibleRange(QDateTime(QDate(2010, 3, 15), QTime()), QDateTime(QDate(2010, 5, 18), QTime())); - qobject_cast(m_chart->coordinatePlane())->adjustRangesToData(); + coordinatePlane->adjustRangesToData(); + m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), this, SLOT(slotTimeout())); + connect(m_timer, &QTimer::timeout, this, &ChartWidget::slotTimeout); } private slots: void slotTimeout() diff --git a/examples/RealTime/main.cpp b/examples/RealTime/main.cpp index 019f4b5b..8e552969 100644 --- a/examples/RealTime/main.cpp +++ b/examples/RealTime/main.cpp @@ -39,8 +39,8 @@ class ChartWidget : public QWidget l->addWidget(&m_chart); setLayout(l); m_timer = new QTimer(this); - connect(m_timer, SIGNAL(timeout()), - this, SLOT(slotTimeout())); + connect(m_timer, &QTimer::timeout, + this, &ChartWidget::slotTimeout); m_timer->start(200); } diff --git a/examples/Stock/Advanced/mainwindow.cpp b/examples/Stock/Advanced/mainwindow.cpp index ba75c6d2..e7548b78 100644 --- a/examples/Stock/Advanced/mainwindow.cpp +++ b/examples/Stock/Advanced/mainwindow.cpp @@ -51,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent) m_diagram.addAxis(bottomAxis); m_diagram.addAxis(bottomAxis); applyColor(QColor("chartreuse")); - const bool connected = connect(colorChooser, SIGNAL(clicked()), SLOT(chooseColor())); + const bool connected = connect(colorChooser, &QPushButton::clicked, this, &MainWindow::chooseColor); Q_ASSERT(connected); Q_UNUSED(connected); diff --git a/examples/TernaryCharts/Advanced/mainwindow.cpp b/examples/TernaryCharts/Advanced/mainwindow.cpp index 94e99c2e..3ae49d2e 100644 --- a/examples/TernaryCharts/Advanced/mainwindow.cpp +++ b/examples/TernaryCharts/Advanced/mainwindow.cpp @@ -47,8 +47,8 @@ MainWindow::MainWindow(QWidget *parent) setupModel(); m_diagram->setModel(&m_model); - connect(m_diagram, SIGNAL(clicked(QModelIndex)), - SLOT(indexClicked(QModelIndex))); + connect(m_diagram, &KDChart::TernaryPointDiagram::clicked, + this, &MainWindow::indexClicked); } void MainWindow::setupModel() diff --git a/examples/Widget/Advanced/mainwindow.cpp b/examples/Widget/Advanced/mainwindow.cpp index 7c56de37..74569c59 100644 --- a/examples/Widget/Advanced/mainwindow.cpp +++ b/examples/Widget/Advanced/mainwindow.cpp @@ -28,12 +28,12 @@ MainWindow::MainWindow(QWidget *parent) typeSelector->setCurrentIndex(1); // we start by LineDiagram - connect(typeSelector, SIGNAL(activated(int)), SLOT(changeType())); + connect(typeSelector, QOverload::of(&QComboBox::activated), this, &MainWindow::changeType); - connect(btnAddDataset, SIGNAL(clicked()), SLOT(addDataset())); + connect(btnAddDataset, &QPushButton::clicked, this, &MainWindow::addDataset); - connect(leadingSelector, SIGNAL(valueChanged(int)), - this, SLOT(changeLeading(int))); + connect(leadingSelector, QOverload::of(&QSpinBox::valueChanged), + this, &MainWindow::changeLeading); } void MainWindow::changeType() @@ -58,10 +58,10 @@ void MainWindow::changeLeading(int leading) void MainWindow::addDataset() { - QStringList parts = lineAddDataset->text().split(';'); + const QStringList parts = lineAddDataset->text().split(';'); bool ok; QVector vec; - foreach (const QString &str, parts) { + for (const QString &str : parts) { const qreal val = str.toDouble(&ok); if (ok) vec.append(val); diff --git a/examples/Zoom/ScrollBars/mainwindow.cpp b/examples/Zoom/ScrollBars/mainwindow.cpp index ef9083ab..95896265 100644 --- a/examples/Zoom/ScrollBars/mainwindow.cpp +++ b/examples/Zoom/ScrollBars/mainwindow.cpp @@ -51,7 +51,7 @@ MainWindow::MainWindow(QWidget *parent) m_lines->addAxis(yAxis); m_chart->coordinatePlane()->replaceDiagram(m_lines); - connect(m_chart, SIGNAL(propertiesChanged()), SLOT(applyNewZoomParameters())); + connect(m_chart, &Chart::propertiesChanged, this, &MainWindow::applyNewZoomParameters); // Set up the legend m_legend = new Legend(m_lines, m_chart); diff --git a/examples/demo/axissettings.cpp b/examples/demo/axissettings.cpp index d5c6b874..254bc129 100644 --- a/examples/demo/axissettings.cpp +++ b/examples/demo/axissettings.cpp @@ -60,10 +60,10 @@ void AxisSettings::Private::init() ui.axisSelection->addItem(QIcon(), tr("Right Y-Axis"), CartesianAxis::Right); ui.axisSelection->addItem(QIcon(), tr("Bottom X-Axis"), CartesianAxis::Bottom); ui.axisSelection->addItem(QIcon(), tr("Top X-Axis"), CartesianAxis::Top); - connect(ui.axisSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int))); - connect(ui.axisVisibility, SIGNAL(toggled(bool)), this, SLOT(setVisible(bool))); - connect(ui.majorTicks, SIGNAL(toggled(bool)), this, SLOT(setShowMajorTickMarks(bool))); - connect(ui.minorTicks, SIGNAL(toggled(bool)), this, SLOT(setShowMinorTickMarks(bool))); + connect(ui.axisSelection, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::currentIndexChanged); + connect(ui.axisVisibility, &QCheckBox::toggled, this, &Private::setVisible); + connect(ui.majorTicks, &QCheckBox::toggled, this, &Private::setShowMajorTickMarks); + connect(ui.minorTicks, &QCheckBox::toggled, this, &Private::setShowMinorTickMarks); ui.axisSelection->setCurrentIndex(0); } @@ -74,8 +74,8 @@ void AxisSettings::Private::currentIndexChanged(int index) auto *plane = qobject_cast(m_chart->coordinatePlane()); auto *diag = qobject_cast(m_chart->coordinatePlane()->diagram()); if (plane && diag) { - QVector axes = diag->axes().toVector(); - Q_FOREACH (CartesianAxis *axis, axes) { + const auto axes = diag->axes(); + for (CartesianAxis *axis : axes) { if (axis->position() == pos) { m_currentAxis = axis; break; @@ -109,9 +109,9 @@ void AxisSettings::Private::setVisible(bool value) auto *plane = qobject_cast(m_chart->coordinatePlane()); auto *diag = qobject_cast(m_chart->coordinatePlane()->diagram()); if (plane && diag) { - QVector axes = m_axisCache[plane]; + const QVector axes = m_axisCache[plane]; bool foundAxis = false; - Q_FOREACH (CartesianAxis *axis, axes) { + for (CartesianAxis *axis : axes) { if (axis->position() == pos) { foundAxis = true; if (!value) { diff --git a/examples/demo/datasetsettings.cpp b/examples/demo/datasetsettings.cpp index 882bff6b..9803129d 100644 --- a/examples/demo/datasetsettings.cpp +++ b/examples/demo/datasetsettings.cpp @@ -126,9 +126,9 @@ DatasetSettings::DatasetSettings(Chart *chart, QWidget *parent) d->ui->colorDisplay->setStyle(QStyleFactory::create(QStringLiteral("cleanlooks"))); d->ui->outlineBtn->setStyle(QStyleFactory::create(QStringLiteral("cleanlooks"))); #endif - connect(d->ui->datasetSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); - connect(d->ui->colorDisplay, SIGNAL(clicked()), d, SLOT(changeColor())); - connect(d->ui->outlineBtn, SIGNAL(clicked()), d, SLOT(changeOutline())); + connect(d->ui->datasetSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &DatasetSettings::indexChanged); + connect(d->ui->colorDisplay, &QPushButton::clicked, d, &Private::changeColor); + connect(d->ui->outlineBtn, &QPushButton::clicked, d, &Private::changeOutline); } DatasetSettings::~DatasetSettings() diff --git a/examples/demo/datavaluesettings.cpp b/examples/demo/datavaluesettings.cpp index 18a9b0fc..ae2adeab 100644 --- a/examples/demo/datavaluesettings.cpp +++ b/examples/demo/datavaluesettings.cpp @@ -93,28 +93,28 @@ void DataValueSettings::Private::init() void DataValueSettings::Private::connectWidgets() { - connect(ui->scopeBarDatasetSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeBarDatasetSB_valueChanged(int))); - connect(ui->scopeBarItemSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeBarItemSB_valueChanged(int))); - connect(ui->scopeDatasetSB, SIGNAL(valueChanged(int)), this, SLOT(on_scopeDatasetSB_valueChanged(int))); - connect(ui->scopeOneBarRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeOneBarRB_toggled(bool))); - connect(ui->scopeDatasetRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeDatasetRB_toggled(bool))); - connect(ui->scopeCommonRB, SIGNAL(toggled(bool)), this, SLOT(on_scopeCommonRB_toggled(bool))); - connect(ui->paintValuesCB, SIGNAL(toggled(bool)), this, SLOT(on_paintValuesCB_toggled(bool))); - connect(ui->fontCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_fontCombo_currentIndexChanged(QString))); - connect(ui->relativeSizeSB, SIGNAL(valueChanged(int)), this, SLOT(on_relativeSizeSB_valueChanged(int))); - connect(ui->minimumSizeSB, SIGNAL(valueChanged(int)), this, SLOT(on_minimumSizeSB_valueChanged(int))); - connect(ui->rotationSB, SIGNAL(valueChanged(int)), this, SLOT(on_rotationSB_valueChanged(int))); - connect(ui->posPosCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_posPosCombo_currentIndexChanged(QString))); - connect(ui->posAlignCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_posAlignCombo_currentIndexChanged(QString))); - connect(ui->posPadHoriSB, SIGNAL(valueChanged(int)), this, SLOT(on_posPadHoriSB_valueChanged(int))); - connect(ui->posPadVertSB, SIGNAL(valueChanged(int)), this, SLOT(on_posPadVertSB_valueChanged(int))); - connect(ui->negPosCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_negPosCombo_currentIndexChanged(QString))); - connect(ui->negAlignCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_negAlignCombo_currentIndexChanged(QString))); - connect(ui->negPadHoriSB, SIGNAL(valueChanged(int)), this, SLOT(on_negPadHoriSB_valueChanged(int))); - connect(ui->negPadVertSB, SIGNAL(valueChanged(int)), this, SLOT(on_negPadVertSB_valueChanged(int))); - connect(ui->labelLE, SIGNAL(textEdited(QString)), this, SLOT(on_labelLE_textEdited(QString))); - connect(ui->prefixLE, SIGNAL(textEdited(QString)), this, SLOT(on_prefixLE_textEdited(QString))); - connect(ui->suffixLE, SIGNAL(textEdited(QString)), this, SLOT(on_suffixLE_textEdited(QString))); + connect(ui->scopeBarDatasetSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_scopeBarDatasetSB_valueChanged); + connect(ui->scopeBarItemSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_scopeBarItemSB_valueChanged); + connect(ui->scopeDatasetSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_scopeDatasetSB_valueChanged); + connect(ui->scopeOneBarRB, &QRadioButton::toggled, this, &Private::on_scopeOneBarRB_toggled); + connect(ui->scopeDatasetRB, &QRadioButton::toggled, this, &Private::on_scopeDatasetRB_toggled); + connect(ui->scopeCommonRB, &QRadioButton::toggled, this, &Private::on_scopeCommonRB_toggled); + connect(ui->paintValuesCB, &QCheckBox::toggled, this, &Private::on_paintValuesCB_toggled); + connect(ui->fontCombo, QOverload::of(&QFontComboBox::currentIndexChanged), this, &Private::on_fontCombo_currentIndexChanged); + connect(ui->relativeSizeSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_relativeSizeSB_valueChanged); + connect(ui->minimumSizeSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_minimumSizeSB_valueChanged); + connect(ui->rotationSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_rotationSB_valueChanged); + connect(ui->posPosCombo, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::on_posPosCombo_currentIndexChanged); + connect(ui->posAlignCombo, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::on_posAlignCombo_currentIndexChanged); + connect(ui->posPadHoriSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_posPadHoriSB_valueChanged); + connect(ui->posPadVertSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_posPadVertSB_valueChanged); + connect(ui->negPosCombo, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::on_negPosCombo_currentIndexChanged); + connect(ui->negAlignCombo, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::on_negAlignCombo_currentIndexChanged); + connect(ui->negPadHoriSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_negPadHoriSB_valueChanged); + connect(ui->negPadVertSB, QOverload::of(&QSpinBox::valueChanged), this, &Private::on_negPadVertSB_valueChanged); + connect(ui->labelLE, &QLineEdit::textEdited, this, &Private::on_labelLE_textEdited); + connect(ui->prefixLE, &QLineEdit::textEdited, this, &Private::on_prefixLE_textEdited); + connect(ui->suffixLE, &QLineEdit::textEdited, this, &Private::on_suffixLE_textEdited); } DataValueSettings::DataValueSettings(KDChart::Chart *chart, QWidget *parent) diff --git a/examples/demo/diagramsettings.cpp b/examples/demo/diagramsettings.cpp index 65d770ff..33e8b0d1 100644 --- a/examples/demo/diagramsettings.cpp +++ b/examples/demo/diagramsettings.cpp @@ -166,11 +166,11 @@ void DiagramSettings::Private::init() ui->diagramBackground->setStyle(QStyleFactory::create(QStringLiteral("cleanlooks"))); #endif - connect(ui->threeDSelector, SIGNAL(toggled(bool)), this, SLOT(changeThreeD())); - connect(ui->diagramBackground, SIGNAL(clicked()), this, SLOT(changeBackgroundColor())); - connect(ui->visibleBtn, SIGNAL(toggled(bool)), this, SLOT(changeBackgroundVisibility())); - connect(ui->barHeightInput, SIGNAL(valueChanged(int)), this, SLOT(changeThreeD())); - connect(ui->autoGradient, SIGNAL(toggled(bool)), this, SLOT(changeAutoGradient())); + connect(ui->threeDSelector, &QCheckBox::toggled, this, &Private::changeThreeD); + connect(ui->diagramBackground, &QPushButton::clicked, this, &Private::changeBackgroundColor); + connect(ui->visibleBtn, &QCheckBox::toggled, this, &Private::changeBackgroundVisibility); + connect(ui->barHeightInput, QOverload::of(&QSpinBox::valueChanged), this, &Private::changeThreeD); + connect(ui->autoGradient, &QCheckBox::toggled, this, &Private::changeAutoGradient); qq->refreshSettings(); } diff --git a/examples/demo/diagramtypedialog.cpp b/examples/demo/diagramtypedialog.cpp index d8023302..9b6a34a9 100644 --- a/examples/demo/diagramtypedialog.cpp +++ b/examples/demo/diagramtypedialog.cpp @@ -75,8 +75,8 @@ void DiagramTypeDialog::Private::init() m_typemap[DiagramTypeDialog::Line] = DiagramTypeDialog::Normal; m_typemap[DiagramTypeDialog::Plotter] = DiagramTypeDialog::Normal; - connect(ui.typeSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(typeChanged(int))); - connect(ui.subtypeSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(subtypeChanged(int))); + connect(ui.typeSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::typeChanged); + connect(ui.subtypeSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::subtypeChanged); } void DiagramTypeDialog::Private::createPlanes() diff --git a/examples/demo/gradientdialog.cpp b/examples/demo/gradientdialog.cpp index 4d858c1d..dc2f5dce 100644 --- a/examples/demo/gradientdialog.cpp +++ b/examples/demo/gradientdialog.cpp @@ -100,7 +100,7 @@ void GradientDialog::Private::updateGradientDisplay() gradient.setStart(0, 0); gradient.setStart(1, 0); gradient.setCoordinateMode(QGradient::ObjectBoundingMode); - Q_FOREACH (const QGradientStop &stop, m_gradient) + for (const QGradientStop &stop : qAsConst(m_gradient)) gradient.setColorAt(stop.first, stop.second); QPalette palette = ui->gradientDisplay->palette(); palette.setBrush(QPalette::Window, gradient); @@ -128,8 +128,8 @@ void GradientDialog::Private::init() redSpin->setMaximum(255); redSpin->setAccelerated(true); redSpin->setValue(redSlider->value()); - connect(redSpin, SIGNAL(valueChanged(int)), redSlider, SLOT(setValue(int))); - connect(redSlider, SIGNAL(valueChanged(int)), redSpin, SLOT(setValue(int))); + connect(redSpin, QOverload::of(&QSpinBox::valueChanged), redSlider, &ColorSlider::setValue); + connect(redSlider, &ColorSlider::valueChanged, redSpin, &QSpinBox::setValue); redLayout->addWidget(redSlider); redLayout->addWidget(redSpin); @@ -148,8 +148,8 @@ void GradientDialog::Private::init() greenSpin->setMaximum(255); greenSpin->setAccelerated(true); greenSpin->setValue(greenSlider->value()); - connect(greenSpin, SIGNAL(valueChanged(int)), greenSlider, SLOT(setValue(int))); - connect(greenSlider, SIGNAL(valueChanged(int)), greenSpin, SLOT(setValue(int))); + connect(greenSpin, QOverload::of(&QSpinBox::valueChanged), greenSlider, &ColorSlider::setValue); + connect(greenSlider, &ColorSlider::valueChanged, greenSpin, &QSpinBox::setValue); greenLayout->addWidget(greenSlider); greenLayout->addWidget(greenSpin); @@ -168,22 +168,22 @@ void GradientDialog::Private::init() blueSpin->setMaximum(255); blueSpin->setAccelerated(true); blueSpin->setValue(blueSlider->value()); - connect(blueSpin, SIGNAL(valueChanged(int)), blueSlider, SLOT(setValue(int))); - connect(blueSlider, SIGNAL(valueChanged(int)), blueSpin, SLOT(setValue(int))); + connect(blueSpin, QOverload::of(&QSpinBox::valueChanged), blueSlider, &ColorSlider::setValue); + connect(blueSlider, &ColorSlider::valueChanged, blueSpin, &QSpinBox::setValue); blueLayout->addWidget(blueSlider); blueLayout->addWidget(blueSpin); updateGradientDisplay(); - connect(redSlider, SIGNAL(valueChanged(int)), this, SLOT(resetColors())); - connect(greenSlider, SIGNAL(valueChanged(int)), this, SLOT(resetColors())); - connect(blueSlider, SIGNAL(valueChanged(int)), this, SLOT(resetColors())); + connect(redSlider, &ColorSlider::valueChanged, this, &Private::resetColors); + connect(greenSlider, &ColorSlider::valueChanged, this, &Private::resetColors); + connect(blueSlider, &ColorSlider::valueChanged, this, &Private::resetColors); - connect(ui->newStop, SIGNAL(clicked()), this, SLOT(insertItem())); - connect(ui->deleteStop, SIGNAL(clicked()), this, SLOT(deleteItem())); - connect(ui->stopSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(changedIndex(int))); + connect(ui->newStop, &QPushButton::clicked, this, &Private::insertItem); + connect(ui->deleteStop, &QPushButton::clicked, this, &Private::deleteItem); + connect(ui->stopSelector, QOverload::of(&QComboBox::currentIndexChanged), this, &Private::changedIndex); - connect(ui->stopPosition, SIGNAL(valueChanged(double)), this, SLOT(changeStopPosition(double))); + connect(ui->stopPosition, QOverload::of(&QDoubleSpinBox::valueChanged), this, &Private::changeStopPosition); } GradientDialog::GradientDialog(QWidget *parent) @@ -230,7 +230,7 @@ QGradient GradientDialog::gradient() const gradient.setStart(0, 0); gradient.setStart(1, 0); gradient.setCoordinateMode(QGradient::ObjectBoundingMode); - Q_FOREACH (const QGradientStop &stop, d->m_gradient) + for (const QGradientStop &stop : qAsConst(d->m_gradient)) gradient.setColorAt(stop.first, stop.second); return gradient; } @@ -239,7 +239,7 @@ void GradientDialog::setGradient(const QGradient &gradient) d->m_gradient.clear(); d->ui->stopSelector->clear(); const QGradientStops stops = gradient.stops(); - Q_FOREACH (const QGradientStop &stop, stops) { + for (const QGradientStop &stop : stops) { d->m_gradient.append(stop); } QStringList newEntries; diff --git a/examples/demo/main.cpp b/examples/demo/main.cpp index 16755858..b277296f 100644 --- a/examples/demo/main.cpp +++ b/examples/demo/main.cpp @@ -38,8 +38,8 @@ // l->addWidget(&m_chart); // setLayout(l); // m_timer = new QTimer(this); -// connect( m_timer, SIGNAL( timeout() ), -// this, SLOT( slotTimeout() ) ); +// connect( m_timer, &QTimer::timeout, +// this, &ChartWidget::slotTimeout ); // m_timer->start( 200 ); // } diff --git a/examples/demo/mainwindow.cpp b/examples/demo/mainwindow.cpp index f95d3568..73939b05 100644 --- a/examples/demo/mainwindow.cpp +++ b/examples/demo/mainwindow.cpp @@ -95,7 +95,7 @@ MainWindow::Private::Private(MainWindow *q) auto *diagramTypeSettingsDock = new QDockWidget(tr("DiagramType"), qq); diagramTypeSettingsDock->setWidget(diagramTypeSettings); diagramTypeSettingsDock->setFloating(false); - connect(diagramTypeSettings, SIGNAL(diagramTypeChanged(DiagramType, Subtype)), this, SLOT(changedChartType())); + connect(diagramTypeSettings, &DiagramTypeDialog::diagramTypeChanged, this, &Private::changedChartType); q->addDockWidget(Qt::LeftDockWidgetArea, diagramTypeSettingsDock); auto *axisSettings = new AxisSettings(m_chartWin, qq); @@ -103,15 +103,15 @@ MainWindow::Private::Private(MainWindow *q) axisSettingsDock->setWidget(axisSettings); axisSettingsDock->setFloating(false); q->addDockWidget(Qt::LeftDockWidgetArea, axisSettingsDock); - connect(diagramTypeSettings, SIGNAL(diagramTypeChanged(DiagramType, Subtype)), axisSettings, SLOT(diagramTypeChanged())); + connect(diagramTypeSettings, &DiagramTypeDialog::diagramTypeChanged, axisSettings, &AxisSettings::diagramTypeChanged); auto *setSettings = new DatasetSettings(m_chartWin, qq); auto *setSettingsDock = new QDockWidget(tr("DatasetSettings"), qq); setSettingsDock->setWidget(setSettings); setSettingsDock->setFloating(false); q->addDockWidget(Qt::LeftDockWidgetArea, setSettingsDock); - connect(this, SIGNAL(datasetCountChanged(int)), setSettings, SLOT(setDatasetCount(int))); - connect(diagramTypeSettings, SIGNAL(diagramTypeChanged(DiagramType, Subtype)), setSettings, SLOT(diagramTypeChanged())); + connect(this, &Private::datasetCountChanged, setSettings, &DatasetSettings::setDatasetCount); + connect(diagramTypeSettings, &DiagramTypeDialog::diagramTypeChanged, setSettings, &DatasetSettings::diagramTypeChanged); setSettings->setDatasetCount(m_model->columnCount()); auto *diagSettings = new DiagramSettings(m_chartWin, qq); @@ -119,14 +119,14 @@ MainWindow::Private::Private(MainWindow *q) diagSettingsDock->setWidget(diagSettings); diagSettingsDock->setFloating(false); q->addDockWidget(Qt::LeftDockWidgetArea, diagSettingsDock); - connect(diagramTypeSettings, SIGNAL(diagramTypeChanged(DiagramType, Subtype)), diagSettings, SLOT(refreshSettings())); + connect(diagramTypeSettings, &DiagramTypeDialog::diagramTypeChanged, diagSettings, &DiagramSettings::refreshSettings); auto *dataValueSettings = new DataValueSettings(m_chartWin, qq); auto *dataValueSettingsDock = new QDockWidget(tr("DataValueSettings"), qq); dataValueSettingsDock->setWidget(dataValueSettings); dataValueSettingsDock->setFloating(false); q->addDockWidget(Qt::RightDockWidgetArea, dataValueSettingsDock); - connect(diagramTypeSettings, SIGNAL(diagramTypeChanged(DiagramType, Subtype)), dataValueSettings, SLOT(refresh())); + connect(diagramTypeSettings, &DiagramTypeDialog::diagramTypeChanged, dataValueSettings, &DataValueSettings::refresh); } int MainWindow::Private::datasetCount() const diff --git a/qtests/CartesianDiagramDataCompressor/CartesianDiagramDataCompressorTests.cpp b/qtests/CartesianDiagramDataCompressor/CartesianDiagramDataCompressorTests.cpp index c0c1c9d6..dda9af60 100644 --- a/qtests/CartesianDiagramDataCompressor/CartesianDiagramDataCompressorTests.cpp +++ b/qtests/CartesianDiagramDataCompressor/CartesianDiagramDataCompressorTests.cpp @@ -117,10 +117,9 @@ private slots: { // test 1: valid point: { - QModelIndexList indexes; CachePosition point(0, 0); - indexes = compressor.mapToModel(point); - Q_FOREACH (const QModelIndex &index, indexes) { + const auto indexes = compressor.mapToModel(point); + for (const QModelIndex &index : indexes) { QVERIFY2(compressor.mapToCache(index) == point, "index mapToModel does not map back to the original cache point"); } diff --git a/qtests/DrawIntoPainter/mainwindow.cpp b/qtests/DrawIntoPainter/mainwindow.cpp index c8e71d32..3ba41f02 100644 --- a/qtests/DrawIntoPainter/mainwindow.cpp +++ b/qtests/DrawIntoPainter/mainwindow.cpp @@ -81,8 +81,8 @@ MainWindow::MainWindow(QWidget *parent) #ifdef USE_FRAME_WIDGET chartFrameWidget->setChart(m_chart); // make sure, we re-draw after changing one of the chart's properties - connect(m_chart, SIGNAL(propertiesChanged()), - chartFrameWidget, SLOT(update())); + connect(m_chart, &Chart::propertiesChanged, + chartFrameWidget, QOverload<>::of(&QWidget::update)); #else chartLayout->addWidget(m_chart); #endif diff --git a/qtests/DrawIntoPainter/mainwindow.ui b/qtests/DrawIntoPainter/mainwindow.ui index da9773db..e8797b38 100644 --- a/qtests/DrawIntoPainter/mainwindow.ui +++ b/qtests/DrawIntoPainter/mainwindow.ui @@ -13,7 +13,9 @@ KD Chart drawing into a foreign QPainter - + + + diff --git a/qtests/ParamVsParam/ModelParamVsParam.cpp b/qtests/ParamVsParam/ModelParamVsParam.cpp index ec8cdd97..f7e93882 100644 --- a/qtests/ParamVsParam/ModelParamVsParam.cpp +++ b/qtests/ParamVsParam/ModelParamVsParam.cpp @@ -14,7 +14,7 @@ ModelParamVsParam::ModelParamVsParam( QObject *p_parent) : QStandardItemModel(p_parent) { - connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); + connect(&m_timer, &QTimer::timeout, this, &ModelParamVsParam::timeout); // m_timer.setSingleShot(true); m_timer.setInterval(2000); } // ModelParamVsParam::ModelParamVsParam() diff --git a/qtests/ParamVsParam/main.cpp b/qtests/ParamVsParam/main.cpp index 5bad1fa8..dcfd1a55 100644 --- a/qtests/ParamVsParam/main.cpp +++ b/qtests/ParamVsParam/main.cpp @@ -28,7 +28,7 @@ private slots: qDebug() << "time constructor:" << t.elapsed() << "ms"; mainWindow.show(); - QTimer::singleShot(0, qApp, SLOT(quit())); + QTimer::singleShot(0, qApp, &QCoreApplication::quit); qDebug() << "time show():" << t.elapsed() << "ms"; // uncomment to see it blink: diff --git a/qtests/ParamVsParam/mainwindow.cpp b/qtests/ParamVsParam/mainwindow.cpp index 41284861..459d2e30 100644 --- a/qtests/ParamVsParam/mainwindow.cpp +++ b/qtests/ParamVsParam/mainwindow.cpp @@ -31,9 +31,9 @@ MainWindow::MainWindow( , m_nrOfSamplesLineEdit(new QLineEdit("4")) , m_paramVsParamGridLayout(new QGridLayout) { - connect(m_timeoutLineEdit, SIGNAL(editingFinished()), SLOT(timeoutEditingFinished())); - connect(m_nrOfParametersLineEdit, SIGNAL(editingFinished()), SLOT(editingFinished())); - connect(m_nrOfSamplesLineEdit, SIGNAL(editingFinished()), SLOT(editingFinished())); + connect(m_timeoutLineEdit, &QLineEdit::editingFinished, this, &MainWindow::timeoutEditingFinished); + connect(m_nrOfParametersLineEdit, &QLineEdit::editingFinished, this, &MainWindow::editingFinished); + connect(m_nrOfSamplesLineEdit, &QLineEdit::editingFinished, this, &MainWindow::editingFinished); auto *vBoxLayout = new QVBoxLayout; setLayout(vBoxLayout); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4543adfb..9de77583 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ # SPDX-License-Identifier: MIT # -add_definitions(-DQT_NO_KEYWORDS -DQT_NO_CAST_FROM_BYTEARRAY -Demit=) +add_definitions(-DQT_NO_KEYWORDS -DQT_NO_CAST_FROM_BYTEARRAY -DQT_NO_SIGNALS_SLOTS_KEYWORDS) set(FORMS KDChart/KDChartDatasetSelector.ui) set(RESOURCES KDChart/KDAB_kdchart_LeveyJennings_resources.qrc) diff --git a/src/KDChart/Cartesian/DiagramFlavors/KDChartPercentPlotter_p.cpp b/src/KDChart/Cartesian/DiagramFlavors/KDChartPercentPlotter_p.cpp index ebf9170c..9c765ddb 100644 --- a/src/KDChart/Cartesian/DiagramFlavors/KDChartPercentPlotter_p.cpp +++ b/src/KDChart/Cartesian/DiagramFlavors/KDChartPercentPlotter_p.cpp @@ -112,7 +112,7 @@ void PercentPlotter::paint(PaintContext *ctx) QList xValues = diagramValues.keys(); // make sure it's sorted std::sort(xValues.begin(), xValues.end()); - Q_FOREACH (const qreal xValue, xValues) { + for (const qreal xValue : qAsConst(xValues)) { // the y-values to the current x-value QVector> &yValues = diagramValues[xValue]; Q_ASSERT(yValues.count() == colCount); diff --git a/src/KDChart/Cartesian/KDChartAbstractCartesianDiagram.cpp b/src/KDChart/Cartesian/KDChartAbstractCartesianDiagram.cpp index 16c97dbe..727b34bb 100644 --- a/src/KDChart/Cartesian/KDChartAbstractCartesianDiagram.cpp +++ b/src/KDChart/Cartesian/KDChartAbstractCartesianDiagram.cpp @@ -46,7 +46,7 @@ AbstractCartesianDiagram::AbstractCartesianDiagram(QWidget *parent, CartesianCoo KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram() { - Q_FOREACH (CartesianAxis *axis, d->axesList) { + for (CartesianAxis *axis : qAsConst(d->axesList)) { axis->deleteObserver(this); } d->axesList.clear(); @@ -55,14 +55,14 @@ KDChart::AbstractCartesianDiagram::~AbstractCartesianDiagram() void AbstractCartesianDiagram::init() { d->compressor.setModel(attributesModel()); - connect(this, SIGNAL(layoutChanged(AbstractDiagram *)), - &d->compressor, SLOT(slotDiagramLayoutChanged(AbstractDiagram *))); - connect(this, SIGNAL(attributesModelAboutToChange(AttributesModel *, AttributesModel *)), - this, SLOT(connectAttributesModel(AttributesModel *))); + connect(this, &AbstractCartesianDiagram::layoutChanged, + &d->compressor, &CartesianDiagramDataCompressor::slotDiagramLayoutChanged); + connect(this, &AbstractCartesianDiagram::attributesModelAboutToChange, + this, &AbstractCartesianDiagram::connectAttributesModel); if (d->plane) { - connect(d->plane, SIGNAL(viewportCoordinateSystemChanged()), - this, SIGNAL(viewportCoordinateSystemChanged())); + connect(d->plane, &AbstractCoordinatePlane::viewportCoordinateSystemChanged, + this, &AbstractCartesianDiagram::viewportCoordinateSystemChanged); } } @@ -101,31 +101,32 @@ void KDChart::AbstractCartesianDiagram::layoutPlanes() void KDChart::AbstractCartesianDiagram::setCoordinatePlane(AbstractCoordinatePlane *plane) { if (coordinatePlane()) { - disconnect(attributesModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - coordinatePlane(), SLOT(relayout())); - disconnect(attributesModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - coordinatePlane(), SLOT(relayout())); - disconnect(attributesModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - coordinatePlane(), SLOT(relayout())); - disconnect(attributesModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - coordinatePlane(), SLOT(relayout())); + disconnect(attributesModel(), &AttributesModel::rowsRemoved, + coordinatePlane(), &AbstractCoordinatePlane::relayout); + disconnect(attributesModel(), &AttributesModel::rowsInserted, + coordinatePlane(), &AbstractCoordinatePlane::relayout); + disconnect(attributesModel(), &AttributesModel::columnsRemoved, + coordinatePlane(), &AbstractCoordinatePlane::relayout); + disconnect(attributesModel(), &AttributesModel::columnsInserted, + coordinatePlane(), &AbstractCoordinatePlane::relayout); disconnect(coordinatePlane()); } AbstractDiagram::setCoordinatePlane(plane); if (plane) { // Readjust the layout when the dataset count changes - connect(attributesModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - plane, SLOT(relayout())); - connect(attributesModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - plane, SLOT(relayout())); - connect(attributesModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - plane, SLOT(relayout())); - connect(attributesModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - plane, SLOT(relayout())); - connect(plane, SIGNAL(viewportCoordinateSystemChanged()), - this, SIGNAL(viewportCoordinateSystemChanged())); - connect(plane, SIGNAL(viewportCoordinateSystemChanged()), this, SLOT(update())); + connect(attributesModel(), &AttributesModel::rowsRemoved, + plane, &AbstractCoordinatePlane::relayout); + connect(attributesModel(), &AttributesModel::rowsInserted, + plane, &AbstractCoordinatePlane::relayout); + connect(attributesModel(), &AttributesModel::columnsRemoved, + plane, &AbstractCoordinatePlane::relayout); + connect(attributesModel(), &AttributesModel::columnsInserted, + plane, &AbstractCoordinatePlane::relayout); + connect(plane, &AbstractCoordinatePlane::viewportCoordinateSystemChanged, + this, &AbstractCartesianDiagram::viewportCoordinateSystemChanged); + connect(plane, &AbstractCoordinatePlane::viewportCoordinateSystemChanged, + this, &AbstractCartesianDiagram::update); } } diff --git a/src/KDChart/Cartesian/KDChartBarDiagram.cpp b/src/KDChart/Cartesian/KDChartBarDiagram.cpp index 94f9f76a..2d5a8218 100644 --- a/src/KDChart/Cartesian/KDChartBarDiagram.cpp +++ b/src/KDChart/Cartesian/KDChartBarDiagram.cpp @@ -89,8 +89,8 @@ void BarDiagram::Private::setOrientationAndType(Qt::Orientation o, BarDiagram::B // AbstractAxis settings - see AbstractDiagram and CartesianAxis barDia->setPercentMode(type == BarDiagram::Percent); barDia->setDataBoundariesDirty(); - emit barDia->layoutChanged(barDia); - emit barDia->propertiesChanged(); + Q_EMIT barDia->layoutChanged(barDia); + Q_EMIT barDia->propertiesChanged(); } #define d d_func() @@ -180,7 +180,7 @@ Qt::Orientation BarDiagram::orientation() const void BarDiagram::setBarAttributes(const BarAttributes &ba) { d->attributesModel->setModelData(QVariant::fromValue(ba), BarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -189,7 +189,7 @@ void BarDiagram::setBarAttributes(const BarAttributes &ba) void BarDiagram::setBarAttributes(int column, const BarAttributes &ba) { d->setDatasetAttrs(column, QVariant::fromValue(ba), BarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -201,7 +201,7 @@ void BarDiagram::setBarAttributes(const QModelIndex &index, const BarAttributes d->attributesModel->mapFromSource(index), QVariant::fromValue(ba), BarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -241,8 +241,8 @@ void BarDiagram::setThreeDBarAttributes(const ThreeDBarAttributes &threeDAttrs) { setDataBoundariesDirty(); d->attributesModel->setModelData(QVariant::fromValue(threeDAttrs), ThreeDBarAttributesRole); - emit layoutChanged(this); - emit propertiesChanged(); + Q_EMIT layoutChanged(this); + Q_EMIT propertiesChanged(); } /** @@ -252,8 +252,8 @@ void BarDiagram::setThreeDBarAttributes(int column, const ThreeDBarAttributes &t { setDataBoundariesDirty(); d->setDatasetAttrs(column, QVariant::fromValue(threeDAttrs), ThreeDBarAttributesRole); - // emit layoutChanged( this ); - emit propertiesChanged(); + // Q_EMIT layoutChanged( this ); + Q_EMIT propertiesChanged(); } /** @@ -266,8 +266,8 @@ void BarDiagram::setThreeDBarAttributes(const QModelIndex &index, const ThreeDBa d->attributesModel->mapFromSource(index), QVariant::fromValue(threeDAttrs), ThreeDBarAttributesRole); - // emit layoutChanged( this ); - emit propertiesChanged(); + // Q_EMIT layoutChanged( this ); + Q_EMIT propertiesChanged(); } /** diff --git a/src/KDChart/Cartesian/KDChartBarDiagram_p.cpp b/src/KDChart/Cartesian/KDChartBarDiagram_p.cpp index 05dc83c6..ac96bd22 100644 --- a/src/KDChart/Cartesian/KDChartBarDiagram_p.cpp +++ b/src/KDChart/Cartesian/KDChartBarDiagram_p.cpp @@ -69,7 +69,7 @@ void BarDiagram::BarDiagramType::paintBars(PaintContext *ctx, const QModelIndex bool drawIt = false; bool hasPointOutside = false; const QRectF r(ctx->rectangle().adjusted(0, -1, 1, 0)); - Q_FOREACH (QPointF pt, topPoints) { + for (QPointF pt : qAsConst(topPoints)) { if (r.contains(pt)) { drawIt = true; } else { diff --git a/src/KDChart/Cartesian/KDChartCartesianAxis.cpp b/src/KDChart/Cartesian/KDChartCartesianAxis.cpp index 15f79f36..a64d46ee 100644 --- a/src/KDChart/Cartesian/KDChartCartesianAxis.cpp +++ b/src/KDChart/Cartesian/KDChartCartesianAxis.cpp @@ -133,12 +133,14 @@ TickIterator::TickIterator(CartesianAxis *a, CartesianCoordinatePlane *plane, ui static QMultiMap allAxisAnnotations(const AbstractCoordinatePlane *plane, bool isY) { QMultiMap annotations; - Q_FOREACH (const AbstractDiagram *diagram, plane->diagrams()) { + const auto constDiagrams = plane->diagrams(); + for (const AbstractDiagram *diagram : constDiagrams) { const auto *cd = qobject_cast(diagram); if (!cd) { continue; } - Q_FOREACH (const CartesianAxis *axis, cd->axes()) { + const auto axes = cd->axes(); + for (const CartesianAxis *axis : axes) { const CartesianAxis::Private *axisPriv = CartesianAxis::Private::get(axis); if (axisPriv->isVertical() == isY) { annotations.unite(axisPriv->annotations); @@ -379,7 +381,7 @@ CartesianAxis::~CartesianAxis() auto *cd = qobject_cast(d->mDiagram); cd->takeAxis(this); } - Q_FOREACH (AbstractDiagram *diagram, d->secondaryDiagrams) { + for (AbstractDiagram *diagram : qAsConst(d->secondaryDiagrams)) { auto *cd = qobject_cast(diagram); cd->takeAxis(this); } @@ -390,7 +392,7 @@ void CartesianAxis::init() d->customTickLength = 3; d->position = Bottom; setCachedSizeDirty(); - connect(this, SIGNAL(coordinateSystemChanged()), SLOT(coordinateSystemChanged())); + connect(this, &AbstractAxis::coordinateSystemChanged, this, &CartesianAxis::coordinateSystemChanged); } bool CartesianAxis::compare(const CartesianAxis *other) const diff --git a/src/KDChart/Cartesian/KDChartCartesianCoordinatePlane.cpp b/src/KDChart/Cartesian/KDChartCartesianCoordinatePlane.cpp index 412ab39a..3746b8a8 100644 --- a/src/KDChart/Cartesian/KDChartCartesianCoordinatePlane.cpp +++ b/src/KDChart/Cartesian/KDChartCartesianCoordinatePlane.cpp @@ -61,10 +61,10 @@ void CartesianCoordinatePlane::addDiagram(AbstractDiagram *diagram) "CartesianCoordinatePlane::addDiagram", "Only cartesian " "diagrams can be added to a cartesian coordinate plane!"); AbstractCoordinatePlane::addDiagram(diagram); - connect(diagram, SIGNAL(layoutChanged(AbstractDiagram *)), - SLOT(slotLayoutChanged(AbstractDiagram *))); + connect(diagram, &AbstractDiagram::layoutChanged, this, + &CartesianCoordinatePlane::slotLayoutChanged); - connect(diagram, SIGNAL(propertiesChanged()), this, SIGNAL(propertiesChanged())); + connect(diagram, &AbstractDiagram::propertiesChanged, this, &CartesianCoordinatePlane::propertiesChanged); } void CartesianCoordinatePlane::paint(QPainter *painter) @@ -127,7 +127,8 @@ QRectF CartesianCoordinatePlane::getRawDataBoundingRectFromDiagrams() const qreal minY = 0; qreal maxY = 0; bool bStarting = true; - Q_FOREACH (const AbstractDiagram *diagram, diagrams()) { + const auto constDiagrams = diagrams(); + for (const AbstractDiagram *diagram : constDiagrams) { QPair dataBoundariesPair = diagram->dataBoundaries(); // qDebug() << "CartesianCoordinatePlane::getRawDataBoundingRectFromDiagrams()\ngets diagram->dataBoundaries: " << dataBoundariesPair.first << dataBoundariesPair.second; if (bStarting || dataBoundariesPair.first.x() < minX) @@ -413,7 +414,7 @@ void CartesianCoordinatePlane::handleFixedDataCoordinateSpaceRelation(const QRec if (doneSetZoomCenter(newCenter)) changed = true; if (changed) - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -436,7 +437,7 @@ void CartesianCoordinatePlane::setIsometricScaling(bool isOn) if (d->isometricScaling != isOn) { d->isometricScaling = isOn; layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -485,7 +486,7 @@ void CartesianCoordinatePlane::setZoomFactors(qreal factorX, qreal factorY) { if (doneSetZoomFactorX(factorX) || doneSetZoomFactorY(factorY)) { d->coordinateTransformation.updateTransform(logicalArea(), drawingArea()); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -493,7 +494,7 @@ void CartesianCoordinatePlane::setZoomFactorX(qreal factor) { if (doneSetZoomFactorX(factor)) { d->coordinateTransformation.updateTransform(logicalArea(), drawingArea()); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -501,7 +502,7 @@ void CartesianCoordinatePlane::setZoomFactorY(qreal factor) { if (doneSetZoomFactorY(factor)) { d->coordinateTransformation.updateTransform(logicalArea(), drawingArea()); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -509,7 +510,7 @@ void CartesianCoordinatePlane::setZoomCenter(const QPointF &point) { if (doneSetZoomCenter(point)) { d->coordinateTransformation.updateTransform(logicalArea(), drawingArea()); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -543,10 +544,12 @@ void CartesianCoordinatePlane::setAxesCalcModes(AxesCalcMode mode) if (d->coordinateTransformation.axesCalcModeY != mode || d->coordinateTransformation.axesCalcModeX != mode) { d->coordinateTransformation.axesCalcModeY = mode; d->coordinateTransformation.axesCalcModeX = mode; - emit propertiesChanged(); - emit viewportCoordinateSystemChanged(); - Q_FOREACH (AbstractDiagram *diag, diagrams()) + Q_EMIT propertiesChanged(); + Q_EMIT viewportCoordinateSystemChanged(); + const auto constDiagrams = diagrams(); + for (AbstractDiagram *diag : constDiagrams) { slotLayoutChanged(diag); + } } } @@ -554,9 +557,9 @@ void CartesianCoordinatePlane::setAxesCalcModeY(AxesCalcMode mode) { if (d->coordinateTransformation.axesCalcModeY != mode) { d->coordinateTransformation.axesCalcModeY = mode; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); setGridNeedsRecalculate(); - emit viewportCoordinateSystemChanged(); + Q_EMIT viewportCoordinateSystemChanged(); } } @@ -564,8 +567,8 @@ void CartesianCoordinatePlane::setAxesCalcModeX(AxesCalcMode mode) { if (d->coordinateTransformation.axesCalcModeX != mode) { d->coordinateTransformation.axesCalcModeX = mode; - emit propertiesChanged(); - emit viewportCoordinateSystemChanged(); + Q_EMIT propertiesChanged(); + Q_EMIT viewportCoordinateSystemChanged(); } } @@ -588,8 +591,8 @@ void CartesianCoordinatePlane::setHorizontalRange(const QPair &ran d->horizontalMin = range.first; d->horizontalMax = range.second; layoutDiagrams(); - emit propertiesChanged(); - emit boundariesChanged(); + Q_EMIT propertiesChanged(); + Q_EMIT boundariesChanged(); } } @@ -601,8 +604,8 @@ void CartesianCoordinatePlane::setVerticalRange(const QPair &range d->verticalMin = range.first; d->verticalMax = range.second; layoutDiagrams(); - emit propertiesChanged(); - emit boundariesChanged(); + Q_EMIT propertiesChanged(); + Q_EMIT boundariesChanged(); } } @@ -624,7 +627,7 @@ void CartesianCoordinatePlane::adjustRangesToData() d->verticalMin = dataBoundingRect.top(); d->verticalMax = dataBoundingRect.bottom(); layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void CartesianCoordinatePlane::adjustHorizontalRangeToData() @@ -633,7 +636,7 @@ void CartesianCoordinatePlane::adjustHorizontalRangeToData() d->horizontalMin = dataBoundingRect.left(); d->horizontalMax = dataBoundingRect.right(); layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void CartesianCoordinatePlane::adjustVerticalRangeToData() @@ -642,7 +645,7 @@ void CartesianCoordinatePlane::adjustVerticalRangeToData() d->verticalMin = dataBoundingRect.bottom(); d->verticalMax = dataBoundingRect.top(); layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void CartesianCoordinatePlane::setAutoAdjustHorizontalRangeToData(unsigned int percentEmpty) @@ -652,7 +655,7 @@ void CartesianCoordinatePlane::setAutoAdjustHorizontalRangeToData(unsigned int p d->horizontalMin = 0.0; d->horizontalMax = 0.0; layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -663,7 +666,7 @@ void CartesianCoordinatePlane::setAutoAdjustVerticalRangeToData(unsigned int per d->verticalMin = 0.0; d->verticalMax = 0.0; layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -687,7 +690,7 @@ void CartesianCoordinatePlane::setGridAttributes( d->gridAttributesVertical = a; setHasOwnGridAttributes(orientation, true); update(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void CartesianCoordinatePlane::resetGridAttributes(Qt::Orientation orientation) @@ -714,7 +717,7 @@ void CartesianCoordinatePlane::setHasOwnGridAttributes(Qt::Orientation orientati d->hasOwnGridAttributesHorizontal = on; else d->hasOwnGridAttributesVertical = on; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool CartesianCoordinatePlane::hasOwnGridAttributes(Qt::Orientation orientation) const @@ -728,7 +731,7 @@ void CartesianCoordinatePlane::setAutoAdjustGridToZoom(bool autoAdjust) if (d->autoAdjustGridToZoom != autoAdjust) { d->autoAdjustGridToZoom = autoAdjust; d->grid->setNeedRecalculate(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } } @@ -748,7 +751,7 @@ AbstractCoordinatePlane *CartesianCoordinatePlane::sharedAxisMasterPlane(QPainte const CartesianAxis *sharedAxis = nullptr; if (diag != nullptr) { const CartesianAxisList axes = diag->axes(); - Q_FOREACH (const CartesianAxis *a, axes) { + for (const CartesianAxis *a : axes) { auto *p = const_cast( dynamic_cast(a->coordinatePlane())); if (p != nullptr && p != this) { @@ -788,7 +791,7 @@ void CartesianCoordinatePlane::setHorizontalRangeReversed(bool reverse) d->reverseHorizontalPlane = reverse; layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool CartesianCoordinatePlane::isHorizontalRangeReversed() const @@ -803,7 +806,7 @@ void CartesianCoordinatePlane::setVerticalRangeReversed(bool reverse) d->reverseVerticalPlane = reverse; layoutDiagrams(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool CartesianCoordinatePlane::isVerticalRangeReversed() const @@ -843,7 +846,8 @@ void CartesianCoordinatePlane::setGeometry(const QRect &rectangle) AbstractCoordinatePlane::setGeometry(d->geometry); - Q_FOREACH (AbstractDiagram *diagram, diagrams()) { + const auto constDiagrams = diagrams(); + for (AbstractDiagram *diagram : constDiagrams) { diagram->resize(d->geometry.size()); } } diff --git a/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.cpp b/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.cpp index 8889f979..97e20698 100644 --- a/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.cpp +++ b/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.cpp @@ -52,7 +52,8 @@ CartesianDiagramDataCompressor::AggregatedDataValueAttributes CartesianDiagramDa // aggregate attributes from all indices in the same CachePosition as index CartesianDiagramDataCompressor::AggregatedDataValueAttributes aggregated; - Q_FOREACH (const QModelIndex &neighborIndex, mapToModel(position)) { + const auto modelList = mapToModel(position); + for (const QModelIndex &neighborIndex : modelList) { DataValueAttributes attrs = diagram->dataValueAttributes(neighborIndex); // only store visible and unique attributes if (!attrs.isVisible()) { @@ -283,30 +284,30 @@ void CartesianDiagramDataCompressor::setModel(QAbstractItemModel *model) } if (m_model != nullptr) { - disconnect(m_model, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), - this, SLOT(slotModelHeaderDataChanged(Qt::Orientation, int, int))); - disconnect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), - this, SLOT(slotModelDataChanged(QModelIndex, QModelIndex))); - disconnect(m_model, SIGNAL(layoutChanged()), - this, SLOT(slotModelLayoutChanged())); - disconnect(m_model, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), - this, SLOT(slotRowsAboutToBeInserted(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), - this, SLOT(slotRowsInserted(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), - this, SLOT(slotRowsAboutToBeRemoved(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), - this, SLOT(slotRowsRemoved(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), - this, SLOT(slotColumnsAboutToBeInserted(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), - this, SLOT(slotColumnsInserted(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), - this, SLOT(slotColumnsRemoved(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), - this, SLOT(slotColumnsAboutToBeRemoved(QModelIndex, int, int))); - disconnect(m_model, SIGNAL(modelReset()), - this, SLOT(rebuildCache())); + disconnect(m_model, &QAbstractItemModel::headerDataChanged, + this, &CartesianDiagramDataCompressor::slotModelHeaderDataChanged); + disconnect(m_model, &QAbstractItemModel::dataChanged, + this, &CartesianDiagramDataCompressor::slotModelDataChanged); + disconnect(m_model, &QAbstractItemModel::layoutChanged, + this, &CartesianDiagramDataCompressor::slotModelLayoutChanged); + disconnect(m_model, &QAbstractItemModel::rowsAboutToBeInserted, + this, &CartesianDiagramDataCompressor::slotRowsAboutToBeInserted); + disconnect(m_model, &QAbstractItemModel::rowsInserted, + this, &CartesianDiagramDataCompressor::slotRowsInserted); + disconnect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved, + this, &CartesianDiagramDataCompressor::slotRowsAboutToBeRemoved); + disconnect(m_model, &QAbstractItemModel::rowsRemoved, + this, &CartesianDiagramDataCompressor::slotRowsRemoved); + disconnect(m_model, &QAbstractItemModel::columnsAboutToBeInserted, + this, &CartesianDiagramDataCompressor::slotColumnsAboutToBeInserted); + disconnect(m_model, &QAbstractItemModel::columnsInserted, + this, &CartesianDiagramDataCompressor::slotColumnsInserted); + disconnect(m_model, &QAbstractItemModel::columnsRemoved, + this, &CartesianDiagramDataCompressor::slotColumnsRemoved); + disconnect(m_model, &QAbstractItemModel::columnsAboutToBeRemoved, + this, &CartesianDiagramDataCompressor::slotColumnsAboutToBeRemoved); + disconnect(m_model, &QAbstractItemModel::modelReset, + this, &CartesianDiagramDataCompressor::rebuildCache); m_model = nullptr; } @@ -314,29 +315,30 @@ void CartesianDiagramDataCompressor::setModel(QAbstractItemModel *model) if (model != nullptr) { m_model = model; - connect(m_model, SIGNAL(headerDataChanged(Qt::Orientation, int, int)), - SLOT(slotModelHeaderDataChanged(Qt::Orientation, int, int))); - connect(m_model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), - SLOT(slotModelDataChanged(QModelIndex, QModelIndex))); - connect(m_model, SIGNAL(layoutChanged()), - SLOT(slotModelLayoutChanged())); - connect(m_model, SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), - SLOT(slotRowsAboutToBeInserted(QModelIndex, int, int))); - connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), - SLOT(slotRowsInserted(QModelIndex, int, int))); - connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), - SLOT(slotRowsAboutToBeRemoved(QModelIndex, int, int))); - connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), - SLOT(slotRowsRemoved(QModelIndex, int, int))); - connect(m_model, SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), - SLOT(slotColumnsAboutToBeInserted(QModelIndex, int, int))); - connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), - SLOT(slotColumnsInserted(QModelIndex, int, int))); - connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), - SLOT(slotColumnsRemoved(QModelIndex, int, int))); - connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), - SLOT(slotColumnsAboutToBeRemoved(QModelIndex, int, int))); - connect(m_model, SIGNAL(modelReset()), SLOT(rebuildCache())); + connect(m_model, &QAbstractItemModel::headerDataChanged, + this, &CartesianDiagramDataCompressor::slotModelHeaderDataChanged); + connect(m_model, &QAbstractItemModel::dataChanged, + this, &CartesianDiagramDataCompressor::slotModelDataChanged); + connect(m_model, &QAbstractItemModel::layoutChanged, + this, &CartesianDiagramDataCompressor::slotModelLayoutChanged); + connect(m_model, &QAbstractItemModel::rowsAboutToBeInserted, + this, &CartesianDiagramDataCompressor::slotRowsAboutToBeInserted); + connect(m_model, &QAbstractItemModel::rowsInserted, + this, &CartesianDiagramDataCompressor::slotRowsInserted); + connect(m_model, &QAbstractItemModel::rowsAboutToBeRemoved, + this, &CartesianDiagramDataCompressor::slotRowsAboutToBeRemoved); + connect(m_model, &QAbstractItemModel::rowsRemoved, + this, &CartesianDiagramDataCompressor::slotRowsRemoved); + connect(m_model, &QAbstractItemModel::columnsAboutToBeInserted, + this, &CartesianDiagramDataCompressor::slotColumnsAboutToBeInserted); + connect(m_model, &QAbstractItemModel::columnsInserted, + this, &CartesianDiagramDataCompressor::slotColumnsInserted); + connect(m_model, &QAbstractItemModel::columnsRemoved, + this, &CartesianDiagramDataCompressor::slotColumnsRemoved); + connect(m_model, &QAbstractItemModel::columnsAboutToBeRemoved, + this, &CartesianDiagramDataCompressor::slotColumnsAboutToBeRemoved); + connect(m_model, &QAbstractItemModel::modelReset, + this, &CartesianDiagramDataCompressor::rebuildCache); } rebuildCache(); calculateSampleStepWidth(); @@ -478,7 +480,7 @@ void CartesianDiagramDataCompressor::retrieveModelData(const CachePosition &posi } result.value = std::numeric_limits::quiet_NaN(); result.key = 0.0; - Q_FOREACH (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { const qreal value = m_modelCache.data(index); if (!ISNAN(value)) { result.value = ISNAN(result.value) ? value : result.value + value; @@ -490,7 +492,7 @@ void CartesianDiagramDataCompressor::retrieveModelData(const CachePosition &posi result.value /= indexes.size(); } - Q_FOREACH (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { // the DataPoint point is visible if any of the underlying, aggregated points is visible if (m_model->data(index, DataHiddenRole).value() == false) { result.hidden = false; diff --git a/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.h b/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.h index 2b600ff3..3ba16a48 100644 --- a/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.h +++ b/src/KDChart/Cartesian/KDChartCartesianDiagramDataCompressor_p.h @@ -61,6 +61,7 @@ class KDCHART_EXPORT CartesianDiagramDataCompressor : public QObject { Q_OBJECT friend class ::CartesianDiagramDataCompressorTests; + friend class AbstractCartesianDiagram; public: class DataPoint diff --git a/src/KDChart/Cartesian/KDChartLeveyJenningsAxis.cpp b/src/KDChart/Cartesian/KDChartLeveyJenningsAxis.cpp index f04ae992..a37fe028 100644 --- a/src/KDChart/Cartesian/KDChartLeveyJenningsAxis.cpp +++ b/src/KDChart/Cartesian/KDChartLeveyJenningsAxis.cpp @@ -44,7 +44,7 @@ LeveyJenningsAxis::~LeveyJenningsAxis() auto *cd = qobject_cast(d->mDiagram); cd->takeAxis(this); } - Q_FOREACH (AbstractDiagram *diagram, d->secondaryDiagrams) { + for (AbstractDiagram *diagram : qAsConst(d->secondaryDiagrams)) { auto *cd = qobject_cast(diagram); cd->takeAxis(this); } diff --git a/src/KDChart/Cartesian/KDChartLeveyJenningsDiagram.cpp b/src/KDChart/Cartesian/KDChartLeveyJenningsDiagram.cpp index 0ec8d628..f5f6f8f2 100644 --- a/src/KDChart/Cartesian/KDChartLeveyJenningsDiagram.cpp +++ b/src/KDChart/Cartesian/KDChartLeveyJenningsDiagram.cpp @@ -300,40 +300,41 @@ float LeveyJenningsDiagram::calculatedStandardDeviation() const return d->calculatedStandardDeviation; } -void LeveyJenningsDiagram::setModel(QAbstractItemModel *model) -{ - if (this->model() != nullptr) { - disconnect(this->model(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(modelReset()), - this, SLOT(calculateMeanAndStandardDeviation())); - disconnect(this->model(), SIGNAL(layoutChanged()), - this, SLOT(calculateMeanAndStandardDeviation())); +void LeveyJenningsDiagram::setModel(QAbstractItemModel *newModel) +{ + QAbstractItemModel *oldModel = model(); + if (oldModel != nullptr) { + disconnect(oldModel, &QAbstractItemModel::dataChanged, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::rowsInserted, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::rowsRemoved, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::columnsInserted, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::columnsRemoved, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::modelReset, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + disconnect(oldModel, &QAbstractItemModel::layoutChanged, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); } - LineDiagram::setModel(model); - if (this->model() != nullptr) { - connect(this->model(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(modelReset()), - this, SLOT(calculateMeanAndStandardDeviation())); - connect(this->model(), SIGNAL(layoutChanged()), - this, SLOT(calculateMeanAndStandardDeviation())); + LineDiagram::setModel(newModel); + if (newModel != nullptr) { + connect(newModel, &QAbstractItemModel::dataChanged, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::rowsInserted, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::rowsRemoved, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::columnsInserted, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::columnsRemoved, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::modelReset, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); + connect(newModel, &QAbstractItemModel::layoutChanged, + this, &LeveyJenningsDiagram::calculateMeanAndStandardDeviation); calculateMeanAndStandardDeviation(); } @@ -360,7 +361,7 @@ void LeveyJenningsDiagram::calculateMeanAndStandardDeviation() const qreal sum = 0.0; qreal sumSquares = 0.0; - Q_FOREACH (qreal value, values) { + for (qreal value : qAsConst(values)) { sum += value; sumSquares += value * value; } @@ -477,13 +478,13 @@ void LeveyJenningsDiagram::drawChanges(PaintContext *ctx) { const unsigned int minTime = timeRange().first.toSecsSinceEpoch(); - Q_FOREACH (const QDateTime &dt, d->fluidicsPackChanges) { + for (const QDateTime &dt : qAsConst(d->fluidicsPackChanges)) { const qreal xValue = (dt.toSecsSinceEpoch() - minTime) / static_cast(24 * 60 * 60); const QPointF point(xValue, 0.0); drawFluidicsPackChangedSymbol(ctx, point); } - Q_FOREACH (const QDateTime &dt, d->sensorChanges) { + for (const QDateTime &dt : qAsConst(d->sensorChanges)) { const qreal xValue = (dt.toSecsSinceEpoch() - minTime) / static_cast(24 * 60 * 60); const QPointF point(xValue, 0.0); drawSensorChangedSymbol(ctx, point); diff --git a/src/KDChart/Cartesian/KDChartLineDiagram.cpp b/src/KDChart/Cartesian/KDChartLineDiagram.cpp index d9f32810..5f1b6db4 100644 --- a/src/KDChart/Cartesian/KDChartLineDiagram.cpp +++ b/src/KDChart/Cartesian/KDChartLineDiagram.cpp @@ -121,8 +121,8 @@ void LineDiagram::setType(const LineType type) // AbstractAxis settings - see AbstractDiagram and CartesianAxis setPercentMode(type == LineDiagram::Percent); setDataBoundariesDirty(); - emit layoutChanged(this); - emit propertiesChanged(); + Q_EMIT layoutChanged(this); + Q_EMIT propertiesChanged(); } /** @@ -144,8 +144,8 @@ void LineDiagram::setCenterDataPoints(bool center) // A B =\ A B // 1......2 =/ 1......2......3 setDataBoundariesDirty(); - emit layoutChanged(this); - emit propertiesChanged(); + Q_EMIT layoutChanged(this); + Q_EMIT propertiesChanged(); } bool LineDiagram::centerDataPoints() const @@ -171,7 +171,7 @@ void LineDiagram::setLineAttributes(const LineAttributes &la) d->attributesModel->setModelData( QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -182,7 +182,7 @@ void LineDiagram::setLineAttributes( const LineAttributes &la) { d->setDatasetAttrs(column, QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -191,7 +191,7 @@ void LineDiagram::setLineAttributes( void LineDiagram::resetLineAttributes(int column) { d->resetDatasetAttrs(column, LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -205,7 +205,7 @@ void LineDiagram::setLineAttributes( d->attributesModel->mapFromSource(index), QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -215,7 +215,7 @@ void LineDiagram::resetLineAttributes(const QModelIndex &index) { d->attributesModel->resetData( d->attributesModel->mapFromSource(index), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -259,7 +259,7 @@ void LineDiagram::setThreeDLineAttributes( d->attributesModel->setModelData( QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -271,7 +271,7 @@ void LineDiagram::setThreeDLineAttributes( { setDataBoundariesDirty(); d->setDatasetAttrs(column, QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -286,7 +286,7 @@ void LineDiagram::setThreeDLineAttributes( d->attributesModel->mapFromSource(index), QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -338,7 +338,7 @@ void LineDiagram::setValueTrackerAttributes(const QModelIndex &index, d->attributesModel->setData(d->attributesModel->mapFromSource(index), QVariant::fromValue(va), KDChart::ValueTrackerAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -364,7 +364,7 @@ qreal LineDiagram::lineTension() const void LineDiagram::setLineTension(qreal tension) { d->tension = tension; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void LineDiagram::resizeEvent(QResizeEvent *) diff --git a/src/KDChart/Cartesian/KDChartPlotter.cpp b/src/KDChart/Cartesian/KDChartPlotter.cpp index 35147b9a..770b49e9 100644 --- a/src/KDChart/Cartesian/KDChartPlotter.cpp +++ b/src/KDChart/Cartesian/KDChartPlotter.cpp @@ -45,14 +45,14 @@ void Plotter::init() d->normalPlotter = new NormalPlotter(this); d->percentPlotter = new PercentPlotter(this); d->implementor = d->normalPlotter; - QObject *test = d->implementor->plotterPrivate(); - connect(this, SIGNAL(boundariesChanged()), test, SLOT(changedProperties())); - // The signal is connected to the superclass's slot at this point because the connection happened + Private *test = d->implementor->plotterPrivate(); + connect(this, &Plotter::boundariesChanged, test, &Private::changedProperties); + // The signal is connected to the superclass's AbstractDiagram slot at this point because the connection happened // in its constructor when "its type was not Plotter yet". - disconnect(this, SIGNAL(attributesModelAboutToChange(AttributesModel *, AttributesModel *)), - this, SLOT(connectAttributesModel(AttributesModel *))); - connect(this, SIGNAL(attributesModelAboutToChange(AttributesModel *, AttributesModel *)), - this, SLOT(connectAttributesModel(AttributesModel *))); + disconnect(this, &AbstractDiagram::attributesModelAboutToChange, + this, &Plotter::connectAttributesModel); + connect(this, &Plotter::attributesModelAboutToChange, + this, &Plotter::connectAttributesModel); setDatasetDimensionInternal(2); } @@ -95,12 +95,12 @@ void Plotter::connectAttributesModel(AttributesModel *newModel) d->compressor.setModel(nullptr); if (attributesModel() != d->plotterCompressor.model()) { d->plotterCompressor.setModel(attributesModel()); - connect(&d->plotterCompressor, SIGNAL(boundariesChanged()), this, SLOT(setDataBoundariesDirty())); + connect(&d->plotterCompressor, &PlotterDiagramCompressor::boundariesChanged, this, &Plotter::setDataBoundariesDirty); if (useDataCompression() != Plotter::SLOPE) { - connect(coordinatePlane(), SIGNAL(internal_geometryChanged(QRect, QRect)), - this, SLOT(setDataBoundariesDirty())); - connect(coordinatePlane(), SIGNAL(geometryChanged(QRect, QRect)), - this, SLOT(setDataBoundariesDirty())); + connect(coordinatePlane(), &AbstractCoordinatePlane::internal_geometryChanged, + this, &Plotter::setDataBoundariesDirty); + connect(coordinatePlane(), &AbstractCoordinatePlane::geometryChanged, + this, &Plotter::setDataBoundariesDirty); calcMergeRadius(); } } @@ -171,8 +171,8 @@ void Plotter::setType(const PlotType type) default: Q_ASSERT_X(false, "Plotter::setType", "unknown plotter subtype"); } - bool connection = connect(this, SIGNAL(boundariesChanged()), - d->implementor->plotterPrivate(), SLOT(changedProperties())); + bool connection = connect(this, &Plotter::boundariesChanged, + d->implementor->plotterPrivate(), &KDChart::Plotter::Private::changedProperties); Q_ASSERT(connection); Q_UNUSED(connection); @@ -180,8 +180,8 @@ void Plotter::setType(const PlotType type) Q_ASSERT(d->implementor->type() == type); setDataBoundariesDirty(); - emit layoutChanged(this); - emit propertiesChanged(); + Q_EMIT layoutChanged(this); + Q_EMIT propertiesChanged(); } /** @@ -198,7 +198,7 @@ Plotter::PlotType Plotter::type() const void Plotter::setLineAttributes(const LineAttributes &la) { d->attributesModel->setModelData(QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -207,7 +207,7 @@ void Plotter::setLineAttributes(const LineAttributes &la) void Plotter::setLineAttributes(int column, const LineAttributes &la) { d->setDatasetAttrs(column, QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -216,7 +216,7 @@ void Plotter::setLineAttributes(int column, const LineAttributes &la) void Plotter::resetLineAttributes(int column) { d->resetDatasetAttrs(column, LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -226,7 +226,7 @@ void Plotter::setLineAttributes(const QModelIndex &index, const LineAttributes & { d->attributesModel->setData(d->attributesModel->mapFromSource(index), QVariant::fromValue(la), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -236,7 +236,7 @@ void Plotter::resetLineAttributes(const QModelIndex &index) { d->attributesModel->resetData( d->attributesModel->mapFromSource(index), LineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -275,7 +275,7 @@ void Plotter::setThreeDLineAttributes(const ThreeDLineAttributes &la) { setDataBoundariesDirty(); d->attributesModel->setModelData(QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -285,7 +285,7 @@ void Plotter::setThreeDLineAttributes(int column, const ThreeDLineAttributes &la { setDataBoundariesDirty(); d->setDatasetAttrs(column, QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -296,7 +296,7 @@ void Plotter::setThreeDLineAttributes(const QModelIndex &index, const ThreeDLine setDataBoundariesDirty(); d->attributesModel->setData(d->attributesModel->mapFromSource(index), QVariant::fromValue(la), ThreeDLineAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -346,7 +346,7 @@ void Plotter::setValueTrackerAttributes(const QModelIndex &index, const ValueTra { d->attributesModel->setData(d->attributesModel->mapFromSource(index), QVariant::fromValue(va), KDChart::ValueTrackerAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** diff --git a/src/KDChart/Cartesian/KDChartPlotterDiagramCompressor.cpp b/src/KDChart/Cartesian/KDChartPlotterDiagramCompressor.cpp index 4f9cf832..1402a44a 100644 --- a/src/KDChart/Cartesian/KDChartPlotterDiagramCompressor.cpp +++ b/src/KDChart/Cartesian/KDChartPlotterDiagramCompressor.cpp @@ -523,7 +523,7 @@ bool PlotterDiagramCompressor::Private::inBoundaries(Qt::Orientation orient, con // } // } // setBoundaries( qMakePair( QPointF( minX, minY ), QPointF( maxX, maxY ) ) ); -// emit m_parent->rowCountChanged(); +// Q_EMIT m_parent->rowCountChanged(); //} #include // TODO this is not threadsafe do never try to invoke the painting in a different thread than this @@ -629,7 +629,7 @@ void PlotterDiagramCompressor::Private::rowsInserted(const QModelIndex & /*paren } } } - emit m_parent->rowCountChanged(); + Q_EMIT m_parent->rowCountChanged(); } void PlotterDiagramCompressor::setCompressionModel(CompressionMode value) @@ -638,7 +638,7 @@ void PlotterDiagramCompressor::setCompressionModel(CompressionMode value) if (d->m_mode != value) { d->m_mode = value; d->clearBuffer(); - emit rowCountChanged(); + Q_EMIT rowCountChanged(); } } @@ -646,7 +646,7 @@ void PlotterDiagramCompressor::Private::setBoundaries(const Boundaries &bound) { if (bound != m_boundary) { m_boundary = bound; - emit m_parent->boundariesChanged(); + Q_EMIT m_parent->boundariesChanged(); } } @@ -735,7 +735,7 @@ void PlotterDiagramCompressor::setForcedDataBoundaries(const QPair d->m_forcedXBoundaries = bounds; } d->clearBuffer(); - emit boundariesChanged(); + Q_EMIT boundariesChanged(); } QAbstractItemModel *PlotterDiagramCompressor::model() const @@ -756,9 +756,9 @@ void PlotterDiagramCompressor::setModel(QAbstractItemModel *model) d->m_bufferlist.resize(datasetCount()); d->m_accumulatedDistances.resize(datasetCount()); d->calculateDataBoundaries(); - connect(d->m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(rowsInserted(QModelIndex, int, int))); - connect(d->m_model, SIGNAL(modelReset()), d, SLOT(clearBuffer())); - connect(d->m_model, SIGNAL(destroyed(QObject *)), d, SLOT(setModelToZero())); + connect(d->m_model, &QAbstractItemModel::rowsInserted, d, &Private::rowsInserted); + connect(d->m_model, &QAbstractItemModel::modelReset, d, &Private::clearBuffer); + connect(d->m_model, &QAbstractItemModel::destroyed, d, &Private::setModelToZero); } } @@ -786,7 +786,7 @@ void PlotterDiagramCompressor::setMergeRadius(qreal radius) if (d->m_mergeRadius != radius) { d->m_mergeRadius = radius; if (d->m_mode != PlotterDiagramCompressor::SLOPE) - emit rowCountChanged(); + Q_EMIT rowCountChanged(); } } @@ -794,7 +794,7 @@ void PlotterDiagramCompressor::setMaxSlopeChange(qreal value) { if (d->m_maxSlopeRadius != value) { d->m_maxSlopeRadius = value; - emit boundariesChanged(); + Q_EMIT boundariesChanged(); } } diff --git a/src/KDChart/Cartesian/KDChartStockDiagram.cpp b/src/KDChart/Cartesian/KDChartStockDiagram.cpp index 009b69e8..f9b0e8a0 100644 --- a/src/KDChart/Cartesian/KDChartStockDiagram.cpp +++ b/src/KDChart/Cartesian/KDChartStockDiagram.cpp @@ -57,7 +57,7 @@ void StockDiagram::init() void StockDiagram::setType(Type type) { d->type = type; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -73,7 +73,7 @@ void StockDiagram::setStockBarAttributes(const StockBarAttributes &attr) attributesModel()->setModelData( QVariant::fromValue(attr), StockBarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } StockBarAttributes StockDiagram::stockBarAttributes() const @@ -84,7 +84,7 @@ StockBarAttributes StockDiagram::stockBarAttributes() const void StockDiagram::setStockBarAttributes(int column, const StockBarAttributes &attr) { d->setDatasetAttrs(column, QVariant::fromValue(attr), StockBarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } StockBarAttributes StockDiagram::stockBarAttributes(int column) const @@ -105,7 +105,7 @@ void StockDiagram::setThreeDBarAttributes(const ThreeDBarAttributes &attr) attributesModel()->setModelData( QVariant::fromValue(attr), ThreeDBarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** @@ -130,7 +130,7 @@ ThreeDBarAttributes StockDiagram::threeDBarAttributes() const void StockDiagram::setThreeDBarAttributes(int column, const ThreeDBarAttributes &attr) { d->setDatasetAttrs(column, QVariant::fromValue(attr), StockBarAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } /** diff --git a/src/KDChart/Cartesian/PaintingHelpers_p.cpp b/src/KDChart/Cartesian/PaintingHelpers_p.cpp index f499c282..70c72497 100644 --- a/src/KDChart/Cartesian/PaintingHelpers_p.cpp +++ b/src/KDChart/Cartesian/PaintingHelpers_p.cpp @@ -256,7 +256,7 @@ void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, QBrush curBrush; QPen curPen; QPolygonF points; - Q_FOREACH (const LineAttributesInfo &lineInfo, lineList) { + for (const LineAttributesInfo &lineInfo : lineList) { const QModelIndex &index = lineInfo.index; const ThreeDLineAttributes td = threeDLineAttributes(diagram, index); @@ -295,7 +295,7 @@ void paintElements(AbstractDiagram::Private *diagramPrivate, PaintContext *ctx, paintObject(diagramPrivate, ctx, curBrush, curPen, points); } - Q_FOREACH (const LineAttributesInfo &lineInfo, lineList) { + for (const LineAttributesInfo &lineInfo : lineList) { const ValueTrackerAttributes vt = valueTrackerAttributes(diagram, lineInfo.index); if (vt.isEnabled()) { PaintingHelpers::paintValueTracker(ctx, vt, lineInfo.nextValue); diff --git a/src/KDChart/KDChartAbstractArea.cpp b/src/KDChart/KDChartAbstractArea.cpp index 3335ef4f..fdf54f2b 100644 --- a/src/KDChart/KDChartAbstractArea.cpp +++ b/src/KDChart/KDChartAbstractArea.cpp @@ -137,5 +137,5 @@ QRect AbstractArea::areaGeometry() const void AbstractArea::positionHasChanged() { - emit positionChanged(this); + Q_EMIT positionChanged(this); } diff --git a/src/KDChart/KDChartAbstractAreaWidget.cpp b/src/KDChart/KDChartAbstractAreaWidget.cpp index 805c493b..f95b8a30 100644 --- a/src/KDChart/KDChartAbstractAreaWidget.cpp +++ b/src/KDChart/KDChartAbstractAreaWidget.cpp @@ -169,5 +169,5 @@ QRect AbstractAreaWidget::areaGeometry() const void AbstractAreaWidget::positionHasChanged() { - emit positionChanged(this); + Q_EMIT positionChanged(this); } diff --git a/src/KDChart/KDChartAbstractAxis.cpp b/src/KDChart/KDChartAbstractAxis.cpp index ce803a67..e16879a0 100644 --- a/src/KDChart/KDChartAbstractAxis.cpp +++ b/src/KDChart/KDChartAbstractAxis.cpp @@ -53,8 +53,8 @@ bool AbstractAxis::Private::setDiagram(AbstractDiagram *diagram_, bool delayedIn delete observer; if (mDiagram) { observer = new DiagramObserver(mDiagram, mAxis); - const bool con = connect(observer, SIGNAL(diagramDataChanged(AbstractDiagram *)), - mAxis, SIGNAL(coordinateSystemChanged())); + const bool con = connect(observer, &DiagramObserver::diagramDataChanged, + mAxis, &AbstractAxis::coordinateSystemChanged); Q_UNUSED(con) Q_ASSERT(con); bNewDiagramStored = true; @@ -101,7 +101,7 @@ AbstractAxis::AbstractAxis(AbstractDiagram *diagram) : AbstractArea(new Private(diagram, this)) { init(); - QTimer::singleShot(0, this, SLOT(delayedInit())); + QTimer::singleShot(0, this, &AbstractAxis::delayedInit); } AbstractAxis::~AbstractAxis() @@ -159,8 +159,8 @@ void AbstractAxis::deleteObserver(AbstractDiagram *diagram) void AbstractAxis::connectSignals() { if (d->observer) { - const bool con = connect(d->observer, SIGNAL(diagramDataChanged(AbstractDiagram *)), - this, SIGNAL(coordinateSystemChanged())); + const bool con = connect(d->observer, &DiagramObserver::diagramDataChanged, + this, &AbstractAxis::coordinateSystemChanged); Q_UNUSED(con); Q_ASSERT(con); } diff --git a/src/KDChart/KDChartAbstractCoordinatePlane.cpp b/src/KDChart/KDChartAbstractCoordinatePlane.cpp index 5fe5fc41..d38051fa 100644 --- a/src/KDChart/KDChartAbstractCoordinatePlane.cpp +++ b/src/KDChart/KDChartAbstractCoordinatePlane.cpp @@ -40,14 +40,14 @@ AbstractCoordinatePlane::AbstractCoordinatePlane(KDChart::Chart *parent) AbstractCoordinatePlane::~AbstractCoordinatePlane() { - emit destroyedCoordinatePlane(this); + Q_EMIT destroyedCoordinatePlane(this); } void AbstractCoordinatePlane::init() { d->initialize(); // virtual method to init the correct grid: cartesian, polar, ... - connect(this, SIGNAL(internal_geometryChanged(QRect, QRect)), - this, SIGNAL(geometryChanged(QRect, QRect)), + connect(this, &AbstractCoordinatePlane::internal_geometryChanged, + this, &AbstractCoordinatePlane::geometryChanged, Qt::QueuedConnection); } @@ -61,13 +61,13 @@ void AbstractCoordinatePlane::addDiagram(AbstractDiagram *diagram) diagram->setCoordinatePlane(this); layoutDiagrams(); layoutPlanes(); // there might be new axes, etc - connect(diagram, SIGNAL(modelsChanged()), this, SLOT(layoutPlanes())); - connect(diagram, SIGNAL(modelDataChanged()), this, SLOT(update())); - connect(diagram, SIGNAL(modelDataChanged()), this, SLOT(relayout())); - connect(this, SIGNAL(boundariesChanged()), diagram, SIGNAL(boundariesChanged())); + connect(diagram, &AbstractDiagram::modelsChanged, this, &AbstractCoordinatePlane::layoutPlanes); + connect(diagram, &AbstractDiagram::modelDataChanged, this, &AbstractCoordinatePlane::update); + connect(diagram, &AbstractDiagram::modelDataChanged, this, &AbstractCoordinatePlane::relayout); + connect(this, &AbstractCoordinatePlane::boundariesChanged, diagram, &AbstractDiagram::boundariesChanged); update(); - emit boundariesChanged(); + Q_EMIT boundariesChanged(); } /*virtual*/ @@ -99,9 +99,9 @@ void AbstractCoordinatePlane::takeDiagram(AbstractDiagram *diagram) d->diagrams.removeAt(idx); diagram->setParent(nullptr); diagram->setCoordinatePlane(nullptr); - disconnect(diagram, SIGNAL(modelsChanged()), this, SLOT(layoutPlanes())); - disconnect(diagram, SIGNAL(modelDataChanged()), this, SLOT(update())); - disconnect(diagram, SIGNAL(modelDataChanged()), this, SLOT(relayout())); + disconnect(diagram, &AbstractDiagram::modelsChanged, this, &AbstractCoordinatePlane::layoutPlanes); + disconnect(diagram, &AbstractDiagram::modelDataChanged, this, &AbstractCoordinatePlane::update); + disconnect(diagram, &AbstractDiagram::modelDataChanged, this, &AbstractCoordinatePlane::relayout); layoutDiagrams(); update(); } @@ -127,7 +127,7 @@ ConstAbstractDiagramList AbstractCoordinatePlane::diagrams() const #ifndef QT_NO_STL qCopy(d->diagrams.begin(), d->diagrams.end(), std::back_inserter(list)); #else - Q_FOREACH (AbstractDiagram *a, d->diagrams) + for (AbstractDiagram *a : d->diagrams) list.push_back(a); #endif return list; @@ -216,7 +216,7 @@ void KDChart::AbstractCoordinatePlane::setGeometry(const QRect &r) if (d->geometry != r) { // inform the outside word by Signal geometryChanged() // via a queued connection to internal_geometryChanged() - emit internal_geometryChanged(d->geometry, r); + Q_EMIT internal_geometryChanged(d->geometry, r); d->geometry = r; // Note: We do *not* call update() here @@ -232,19 +232,19 @@ QRect KDChart::AbstractCoordinatePlane::geometry() const void KDChart::AbstractCoordinatePlane::update() { // qDebug("KDChart::AbstractCoordinatePlane::update() called"); - emit needUpdate(); + Q_EMIT needUpdate(); } void KDChart::AbstractCoordinatePlane::relayout() { // qDebug("KDChart::AbstractCoordinatePlane::relayout() called"); - emit needRelayout(); + Q_EMIT needRelayout(); } void KDChart::AbstractCoordinatePlane::layoutPlanes() { // qDebug("KDChart::AbstractCoordinatePlane::relayout() called"); - emit needLayoutPlanes(); + Q_EMIT needLayoutPlanes(); } void KDChart::AbstractCoordinatePlane::setRubberBandZoomingEnabled(bool enable) @@ -268,7 +268,7 @@ void KDChart::AbstractCoordinatePlane::setCornerSpacersEnabled(bool enable) return; d->enableCornerSpacers = enable; - emit needRelayout(); + Q_EMIT needRelayout(); } bool KDChart::AbstractCoordinatePlane::isCornerSpacersEnabled() const @@ -305,7 +305,7 @@ void KDChart::AbstractCoordinatePlane::mousePressEvent(QMouseEvent *event) } } - Q_FOREACH (AbstractDiagram *a, d->diagrams) { + for (AbstractDiagram *a : qAsConst(d->diagrams)) { a->mousePressEvent(event); } } @@ -317,7 +317,7 @@ void KDChart::AbstractCoordinatePlane::mouseDoubleClickEvent(QMouseEvent *event) // which is pretty annoying when zooming out fast mousePressEvent(event); } - Q_FOREACH (AbstractDiagram *a, d->diagrams) { + for (AbstractDiagram *a : qAsConst(d->diagrams)) { a->mouseDoubleClickEvent(event); } } @@ -367,7 +367,7 @@ void KDChart::AbstractCoordinatePlane::mouseReleaseEvent(QMouseEvent *event) event->accept(); } - Q_FOREACH (AbstractDiagram *a, d->diagrams) { + for (AbstractDiagram *a : qAsConst(d->diagrams)) { a->mouseReleaseEvent(event); } } @@ -381,7 +381,7 @@ void KDChart::AbstractCoordinatePlane::mouseMoveEvent(QMouseEvent *event) event->accept(); } - Q_FOREACH (AbstractDiagram *a, d->diagrams) { + for (AbstractDiagram *a : qAsConst(d->diagrams)) { a->mouseMoveEvent(event); } } diff --git a/src/KDChart/KDChartAbstractDiagram.cpp b/src/KDChart/KDChartAbstractDiagram.cpp index a9263560..5d060db1 100644 --- a/src/KDChart/KDChartAbstractDiagram.cpp +++ b/src/KDChart/KDChartAbstractDiagram.cpp @@ -44,7 +44,7 @@ AbstractDiagram::AbstractDiagram(QWidget *parent, AbstractCoordinatePlane *plane AbstractDiagram::~AbstractDiagram() { - emit aboutToBeDestroyed(); + Q_EMIT aboutToBeDestroyed(); delete _d; } @@ -116,21 +116,21 @@ void AbstractDiagram::setModel(QAbstractItemModel *newModel) scheduleDelayedItemsLayout(); setDataBoundariesDirty(); - emit modelsChanged(); + Q_EMIT modelsChanged(); } void AbstractDiagram::setSelectionModel(QItemSelectionModel *newSelectionModel) { if (selectionModel()) { - disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SIGNAL(modelsChanged())); - disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SIGNAL(modelsChanged())); + disconnect(selectionModel(), &QItemSelectionModel::currentChanged, this, &AbstractDiagram::modelsChanged); + disconnect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &AbstractDiagram::modelsChanged); } QAbstractItemView::setSelectionModel(newSelectionModel); if (selectionModel()) { - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SIGNAL(modelsChanged())); - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SIGNAL(modelsChanged())); + connect(selectionModel(), &QItemSelectionModel::currentChanged, this, &AbstractDiagram::modelsChanged); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, this, &AbstractDiagram::modelsChanged); } - emit modelsChanged(); + Q_EMIT modelsChanged(); } /*! Sets an external AttributesModel on this diagram. By default, a diagram has it's @@ -157,7 +157,7 @@ void AbstractDiagram::setAttributesModel(AttributesModel *amodel) d->setAttributesModel(amodel); scheduleDelayedItemsLayout(); setDataBoundariesDirty(); - emit modelsChanged(); + Q_EMIT modelsChanged(); } bool AbstractDiagram::usesExternalAttributesModel() const @@ -231,19 +231,19 @@ void AbstractDiagram::setHidden(const QModelIndex &index, bool hidden) conditionallyMapFromSource(index), QVariant::fromValue(hidden), DataHiddenRole); - emit dataHidden(); + Q_EMIT dataHidden(); } void AbstractDiagram::setHidden(int dataset, bool hidden) { d->setDatasetAttrs(dataset, QVariant::fromValue(hidden), DataHiddenRole); - emit dataHidden(); + Q_EMIT dataHidden(); } void AbstractDiagram::setHidden(bool hidden) { d->attributesModel->setModelData(QVariant::fromValue(hidden), DataHiddenRole); - emit dataHidden(); + Q_EMIT dataHidden(); } bool AbstractDiagram::isHidden() const @@ -275,13 +275,13 @@ void AbstractDiagram::setDataValueAttributes(const QModelIndex &index, { d->attributesModel->setData(conditionallyMapFromSource(index), QVariant::fromValue(a), DataValueLabelAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setDataValueAttributes(int dataset, const DataValueAttributes &a) { d->setDatasetAttrs(dataset, QVariant::fromValue(a), DataValueLabelAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } DataValueAttributes AbstractDiagram::dataValueAttributes() const @@ -320,7 +320,7 @@ DataValueAttributes AbstractDiagram::dataValueAttributes(const QModelIndex &inde void AbstractDiagram::setDataValueAttributes(const DataValueAttributes &a) { d->attributesModel->setModelData(QVariant::fromValue(a), DataValueLabelAttributesRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setAllowOverlappingDataValueTexts(bool allow) @@ -329,7 +329,7 @@ void AbstractDiagram::setAllowOverlappingDataValueTexts(bool allow) attrs.setShowOverlappingDataLabels(allow); setDataValueAttributes(attrs); d->allowOverlappingDataValueTexts = allow; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool AbstractDiagram::allowOverlappingDataValueTexts() const @@ -340,7 +340,7 @@ bool AbstractDiagram::allowOverlappingDataValueTexts() const void AbstractDiagram::setAntiAliasing(bool enabled) { d->antiAliasing = enabled; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool AbstractDiagram::antiAliasing() const @@ -351,7 +351,7 @@ bool AbstractDiagram::antiAliasing() const void AbstractDiagram::setPercentMode(bool percent) { d->percent = percent; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool AbstractDiagram::percentMode() const @@ -603,20 +603,20 @@ void AbstractDiagram::setPen(const QModelIndex &index, const QPen &pen) attributesModel()->setData( conditionallyMapFromSource(index), QVariant::fromValue(pen), DatasetPenRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setPen(const QPen &pen) { attributesModel()->setModelData( QVariant::fromValue(pen), DatasetPenRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setPen(int dataset, const QPen &pen) { d->setDatasetAttrs(dataset, QVariant::fromValue(pen), DatasetPenRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } QPen AbstractDiagram::pen() const @@ -645,20 +645,20 @@ void AbstractDiagram::setBrush(const QModelIndex &index, const QBrush &brush) attributesModel()->setData( conditionallyMapFromSource(index), QVariant::fromValue(brush), DatasetBrushRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setBrush(const QBrush &brush) { attributesModel()->setModelData( QVariant::fromValue(brush), DatasetBrushRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void AbstractDiagram::setBrush(int dataset, const QBrush &brush) { d->setDatasetAttrs(dataset, QVariant::fromValue(brush), DatasetBrushRole); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } QBrush AbstractDiagram::brush() const @@ -803,7 +803,7 @@ void AbstractDiagram::setSelection(const QRect &rect, QItemSelectionModel::Selec { const QModelIndexList indexes = d->indexesIn(rect); QItemSelection selection; - Q_FOREACH (const QModelIndex &index, indexes) { + for (const QModelIndex &index : indexes) { selection.append(QItemSelectionRange(index)); } selectionModel()->select(selection, command); @@ -812,7 +812,8 @@ void AbstractDiagram::setSelection(const QRect &rect, QItemSelectionModel::Selec QRegion AbstractDiagram::visualRegionForSelection(const QItemSelection &selection) const { QPolygonF polygon; - Q_FOREACH (const QModelIndex &index, selection.indexes()) { + const auto constIndexes = selection.indexes(); + for (const QModelIndex &index : constIndexes) { polygon << d->reverseMapper.polygon(index.row(), index.column()); } return polygon.isEmpty() ? QRegion() : QRegion(polygon.toPolygon()); @@ -938,7 +939,7 @@ void AbstractDiagram::setDatasetDimensionInternal(int dimension) d->datasetDimension = dimension; d->attributesModel->setDatasetDimension(dimension); setDataBoundariesDirty(); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } qreal AbstractDiagram::valueForCell(int row, int column) const diff --git a/src/KDChart/KDChartAbstractDiagram_p.cpp b/src/KDChart/KDChartAbstractDiagram_p.cpp index b9a41891..a4bbaca6 100644 --- a/src/KDChart/KDChartAbstractDiagram_p.cpp +++ b/src/KDChart/KDChartAbstractDiagram_p.cpp @@ -96,39 +96,39 @@ void AbstractDiagram::Private::setAttributesModel(AttributesModel *amodel) if (qobject_cast(attributesModel)) { delete attributesModel; } else { - disconnect(attributesModel, SIGNAL(rowsInserted(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(columnsInserted(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(columnsRemoved(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(modelReset()), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(layoutChanged()), - diagram, SLOT(setDataBoundariesDirty())); - disconnect(attributesModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), - diagram, SIGNAL(modelDataChanged())); + disconnect(attributesModel, &AttributesModel::rowsInserted, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::columnsInserted, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::rowsRemoved, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::columnsRemoved, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::modelReset, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::layoutChanged, + diagram, &AbstractDiagram::setDataBoundariesDirty); + disconnect(attributesModel, &AttributesModel::dataChanged, + diagram, &AbstractDiagram::modelDataChanged); } } - emit diagram->attributesModelAboutToChange(amodel, attributesModel); - - connect(amodel, SIGNAL(rowsInserted(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(columnsInserted(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(rowsRemoved(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(columnsRemoved(QModelIndex, int, int)), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(modelReset()), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(layoutChanged()), - diagram, SLOT(setDataBoundariesDirty())); - connect(amodel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), - diagram, SIGNAL(modelDataChanged())); + Q_EMIT diagram->attributesModelAboutToChange(amodel, attributesModel); + + connect(amodel, &AttributesModel::rowsInserted, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::columnsInserted, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::rowsRemoved, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::columnsRemoved, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::modelReset, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::layoutChanged, + diagram, &AbstractDiagram::setDataBoundariesDirty); + connect(amodel, &AttributesModel::dataChanged, + diagram, &AbstractDiagram::modelDataChanged); attributesModel = amodel; } @@ -372,7 +372,7 @@ void AbstractDiagram::Private::paintDataValueTextsAndMarkers( ctx->painter()->setClipping(false); if (paintMarkers && !justCalculateRect) { - Q_FOREACH (const LabelPaintInfo &info, cache.paintReplay) { + for (const LabelPaintInfo &info : qAsConst(cache.paintReplay)) { diagram->paintMarker(ctx->painter(), info.index, info.markerPos); } } @@ -389,7 +389,7 @@ void AbstractDiagram::Private::paintDataValueTextsAndMarkers( forgetAlreadyPaintedDataValues(); - Q_FOREACH (const LabelPaintInfo &info, cache.paintReplay) { + for (const LabelPaintInfo &info : qAsConst(cache.paintReplay)) { const QPointF pos = info.labelArea.elementAt(0); paintDataValueText(ctx->painter(), info.attrs, pos, info.isValuePositive, info.value, justCalculateRect, cumulatedBoundingRect); diff --git a/src/KDChart/KDChartAttributesModel.cpp b/src/KDChart/KDChartAttributesModel.cpp index a3fe93c8..5e66ff81 100644 --- a/src/KDChart/KDChartAttributesModel.cpp +++ b/src/KDChart/KDChartAttributesModel.cpp @@ -366,7 +366,7 @@ bool AttributesModel::setData(const QModelIndex &index, const QVariant &value, i QMap> &colDataMap = d->dataMap[index.column()]; QMap &dataMap = colDataMap[index.row()]; dataMap.insert(role, value); - emit attributesChanged(index, index); + Q_EMIT attributesChanged(index, index); return true; } } @@ -394,18 +394,18 @@ bool AttributesModel::setHeaderData(int section, Qt::Orientation orientation, int numRows = rowCount(QModelIndex()); int numCols = columnCount(QModelIndex()); if (orientation == Qt::Horizontal && numRows > 0) - emit attributesChanged(index(0, section, QModelIndex()), - index(numRows - 1, section, QModelIndex())); + Q_EMIT attributesChanged(index(0, section, QModelIndex()), + index(numRows - 1, section, QModelIndex())); else if (orientation == Qt::Vertical && numCols > 0) - emit attributesChanged(index(section, 0, QModelIndex()), - index(section, numCols - 1, QModelIndex())); - emit headerDataChanged(orientation, section, section); + Q_EMIT attributesChanged(index(section, 0, QModelIndex()), + index(section, numCols - 1, QModelIndex())); + Q_EMIT headerDataChanged(orientation, section, section); // FIXME: This only makes sense for orientation == Qt::Horizontal, // but what if orientation == Qt::Vertical? if (section != -1 && numRows > 0) - emit dataChanged(index(0, section, QModelIndex()), - index(numRows - 1, section, QModelIndex())); + Q_EMIT dataChanged(index(0, section, QModelIndex()), + index(numRows - 1, section, QModelIndex())); } return true; } @@ -448,8 +448,8 @@ bool KDChart::AttributesModel::setModelData(const QVariant value, int role) int numRows = rowCount(QModelIndex()); int numCols = columnCount(QModelIndex()); if (sourceModel() && numRows > 0 && numCols > 0) { - emit attributesChanged(index(0, 0, QModelIndex()), - index(numRows - 1, numCols - 1, QModelIndex())); + Q_EMIT attributesChanged(index(0, 0, QModelIndex()), + index(numRows - 1, numCols - 1, QModelIndex())); beginResetModel(); endResetModel(); } @@ -479,56 +479,61 @@ int AttributesModel::columnCount(const QModelIndex &index) const } } -void AttributesModel::setSourceModel(QAbstractItemModel *sourceModel) -{ - if (this->sourceModel() != nullptr) { - disconnect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &))); - disconnect(this->sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(slotRowsInserted(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(slotRowsAboutToBeInserted(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsAboutToBeRemoved(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(slotColumnsInserted(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotColumnsRemoved(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(slotColumnsAboutToBeInserted(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(slotColumnsAboutToBeRemoved(const QModelIndex &, int, int))); - disconnect(this->sourceModel(), SIGNAL(modelReset()), - this, SIGNAL(modelReset())); - disconnect(this->sourceModel(), SIGNAL(layoutChanged()), - this, SIGNAL(layoutChanged())); - } - QAbstractProxyModel::setSourceModel(sourceModel); - if (this->sourceModel() != nullptr) { - connect(this->sourceModel(), SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &))); - connect(this->sourceModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(slotRowsInserted(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(slotRowsAboutToBeInserted(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(slotColumnsInserted(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotColumnsRemoved(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(slotColumnsAboutToBeInserted(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(slotColumnsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(this->sourceModel(), SIGNAL(modelReset()), - this, SIGNAL(modelReset())); - connect(this->sourceModel(), SIGNAL(layoutChanged()), - this, SIGNAL(layoutChanged())); +void AttributesModel::setSourceModel(QAbstractItemModel *newModel) +{ + QAbstractItemModel *oldModel = sourceModel(); + if (oldModel != nullptr) { + disconnect(oldModel, &QAbstractItemModel::dataChanged, + this, &AttributesModel::slotDataChanged); + disconnect(oldModel, &QAbstractItemModel::rowsInserted, + this, &AttributesModel::slotRowsInserted); + disconnect(oldModel, &QAbstractItemModel::rowsRemoved, + this, &AttributesModel::slotRowsRemoved); + disconnect(oldModel, &QAbstractItemModel::rowsAboutToBeInserted, + this, &AttributesModel::slotRowsAboutToBeInserted); + disconnect(oldModel, &QAbstractItemModel::rowsAboutToBeRemoved, + this, &AttributesModel::slotRowsAboutToBeRemoved); + disconnect(oldModel, &QAbstractItemModel::columnsInserted, + this, &AttributesModel::slotColumnsInserted); + disconnect(oldModel, &QAbstractItemModel::columnsRemoved, + this, &AttributesModel::slotColumnsRemoved); + disconnect(oldModel, &QAbstractItemModel::columnsAboutToBeInserted, + this, &AttributesModel::slotColumnsAboutToBeInserted); + disconnect(oldModel, &QAbstractItemModel::columnsAboutToBeRemoved, + this, &AttributesModel::slotColumnsAboutToBeRemoved); + disconnect(oldModel, &QAbstractItemModel::modelAboutToBeReset, + this, &AttributesModel::modelAboutToBeReset); + disconnect(oldModel, &QAbstractItemModel::modelReset, + this, &AttributesModel::modelReset); + disconnect(oldModel, &QAbstractItemModel::layoutChanged, + this, &AttributesModel::layoutChanged); + } + QAbstractProxyModel::setSourceModel(newModel); + if (newModel != nullptr) { + connect(newModel, &QAbstractItemModel::dataChanged, + this, &AttributesModel::slotDataChanged); + connect(newModel, &QAbstractItemModel::rowsInserted, + this, &AttributesModel::slotRowsInserted); + connect(newModel, &QAbstractItemModel::rowsRemoved, + this, &AttributesModel::slotRowsRemoved); + connect(newModel, &QAbstractItemModel::rowsAboutToBeInserted, + this, &AttributesModel::slotRowsAboutToBeInserted); + connect(newModel, &QAbstractItemModel::rowsAboutToBeRemoved, + this, &AttributesModel::slotRowsAboutToBeRemoved); + connect(newModel, &QAbstractItemModel::columnsInserted, + this, &AttributesModel::slotColumnsInserted); + connect(newModel, &QAbstractItemModel::columnsRemoved, + this, &AttributesModel::slotColumnsRemoved); + connect(newModel, &QAbstractItemModel::columnsAboutToBeInserted, + this, &AttributesModel::slotColumnsAboutToBeInserted); + connect(newModel, &QAbstractItemModel::columnsAboutToBeRemoved, + this, &AttributesModel::slotColumnsAboutToBeRemoved); + connect(newModel, &QAbstractItemModel::modelAboutToBeReset, + this, &AttributesModel::modelAboutToBeReset); + connect(newModel, &QAbstractItemModel::modelReset, + this, &AttributesModel::modelReset); + connect(newModel, &QAbstractItemModel::layoutChanged, + this, &AttributesModel::layoutChanged); } } @@ -640,7 +645,7 @@ void AttributesModel::slotColumnsRemoved(const QModelIndex &parent, int start, i void AttributesModel::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - emit dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight)); + Q_EMIT dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight)); } void AttributesModel::setDefaultForRole(int role, const QVariant &value) diff --git a/src/KDChart/KDChartChart.cpp b/src/KDChart/KDChartChart.cpp index e008a34b..0fe96eb5 100644 --- a/src/KDChart/KDChartChart.cpp +++ b/src/KDChart/KDChartChart.cpp @@ -270,7 +270,7 @@ void Chart::Private::slotUnregisterDestroyedHeaderFooter(HeaderFooter *hf) void Chart::Private::slotUnregisterDestroyedPlane(AbstractCoordinatePlane *plane) { coordinatePlanes.removeAll(plane); - Q_FOREACH (AbstractCoordinatePlane *p, coordinatePlanes) { + for (AbstractCoordinatePlane *p : qAsConst(coordinatePlanes)) { if (p->referenceCoordinatePlane() == plane) { p->setReferenceCoordinatePlane(nullptr); } @@ -328,8 +328,10 @@ static QVector getPrioritySortedConnectedComponents(QVector connectedComponents; QHash visitedComponents; - Q_FOREACH (LayoutGraphNode *node, nodeList) + for (LayoutGraphNode *node : qAsConst(nodeList)) { visitedComponents[node] = Unknown; + } + for (int i = 0; i < nodeList.size(); ++i) { LayoutGraphNode *curNode = nodeList[i]; LayoutGraphNode *representativeNode = curNode; @@ -380,7 +382,8 @@ void checkExistingAxes(LayoutGraphNode *node) if (node && node->diagramPlane && node->diagramPlane->diagram()) { auto *diag = qobject_cast(node->diagramPlane->diagram()); if (diag) { - Q_FOREACH (const CartesianAxis *axis, diag->axes()) { + const auto constAxes = diag->axes(); + for (const CartesianAxis *axis : constAxes) { switch (axis->position()) { case (CartesianAxis::Top): node->topAxesLayout = true; @@ -430,19 +433,24 @@ static CoordinatePlaneList findSharingAxisDiagrams(AbstractCoordinatePlane *plan return CoordinatePlaneList(); QList axes; - Q_FOREACH (CartesianAxis *axis, diagram->axes()) { - if ((type == Chart::Private::Ordinate && (axis->position() == CartesianAxis::Left || axis->position() == CartesianAxis::Right)) - || (type == Chart::Private::Abscissa && (axis->position() == CartesianAxis::Top || axis->position() == CartesianAxis::Bottom))) { - axes.append(axis); + { + const auto constAxes = diagram->axes(); + for (CartesianAxis *axis : constAxes) { + if ((type == Chart::Private::Ordinate && (axis->position() == CartesianAxis::Left || axis->position() == CartesianAxis::Right)) + || (type == Chart::Private::Abscissa && (axis->position() == CartesianAxis::Top || axis->position() == CartesianAxis::Bottom))) { + axes.append(axis); + } } } - Q_FOREACH (AbstractCoordinatePlane *curPlane, list) { + + for (AbstractCoordinatePlane *curPlane : list) { auto *diagram = qobject_cast(curPlane->diagram()); if (!diagram) continue; - Q_FOREACH (CartesianAxis *curSearchedAxis, axes) { - Q_FOREACH (CartesianAxis *curAxis, diagram->axes()) { + for (CartesianAxis *curSearchedAxis : axes) { + const auto constAxes = diagram->axes(); + for (CartesianAxis *curAxis : constAxes) { if (curSearchedAxis == curAxis) { result.append(curPlane); if (!sharedAxes->contains(curSearchedAxis)) @@ -466,7 +474,7 @@ QVector Chart::Private::buildPlaneLayoutGraph() QHash planeNodeMapping; QVector allNodes; // create all nodes and a mapping between plane and nodes - Q_FOREACH (AbstractCoordinatePlane *curPlane, coordinatePlanes) { + for (AbstractCoordinatePlane *curPlane : qAsConst(coordinatePlanes)) { if (curPlane->diagram()) { allNodes.append(new LayoutGraphNode); allNodes[allNodes.size() - 1]->diagramPlane = curPlane; @@ -476,7 +484,7 @@ QVector Chart::Private::buildPlaneLayoutGraph() } } // build the graph connections - Q_FOREACH (LayoutGraphNode *curNode, allNodes) { + for (LayoutGraphNode *curNode : qAsConst(allNodes)) { QVector sharedAxes; CoordinatePlaneList xSharedPlanes = findSharingAxisDiagrams(curNode->diagramPlane, coordinatePlanes, Abscissa, &sharedAxes); Q_ASSERT(sharedAxes.size() < 2); @@ -562,20 +570,22 @@ QHash Chart::Private::buildPlaneLayoutInfo * laid out vertically or horizontally next to each other. */ QHash axisInfos; QHash planeInfos; - Q_FOREACH (AbstractCoordinatePlane *plane, coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) { PlaneInfo p; // first check if we share space with another plane p.referencePlane = plane->referenceCoordinatePlane(); planeInfos.insert(plane, p); - Q_FOREACH (AbstractDiagram *abstractDiagram, plane->diagrams()) { + const auto constDiagrams = plane->diagrams(); + for (AbstractDiagram *abstractDiagram : constDiagrams) { auto *diagram = qobject_cast(abstractDiagram); if (!diagram) { continue; } - Q_FOREACH (CartesianAxis *axis, diagram->axes()) { + const auto constAxes = diagram->axes(); + for (CartesianAxis *axis : constAxes) { if (!axisInfos.contains(axis)) { /* If this is the first time we see this axis, add it, with the * current plane. The first plane added to the chart that has @@ -637,11 +647,11 @@ void Chart::Private::slotLayoutPlanes() if (hadPlanesLayout) planesLayout->getContentsMargins(&left, &top, &right, &bottom); - Q_FOREACH (AbstractLayoutItem *plane, planeLayoutItems) { + for (AbstractLayoutItem *plane : qAsConst(planeLayoutItems)) { plane->removeFromParentLayout(); } // TODO they should get a correct parent, but for now it works - Q_FOREACH (AbstractLayoutItem *plane, planeLayoutItems) { + for (AbstractLayoutItem *plane : qAsConst(planeLayoutItems)) { if (dynamic_cast(plane)) delete plane; } @@ -679,7 +689,8 @@ void Chart::Private::slotLayoutPlanes() col = 0; for (LayoutGraphNode *curColComponent = curRowComponent; curColComponent; curColComponent = curColComponent->leftSuccesor) { Q_ASSERT(curColComponent->diagramPlane->diagrams().size() == 1); - Q_FOREACH (AbstractDiagram *diagram, curColComponent->diagramPlane->diagrams()) { + const auto constDiagrams = curColComponent->diagramPlane->diagrams(); + for (AbstractDiagram *diagram : constDiagrams) { const int planeRowOffset = 1; // curColComponent->topAxesLayout ? 1 : 0; const int planeColOffset = 1; // curColComponent->leftAxesLayout ? 1 : 0; // qDebug() << Q_FUNC_INFO << row << col << planeRowOffset << planeColOffset; @@ -699,7 +710,8 @@ void Chart::Private::slotLayoutPlanes() curColComponent->sharedSuccesor->diagramPlane->setParentLayout(gridPlaneLayout); planeLayoutItems << curColComponent->sharedSuccesor->diagramPlane; } - Q_FOREACH (CartesianAxis *axis, cartDiag->axes()) { + const auto constAxes = cartDiag->axes(); + for (CartesianAxis *axis : constAxes) { if (axis->isAbscissa()) { if (curColComponent->bottomSuccesor) continue; @@ -802,7 +814,7 @@ void Chart::Private::slotLayoutPlanes() * gets their own. See buildPlaneLayoutInfos() for more details. */ QHash planeInfos = buildPlaneLayoutInfos(); QHash axisInfos; - Q_FOREACH (AbstractCoordinatePlane *plane, coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) { Q_ASSERT(planeInfos.contains(plane)); PlaneInfo &pi = planeInfos[plane]; const int column = pi.horizontalOffset; @@ -834,7 +846,8 @@ void Chart::Private::slotLayoutPlanes() // qDebug() << "Chart slotLayoutPlanes() calls planeLayout->addItem("<< row << column << ")"; planeLayout->setRowStretch(row, 2); planeLayout->setColumnStretch(column, 2); - Q_FOREACH (AbstractDiagram *abstractDiagram, plane->diagrams()) { + const auto constDiagrams = plane->diagrams(); + for (AbstractDiagram *abstractDiagram : constDiagrams) { auto *diagram = qobject_cast(abstractDiagram); if (!diagram) { @@ -878,7 +891,8 @@ void Chart::Private::slotLayoutPlanes() } // pi.leftAxesLayout->setSizeConstraint( QLayout::SetFixedSize ); - Q_FOREACH (CartesianAxis *axis, diagram->axes()) { + const auto constAxes = diagram->axes(); + for (CartesianAxis *axis : constAxes) { if (axisInfos.contains(axis)) { continue; // already laid out this one } @@ -1038,7 +1052,7 @@ void Chart::Private::slotResizePlanes() layout->activate(); } // Adapt diagram drawing to the new size - Q_FOREACH (AbstractCoordinatePlane *plane, coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(coordinatePlanes)) { plane->layoutDiagrams(); } } @@ -1046,7 +1060,7 @@ void Chart::Private::slotResizePlanes() void Chart::Private::updateDirtyLayouts() { if (isPlanesLayoutDirty) { - Q_FOREACH (AbstractCoordinatePlane *p, coordinatePlanes) { + for (AbstractCoordinatePlane *p : qAsConst(coordinatePlanes)) { p->setGridNeedsRecalculate(); p->layoutPlanes(); p->layoutDiagrams(); @@ -1083,13 +1097,13 @@ void Chart::Private::paintAll(QPainter *painter) chart->reLayoutFloatingLegends(); - Q_FOREACH (AbstractLayoutItem *planeLayoutItem, planeLayoutItems) { + for (AbstractLayoutItem *planeLayoutItem : qAsConst(planeLayoutItems)) { planeLayoutItem->paintAll(*painter); } - Q_FOREACH (TextArea *textLayoutItem, textLayoutItems) { + for (TextArea *textLayoutItem : qAsConst(textLayoutItems)) { textLayoutItem->paintAll(*painter); } - Q_FOREACH (Legend *legend, legends) { + for (Legend *legend : qAsConst(legends)) { const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); if (!hidden) { // qDebug() << "painting legend at " << legend->geometry(); @@ -1196,12 +1210,12 @@ void Chart::insertCoordinatePlane(int index, AbstractCoordinatePlane *plane) return; } - connect(plane, SIGNAL(destroyedCoordinatePlane(AbstractCoordinatePlane *)), - d, SLOT(slotUnregisterDestroyedPlane(AbstractCoordinatePlane *))); - connect(plane, SIGNAL(needUpdate()), this, SLOT(update())); - connect(plane, SIGNAL(needRelayout()), d, SLOT(slotResizePlanes())); - connect(plane, SIGNAL(needLayoutPlanes()), d, SLOT(slotLayoutPlanes())); - connect(plane, SIGNAL(propertiesChanged()), this, SIGNAL(propertiesChanged())); + connect(plane, &AbstractCoordinatePlane::destroyedCoordinatePlane, + d, &Private::slotUnregisterDestroyedPlane); + connect(plane, &AbstractCoordinatePlane::needUpdate, this, QOverload<>::of(&Chart::update)); + connect(plane, &AbstractCoordinatePlane::needRelayout, d, &Private::slotResizePlanes); + connect(plane, &AbstractCoordinatePlane::needLayoutPlanes, d, &Private::slotLayoutPlanes); + connect(plane, &AbstractCoordinatePlane::propertiesChanged, this, &Chart::propertiesChanged); d->coordinatePlanes.insert(index, plane); plane->setParent(this); d->slotLayoutPlanes(); @@ -1237,9 +1251,9 @@ void Chart::takeCoordinatePlane(AbstractCoordinatePlane *plane) d->mouseClickedPlanes.removeAll(plane); } d->slotLayoutPlanes(); - // Need to emit the signal: In case somebody has connected the signal + // Need to Q_EMIT the signal: In case somebody has connected the signal // to her own slot for e.g. calling update() on a widget containing the chart. - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void Chart::setGlobalLeading(int left, int top, int right, int bottom) @@ -1369,7 +1383,7 @@ void Chart::resizeEvent(QResizeEvent *event) void Chart::reLayoutFloatingLegends() { - Q_FOREACH (Legend *legend, d->legends) { + for (Legend *legend : qAsConst(d->legends)) { const bool hidden = legend->isHidden() && legend->testAttribute(Qt::WA_WState_ExplicitShowHide); if (legend->position().isFloating() && !hidden) { // resize the legend @@ -1402,7 +1416,7 @@ void Chart::paintEvent(QPaintEvent *) { QPainter painter(this); d->paintAll(&painter); - emit finishedDrawing(); + Q_EMIT finishedDrawing(); } void Chart::addHeaderFooter(HeaderFooter *hf) @@ -1418,10 +1432,10 @@ void Chart::addHeaderFooter(HeaderFooter *hf) d->headerFooters.append(hf); d->textLayoutItems.append(hf); - connect(hf, SIGNAL(destroyedHeaderFooter(HeaderFooter *)), - d, SLOT(slotUnregisterDestroyedHeaderFooter(HeaderFooter *))); - connect(hf, SIGNAL(positionChanged(HeaderFooter *)), - d, SLOT(slotHeaderFooterPositionChanged(HeaderFooter *))); + connect(hf, &HeaderFooter::destroyedHeaderFooter, + d, &Private::slotUnregisterDestroyedHeaderFooter); + connect(hf, &HeaderFooter::positionChanged, + d, &Private::slotHeaderFooterPositionChanged); // set the text attributes (why?) @@ -1468,8 +1482,8 @@ void Chart::takeHeaderFooter(HeaderFooter *headerFooter) if (idx == -1) { return; } - disconnect(headerFooter, SIGNAL(destroyedHeaderFooter(HeaderFooter *)), - d, SLOT(slotUnregisterDestroyedHeaderFooter(HeaderFooter *))); + disconnect(headerFooter, &HeaderFooter::destroyedHeaderFooter, + d, &Private::slotUnregisterDestroyedHeaderFooter); d->headerFooters.takeAt(idx); headerFooter->removeFromParentLayout(); @@ -1511,7 +1525,7 @@ void Chart::addLegend(Legend *legend) { legend->show(); addLegendInternal(legend, true); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void Chart::addLegendInternal(Legend *legend, bool setMeasures) @@ -1600,11 +1614,11 @@ void Chart::addLegendInternal(Legend *legend, bool setMeasures) sameAlignmentLayout->addItem(new MyWidgetItem(legend, legend->alignment())); } - connect(legend, SIGNAL(destroyedLegend(Legend *)), - d, SLOT(slotUnregisterDestroyedLegend(Legend *))); - connect(legend, SIGNAL(positionChanged(AbstractAreaWidget *)), - d, SLOT(slotLegendPositionChanged(AbstractAreaWidget *))); - connect(legend, SIGNAL(propertiesChanged()), this, SIGNAL(propertiesChanged())); + connect(legend, &Legend::destroyedLegend, + d, &Private::slotUnregisterDestroyedLegend); + connect(legend, &Legend::positionChanged, + d, &Private::slotLegendPositionChanged); + connect(legend, &Legend::propertiesChanged, this, &Chart::propertiesChanged); d->slotResizePlanes(); } @@ -1640,7 +1654,7 @@ void Chart::takeLegend(Legend *legend) legend->setParent(nullptr); d->slotResizePlanes(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } Legend *Chart::legend() @@ -1648,7 +1662,7 @@ Legend *Chart::legend() return d->legends.isEmpty() ? 0 : d->legends.first(); } -LegendList Chart::legends() +LegendList Chart::legends() const { return d->legends; } @@ -1657,7 +1671,7 @@ void Chart::mousePressEvent(QMouseEvent *event) { const QPoint pos = mapFromGlobal(event->globalPos()); - Q_FOREACH (AbstractCoordinatePlane *plane, d->coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) { if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) { QMouseEvent ev(QEvent::MouseButtonPress, pos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); @@ -1671,7 +1685,7 @@ void Chart::mouseDoubleClickEvent(QMouseEvent *event) { const QPoint pos = mapFromGlobal(event->globalPos()); - Q_FOREACH (AbstractCoordinatePlane *plane, d->coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) { if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) { QMouseEvent ev(QEvent::MouseButtonPress, pos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); @@ -1689,7 +1703,7 @@ void Chart::mouseMoveEvent(QMouseEvent *event) QSet::fromList(d->mouseClickedPlanes); #endif - Q_FOREACH (AbstractCoordinatePlane *plane, d->coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) { if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) { eventReceivers.insert(plane); } @@ -1697,7 +1711,7 @@ void Chart::mouseMoveEvent(QMouseEvent *event) const QPoint pos = mapFromGlobal(event->globalPos()); - Q_FOREACH (AbstractCoordinatePlane *plane, eventReceivers) { + for (AbstractCoordinatePlane *plane : qAsConst(eventReceivers)) { QMouseEvent ev(QEvent::MouseMove, pos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); plane->mouseMoveEvent(&ev); @@ -1713,7 +1727,7 @@ void Chart::mouseReleaseEvent(QMouseEvent *event) QSet::fromList(d->mouseClickedPlanes); #endif - Q_FOREACH (AbstractCoordinatePlane *plane, d->coordinatePlanes) { + for (AbstractCoordinatePlane *plane : qAsConst(d->coordinatePlanes)) { if (plane->geometry().contains(event->pos()) && plane->diagrams().size() > 0) { eventReceivers.insert(plane); } @@ -1721,7 +1735,7 @@ void Chart::mouseReleaseEvent(QMouseEvent *event) const QPoint pos = mapFromGlobal(event->globalPos()); - Q_FOREACH (AbstractCoordinatePlane *plane, eventReceivers) { + for (AbstractCoordinatePlane *plane : qAsConst(eventReceivers)) { QMouseEvent ev(QEvent::MouseButtonRelease, pos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); plane->mouseReleaseEvent(&ev); @@ -1735,8 +1749,9 @@ bool Chart::event(QEvent *event) if (event->type() == QEvent::ToolTip) { const QHelpEvent *const helpEvent = static_cast(event); for (int stage = 0; stage < 2; ++stage) { - Q_FOREACH (const AbstractCoordinatePlane *const plane, d->coordinatePlanes) { - Q_FOREACH (const AbstractDiagram *diagram, plane->diagrams()) { + for (const AbstractCoordinatePlane *const plane : qAsConst(d->coordinatePlanes)) { + const auto constDiagrams = plane->diagrams(); + for (const AbstractDiagram *diagram : constDiagrams) { QModelIndex index; if (stage == 0) { diff --git a/src/KDChart/KDChartChart.h b/src/KDChart/KDChartChart.h index 8b8bf0f9..ed95e90e 100644 --- a/src/KDChart/KDChartChart.h +++ b/src/KDChart/KDChartChart.h @@ -271,7 +271,7 @@ class KDCHART_EXPORT Chart : public QWidget * The list of all legends associated with the chart. * @return The list of all legends associated with the chart. */ - LegendList legends(); + LegendList legends() const; /** * Add the given legend to the chart. The chart takes ownership. diff --git a/src/KDChart/KDChartDatasetProxyModel.cpp b/src/KDChart/KDChartDatasetProxyModel.cpp index 1f0c9b06..3db94e25 100644 --- a/src/KDChart/KDChartDatasetProxyModel.cpp +++ b/src/KDChart/KDChartDatasetProxyModel.cpp @@ -252,15 +252,15 @@ void DatasetProxyModel::initializeDatasetDecriptors( void DatasetProxyModel::setSourceModel(QAbstractItemModel *m) { if (sourceModel()) { - disconnect(sourceModel(), SIGNAL(layoutChanged()), - this, SLOT(resetDatasetDescriptions())); + disconnect(sourceModel(), &QAbstractItemModel::layoutChanged, + this, &DatasetProxyModel::resetDatasetDescriptions); } QSortFilterProxyModel::setSourceModel(m); mRootIndex = QModelIndex(); if (m) { - connect(m, SIGNAL(layoutChanged()), - this, SLOT(resetDatasetDescriptions())); - connect(m, SIGNAL(layoutChanged()), this, SIGNAL(layoutChanged())); + connect(m, &QAbstractItemModel::layoutChanged, + this, &DatasetProxyModel::resetDatasetDescriptions); + connect(m, &QAbstractItemModel::layoutChanged, this, &DatasetProxyModel::layoutChanged); } resetDatasetDescriptions(); } diff --git a/src/KDChart/KDChartDatasetSelector.cpp b/src/KDChart/KDChartDatasetSelector.cpp index 2d9c0f97..2c5d6e28 100644 --- a/src/KDChart/KDChartDatasetSelector.cpp +++ b/src/KDChart/KDChartDatasetSelector.cpp @@ -68,7 +68,7 @@ void DatasetSelectorWidget::on_groupBox_toggled(bool state) if (state) { calculateMapping(); } else { - emit mappingDisabled(); + Q_EMIT mappingDisabled(); } } @@ -103,19 +103,19 @@ void DatasetSelectorWidget::resetDisplayValues() mUi->sbColumnCount->setMaximum(mSourceColumnCount); mUi->sbColumnCount->setValue(mSourceColumnCount); mUi->groupBox->setChecked(false); - emit mappingDisabled(); + Q_EMIT mappingDisabled(); } void DatasetSelectorWidget::calculateMapping() { if (mSourceColumnCount < 2 && mSourceRowCount < 2) { mUi->groupBox->setEnabled(false); - emit mappingDisabled(); + Q_EMIT mappingDisabled(); } else { mUi->groupBox->setEnabled(true); if (!mUi->groupBox->isChecked()) { - emit mappingDisabled(); + Q_EMIT mappingDisabled(); return; } @@ -161,6 +161,6 @@ void DatasetSelectorWidget::calculateMapping() } // and tell the world: - emit configureDatasetProxyModel(rowConfig, columnConfig); + Q_EMIT configureDatasetProxyModel(rowConfig, columnConfig); } } diff --git a/src/KDChart/KDChartDiagramObserver.cpp b/src/KDChart/KDChartDiagramObserver.cpp index 92dd527c..6b4a4a8b 100644 --- a/src/KDChart/KDChartDiagramObserver.cpp +++ b/src/KDChart/KDChartDiagramObserver.cpp @@ -23,9 +23,9 @@ DiagramObserver::DiagramObserver(AbstractDiagram *diagram, QObject *parent) , m_diagram(diagram) { if (m_diagram) { - connect(m_diagram, SIGNAL(destroyed(QObject *)), SLOT(slotDestroyed(QObject *))); - connect(m_diagram, SIGNAL(aboutToBeDestroyed()), SLOT(slotAboutToBeDestroyed())); - connect(m_diagram, SIGNAL(modelsChanged()), SLOT(slotModelsChanged())); + connect(m_diagram, &AbstractDiagram::destroyed, this, &DiagramObserver::slotDestroyed); + connect(m_diagram, &AbstractDiagram::aboutToBeDestroyed, this, &DiagramObserver::slotAboutToBeDestroyed); + connect(m_diagram, &AbstractDiagram::modelsChanged, this, &DiagramObserver::slotModelsChanged); } init(); } @@ -55,31 +55,32 @@ void DiagramObserver::init() if (m_attributesmodel) disconnect(m_attributesmodel); - const bool con = connect(m_diagram, SIGNAL(viewportCoordinateSystemChanged()), this, SLOT(slotDataChanged())); + const bool con = connect(m_diagram, &AbstractDiagram::viewportCoordinateSystemChanged, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); Q_ASSERT(con); Q_UNUSED(con) - connect(m_diagram, SIGNAL(dataHidden()), SLOT(slotDataHidden())); + connect(m_diagram, &AbstractDiagram::dataHidden, this, &DiagramObserver::slotDataHidden); if (m_diagram->model()) { - connect(m_diagram->model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), - SLOT(slotDataChanged(QModelIndex, QModelIndex))); - connect(m_diagram->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), - SLOT(slotDataChanged())); - connect(m_diagram->model(), SIGNAL(columnsInserted(QModelIndex, int, int)), - SLOT(slotDataChanged())); - connect(m_diagram->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), - SLOT(slotDataChanged())); - connect(m_diagram->model(), SIGNAL(columnsRemoved(QModelIndex, int, int)), - SLOT(slotDataChanged())); - connect(m_diagram->model(), SIGNAL(modelReset()), - SLOT(slotDataChanged())); - connect(m_diagram->model(), SIGNAL(headerDataChanged(Qt::Orientation, int, int)), - SLOT(slotHeaderDataChanged(Qt::Orientation, int, int))); + connect(m_diagram->model(), &QAbstractItemModel::dataChanged, + this, QOverload::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::rowsInserted, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::columnsInserted, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::rowsRemoved, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::columnsRemoved, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::modelReset, + this, QOverload<>::of(&DiagramObserver::slotDataChanged)); + connect(m_diagram->model(), &QAbstractItemModel::headerDataChanged, + this, &DiagramObserver::slotHeaderDataChanged); } if (m_diagram->attributesModel()) - connect(m_diagram->attributesModel(), SIGNAL(attributesChanged(QModelIndex, QModelIndex)), - SLOT(slotAttributesChanged(QModelIndex, QModelIndex))); + connect(m_diagram->attributesModel(), &AttributesModel::attributesChanged, + this, QOverload::of(&DiagramObserver::slotAttributesChanged)); m_model = m_diagram->model(); m_attributesmodel = m_diagram->attributesModel(); } @@ -87,16 +88,16 @@ void DiagramObserver::init() void DiagramObserver::slotDestroyed(QObject *) { // qDebug() << this << "emits signal\n" - // " emit diagramDestroyed(" << m_diagram << ")"; + // " Q_EMIT diagramDestroyed(" << m_diagram << ")"; AbstractDiagram *diag = m_diagram; disconnect(m_diagram, nullptr, this, nullptr); m_diagram = nullptr; - emit diagramDestroyed(diag); + Q_EMIT diagramDestroyed(diag); } void DiagramObserver::slotAboutToBeDestroyed() { - emit diagramAboutToBeDestroyed(m_diagram); + Q_EMIT diagramAboutToBeDestroyed(m_diagram); } void DiagramObserver::slotModelsChanged() @@ -109,7 +110,7 @@ void DiagramObserver::slotModelsChanged() void DiagramObserver::slotHeaderDataChanged(Qt::Orientation, int, int) { // qDebug() << "DiagramObserver::slotHeaderDataChanged()"; - emit diagramDataChanged(m_diagram); + Q_EMIT diagramDataChanged(m_diagram); } void DiagramObserver::slotDataChanged(QModelIndex, QModelIndex) @@ -120,13 +121,13 @@ void DiagramObserver::slotDataChanged(QModelIndex, QModelIndex) void DiagramObserver::slotDataChanged() { // qDebug() << "DiagramObserver::slotDataChanged()"; - emit diagramDataChanged(m_diagram); + Q_EMIT diagramDataChanged(m_diagram); } void DiagramObserver::slotDataHidden() { // qDebug() << "DiagramObserver::slotDataHidden()"; - emit diagramDataHidden(m_diagram); + Q_EMIT diagramDataHidden(m_diagram); } void DiagramObserver::slotAttributesChanged(QModelIndex, QModelIndex) @@ -137,5 +138,5 @@ void DiagramObserver::slotAttributesChanged(QModelIndex, QModelIndex) void DiagramObserver::slotAttributesChanged() { // qDebug() << "DiagramObserver::slotAttributesChanged()"; - emit diagramAttributesChanged(m_diagram); + Q_EMIT diagramAttributesChanged(m_diagram); } diff --git a/src/KDChart/KDChartHeaderFooter.cpp b/src/KDChart/KDChartHeaderFooter.cpp index 52471d34..5cb604f8 100644 --- a/src/KDChart/KDChartHeaderFooter.cpp +++ b/src/KDChart/KDChartHeaderFooter.cpp @@ -46,7 +46,7 @@ HeaderFooter::HeaderFooter(Chart *parent) HeaderFooter::~HeaderFooter() { - emit destroyedHeaderFooter(this); + Q_EMIT destroyedHeaderFooter(this); } void HeaderFooter::setParent(QObject *parent) @@ -98,7 +98,7 @@ void HeaderFooter::setType(HeaderFooterType type) { if (d->type != type) { d->type = type; - emit positionChanged(this); + Q_EMIT positionChanged(this); } } @@ -111,7 +111,7 @@ void HeaderFooter::setPosition(Position position) { if (d->position != position) { d->position = position; - emit positionChanged(this); + Q_EMIT positionChanged(this); } } diff --git a/src/KDChart/KDChartLegend.cpp b/src/KDChart/KDChartLegend.cpp index 12c53604..59356e07 100644 --- a/src/KDChart/KDChartLegend.cpp +++ b/src/KDChart/KDChartLegend.cpp @@ -74,7 +74,7 @@ Legend::Legend(AbstractDiagram *diagram, QWidget *parent) Legend::~Legend() { - emit destroyedLegend(this); + Q_EMIT destroyedLegend(this); } void Legend::init() @@ -125,7 +125,7 @@ QSize Legend::sizeHint() const #ifdef DEBUG_LEGEND_PAINT qDebug() << "Legend::sizeHint() started"; #endif - Q_FOREACH (AbstractLayoutItem *paintItem, d->paintItems) { + for (AbstractLayoutItem *paintItem : qAsConst(d->paintItems)) { paintItem->sizeHint(); } return AbstractAreaWidget::sizeHint(); @@ -212,7 +212,7 @@ void Legend::paint(QPainter *painter) activateTheLayout(); - Q_FOREACH (AbstractLayoutItem *paintItem, d->paintItems) { + for (AbstractLayoutItem *paintItem : qAsConst(d->paintItems)) { paintItem->paint(painter); } @@ -224,7 +224,7 @@ void Legend::paint(QPainter *painter) uint Legend::datasetCount() const { int modelLabelsCount = 0; - Q_FOREACH (DiagramObserver *observer, d->observers) { + for (DiagramObserver *observer : d->observers) { AbstractDiagram *diagram = observer->diagram(); Q_ASSERT(diagram->datasetLabels().count() == diagram->datasetBrushes().count()); modelLabelsCount += diagram->datasetLabels().count(); @@ -284,14 +284,10 @@ void Legend::addDiagram(AbstractDiagram *newDiagram) } else { d->observers.append(observer); } - connect(observer, SIGNAL(diagramAboutToBeDestroyed(AbstractDiagram *)), - SLOT(resetDiagram(AbstractDiagram *))); - connect(observer, SIGNAL(diagramDataChanged(AbstractDiagram *)), - SLOT(setNeedRebuild())); - connect(observer, SIGNAL(diagramDataHidden(AbstractDiagram *)), - SLOT(setNeedRebuild())); - connect(observer, SIGNAL(diagramAttributesChanged(AbstractDiagram *)), - SLOT(setNeedRebuild())); + connect(observer, &DiagramObserver::diagramAboutToBeDestroyed, this, &Legend::resetDiagram); + connect(observer, &DiagramObserver::diagramDataChanged, this, &Legend::setNeedRebuild); + connect(observer, &DiagramObserver::diagramDataHidden, this, &Legend::setNeedRebuild); + connect(observer, &DiagramObserver::diagramAttributesChanged, this, &Legend::setNeedRebuild); setNeedRebuild(); } } @@ -317,10 +313,13 @@ void Legend::removeDiagram(AbstractDiagram *oldDiagram) if (oldDiagram) { DiagramObserver *oldObs = d->findObserverForDiagram(oldDiagram); if (oldObs) { + d->observers.removeOne(oldObs); delete oldObs; - d->observers.removeAt(d->observers.indexOf(oldObs)); } - setNeedRebuild(); + + // We might be in the middle of a KDChart dctor and hit the assertObjectType + // so queue the rebuild + QMetaObject::invokeMethod(this, &Legend::setNeedRebuild, Qt::QueuedConnection); } } @@ -408,8 +407,8 @@ void Legend::setPosition(Position position) void Legend::emitPositionChanged() { - emit positionChanged(this); - emit propertiesChanged(); + Q_EMIT positionChanged(this); + Q_EMIT propertiesChanged(); } Position Legend::position() const @@ -776,7 +775,7 @@ void Legend::resizeEvent(QResizeEvent *event) #endif forceRebuild(); sizeHint(); - QTimer::singleShot(0, this, SLOT(emitPositionChanged())); + QTimer::singleShot(0, this, &Legend::emitPositionChanged); } void Legend::Private::fetchPaintOptions(Legend *q) @@ -1002,7 +1001,7 @@ void Legend::buildLegend() updateToplevelLayout(this); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); #ifdef DEBUG_LEGEND_PAINT qDebug() << "leaving Legend::buildLegend()"; #endif @@ -1135,7 +1134,7 @@ int Legend::heightForWidth(int width) const int currentLineWidth = 0; int currentLineHeight = 0; - Q_FOREACH (const HDatasetItem &hdsItem, d->hLayoutDatasets) { + for (const HDatasetItem &hdsItem : qAsConst(d->hLayoutDatasets)) { const int payloadWidth = hdsItem.markerLine->sizeHint().width() + hdsItem.label->sizeHint().width(); if (!currentLineWidth) { // first iteration diff --git a/src/KDChart/KDChartModelDataCache_p.cpp b/src/KDChart/KDChartModelDataCache_p.cpp index 02c84997..65d5c76a 100644 --- a/src/KDChart/KDChartModelDataCache_p.cpp +++ b/src/KDChart/KDChartModelDataCache_p.cpp @@ -26,26 +26,26 @@ ModelSignalMapperConnector::~ModelSignalMapperConnector() void ModelSignalMapperConnector::connectSignals(QAbstractItemModel *model) { - connect(model, SIGNAL(destroyed()), this, SLOT(resetModel())); - connect(model, SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(columnsInserted(QModelIndex, int, int))); - connect(model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(columnsRemoved(QModelIndex, int, int))); - connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(dataChanged(QModelIndex, QModelIndex))); - connect(model, SIGNAL(layoutChanged()), this, SLOT(layoutChanged())); - connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); - connect(model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(rowsInserted(QModelIndex, int, int))); - connect(model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); + connect(model, &QAbstractItemModel::destroyed, this, &ModelSignalMapperConnector::resetModel); + connect(model, &QAbstractItemModel::columnsInserted, this, &ModelSignalMapperConnector::columnsInserted); + connect(model, &QAbstractItemModel::columnsRemoved, this, &ModelSignalMapperConnector::columnsRemoved); + connect(model, &QAbstractItemModel::dataChanged, this, &ModelSignalMapperConnector::dataChanged); + connect(model, &QAbstractItemModel::layoutChanged, this, &ModelSignalMapperConnector::layoutChanged); + connect(model, &QAbstractItemModel::modelReset, this, &ModelSignalMapperConnector::modelReset); + connect(model, &QAbstractItemModel::rowsInserted, this, &ModelSignalMapperConnector::rowsInserted); + connect(model, &QAbstractItemModel::rowsRemoved, this, &ModelSignalMapperConnector::rowsRemoved); } void ModelSignalMapperConnector::disconnectSignals(QAbstractItemModel *model) { - disconnect(model, SIGNAL(destroyed()), this, SLOT(resetModel())); - disconnect(model, SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(columnsInserted(QModelIndex, int, int))); - disconnect(model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(columnsRemoved(QModelIndex, int, int))); - disconnect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(dataChanged(QModelIndex, QModelIndex))); - disconnect(model, SIGNAL(layoutChanged()), this, SLOT(layoutChanged())); - disconnect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); - disconnect(model, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(rowsInserted(QModelIndex, int, int))); - disconnect(model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(rowsRemoved(QModelIndex, int, int))); + disconnect(model, &QAbstractItemModel::destroyed, this, &ModelSignalMapperConnector::resetModel); + disconnect(model, &QAbstractItemModel::columnsInserted, this, &ModelSignalMapperConnector::columnsInserted); + disconnect(model, &QAbstractItemModel::columnsRemoved, this, &ModelSignalMapperConnector::columnsRemoved); + disconnect(model, &QAbstractItemModel::dataChanged, this, &ModelSignalMapperConnector::dataChanged); + disconnect(model, &QAbstractItemModel::layoutChanged, this, &ModelSignalMapperConnector::layoutChanged); + disconnect(model, &QAbstractItemModel::modelReset, this, &ModelSignalMapperConnector::modelReset); + disconnect(model, &QAbstractItemModel::rowsInserted, this, &ModelSignalMapperConnector::rowsInserted); + disconnect(model, &QAbstractItemModel::rowsRemoved, this, &ModelSignalMapperConnector::rowsRemoved); } void ModelSignalMapperConnector::resetModel() diff --git a/src/KDChart/KDChartPalette.cpp b/src/KDChart/KDChartPalette.cpp index 4a8bfbe6..9967bce6 100644 --- a/src/KDChart/KDChartPalette.cpp +++ b/src/KDChart/KDChartPalette.cpp @@ -160,7 +160,7 @@ void Palette::addBrush(const QBrush &brush, int position) } else { d->brushes.insert(position, brush); } - emit changed(); + Q_EMIT changed(); } QBrush Palette::getBrush(int position) const @@ -175,5 +175,5 @@ void Palette::removeBrush(int position) if (position < 0 || position >= size()) return; d->brushes.remove(position); - emit changed(); + Q_EMIT changed(); } diff --git a/src/KDChart/KDChartTextArea.cpp b/src/KDChart/KDChartTextArea.cpp index a3d3cfe9..d570278f 100644 --- a/src/KDChart/KDChartTextArea.cpp +++ b/src/KDChart/KDChartTextArea.cpp @@ -90,5 +90,5 @@ QRect TextArea::areaGeometry() const void TextArea::positionHasChanged() { - emit positionChanged(this); + Q_EMIT positionChanged(this); } diff --git a/src/KDChart/KDChartTextLabelCache.cpp b/src/KDChart/KDChartTextLabelCache.cpp index 099d5ba7..931603fa 100644 --- a/src/KDChart/KDChartTextLabelCache.cpp +++ b/src/KDChart/KDChartTextLabelCache.cpp @@ -245,17 +245,18 @@ void PrerenderedLabel::paint() const painter.setPen(QPen(Qt::red, 2)); painter.setBrush(Qt::red); // paint markers for the reference points - QList positions; - positions << KDChartEnums::PositionCenter - << KDChartEnums::PositionNorthWest - << KDChartEnums::PositionNorth - << KDChartEnums::PositionNorthEast - << KDChartEnums::PositionEast - << KDChartEnums::PositionSouthEast - << KDChartEnums::PositionSouth - << KDChartEnums::PositionSouthWest - << KDChartEnums::PositionWest; - Q_FOREACH (KDChartEnums::PositionValue position, positions) { // krazy:exclude=foreach + const QList positions = { + KDChartEnums::PositionCenter, + KDChartEnums::PositionNorthWest, + KDChartEnums::PositionNorth, + KDChartEnums::PositionNorthEast, + KDChartEnums::PositionEast, + KDChartEnums::PositionSouthEast, + KDChartEnums::PositionSouth, + KDChartEnums::PositionSouthWest, + KDChartEnums::PositionWest, + }; + for (KDChartEnums::PositionValue position : positions) { static const double Radius = 0.5; static const double Diameter = 2 * Radius; diff --git a/src/KDChart/KDChartWidget.cpp b/src/KDChart/KDChartWidget.cpp index 3214d677..6766d84e 100644 --- a/src/KDChart/KDChartWidget.cpp +++ b/src/KDChart/KDChartWidget.cpp @@ -431,13 +431,15 @@ void Widget::setType(ChartType chartType, SubType chartSubType) qobject_cast(coordinatePlane()->diagram()); auto *newDiag = qobject_cast(diag); - Q_FOREACH (CartesianAxis *axis, oldDiag->axes()) { + const auto constAxes = oldDiag->axes(); + for (CartesianAxis *axis : constAxes) { oldDiag->takeAxis(axis); newDiag->addAxis(axis); } } - Q_FOREACH (Legend *l, d->m_chart.legends()) { + const auto constLegends = d->m_chart.legends(); + for (Legend *l : constLegends) { l->setDiagram(diag); } diff --git a/src/KDChart/Polar/KDChartAbstractPieDiagram.cpp b/src/KDChart/Polar/KDChartAbstractPieDiagram.cpp index 6afdd39f..d113d551 100644 --- a/src/KDChart/Polar/KDChartAbstractPieDiagram.cpp +++ b/src/KDChart/Polar/KDChartAbstractPieDiagram.cpp @@ -103,19 +103,19 @@ bool AbstractPieDiagram::autoRotateLabels() const void AbstractPieDiagram::setPieAttributes(const PieAttributes &attrs) { d->attributesModel->setModelData(QVariant::fromValue(attrs), PieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } void AbstractPieDiagram::setPieAttributes(int column, const PieAttributes &attrs) { d->setDatasetAttrs(column, QVariant::fromValue(attrs), PieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } void AbstractPieDiagram::setPieAttributes(const QModelIndex &index, const PieAttributes &attrs) { d->attributesModel->setData(index, QVariant::fromValue(attrs), PieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } PieAttributes AbstractPieDiagram::pieAttributes() const @@ -142,19 +142,19 @@ PieAttributes AbstractPieDiagram::pieAttributes(const QModelIndex &index) const void AbstractPieDiagram::setThreeDPieAttributes(const ThreeDPieAttributes &tda) { d->attributesModel->setModelData(QVariant::fromValue(tda), ThreeDPieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } void AbstractPieDiagram::setThreeDPieAttributes(int column, const ThreeDPieAttributes &tda) { d->setDatasetAttrs(column, QVariant::fromValue(tda), ThreeDPieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } void AbstractPieDiagram::setThreeDPieAttributes(const QModelIndex &index, const ThreeDPieAttributes &tda) { model()->setData(index, QVariant::fromValue(tda), ThreeDPieAttributesRole); - emit layoutChanged(this); + Q_EMIT layoutChanged(this); } ThreeDPieAttributes AbstractPieDiagram::threeDPieAttributes() const diff --git a/src/KDChart/Polar/KDChartPieDiagram.cpp b/src/KDChart/Polar/KDChartPieDiagram.cpp index f64b4c05..78b54e3c 100644 --- a/src/KDChart/Polar/KDChartPieDiagram.cpp +++ b/src/KDChart/Polar/KDChartPieDiagram.cpp @@ -489,7 +489,7 @@ void PieDiagram::paintInternal(PaintContext *paintContext) const QPointF center = paintContext->rectangle().center(); const PainterSaver painterSaver(paintContext->painter()); paintContext->painter()->setBrush(Qt::NoBrush); - Q_FOREACH (const LabelPaintInfo &pi, d->labelPaintCache.paintReplay) { + for (const LabelPaintInfo &pi : qAsConst(d->labelPaintCache.paintReplay)) { // we expect the PainterPath to be a rectangle if (pi.labelArea.elementCount() != 5) { continue; diff --git a/src/KDChart/Polar/KDChartPolarCoordinatePlane.cpp b/src/KDChart/Polar/KDChartPolarCoordinatePlane.cpp index 72c58d69..b834a24a 100644 --- a/src/KDChart/Polar/KDChartPolarCoordinatePlane.cpp +++ b/src/KDChart/Polar/KDChartPolarCoordinatePlane.cpp @@ -54,8 +54,7 @@ void PolarCoordinatePlane::addDiagram(AbstractDiagram *diagram) "PolarCoordinatePlane::addDiagram", "Only polar" "diagrams can be added to a polar coordinate plane!"); AbstractCoordinatePlane::addDiagram(diagram); - connect(diagram, SIGNAL(layoutChanged(AbstractDiagram *)), - SLOT(slotLayoutChanged(AbstractDiagram *))); + connect(diagram, &AbstractDiagram::layoutChanged, this, &PolarCoordinatePlane::slotLayoutChanged); } void PolarCoordinatePlane::paint(QPainter *painter) @@ -148,7 +147,8 @@ void PolarCoordinatePlane::layoutDiagrams() // FIXME distribute space according to options: const qreal oldStartPosition = startPosition(); d->coordinateTransformations.clear(); - Q_FOREACH (AbstractDiagram *diagram, diagrams()) { + const auto constDiagrams = diagrams(); + for (AbstractDiagram *diagram : constDiagrams) { auto *polarDiagram = dynamic_cast(diagram); Q_ASSERT(polarDiagram); QPair dataBoundariesPair = polarDiagram->dataBoundaries(); @@ -307,7 +307,7 @@ void KDChart::PolarCoordinatePlane::setGridAttributes( d->gridAttributesSagittal = a; setHasOwnGridAttributes(circular, true); update(); - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } void KDChart::PolarCoordinatePlane::resetGridAttributes( @@ -349,7 +349,7 @@ void KDChart::PolarCoordinatePlane::setHasOwnGridAttributes( d->hasOwnGridAttributesCircular = on; else d->hasOwnGridAttributesSagittal = on; - emit propertiesChanged(); + Q_EMIT propertiesChanged(); } bool KDChart::PolarCoordinatePlane::hasOwnGridAttributes( diff --git a/src/KDChart/Polar/KDChartRadarDiagram.cpp b/src/KDChart/Polar/KDChartRadarDiagram.cpp index 2aca9786..62c33568 100644 --- a/src/KDChart/Polar/KDChartRadarDiagram.cpp +++ b/src/KDChart/Polar/KDChartRadarDiagram.cpp @@ -250,7 +250,7 @@ void RadarDiagram::paint(PaintContext *ctx, // first fill the areas with the brush-color and the defined alpha-value. if (d->fillAlpha > 0.0) { - Q_FOREACH (const Polygon &p, polygons) { + for (const Polygon &p : polygons) { PainterSaver painterSaver(ctx->painter()); ctx->painter()->setRenderHint(QPainter::Antialiasing); QBrush br = p.brush; @@ -264,7 +264,7 @@ void RadarDiagram::paint(PaintContext *ctx, } // then draw the poly-lines. - Q_FOREACH (const Polygon &p, polygons) { + for (const Polygon &p : polygons) { PainterSaver painterSaver(ctx->painter()); ctx->painter()->setRenderHint(QPainter::Antialiasing); ctx->painter()->setBrush(p.brush); diff --git a/src/KDChart/ReverseMapper.cpp b/src/KDChart/ReverseMapper.cpp index 78456902..2553f6f9 100644 --- a/src/KDChart/ReverseMapper.cpp +++ b/src/KDChart/ReverseMapper.cpp @@ -54,9 +54,9 @@ QModelIndexList ReverseMapper::indexesIn(const QRect &rect) const { Q_ASSERT(m_diagram); if (m_scene && m_scene->sceneRect().intersects(rect)) { - QList items = m_scene->items(rect); + const QList items = m_scene->items(rect); QModelIndexList indexes; - Q_FOREACH (QGraphicsItem *item, items) { + for (QGraphicsItem *item : items) { auto *i = qgraphicsitem_cast(item); if (i) { QModelIndex index(m_diagram->model()->index(i->row(), i->column(), m_diagram->rootIndex())); // checked @@ -73,9 +73,9 @@ QModelIndexList ReverseMapper::indexesAt(const QPointF &point) const { Q_ASSERT(m_diagram); if (m_scene && m_scene->sceneRect().contains(point)) { - QList items = m_scene->items(point); + const QList items = m_scene->items(point); QModelIndexList indexes; - Q_FOREACH (QGraphicsItem *item, items) { + for (QGraphicsItem *item : items) { auto *i = qgraphicsitem_cast(item); if (i) { QModelIndex index(m_diagram->model()->index(i->row(), i->column(), m_diagram->rootIndex())); // checked diff --git a/src/KDChart/Ternary/KDChartTernaryAxis.cpp b/src/KDChart/Ternary/KDChartTernaryAxis.cpp index 44020601..329e7556 100644 --- a/src/KDChart/Ternary/KDChartTernaryAxis.cpp +++ b/src/KDChart/Ternary/KDChartTernaryAxis.cpp @@ -66,9 +66,11 @@ void TernaryAxis::paintCtx(PaintContext *paintContext) // QObject* refArea = plane->parent(); // paint the axis label (across the triangle, that one): - QList labels; - labels << m_label << m_fifty; - Q_FOREACH (PrerenderedLabel *label, labels) { + const QList labels = { + m_label, + m_fifty, + }; + for (PrerenderedLabel *label : labels) { const QPixmap &pixmap = label->pixmap(); QPointF point = plane->translate(label->position()) - label->referencePointLocation(); diff --git a/src/KDChart/Ternary/KDChartTernaryCoordinatePlane.cpp b/src/KDChart/Ternary/KDChartTernaryCoordinatePlane.cpp index 4a895d58..2386f9eb 100644 --- a/src/KDChart/Ternary/KDChartTernaryCoordinatePlane.cpp +++ b/src/KDChart/Ternary/KDChartTernaryCoordinatePlane.cpp @@ -67,11 +67,13 @@ void TernaryCoordinatePlane::layoutDiagrams() { QSizeF topleft(0.0, 0.0); QSizeF bottomRight(0.0, 0.0); - Q_FOREACH (AbstractDiagram *abstractDiagram, diagrams()) { + const auto constDiagrams = diagrams(); + for (AbstractDiagram *abstractDiagram : constDiagrams) { auto *diagram = qobject_cast(abstractDiagram); Q_ASSERT(diagram); - Q_FOREACH (TernaryAxis *axis, diagram->axes()) { + const auto constAxes = diagram->axes(); + for (TernaryAxis *axis : constAxes) { QPair margin = axis->requiredMargins(); topleft = topleft.expandedTo(margin.first); bottomRight = bottomRight.expandedTo(margin.second); diff --git a/src/KDChart/Ternary/KDChartTernaryGrid.cpp b/src/KDChart/Ternary/KDChartTernaryGrid.cpp index e2d8c1b5..0ba849e2 100644 --- a/src/KDChart/Ternary/KDChartTernaryGrid.cpp +++ b/src/KDChart/Ternary/KDChartTernaryGrid.cpp @@ -80,7 +80,7 @@ void TernaryGrid::drawGrid(PaintContext *context) QVector lines[MaxDepth]; { - Q_FOREACH (const TickInfo &tick, m_tickInfo) { + for (const TickInfo &tick : qAsConst(m_tickInfo)) { const qreal &percent = tick.percentage; { // draw parallels to B TernaryPoint ternaryStart(percent, 1.0 - percent); @@ -150,7 +150,7 @@ void TernaryGrid::drawGrid(PaintContext *context) percentages.end()); { - Q_FOREACH (const TickInfo &tick, percentages) { + for (const TickInfo &tick : percentages) { const qreal &percent = tick.percentage; { // BC axis markers: const QPointF markerDistance(FullMarkerDistanceBC diff --git a/src/KDGantt/kdganttconstraintmodel.cpp b/src/KDGantt/kdganttconstraintmodel.cpp index 25644401..a1b8d128 100644 --- a/src/KDGantt/kdganttconstraintmodel.cpp +++ b/src/KDGantt/kdganttconstraintmodel.cpp @@ -116,14 +116,14 @@ void ConstraintModel::addConstraint(const Constraint &c) d->constraints.push_back(c); d->addConstraintToIndex(c.startIndex(), c); d->addConstraintToIndex(c.endIndex(), c); - emit constraintAdded(c); + Q_EMIT constraintAdded(c); } else if ((*it).dataMap() != c.dataMap()) { Constraint tmp(*it); // save to avoid re-entrancy issues removeConstraint(tmp); d->constraints.push_back(c); d->addConstraintToIndex(c.startIndex(), c); d->addConstraintToIndex(c.endIndex(), c); - emit constraintAdded(c); + Q_EMIT constraintAdded(c); } } @@ -148,7 +148,7 @@ bool ConstraintModel::removeConstraint(const Constraint &c) if (rc) { d->removeConstraintFromIndex(c.startIndex(), c); d->removeConstraintFromIndex(c.endIndex(), c); - emit constraintRemoved(c); + Q_EMIT constraintRemoved(c); } return rc; @@ -160,8 +160,8 @@ bool ConstraintModel::removeConstraint(const Constraint &c) */ void ConstraintModel::clear() { - QList lst = constraints(); - Q_FOREACH (const Constraint &c, lst) { + const QList lst = constraints(); + for (const Constraint &c : lst) { removeConstraint(c); } } @@ -171,7 +171,7 @@ void ConstraintModel::cleanup() { #if 0 QSet orphans; - Q_FOREACH( const Constraint& c, d->constraints ) { + for (const Constraint& c, qAsConst(d->constraints)) { if ( !c.startIndex().isValid() || !c.endIndex().isValid() ) orphans.insert( c ); } //qDebug() << "Constraint::cleanup() found" << orphans << "orphans"; @@ -198,14 +198,14 @@ QList ConstraintModel::constraintsForIndex(const QModelIndex &idx) c if (!idx.isValid()) { // Because of a Qt bug we need to treat this as a special case QSet result; - Q_FOREACH (const Constraint &c, d->constraints) { + for (const Constraint &c : d->constraints) { if (!c.startIndex().isValid() || !c.endIndex().isValid()) result.insert(c); } return result.values(); } else { QList result; - Q_FOREACH (const Constraint &c, d->constraints) { + for (const Constraint &c : d->constraints) { if (c.startIndex() == idx || c.endIndex() == idx) result.push_back(c); } @@ -222,7 +222,8 @@ bool ConstraintModel::hasConstraint(const Constraint &c) const { /* // Because of a Qt bug we have to search like this - Q_FOREACH( Constraint c2, d->constraints ) { + const auto constraints = model.constraints(); + for ( Constraint c2 : constraints ) { if ( c==c2 ) return true; } return false; @@ -241,7 +242,8 @@ bool ConstraintModel::hasConstraint(const Constraint &c) const QDebug operator<<(QDebug dbg, const KDGantt::ConstraintModel &model) { dbg << "KDGantt::ConstraintModel[ " << static_cast(&model) << ": [\n"; - Q_FOREACH (const Constraint &c, model.constraints()) { + const auto constraints = model.constraints(); + for (const Constraint &c : constraints) { dbg << "\t" << c << "\n"; } dbg << "]\n"; diff --git a/src/KDGantt/kdganttconstraintproxy.cpp b/src/KDGantt/kdganttconstraintproxy.cpp index db3eba39..142b8dea 100644 --- a/src/KDGantt/kdganttconstraintproxy.cpp +++ b/src/KDGantt/kdganttconstraintproxy.cpp @@ -36,10 +36,10 @@ void ConstraintProxy::setSourceModel(ConstraintModel *src) copyFromSource(); - connect(m_source, SIGNAL(constraintAdded(const KDGantt::Constraint &)), - this, SLOT(slotSourceConstraintAdded(const KDGantt::Constraint &))); - connect(m_source, SIGNAL(constraintRemoved(const KDGantt::Constraint &)), - this, SLOT(slotSourceConstraintRemoved(const KDGantt::Constraint &))); + connect(m_source, &ConstraintModel::constraintAdded, + this, &ConstraintProxy::slotSourceConstraintAdded); + connect(m_source, &ConstraintModel::constraintRemoved, + this, &ConstraintProxy::slotSourceConstraintRemoved); } void ConstraintProxy::setDestinationModel(ConstraintModel *dest) @@ -50,10 +50,10 @@ void ConstraintProxy::setDestinationModel(ConstraintModel *dest) copyFromSource(); - connect(m_destination, SIGNAL(constraintAdded(const KDGantt::Constraint &)), - this, SLOT(slotDestinationConstraintAdded(const KDGantt::Constraint &))); - connect(m_destination, SIGNAL(constraintRemoved(const KDGantt::Constraint &)), - this, SLOT(slotDestinationConstraintRemoved(const KDGantt::Constraint &))); + connect(m_destination, &ConstraintModel::constraintAdded, + this, &ConstraintProxy::slotDestinationConstraintAdded); + connect(m_destination, &ConstraintModel::constraintRemoved, + this, &ConstraintProxy::slotDestinationConstraintRemoved); } void ConstraintProxy::setProxyModel(QAbstractProxyModel *proxy) @@ -64,8 +64,8 @@ void ConstraintProxy::setProxyModel(QAbstractProxyModel *proxy) m_proxy->disconnect(this); m_proxy = proxy; if (m_proxy) { - connect(m_proxy, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged())); - connect(m_proxy, SIGNAL(modelReset()), this, SLOT(slotLayoutChanged())); + connect(m_proxy, &QAbstractProxyModel::layoutChanged, this, &ConstraintProxy::slotLayoutChanged); + connect(m_proxy, &QAbstractProxyModel::modelReset, this, &ConstraintProxy::slotLayoutChanged); } } @@ -89,7 +89,7 @@ void ConstraintProxy::copyFromSource() if (!m_source) return; const QList lst = m_source->constraints(); - Q_FOREACH (const Constraint &c, lst) { + for (const Constraint &c : lst) { Constraint temp(m_proxy->mapFromSource(c.startIndex()), m_proxy->mapFromSource(c.endIndex()), c.type(), c.relationType(), c.dataMap()); m_destination->addConstraint(temp); diff --git a/src/KDGantt/kdganttdatetimegrid.cpp b/src/KDGantt/kdganttdatetimegrid.cpp index 83d0acf2..050a8587 100644 --- a/src/KDGantt/kdganttdatetimegrid.cpp +++ b/src/KDGantt/kdganttdatetimegrid.cpp @@ -311,7 +311,7 @@ QDateTime DateTimeGrid::startDateTime() const void DateTimeGrid::setStartDateTime(const QDateTime &dt) { d->startDateTime = dt; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \returns The width in pixels for each day in the grid. @@ -345,7 +345,7 @@ void DateTimeGrid::setDayWidth(qreal w) { assert(w > 0); d->dayWidth = w; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \param s The scale to be used to paint the grid. @@ -365,7 +365,7 @@ void DateTimeGrid::setDayWidth(qreal w) void DateTimeGrid::setScale(Scale s) { d->scale = s; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \returns The scale used to paint the grid. @@ -390,7 +390,7 @@ void DateTimeGrid::setUserDefinedLowerScale(DateTimeScaleFormatter *lower) { delete d->lower; d->lower = lower; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! Sets the scale formatter for the upper part of the header to the @@ -404,7 +404,7 @@ void DateTimeGrid::setUserDefinedUpperScale(DateTimeScaleFormatter *upper) { delete d->upper; d->upper = upper; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \return The DateTimeScaleFormatter being used to render the lower scale. @@ -429,7 +429,7 @@ DateTimeScaleFormatter *DateTimeGrid::userDefinedUpperScale() const void DateTimeGrid::setWeekStart(Qt::DayOfWeek ws) { d->weekStart = ws; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \returns The start day of the week */ @@ -447,7 +447,7 @@ Qt::DayOfWeek DateTimeGrid::weekStart() const void DateTimeGrid::setFreeDays(const QSet &fd) { d->freeDays = fd; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \returns The days marked as free in the grid. */ @@ -489,7 +489,7 @@ void DateTimeGrid::setRowSeparators(bool enable) void DateTimeGrid::setNoInformationBrush(const QBrush &brush) { d->noInformationBrush = brush; - emit gridChanged(); + Q_EMIT gridChanged(); } /*! \returns the brush used to mark rows with no information. @@ -590,7 +590,7 @@ bool DateTimeGrid::mapFromChart(const Span &span, const QModelIndex &idx, QDateTime st = d->chartXtoDateTime(span.start()); QDateTime et = d->chartXtoDateTime(span.start() + span.length()); // qDebug() << "DateTimeGrid::mapFromChart("< "<< st << et; - Q_FOREACH (const Constraint &c, constraints) { + for (const Constraint &c : constraints) { if (c.type() != Constraint::TypeHard || !isSatisfiedConstraint(c)) continue; if (c.startIndex() == idx) { diff --git a/src/KDGantt/kdganttforwardingproxymodel.cpp b/src/KDGantt/kdganttforwardingproxymodel.cpp index c40b41b2..685e5e8d 100644 --- a/src/KDGantt/kdganttforwardingproxymodel.cpp +++ b/src/KDGantt/kdganttforwardingproxymodel.cpp @@ -88,31 +88,31 @@ void ForwardingProxyModel::setSourceModel(QAbstractItemModel *model) if (!model) return; - connect(model, SIGNAL(modelAboutToBeReset()), this, SLOT(sourceModelAboutToBeReset())); - connect(model, SIGNAL(modelReset()), this, SLOT(sourceModelReset())); - connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(sourceLayoutAboutToBeChanged())); - connect(model, SIGNAL(layoutChanged()), this, SLOT(sourceLayoutChanged())); - - connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(sourceDataChanged(const QModelIndex &, const QModelIndex &))); - - connect(model, SIGNAL(columnsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(sourceColumnsAboutToBeInserted(const QModelIndex &, int, int))); - connect(model, SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceColumnsInserted(const QModelIndex &, int, int))); - connect(model, SIGNAL(columnsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceColumnsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(model, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceColumnsRemoved(const QModelIndex &, int, int))); - - connect(model, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsAboutToBeInserted(const QModelIndex &, int, int))); - connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(sourceRowsInserted(const QModelIndex &, int, int))); - connect(model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(sourceRowsRemoved(const QModelIndex &, int, int))); + connect(model, &QAbstractItemModel::modelAboutToBeReset, this, &ForwardingProxyModel::sourceModelAboutToBeReset); + connect(model, &QAbstractItemModel::modelReset, this, &ForwardingProxyModel::sourceModelReset); + connect(model, &QAbstractItemModel::layoutAboutToBeChanged, this, &ForwardingProxyModel::sourceLayoutAboutToBeChanged); + connect(model, &QAbstractItemModel::layoutChanged, this, &ForwardingProxyModel::sourceLayoutChanged); + + connect(model, &QAbstractItemModel::dataChanged, + this, &ForwardingProxyModel::sourceDataChanged); + + connect(model, &QAbstractItemModel::columnsAboutToBeInserted, + this, &ForwardingProxyModel::sourceColumnsAboutToBeInserted); + connect(model, &QAbstractItemModel::columnsInserted, + this, &ForwardingProxyModel::sourceColumnsInserted); + connect(model, &QAbstractItemModel::columnsAboutToBeRemoved, + this, &ForwardingProxyModel::sourceColumnsAboutToBeRemoved); + connect(model, &QAbstractItemModel::columnsRemoved, + this, &ForwardingProxyModel::sourceColumnsRemoved); + + connect(model, &QAbstractItemModel::rowsAboutToBeInserted, + this, &ForwardingProxyModel::sourceRowsAboutToBeInserted); + connect(model, &QAbstractItemModel::rowsInserted, + this, &ForwardingProxyModel::sourceRowsInserted); + connect(model, &QAbstractItemModel::rowsAboutToBeRemoved, + this, &ForwardingProxyModel::sourceRowsAboutToBeRemoved); + connect(model, &QAbstractItemModel::rowsRemoved, + this, &ForwardingProxyModel::sourceRowsRemoved); } /*! Called when the source model is about to be reset. @@ -140,7 +140,7 @@ void ForwardingProxyModel::sourceModelReset() void ForwardingProxyModel::sourceLayoutAboutToBeChanged() { // qDebug() << "ForwardingProxyModel::sourceLayoutAboutToBeChanged()"; - emit layoutAboutToBeChanged(); + Q_EMIT layoutAboutToBeChanged(); } /*! Called when the layout of the source model has changed. @@ -159,7 +159,7 @@ void ForwardingProxyModel::sourceLayoutChanged() void ForwardingProxyModel::sourceDataChanged(const QModelIndex &from, const QModelIndex &to) { // qDebug() << "ForwardingProxyModel::sourceDataChanged("<constraint().relationType()); item->setStart(s); } } - { // Workaround for multiple definition error with MSVC6 - Q_FOREACH (ConstraintGraphicsItem *item, m_endConstraints) { + { + // Workaround for multiple definition error with MSVC6 + for (ConstraintGraphicsItem *item : qAsConst(m_endConstraints)) { QPointF e = endConnector(item->constraint().relationType()); item->setEnd(e); } diff --git a/src/KDGantt/kdganttgraphicsscene.cpp b/src/KDGantt/kdganttgraphicsscene.cpp index 5e013bcf..80a4652c 100644 --- a/src/KDGantt/kdganttgraphicsscene.cpp +++ b/src/KDGantt/kdganttgraphicsscene.cpp @@ -68,8 +68,8 @@ void GraphicsScene::Private::resetConstraintItems() q->clearConstraintItems(); if (constraintModel.isNull()) return; - QList clst = constraintModel->constraints(); - Q_FOREACH (const Constraint &c, clst) { + const QList clst = constraintModel->constraints(); + for (const Constraint &c : clst) { createConstraintItem(c); } q->updateItems(); @@ -163,7 +163,7 @@ void GraphicsScene::init() { setItemIndexMethod(QGraphicsScene::NoIndex); setConstraintModel(new ConstraintModel(this)); - connect(d->grid, SIGNAL(gridChanged()), this, SLOT(slotGridChanged())); + connect(d->grid, &AbstractGrid::gridChanged, this, &GraphicsScene::slotGridChanged); } /* NOTE: The delegate should really be a property @@ -230,10 +230,10 @@ void GraphicsScene::setConstraintModel(ConstraintModel *cm) } d->constraintModel = cm; - connect(cm, SIGNAL(constraintAdded(const KDGantt::Constraint &)), - this, SLOT(slotConstraintAdded(const KDGantt::Constraint &))); - connect(cm, SIGNAL(constraintRemoved(const KDGantt::Constraint &)), - this, SLOT(slotConstraintRemoved(const KDGantt::Constraint &))); + connect(cm, &ConstraintModel::constraintAdded, + this, &GraphicsScene::slotConstraintAdded); + connect(cm, &ConstraintModel::constraintRemoved, + this, &GraphicsScene::slotConstraintRemoved); d->resetConstraintItems(); } @@ -268,7 +268,7 @@ void GraphicsScene::setGrid(AbstractGrid *grid) model = d->grid->model(); } d->grid = grid; - connect(d->grid, SIGNAL(gridChanged()), this, SLOT(slotGridChanged())); + connect(d->grid, &AbstractGrid::gridChanged, this, &GraphicsScene::slotGridChanged); d->grid->setModel(model); slotGridChanged(); } @@ -419,7 +419,7 @@ void GraphicsScene::insertItem(const QPersistentModelIndex &idx, GraphicsItem *i // Create items for constraints const QModelIndex sidx = summaryHandlingModel()->mapToSource(idx); const QList clst = d->constraintModel->constraintsForIndex(sidx); - Q_FOREACH (const Constraint &c, clst) { + for (const Constraint &c : clst) { QModelIndex other_idx; if (c.startIndex() == sidx) { other_idx = c.endIndex(); @@ -469,7 +469,7 @@ void GraphicsScene::removeItem(const QModelIndex &idx) QSet::fromList(startConstraints) + QSet::fromList(endConstraints); #endif - Q_FOREACH (ConstraintGraphicsItem *citem, clst) { + for (ConstraintGraphicsItem *citem : clst) { d->deleteConstraintItem(citem); } } @@ -565,7 +565,7 @@ void GraphicsScene::slotGridChanged() { updateItems(); update(); - emit gridChanged(); + Q_EMIT gridChanged(); } void GraphicsScene::helpEvent(QGraphicsSceneHelpEvent *helpEvent) @@ -621,22 +621,22 @@ void GraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) void GraphicsScene::itemEntered(const QModelIndex &idx) { - emit entered(idx); + Q_EMIT entered(idx); } void GraphicsScene::itemPressed(const QModelIndex &idx) { - emit pressed(idx); + Q_EMIT pressed(idx); } void GraphicsScene::itemClicked(const QModelIndex &idx) { - emit clicked(idx); + Q_EMIT clicked(idx); } void GraphicsScene::itemDoubleClicked(const QModelIndex &idx) { - emit qrealClicked(idx); + Q_EMIT qrealClicked(idx); } void GraphicsScene::setDragSource(GraphicsItem *item) @@ -791,7 +791,7 @@ void GraphicsScene::doPrint(QPainter *painter, const QRectF &targetRect, } while ((sidx = rowController()->indexBelow(sidx)).isValid()); // Add a little margin to textWidth textWidth += QFontMetricsF(sceneFont).horizontalAdvance(QString::fromLatin1("X")); - Q_FOREACH (QGraphicsTextItem *item, textLabels) { + for (QGraphicsTextItem *item : qAsConst(textLabels)) { item->setPos(scnRect.left() - textWidth, item->y()); item->show(); } diff --git a/src/KDGantt/kdganttgraphicsview.cpp b/src/KDGantt/kdganttgraphicsview.cpp index 88771634..97ed3aaf 100644 --- a/src/KDGantt/kdganttgraphicsview.cpp +++ b/src/KDGantt/kdganttgraphicsview.cpp @@ -269,22 +269,22 @@ void GraphicsView::Private::slotRowsRemoved(const QModelIndex &parent, int start void GraphicsView::Private::slotItemClicked(const QModelIndex &idx) { QModelIndex sidx = idx; // scene.summaryHandlingModel()->mapToSource( idx ); - emit q->clicked(sidx); + Q_EMIT q->clicked(sidx); if (q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, q)) - emit q->activated(sidx); + Q_EMIT q->activated(sidx); } void GraphicsView::Private::slotItemDoubleClicked(const QModelIndex &idx) { QModelIndex sidx = idx; // scene.summaryHandlingModel()->mapToSource( idx ); - emit q->qrealClicked(sidx); + Q_EMIT q->qrealClicked(sidx); if (!q->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, nullptr, q)) - emit q->activated(sidx); + Q_EMIT q->activated(sidx); } void GraphicsView::Private::slotHeaderContextMenuRequested(const QPoint &pt) { - emit q->headerContextMenuRequested(headerwidget.mapToGlobal(pt)); + Q_EMIT q->headerContextMenuRequested(headerwidget.mapToGlobal(pt)); } /*!\class KDGantt::GraphicsView kdganttgraphicsview.h KDGanttGraphicsView @@ -315,22 +315,32 @@ GraphicsView::GraphicsView(QWidget *parent) #if defined KDAB_EVAL EvalDialog::checkEvalLicense("KD Gantt"); #endif - connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(slotHorizontalScrollValueChanged(int))); - connect(&_d->scene, SIGNAL(gridChanged()), - this, SLOT(slotGridChanged())); - connect(&_d->scene, SIGNAL(entered(const QModelIndex &)), - this, SIGNAL(entered(const QModelIndex &))); - connect(&_d->scene, SIGNAL(pressed(const QModelIndex &)), - this, SIGNAL(pressed(const QModelIndex &))); - connect(&_d->scene, SIGNAL(clicked(const QModelIndex &)), - this, SLOT(slotItemClicked(const QModelIndex &))); - connect(&_d->scene, SIGNAL(qrealClicked(const QModelIndex &)), - this, SLOT(slotItemDoubleClicked(const QModelIndex &))); - connect(&_d->scene, SIGNAL(sceneRectChanged(const QRectF &)), - this, SLOT(updateSceneRect())); - connect(&_d->headerwidget, SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(slotHeaderContextMenuRequested(const QPoint &))); + connect(horizontalScrollBar(), &QScrollBar::valueChanged, + this, [this](int value) { + _d->slotHorizontalScrollValueChanged(value); + }); + connect(&_d->scene, &GraphicsScene::gridChanged, + this, [this] { + _d->slotGridChanged(); + }); + connect(&_d->scene, &GraphicsScene::entered, + this, &GraphicsView::entered); + connect(&_d->scene, &GraphicsScene::pressed, + this, &GraphicsView::pressed); + connect(&_d->scene, &GraphicsScene::clicked, + this, [this](const QModelIndex &index) { + _d->slotItemClicked(index); + }); + connect(&_d->scene, &GraphicsScene::qrealClicked, + this, [this](const QModelIndex &index) { + _d->slotItemDoubleClicked(index); + }); + connect(&_d->scene, &GraphicsScene::sceneRectChanged, + this, &GraphicsView::updateSceneRect); + connect(&_d->headerwidget, &HeaderWidget::customContextMenuRequested, + this, [this](const QPoint &point) { + _d->slotHeaderContextMenuRequested(point); + }); setScene(&_d->scene); // HACK! @@ -371,8 +381,7 @@ void GraphicsView::setModel(QAbstractItemModel *model) } d->scene.setModel(model); - connect(model, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(updateSceneRect())); + connect(model, &QAbstractItemModel::dataChanged, this, &GraphicsView::updateSceneRect); updateScene(); } @@ -391,22 +400,38 @@ void GraphicsView::setSummaryHandlingModel(QAbstractProxyModel *proxyModel) /* Connections. We have to rely on the treeview * to receive the signals before we do(!) */ - connect(proxyModel, SIGNAL(columnsInserted(const QModelIndex &, int, int)), - this, SLOT(slotColumnsInserted(const QModelIndex &, int, int))); - connect(proxyModel, SIGNAL(columnsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotColumnsRemoved(const QModelIndex &, int, int))); - connect(proxyModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), - this, SLOT(slotDataChanged(const QModelIndex &, const QModelIndex &))); - connect(proxyModel, SIGNAL(layoutChanged()), - this, SLOT(slotLayoutChanged())); - connect(proxyModel, SIGNAL(modelReset()), - this, SLOT(slotModelReset())); - connect(proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), - this, SLOT(slotRowsInserted(const QModelIndex &, int, int))); - connect(proxyModel, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsAboutToBeRemoved(const QModelIndex &, int, int))); - connect(proxyModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), - this, SLOT(slotRowsRemoved(const QModelIndex &, int, int))); + connect(proxyModel, &QAbstractProxyModel::columnsInserted, + this, [this](const QModelIndex &parent, int first, int last) { + d->slotColumnsInserted(parent, first, last); + }); + connect(proxyModel, &QAbstractProxyModel::columnsRemoved, + this, [this](const QModelIndex &parent, int first, int last) { + d->slotColumnsRemoved(parent, first, last); + }); + connect(proxyModel, &QAbstractProxyModel::dataChanged, + this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight) { + d->slotDataChanged(topLeft, bottomRight); + }); + connect(proxyModel, &QAbstractProxyModel::layoutChanged, + this, [this] { + d->slotLayoutChanged(); + }); + connect(proxyModel, &QAbstractProxyModel::modelReset, + this, [this] { + d->slotModelReset(); + }); + connect(proxyModel, &QAbstractProxyModel::rowsInserted, + this, [this](const QModelIndex &parent, int first, int last) { + d->slotRowsInserted(parent, first, last); + }); + connect(proxyModel, &QAbstractProxyModel::rowsAboutToBeRemoved, + this, [this](const QModelIndex &parent, int first, int last) { + d->slotRowsAboutToBeRemoved(parent, first, last); + }); + connect(proxyModel, &QAbstractProxyModel::rowsRemoved, + this, [this](const QModelIndex &parent, int first, int last) { + d->slotRowsRemoved(parent, first, last); + }); updateScene(); } diff --git a/src/KDGantt/kdganttgraphicsview.h b/src/KDGantt/kdganttgraphicsview.h index b945c213..65ddf248 100644 --- a/src/KDGantt/kdganttgraphicsview.h +++ b/src/KDGantt/kdganttgraphicsview.h @@ -36,22 +36,6 @@ class KDGANTT_EXPORT GraphicsView : public QGraphicsView KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC(GraphicsView) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) - - Q_PRIVATE_SLOT(d, void slotGridChanged()) - Q_PRIVATE_SLOT(d, void slotHorizontalScrollValueChanged(int)) - Q_PRIVATE_SLOT(d, void slotHeaderContextMenuRequested(const QPoint &)) - /* slots for QAbstractItemModel signals */ - Q_PRIVATE_SLOT(d, void slotColumnsInserted(const QModelIndex &parent, int start, int end)) - Q_PRIVATE_SLOT(d, void slotColumnsRemoved(const QModelIndex &parent, int start, int end)) - Q_PRIVATE_SLOT(d, void slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)) - Q_PRIVATE_SLOT(d, void slotLayoutChanged()) - Q_PRIVATE_SLOT(d, void slotModelReset()) - Q_PRIVATE_SLOT(d, void slotRowsInserted(const QModelIndex &parent, int start, int end)) - Q_PRIVATE_SLOT(d, void slotRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)) - Q_PRIVATE_SLOT(d, void slotRowsRemoved(const QModelIndex &parent, int start, int end)) - - Q_PRIVATE_SLOT(d, void slotItemClicked(const QModelIndex &idx)) - Q_PRIVATE_SLOT(d, void slotItemDoubleClicked(const QModelIndex &idx)) public: explicit GraphicsView(QWidget *parent = nullptr); ~GraphicsView() override; diff --git a/src/KDGantt/kdganttlegend.cpp b/src/KDGantt/kdganttlegend.cpp index 369cbefc..5974eb92 100644 --- a/src/KDGantt/kdganttlegend.cpp +++ b/src/KDGantt/kdganttlegend.cpp @@ -68,21 +68,22 @@ QSize Legend::minimumSizeHint() const return measureItem(rootIndex()); } -void Legend::setModel(QAbstractItemModel *model) +void Legend::setModel(QAbstractItemModel *newModel) { - if (this->model() != nullptr) { - disconnect(this->model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged())); - disconnect(this->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataChanged())); - disconnect(this->model(), SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataChanged())); + QAbstractItemModel *oldModel = model(); + if (oldModel != nullptr) { + disconnect(oldModel, &QAbstractItemModel::dataChanged, this, &Legend::modelDataChanged); + disconnect(oldModel, &QAbstractItemModel::rowsRemoved, this, &Legend::modelDataChanged); + disconnect(oldModel, &QAbstractItemModel::columnsRemoved, this, &Legend::modelDataChanged); } - QAbstractItemView::setModel(model); - d->proxyModel.setSourceModel(model); + QAbstractItemView::setModel(newModel); + d->proxyModel.setSourceModel(newModel); - if (this->model() != nullptr) { - connect(this->model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged())); - connect(this->model(), SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataChanged())); - connect(this->model(), SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataChanged())); + if (newModel != nullptr) { + connect(newModel, &QAbstractItemModel::dataChanged, this, &Legend::modelDataChanged); + connect(newModel, &QAbstractItemModel::rowsRemoved, this, &Legend::modelDataChanged); + connect(newModel, &QAbstractItemModel::columnsRemoved, this, &Legend::modelDataChanged); } } diff --git a/src/KDGantt/kdganttsummaryhandlingproxymodel.cpp b/src/KDGantt/kdganttsummaryhandlingproxymodel.cpp index 54dcdcd4..96c996b7 100644 --- a/src/KDGantt/kdganttsummaryhandlingproxymodel.cpp +++ b/src/KDGantt/kdganttsummaryhandlingproxymodel.cpp @@ -172,7 +172,7 @@ void SummaryHandlingProxyModel::sourceDataChanged(const QModelIndex &from, const // qDebug() << "removing " << parentIdx << "from cache"; d->removeFromCache(dataIdx); QModelIndex proxyDataIdx = mapFromSource(dataIdx); - emit dataChanged(proxyDataIdx, proxyDataIdx); + Q_EMIT dataChanged(proxyDataIdx, proxyDataIdx); } } while ((parentIdx = model->parent(parentIdx)) != QModelIndex()); @@ -256,7 +256,7 @@ bool SummaryHandlingProxyModel::setData(const QModelIndex &index, const QVariant // qDebug() << "removing " << parentIdx << "from cache"; d->removeFromCache(parentIdx); QModelIndex proxyParentIdx = mapFromSource(parentIdx); - emit dataChanged(proxyParentIdx, proxyParentIdx); + Q_EMIT dataChanged(proxyParentIdx, proxyParentIdx); } } while ((parentIdx = model->parent(parentIdx)) != QModelIndex()); } diff --git a/src/KDGantt/kdganttview.cpp b/src/KDGantt/kdganttview.cpp index 79125e69..9ee1b5a1 100644 --- a/src/KDGantt/kdganttview.cpp +++ b/src/KDGantt/kdganttview.cpp @@ -281,21 +281,30 @@ void View::setLeftView(QAbstractItemView *aiv) d->leftWidget = aiv; d->splitter.insertWidget(0, d->leftWidget); - if (qobject_cast(d->leftWidget)) { - connect(d->leftWidget, SIGNAL(collapsed(const QModelIndex &)), - this, SLOT(slotCollapsed(const QModelIndex &))); - connect(d->leftWidget, SIGNAL(expanded(const QModelIndex &)), - this, SLOT(slotExpanded(const QModelIndex &))); + auto leftWidgetTreeView = qobject_cast(d->leftWidget); + if (leftWidgetTreeView) { + connect(leftWidgetTreeView, &QTreeView::collapsed, + this, [this](const QModelIndex &index) { + d->slotCollapsed(index); + }); + connect(leftWidgetTreeView, &QTreeView::expanded, + this, [this](const QModelIndex &index) { + d->slotExpanded(index); + }); } - connect(d->gfxview->verticalScrollBar(), SIGNAL(valueChanged(int)), - d->leftWidget->verticalScrollBar(), SLOT(setValue(int))); - connect(d->leftWidget->verticalScrollBar(), SIGNAL(valueChanged(int)), - d->gfxview->verticalScrollBar(), SLOT(setValue(int))); - connect(d->leftWidget->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), - this, SLOT(slotLeftWidgetVerticalRangeChanged(int, int))); - connect(d->gfxview->verticalScrollBar(), SIGNAL(rangeChanged(int, int)), - this, SLOT(slotGfxViewVerticalRangeChanged(int, int))); + connect(d->gfxview->verticalScrollBar(), &QScrollBar::valueChanged, + d->leftWidget->verticalScrollBar(), &QScrollBar::setValue); + connect(d->leftWidget->verticalScrollBar(), &QScrollBar::valueChanged, + d->gfxview->verticalScrollBar(), &QScrollBar::setValue); + connect(d->leftWidget->verticalScrollBar(), &QScrollBar::rangeChanged, + this, [this](int min, int max) { + d->slotLeftWidgetVerticalRangeChanged(min, max); + }); + connect(d->gfxview->verticalScrollBar(), &QScrollBar::rangeChanged, + this, [this](int min, int max) { + d->slotLeftWidgetVerticalRangeChanged(min, max); + }); } /*! Sets \a ctrl to be the rowcontroller used by this View. @@ -625,7 +634,7 @@ KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, View, "test") { View view(nullptr); #if 0 // GUI tests do not work well on the server - QTimer::singleShot( 1000, qApp, SLOT( quit() ) ); + QTimer::singleShot( 1000, qApp, &QCoreApplication::quit ); view.show(); qApp->exec(); @@ -635,7 +644,7 @@ KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, View, "test") view.setLeftView( tv ); view.setRowController( new TreeViewRowController(tv,view.ganttProxyModel()) ); - QTimer::singleShot( 1000, qApp, SLOT( quit() ) ); + QTimer::singleShot( 1000, qApp, &QCoreApplication::quit ); qApp->exec(); QPixmap screenshot2 = QPixmap::grabWidget( &view ); @@ -646,7 +655,7 @@ KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, View, "test") view.setLeftView(lv); view.setRowController( new ListViewRowController(lv,view.ganttProxyModel())); view.show(); - QTimer::singleShot( 1000, qApp, SLOT( quit() ) ); + QTimer::singleShot( 1000, qApp, &QCoreApplication::quit ); qApp->exec(); #endif } diff --git a/src/KDGantt/kdganttview.h b/src/KDGantt/kdganttview.h index 40921b56..59ae7a83 100644 --- a/src/KDGantt/kdganttview.h +++ b/src/KDGantt/kdganttview.h @@ -36,11 +36,6 @@ class KDGANTT_EXPORT View : public QWidget { Q_OBJECT KDGANTT_DECLARE_PRIVATE_BASE_POLYMORPHIC_QWIDGET(View) - Q_PRIVATE_SLOT(d, void slotCollapsed(const QModelIndex &)) - Q_PRIVATE_SLOT(d, void slotExpanded(const QModelIndex &)) - Q_PRIVATE_SLOT(d, void slotVerticalScrollValueChanged(int)) - Q_PRIVATE_SLOT(d, void slotLeftWidgetVerticalRangeChanged(int, int)) - Q_PRIVATE_SLOT(d, void slotGfxViewVerticalRangeChanged(int, int)) public: explicit View(QWidget *parent = nullptr); diff --git a/tests/DelayedData/main.cpp b/tests/DelayedData/main.cpp index 74a7a624..494b55ed 100644 --- a/tests/DelayedData/main.cpp +++ b/tests/DelayedData/main.cpp @@ -54,10 +54,10 @@ class ChartWidget : public QWidget m_rowbutton.setText(tr("Add rows")); m_colbutton.setText(tr("Add columns")); - connect(&m_rowbutton, SIGNAL(clicked()), - this, SLOT(addRows())); - connect(&m_colbutton, SIGNAL(clicked()), - this, SLOT(addCols())); + connect(&m_rowbutton, &QPushButton::clicked, + this, &ChartWidget::addRows); + connect(&m_colbutton, &QPushButton::clicked, + this, &ChartWidget::addCols); auto *l = new QVBoxLayout(this); l->addWidget(&m_chart); diff --git a/tests/Gantt/apireview/entrydialog.cpp b/tests/Gantt/apireview/entrydialog.cpp index 582a793e..da4baed8 100644 --- a/tests/Gantt/apireview/entrydialog.cpp +++ b/tests/Gantt/apireview/entrydialog.cpp @@ -40,8 +40,9 @@ void EntryDialog::init() for (int row = 0; row < model->rowCount(); ++row) addDependItem(model, model->index(row, 0)); - connect(ui->startDate, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(updateEndDate(const QDateTime &))); - connect(ui->readOnly, SIGNAL(toggled(bool)), this, SLOT(disableEditing(bool))); + connect(ui->startDate, &QDateTimeEdit::dateTimeChanged, + this, &EntryDialog::updateEndDate); + connect(ui->readOnly, &QCheckBox::toggled, this, &EntryDialog::disableEditing); ui->startDate->setDateTime(QDateTime::currentDateTime()); } diff --git a/tests/Gantt/apireview/mainwindow.cpp b/tests/Gantt/apireview/mainwindow.cpp index 49307f2e..928ee9a9 100644 --- a/tests/Gantt/apireview/mainwindow.cpp +++ b/tests/Gantt/apireview/mainwindow.cpp @@ -47,15 +47,15 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) leftView->setColumnHidden(5, true); leftView->header()->setStretchLastSection(true); - connect(ui->ganttView->leftView(), SIGNAL(customContextMenuRequested(const QPoint &)), - this, SLOT(showContextMenu(const QPoint &))); - connect(ui->ganttView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), - this, SLOT(enableActions(const QItemSelection &))); - - connect(ui->ganttView->graphicsView(), SIGNAL(clicked(const QModelIndex &)), - this, SLOT(slotClicked(const QModelIndex &))); - connect(ui->ganttView->graphicsView(), SIGNAL(qrealClicked(const QModelIndex &)), - this, SLOT(slotDoubleClicked(const QModelIndex &))); + connect(ui->ganttView->leftView(), &QAbstractItemView::customContextMenuRequested, + this, &MainWindow::showContextMenu); + connect(ui->ganttView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &MainWindow::enableActions); + + connect(ui->ganttView->graphicsView(), &KDGantt::GraphicsView::clicked, + this, &MainWindow::slotClicked); + connect(ui->ganttView->graphicsView(), &KDGantt::GraphicsView::qrealClicked, + this, &MainWindow::slotDoubleClicked); } void MainWindow::initModel() @@ -77,25 +77,25 @@ void MainWindow::initActions() { newEntryAction = new QAction(tr("New entry"), this); newEntryAction->setShortcut(QKeySequence::New); - connect(newEntryAction, SIGNAL(triggered()), this, SLOT(addNewEntry())); + connect(newEntryAction, &QAction::triggered, this, &MainWindow::addNewEntry); removeEntryAction = new QAction(tr("Remove entry"), this); removeEntryAction->setShortcut(QKeySequence::Delete); - connect(removeEntryAction, SIGNAL(triggered()), this, SLOT(removeEntry())); + connect(removeEntryAction, &QAction::triggered, this, &MainWindow::removeEntry); demoAction = new QAction(tr("Demo entry"), this); - connect(demoAction, SIGNAL(triggered()), this, SLOT(addDemoEntry())); + connect(demoAction, &QAction::triggered, this, &MainWindow::addDemoEntry); printAction = new QAction(tr("Print Preview..."), this); - connect(printAction, SIGNAL(triggered()), this, SLOT(printPreview())); + connect(printAction, &QAction::triggered, this, &MainWindow::printPreview); zoomInAction = new QAction(tr("Zoom In"), this); zoomInAction->setShortcut(QKeySequence::ZoomIn); - connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn())); + connect(zoomInAction, &QAction::triggered, this, &MainWindow::zoomIn); zoomOutAction = new QAction(tr("Zoom Out"), this); zoomOutAction->setShortcut(QKeySequence::ZoomOut); - connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut())); + connect(zoomOutAction, &QAction::triggered, this, &MainWindow::zoomOut); ui->ganttView->leftView()->setContextMenuPolicy(Qt::CustomContextMenu); ui->ganttView->leftView()->addAction(newEntryAction); diff --git a/tests/Gantt/customconstraints/main.cpp b/tests/Gantt/customconstraints/main.cpp index 57e4b205..6b994f52 100644 --- a/tests/Gantt/customconstraints/main.cpp +++ b/tests/Gantt/customconstraints/main.cpp @@ -107,8 +107,8 @@ class MyWidget : public QWidget view.setGrid(&grid); view.setModel(&model); - connect(&slider, SIGNAL(valueChanged(int)), - this, SLOT(slotZoom(int))); + connect(&slider, &QSlider::valueChanged, + this, &MyWidget::slotZoom); } public slots: diff --git a/tests/Gantt/gfxview/main.cpp b/tests/Gantt/gfxview/main.cpp index 9076c691..168bd87d 100644 --- a/tests/Gantt/gfxview/main.cpp +++ b/tests/Gantt/gfxview/main.cpp @@ -157,8 +157,8 @@ int main(int argc, char **argv) view->setModel(&model); #if 0 QPushButton* pb = new QPushButton( QObject::tr( "Reset" ) ); - QObject::connect( pb, SIGNAL( clicked() ), - &model, SIGNAL( modelReset() ) ); + QObject::connect( pb, &QPushButton::clicked, + &model, &MyStandardItemModel::modelReset ); pb->show(); #endif return app.exec(); diff --git a/tests/Gantt/listview/main.cpp b/tests/Gantt/listview/main.cpp index 1d2a562a..5785888f 100644 --- a/tests/Gantt/listview/main.cpp +++ b/tests/Gantt/listview/main.cpp @@ -110,8 +110,8 @@ class MyWidget : public QWidget view.setGrid(&grid); view.setModel(&model); // view.setConstraintModel( &cmodel ); - connect(&slider, SIGNAL(valueChanged(int)), - this, SLOT(slotZoom(int))); + connect(&slider, &QSlider::valueChanged, + this, &MyWidget::slotZoom); } public slots: diff --git a/tests/Gantt/reorder/main.cpp b/tests/Gantt/reorder/main.cpp index f6a896da..b5ca1ebb 100644 --- a/tests/Gantt/reorder/main.cpp +++ b/tests/Gantt/reorder/main.cpp @@ -100,61 +100,6 @@ class MyTaskModel : public QAbstractTableModel } }; -/* Test class to see the effect of moving rows */ -class MoveHelper : public QObject -{ -public: - MoveHelper(MyTaskModel *model, - KDGantt::ConstraintModel *, - KDGantt::View *, -#if 0 - KDGantt::ConstraintModel* constraints, - KDGantt::View* view, -#endif - int row1, int row2) - : QObject(model) - , m_model(model) - , -#if 0 - m_constraints( constraints ), - m_view( view ), -#endif - m_row1(row1) - , m_row2(row2) - { - } - - void showContraints(const QString & /*pfx*/) - { -#if 0 - qDebug() << pfx << *m_constraints; - qDebug() << "0:" << m_constraints->constraintsForIndex( m_model->index( 0, 0 ) ); - qDebug() << "1:"<< m_constraints->constraintsForIndex( m_model->index( 1, 0 ) ); - qDebug() << "2:"<< m_constraints->constraintsForIndex( m_model->index( 2, 0 ) ); - qDebug() << "3:"<< m_constraints->constraintsForIndex( m_model->index( 3, 0 ) ); -#endif - } - - ~MoveHelper() override - { - qDebug() << "Moving row" << m_row1 << "to" << m_row2; - showContraints("Before:"); - m_model->moveRow(m_row1, m_row2); - showContraints("After:"); - - // Hack until KDGantt supports this: - // m_view->setConstraintModel( m_constraints ); - } - -private: - MyTaskModel *m_model; -#if 0 - KDGantt::ConstraintModel* m_constraints; - KDGantt::View* m_view; -#endif - int m_row1, m_row2; -}; - int main(int argc, char **argv) { QApplication app(argc, argv); @@ -172,8 +117,11 @@ int main(int argc, char **argv) view->setConstraintModel(&constraints); view->show(); - /* After 5 seconds, move row 1 to pos 0: */ - QTimer::singleShot(5000, new MoveHelper(&model, &constraints, view, 1, 0), SLOT(deleteLater())); + QTimer::singleShot(5000, &app, [&model] { + /* After 5 seconds, move row 1 to pos 0: */ + qDebug() << "Moving row" << 1 << "to" << 0; + model.moveRow(1, 0); + }); return app.exec(); } diff --git a/tests/Gantt/view/main.cpp b/tests/Gantt/view/main.cpp index 2a13b0bf..d84c67b2 100644 --- a/tests/Gantt/view/main.cpp +++ b/tests/Gantt/view/main.cpp @@ -118,19 +118,19 @@ class MyWidget : public QWidget view.setGrid(&grid); view.setModel(&model); // view.setConstraintModel( &cmodel ); - connect(&slider, SIGNAL(valueChanged(int)), - this, SLOT(slotZoom(int))); + connect(&slider, &QSlider::valueChanged, + this, &MyWidget::slotZoom); auto *pb1 = new QPushButton(tr("Print Preview...")); auto *pb2 = new QPushButton(tr("Print...")); l->addWidget(pb1); l->addWidget(pb2); - connect(pb1, SIGNAL(clicked()), this, SLOT(slotPrintPreview())); - connect(pb2, SIGNAL(clicked()), this, SLOT(slotPrint())); + connect(pb1, &QPushButton::clicked, this, &MyWidget::slotPrintPreview); + connect(pb2, &QPushButton::clicked, this, &MyWidget::slotPrint); view.graphicsView()->setHeaderContextMenuPolicy(Qt::CustomContextMenu); - connect(view.graphicsView(), SIGNAL(headerContextMenuRequested(const QPoint &)), - this, SLOT(slotHeaderMenu(const QPoint &))); + connect(view.graphicsView(), &KDGantt::GraphicsView::headerContextMenuRequested, + this, &MyWidget::slotHeaderMenu); } public slots: