From 69004c9bef78db4686b2664f74b6ffde56a9b0a3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 5 Jan 2016 14:42:17 -0200 Subject: [PATCH] Mode signal/slots to new style Also, changed an if(true) then true; else false; code Signed-off-by: Tomaz Canabrava --- src/ui/QGCHilXPlaneConfiguration.cc | 7 +-- src/ui/QGCMAVLinkInspector.cc | 17 ++++--- src/ui/SerialConfigurationWindow.cc | 25 ++++++----- src/ui/linechart/LinechartPlot.cc | 4 +- src/ui/linechart/LinechartWidget.cc | 70 ++++++++++++++--------------- 5 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/ui/QGCHilXPlaneConfiguration.cc b/src/ui/QGCHilXPlaneConfiguration.cc index e553ddb3c..1709e11b9 100644 --- a/src/ui/QGCHilXPlaneConfiguration.cc +++ b/src/ui/QGCHilXPlaneConfiguration.cc @@ -35,10 +35,11 @@ QGCHilXPlaneConfiguration::QGCHilXPlaneConfiguration(QGCHilLink* link, QGCHilCon // XXX not implemented yet //ui->airframeComboBox->hide(); ui->sensorHilCheckBox->setChecked(xplane->sensorHilEnabled()); - connect(xplane, SIGNAL(sensorHilChanged(bool)), ui->sensorHilCheckBox, SLOT(setChecked(bool))); - connect(ui->sensorHilCheckBox, SIGNAL(clicked(bool)), xplane, SLOT(enableSensorHIL(bool))); + connect(xplane, &QGCXPlaneLink::sensorHilChanged, ui->sensorHilCheckBox, &QCheckBox::setChecked); + connect(ui->sensorHilCheckBox, &QCheckBox::clicked, xplane, &QGCXPlaneLink::enableSensorHIL); - connect(link, SIGNAL(versionChanged(int)), this, SLOT(setVersion(int))); + connect(link, static_cast(&QGCHilLink::versionChanged), + this, &QGCHilXPlaneConfiguration::setVersion); } ui->hostComboBox->clear(); diff --git a/src/ui/QGCMAVLinkInspector.cc b/src/ui/QGCMAVLinkInspector.cc index 56f4d2093..71d6a8317 100644 --- a/src/ui/QGCMAVLinkInspector.cc +++ b/src/ui/QGCMAVLinkInspector.cc @@ -43,21 +43,24 @@ QGCMAVLinkInspector::QGCMAVLinkInspector(const QString& title, QAction* action, rateHeader << tr("#ID"); rateHeader << tr("Rate"); ui->rateTreeWidget->setHeaderLabels(rateHeader); - connect(ui->rateTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), - this, SLOT(rateTreeItemChanged(QTreeWidgetItem*,int))); + connect(ui->rateTreeWidget, &QTreeWidget::itemChanged, + this, &QGCMAVLinkInspector::rateTreeItemChanged); ui->rateTreeWidget->hide(); // Connect the UI - connect(ui->systemComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuSystem(int))); - connect(ui->componentComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectDropDownMenuComponent(int))); - connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(clearView())); + connect(ui->systemComboBox, static_cast(&QComboBox::currentIndexChanged), + this, &QGCMAVLinkInspector::selectDropDownMenuSystem); + connect(ui->componentComboBox, static_cast(&QComboBox::currentIndexChanged), + this, &QGCMAVLinkInspector::selectDropDownMenuComponent); + + connect(ui->clearButton, &QPushButton::clicked, this, &QGCMAVLinkInspector::clearView); // Connect external connections connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::vehicleAdded, this, &QGCMAVLinkInspector::_vehicleAdded); - connect(protocol, SIGNAL(messageReceived(LinkInterface*,mavlink_message_t)), this, SLOT(receiveMessage(LinkInterface*,mavlink_message_t))); + connect(protocol, &MAVLinkProtocol::messageReceived, this, &QGCMAVLinkInspector::receiveMessage); // Attach the UI's refresh rate to a timer. - connect(&updateTimer, SIGNAL(timeout()), this, SLOT(refreshView())); + connect(&updateTimer, &QTimer::timeout, this, &QGCMAVLinkInspector::refreshView); updateTimer.start(updateInterval); loadSettings(); diff --git a/src/ui/SerialConfigurationWindow.cc b/src/ui/SerialConfigurationWindow.cc index 61406ff52..e6e3e27fd 100644 --- a/src/ui/SerialConfigurationWindow.cc +++ b/src/ui/SerialConfigurationWindow.cc @@ -71,15 +71,20 @@ SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config } // Connect the individual user interface inputs - connect(_ui.portName, SIGNAL(currentIndexChanged(int)), this, SLOT(setPortName(int))); - connect(_ui.baudRate, SIGNAL(activated(int)), this, SLOT(setBaudRate(int))); - connect(_ui.flowControlCheckBox,SIGNAL(toggled(bool)), this, SLOT(enableFlowControl(bool))); - connect(_ui.parNone, SIGNAL(toggled(bool)), this, SLOT(setParityNone(bool))); - connect(_ui.parOdd, SIGNAL(toggled(bool)), this, SLOT(setParityOdd(bool))); - connect(_ui.parEven, SIGNAL(toggled(bool)), this, SLOT(setParityEven(bool))); - connect(_ui.dataBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setDataBits(int))); - connect(_ui.stopBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setStopBits(int))); - connect(_ui.advCheckBox, SIGNAL(clicked(bool)), _ui.advGroupBox, SLOT(setVisible(bool))); + connect(_ui.portName, static_cast(&QComboBox::currentIndexChanged), + this, &SerialConfigurationWindow::setPortName); + connect(_ui.baudRate, static_cast(&QComboBox::activated), + this, &SerialConfigurationWindow::setBaudRate); + connect(_ui.dataBitsSpinBox, static_cast(&QSpinBox::valueChanged), + this, &SerialConfigurationWindow::setDataBits); + connect(_ui.stopBitsSpinBox, static_cast(&QSpinBox::valueChanged), + this, &SerialConfigurationWindow::setStopBits); + + connect(_ui.flowControlCheckBox,&QCheckBox::toggled, this, &SerialConfigurationWindow::enableFlowControl); + connect(_ui.parNone, &QRadioButton::toggled, this, &SerialConfigurationWindow::setParityNone); + connect(_ui.parOdd, &QRadioButton::toggled, this, &SerialConfigurationWindow::setParityOdd); + connect(_ui.parEven, &QRadioButton::toggled, this, &SerialConfigurationWindow::setParityEven); + connect(_ui.advCheckBox, &QCheckBox::clicked, _ui.advGroupBox, &QWidget::setVisible); _ui.advCheckBox->setCheckable(true); _ui.advCheckBox->setChecked(false); @@ -112,7 +117,7 @@ SerialConfigurationWindow::SerialConfigurationWindow(SerialConfiguration *config _ui.stopBitsSpinBox->setValue(_config->stopBits()); _portCheckTimer = new QTimer(this); _portCheckTimer->setInterval(1000); - connect(_portCheckTimer, SIGNAL(timeout()), this, SLOT(setupPortList())); + connect(_portCheckTimer, &QTimer::timeout, this, &SerialConfigurationWindow::setupPortList); // Display the widget setWindowTitle(tr("Serial Communication Settings")); diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 510e0cf45..37867390f 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -78,10 +78,10 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval): // Start QTimer for plot update updateTimer = new QTimer(this); - connect(updateTimer, SIGNAL(timeout()), this, SLOT(paintRealtime())); + connect(updateTimer, &QTimer::timeout, this, &LinechartPlot::paintRealtime); //updateTimer->start(DEFAULT_REFRESH_RATE); - connect(&timeoutTimer, SIGNAL(timeout()), this, SLOT(removeTimedOutCurves())); + connect(&timeoutTimer, &QTimer::timeout, this, &LinechartPlot::removeTimedOutCurves); //timeoutTimer.start(5000); } diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 7726de0b3..3c371e009 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -104,15 +104,17 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent QLabel* mean; QLabel* variance; - connect(ui.recolorButton, SIGNAL(clicked()), this, SLOT(recolor())); - connect(ui.shortNameCheckBox, SIGNAL(clicked(bool)), this, SLOT(setShortNames(bool))); - connect(ui.plotFilterLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(filterCurves(const QString&))); - new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), this, SLOT(setPlotFilterLineEditFocus())); + connect(ui.recolorButton, &QPushButton::clicked, this, &LinechartWidget::recolor); + connect(ui.shortNameCheckBox, &QCheckBox::clicked, this, &LinechartWidget::setShortNames); + connect(ui.plotFilterLineEdit, &QLineEdit::textChanged, this, &LinechartWidget::filterCurves); + QShortcut *shortcut = new QShortcut(this); + shortcut->setKey(QKeySequence(Qt::CTRL + Qt::Key_F)); + connect(shortcut, &QShortcut::activated, this, &LinechartWidget::setPlotFilterLineEditFocus); int labelRow = curvesWidgetLayout->rowCount(); selectAllCheckBox = new QCheckBox("", this); - connect(selectAllCheckBox, SIGNAL(clicked(bool)), this, SLOT(selectAllCurves(bool))); + connect(selectAllCheckBox, &QCheckBox::clicked, this, &LinechartWidget::selectAllCurves); curvesWidgetLayout->addWidget(selectAllCheckBox, labelRow, 0, 1, 2); label = new QLabel(this); @@ -144,8 +146,9 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent connect(qgcApp(), &QGCApplication::styleChanged, this, &LinechartWidget::recolor); updateTimer->setInterval(updateInterval); - connect(updateTimer, SIGNAL(timeout()), this, SLOT(refresh())); - connect(ui.uasSelectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectActiveSystem(int))); + connect(updateTimer, &QTimer::timeout, this, &LinechartWidget::refresh); + connect(ui.uasSelectionBox, static_cast(&QComboBox::currentIndexChanged), + this, &LinechartWidget::selectActiveSystem); readSettings(); } @@ -243,7 +246,7 @@ void LinechartWidget::createLayout() setAverageWindow(200); averageSpinBox->setMaximum(9999); hlayout->addWidget(averageSpinBox); - connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); + connect(averageSpinBox,static_cast(&QSpinBox::valueChanged), this, &LinechartWidget::setAverageWindow); // Log Button logButton = new QToolButton(this); @@ -251,7 +254,7 @@ void LinechartWidget::createLayout() logButton->setWhatsThis(tr("Start to log curve data into a CSV or TXT file")); logButton->setText(tr("Start Logging")); hlayout->addWidget(logButton); - connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); + connect(logButton, &QToolButton::clicked, this, &LinechartWidget::startLogging); // Ground time button timeButton = new QCheckBox(this); @@ -259,8 +262,8 @@ void LinechartWidget::createLayout() timeButton->setToolTip(tr("Overwrite timestamp of data from vehicle with ground receive time. Helps if the plots are not visible because of missing or invalid onboard time.")); timeButton->setWhatsThis(tr("Overwrite timestamp of data from vehicle with ground receive time. Helps if the plots are not visible because of missing or invalid onboard time.")); hlayout->addWidget(timeButton); - connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); - connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); + connect(timeButton, &QCheckBox::clicked, activePlot, &LinechartPlot::enforceGroundTime); + connect(timeButton, &QCheckBox::clicked, this, &LinechartWidget::writeSettings); hlayout->addStretch(); @@ -283,27 +286,30 @@ void LinechartWidget::createLayout() timeScaleCmb->setMinimumContentsLength(12); hlayout->addWidget(timeScaleCmb); - connect(timeScaleCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(timeScaleChanged(int))); + connect(timeScaleCmb, static_cast(&QComboBox::currentIndexChanged), + this, &LinechartWidget::timeScaleChanged); // Initialize the "Show units" checkbox. This is configured in the .ui file, so all // we do here is attach the clicked() signal. - connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings())); + connect(ui.showUnitsCheckBox, &QCheckBox::clicked, this, &LinechartWidget::writeSettings); // Add actions averageSpinBox->setValue(activePlot->getAverageWindow()); // Connect notifications from the user interface to the plot - connect(this, SIGNAL(curveRemoved(QString)), activePlot, SLOT(hideCurve(QString))); + connect(this, &LinechartWidget::curveRemoved, activePlot, &LinechartPlot::hideCurve); // Update scrollbar when plot window changes (via translator method setPlotWindowPosition() // connect(activePlot, SIGNAL(windowPositionChanged(quint64)), this, SLOT(setPlotWindowPosition(quint64))); - connect(activePlot, SIGNAL(curveRemoved(QString)), this, SLOT(removeCurve(QString))); + connect(activePlot, &LinechartPlot::curveRemoved, this, &LinechartWidget::removeCurve); // Update plot when scrollbar is moved (via translator method setPlotWindowPosition() - connect(this, SIGNAL(plotWindowPositionUpdated(quint64)), activePlot, SLOT(setWindowPosition(quint64))); + //TODO: impossible to + connect(this, static_cast(&LinechartWidget::plotWindowPositionUpdated), + activePlot, &LinechartPlot::setWindowPosition); // Set scaling - connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool))); + connect(scalingLogButton, &QToolButton::toggled, this, &LinechartWidget::toggleLogarithmicScaling); } void LinechartWidget::timeScaleChanged(int index) @@ -466,8 +472,8 @@ void LinechartWidget::startLogging() curvesWidget->setEnabled(false); logindex++; logButton->setText(tr("Stop logging")); - disconnect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); - connect(logButton, SIGNAL(clicked()), this, SLOT(stopLogging())); + disconnect(logButton, &QToolButton::clicked, this, &LinechartWidget::startLogging); + connect(logButton, &QToolButton::clicked, this, &LinechartWidget::stopLogging); } } } @@ -481,28 +487,20 @@ void LinechartWidget::stopLogging() logFile->close(); // Postprocess log file compressor = new LogCompressor(logFile->fileName(), logFile->fileName()); - connect(compressor, SIGNAL(finishedFile(QString)), this, SIGNAL(logfileWritten(QString))); + connect(compressor, &LogCompressor::finishedFile, this, &LinechartWidget::logfileWritten); QMessageBox::StandardButton button = QGCMessageBox::question( tr("Starting Log Compression"), tr("Should empty fields (e.g. due to packet drops) be filled with the previous value of the same variable (zero order hold)?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - bool fill; - if (button == QMessageBox::Yes) - { - fill = true; - } - else - { - fill = false; - } + bool fill = (button == QMessageBox::Yes); compressor->startCompression(fill); } logButton->setText(tr("Start logging")); - disconnect(logButton, SIGNAL(clicked()), this, SLOT(stopLogging())); - connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); + disconnect(logButton, &QToolButton::clicked, this, &LinechartWidget::stopLogging); + connect(logButton, &QToolButton::clicked, this, &LinechartWidget::startLogging); } /** @@ -580,7 +578,7 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit) curveUnits.insert(curve+unit, unitLabel); curvesWidgetLayout->addWidget(unitLabel, labelRow, 4); unitLabel->setVisible(ui.showUnitsCheckBox->isChecked()); - connect(ui.showUnitsCheckBox, SIGNAL(clicked(bool)), unitLabel, SLOT(setVisible(bool))); + connect(ui.showUnitsCheckBox, &QCheckBox::clicked, unitLabel, &QLabel::setVisible); // Mean mean = new QLabel(this); @@ -617,14 +615,14 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit) // Set stretch factors so that the label gets the whole space - +plot; // Load visibility settings // TODO // Connect actions - connect(selectAllCheckBox, SIGNAL(clicked(bool)), checkBox, SLOT(setChecked(bool))); - QObject::connect(checkBox, SIGNAL(clicked(bool)), this, SLOT(takeButtonClick(bool))); - QObject::connect(this, SIGNAL(curveVisible(QString, bool)), plot, SLOT(setVisibleById(QString, bool))); + connect(selectAllCheckBox, &QCheckBox::clicked, checkBox, &QCheckBox::setChecked); + QObject::connect(checkBox, &QCheckBox::clicked, this, &LinechartWidget::takeButtonClick); + QObject::connect(this, &LinechartWidget::curveVisible, plot, &LinechartPlot::setVisibleById); // Set UI components to initial state checkBox->setChecked(false); -- 2.22.0