From 13e5381d3af23b765066c037a2f3b1be7bb1dfc7 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Tue, 8 Oct 2013 17:11:34 +0100 Subject: [PATCH 01/13] DataPlot - Don't crash if the user cancels saving the data or image file --- src/ui/QGCDataPlot2D.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 02dc9d1..4a24151 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -120,6 +120,8 @@ void QGCDataPlot2D::savePlot() fileName = QFileDialog::getSaveFileName( this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), "PDF Documents (*.pdf);;SVG Images (*.svg)"); + if (fileName.isEmpty()) + return; if (!fileName.contains(".")) { // .pdf is default extension @@ -138,6 +140,8 @@ void QGCDataPlot2D::savePlot() fileName = QFileDialog::getSaveFileName( this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), "PDF Documents (*.pdf);;SVG Images (*.svg)"); + if (fileName.isEmpty()) + return; //Abort if cancelled } if (fileName.endsWith(".pdf")) { @@ -689,6 +693,8 @@ void QGCDataPlot2D::saveCsvLog() fileName = QFileDialog::getSaveFileName( this, "Export CSV File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), "CSV file (*.csv);;Text file (*.txt)"); + if (fileName.isEmpty()) + return; //User cancelled if (!fileName.contains(".")) { // .csv is default extension From c90c55d4803faef1d4d26326f6c35cd037dd3c21 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Tue, 8 Oct 2013 22:42:52 +0100 Subject: [PATCH 02/13] CommConfigurationWindow - make it a proper QDialog, and not a floating widget --- src/ui/CommConfigurationWindow.cc | 2 +- src/ui/CommConfigurationWindow.h | 4 ++-- src/ui/MainWindow.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 099c28f..223abd9 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -55,7 +55,7 @@ This file is part of the QGROUNDCONTROL project #include "LinkManager.h" #include "MainWindow.h" -CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent) : QWidget(parent) +CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolInterface* protocol, QWidget *parent) : QDialog(parent) { this->link = link; diff --git a/src/ui/CommConfigurationWindow.h b/src/ui/CommConfigurationWindow.h index 4333e5a..65912b0 100644 --- a/src/ui/CommConfigurationWindow.h +++ b/src/ui/CommConfigurationWindow.h @@ -33,7 +33,7 @@ This file is part of the QGROUNDCONTROL project #define _COMMCONFIGURATIONWINDOW_H_ #include -#include +#include #include #include "LinkInterface.h" #include "ProtocolInterface.h" @@ -62,7 +62,7 @@ enum qgc_protocol_t { /** * @brief Configuration window for communication links */ -class CommConfigurationWindow : public QWidget +class CommConfigurationWindow : public QDialog { Q_OBJECT diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 354c73b..2a5450c 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -1683,7 +1683,7 @@ void MainWindow::addLink(LinkInterface *link) if (!found) { - CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, NULL); + CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this); commsWidgetList.append(commWidget); connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*))); QAction* action = commWidget->getAction(); From b9bd45928ffc74b2400123213e189eb30c965a1e Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Tue, 8 Oct 2013 22:54:25 +0100 Subject: [PATCH 03/13] CommConfigurationWindow - don't try to manually center, now that it is a proper QDialog --- src/ui/CommConfigurationWindow.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 223abd9..ffb163b 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -62,11 +62,6 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn // Setup the user interface according to link type ui.setupUi(this); - // Center the window on the screen. - QRect position = frameGeometry(); - position.moveCenter(QDesktopWidget().availableGeometry().center()); - move(position.topLeft()); - // Initialize basic ui state // Do not allow changes here unless advanced is checked From 6f8802dabb09f1287e25e6d0543fc41a1d382788 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Tue, 8 Oct 2013 23:26:50 +0100 Subject: [PATCH 04/13] CommConfigurationWindow - changing the link type should update the window --- src/ui/CommConfigurationWindow.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index ffb163b..81bb4b6 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -183,9 +183,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn qDebug() << "Link is NOT a known link, can't open configuration window"; } -#ifdef XBEELINK connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(setLinkType(int))); -#endif // XBEELINK // Open details pane for MAVLink if necessary MAVLinkProtocol* mavlink = dynamic_cast(protocol); From 96ab4dc87d428348b0588037167bccf053978b43 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Wed, 9 Oct 2013 00:18:47 +0100 Subject: [PATCH 05/13] Comm Settings - move the "link type" combobox to the top, and clean it up * The "Simulation" option is now not selectable. * If the link is a simulation, then you can't change it to a different link type. * The OPAL option is not shown if support is not compiled in. * Fix the buddy, tab order and accelerators in the GUI. --- src/ui/CommConfigurationWindow.cc | 38 ++++++++++------- src/ui/CommConfigurationWindow.h | 7 +++- src/ui/CommSettings.ui | 87 ++++++++++++++++++++++++++++----------- 3 files changed, 94 insertions(+), 38 deletions(-) diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 81bb4b6..462f1c4 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -66,7 +66,6 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn // Do not allow changes here unless advanced is checked ui.connectionType->setEnabled(false); - ui.linkType->setEnabled(false); ui.protocolGroupBox->setVisible(false); ui.protocolTypeGroupBox->setVisible(false); @@ -78,14 +77,19 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn //connect(ui.advCheckBox,SIGNAL(clicked(bool)),ui.advancedOptionsCheckBox,SLOT(setChecked(bool))); connect(ui.advCheckBox,SIGNAL(clicked(bool)),ui.protocolTypeGroupBox,SLOT(setVisible(bool))); connect(ui.advCheckBox, SIGNAL(clicked(bool)), ui.connectionType, SLOT(setEnabled(bool))); - connect(ui.advCheckBox, SIGNAL(clicked(bool)), ui.linkType, SLOT(setEnabled(bool))); connect(ui.advCheckBox, SIGNAL(clicked(bool)), ui.protocolGroupBox, SLOT(setVisible(bool))); // add link types ui.linkType->addItem(tr("Serial"), QGC_LINK_SERIAL); ui.linkType->addItem(tr("UDP"), QGC_LINK_UDP); - ui.linkType->addItem(tr("Simulation"), QGC_LINK_SIMULATION); + if(dynamic_cast(link)) { + //Only show simulation option if already setup elsewhere as a simulation + ui.linkType->addItem(tr("Simulation"), QGC_LINK_SIMULATION); + } + +#ifdef OPAL_RT ui.linkType->addItem(tr("Opal-RT Link"), QGC_LINK_OPAL); +#endif #ifdef XBEELINK ui.linkType->addItem(tr("Xbee API"),QGC_LINK_XBEE); #endif // XBEELINK @@ -135,18 +139,19 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn QWidget* conf = new SerialConfigurationWindow(serial, this); ui.linkScrollArea->setWidget(conf); ui.linkGroupBox->setTitle(tr("Serial Link")); - ui.linkType->setCurrentIndex(0); + ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_SERIAL)); } UDPLink* udp = dynamic_cast(link); if (udp != 0) { QWidget* conf = new QGCUDPLinkConfiguration(udp, this); ui.linkScrollArea->setWidget(conf); ui.linkGroupBox->setTitle(tr("UDP Link")); - ui.linkType->setCurrentIndex(1); + ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_UDP)); } MAVLinkSimulationLink* sim = dynamic_cast(link); if (sim != 0) { - ui.linkType->setCurrentIndex(2); + ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_SIMULATION)); + ui.linkType->setEnabled(false); //Don't allow the user to change to a non-simulation ui.linkGroupBox->setTitle(tr("MAVLink Simulation Link")); } #ifdef OPAL_RT @@ -156,7 +161,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight, ui.linkGroupBox); layout->addWidget(conf); ui.linkGroupBox->setLayout(layout); - ui.linkType->setCurrentIndex(3); + ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_OPAL)); ui.linkGroupBox->setTitle(tr("Opal-RT Link")); } #endif @@ -167,7 +172,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn QWidget* conf = new XbeeConfigurationWindow(xbee,this); ui.linkScrollArea->setWidget(conf); ui.linkGroupBox->setTitle(tr("Xbee Link")); - ui.linkType->setCurrentIndex(4); + ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_XBEE)); connect(xbee,SIGNAL(tryConnectBegin(bool)),ui.actionConnect,SLOT(setDisabled(bool))); connect(xbee,SIGNAL(tryConnectEnd(bool)),ui.actionConnect,SLOT(setEnabled(bool))); } @@ -183,7 +188,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn qDebug() << "Link is NOT a known link, can't open configuration window"; } - connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(setLinkType(int))); + connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(linkCurrentIndexChanged(int))); // Open details pane for MAVLink if necessary MAVLinkProtocol* mavlink = dynamic_cast(protocol); @@ -213,7 +218,12 @@ QAction* CommConfigurationWindow::getAction() return action; } -void CommConfigurationWindow::setLinkType(int linktype) +void CommConfigurationWindow::linkCurrentIndexChanged(int currentIndex) +{ + setLinkType(static_cast(ui.linkType->itemData(currentIndex).toInt())); +} + +void CommConfigurationWindow::setLinkType(qgc_link_t linktype) { if(link->isConnected()) { @@ -230,7 +240,7 @@ void CommConfigurationWindow::setLinkType(int linktype) switch(linktype) { #ifdef XBEELINK - case 4: + case QGC_LINK_XBEE: { XbeeLink *xbee = new XbeeLink(); tmpLink = xbee; @@ -238,7 +248,7 @@ void CommConfigurationWindow::setLinkType(int linktype) break; } #endif // XBEELINK - case 1: + case QGC_LINK_UDP: { UDPLink *udp = new UDPLink(); tmpLink = udp; @@ -247,7 +257,7 @@ void CommConfigurationWindow::setLinkType(int linktype) } #ifdef OPAL_RT - case 3: + case QGC_LINK_OPAL: { OpalLink* opal = new OpalLink(); tmpLink = opal; @@ -258,7 +268,7 @@ void CommConfigurationWindow::setLinkType(int linktype) default: { } - case 0: + case QGC_LINK_SERIAL: { SerialLink *serial = new SerialLink(); tmpLink = serial; diff --git a/src/ui/CommConfigurationWindow.h b/src/ui/CommConfigurationWindow.h index 65912b0..47e2b4c 100644 --- a/src/ui/CommConfigurationWindow.h +++ b/src/ui/CommConfigurationWindow.h @@ -47,7 +47,9 @@ enum qgc_link_t { #ifdef XBEELINK QGC_LINK_XBEE, #endif +#ifdef OPAL_RT QGC_LINK_OPAL +#endif }; enum qgc_protocol_t { @@ -71,9 +73,12 @@ public: ~CommConfigurationWindow(); QAction* getAction(); + void setLinkType(qgc_link_t linktype); + +private slots: + void linkCurrentIndexChanged(int currentIndex); public slots: - void setLinkType(int linktype); /** @brief Set the protocol for this link */ void setProtocol(int protocol); void setConnection(); diff --git a/src/ui/CommSettings.ui b/src/ui/CommSettings.ui index 73b4d76..e04678c 100644 --- a/src/ui/CommSettings.ui +++ b/src/ui/CommSettings.ui @@ -15,6 +15,23 @@ + + + + + Link &Type: + + + linkType + + + + + + + + + Link @@ -23,7 +40,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -36,8 +62,8 @@ 0 0 - 292 - 81 + 298 + 90 @@ -49,7 +75,7 @@ - Show Advanced Protocol Options + &Show Advanced Protocol Options @@ -61,34 +87,27 @@ - - - - Link Type - - - - - - -1 - - + + - Advanced Options + &Protocol: + + + connectionType - - + + - Protocol + &Advanced Options @@ -113,7 +132,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -126,8 +154,8 @@ 0 0 - 292 - 81 + 298 + 90 @@ -217,7 +245,20 @@ connectionStatusLabel advCheckBox protocolTypeGroupBox + linkType + label + + linkType + linkScrollArea + advCheckBox + connectionType + advancedOptionsCheckBox + protocolScrollArea + connectButton + deleteButton + closeButton + From b0d4abacd47c37ddda1b6ad13099b94bd125fde2 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Thu, 10 Oct 2013 11:27:36 +0100 Subject: [PATCH 06/13] Change QString function parameters to const QString & --- src/ui/linechart/ChartPlot.cc | 2 +- src/ui/linechart/ChartPlot.h | 2 +- src/ui/linechart/IncrementalPlot.cc | 8 ++++---- src/ui/linechart/IncrementalPlot.h | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ui/linechart/ChartPlot.cc b/src/ui/linechart/ChartPlot.cc index 665ff52..a1741f8 100644 --- a/src/ui/linechart/ChartPlot.cc +++ b/src/ui/linechart/ChartPlot.cc @@ -70,7 +70,7 @@ QColor ChartPlot::getNextColor() return colors[nextColorIndex++]; } -QColor ChartPlot::getColorForCurve(QString id) +QColor ChartPlot::getColorForCurve(const QString &id) { return curves.value(id)->pen().color(); } diff --git a/src/ui/linechart/ChartPlot.h b/src/ui/linechart/ChartPlot.h index 74a2320..c5196ae 100644 --- a/src/ui/linechart/ChartPlot.h +++ b/src/ui/linechart/ChartPlot.h @@ -17,7 +17,7 @@ public: QColor getNextColor(); /** @brief Get color for curve id */ - QColor getColorForCurve(QString id); + QColor getColorForCurve(const QString &id); /** @brief Reset color map */ void shuffleColors(); diff --git a/src/ui/linechart/IncrementalPlot.cc b/src/ui/linechart/IncrementalPlot.cc index d227105..6a5e13f 100644 --- a/src/ui/linechart/IncrementalPlot.cc +++ b/src/ui/linechart/IncrementalPlot.cc @@ -155,7 +155,7 @@ void IncrementalPlot::showLegend(bool show) * * @param style Formatting string for line/data point style */ -void IncrementalPlot::setStyleText(QString style) +void IncrementalPlot::setStyleText(const QString &style) { foreach (QwtPlotCurve* curve, curves) { // Style of datapoints @@ -250,12 +250,12 @@ void IncrementalPlot::updateScale() zoomer->setZoomBase(true); } -void IncrementalPlot::appendData(QString key, double x, double y) +void IncrementalPlot::appendData(const QString &key, double x, double y) { appendData(key, &x, &y, 1); } -void IncrementalPlot::appendData(QString key, double *x, double *y, int size) +void IncrementalPlot::appendData(const QString &key, double *x, double *y, int size) { CurveData* data; QwtPlotCurve* curve; @@ -349,7 +349,7 @@ void IncrementalPlot::appendData(QString key, double *x, double *y, int size) /** * @return Number of copied data points, 0 on failure */ -int IncrementalPlot::data(QString key, double* r_x, double* r_y, int maxSize) +int IncrementalPlot::data(const QString &key, double* r_x, double* r_y, int maxSize) { int result = 0; if (d_data.contains(key)) { diff --git a/src/ui/linechart/IncrementalPlot.h b/src/ui/linechart/IncrementalPlot.h index 06dee02..0b7f2d3 100644 --- a/src/ui/linechart/IncrementalPlot.h +++ b/src/ui/linechart/IncrementalPlot.h @@ -84,14 +84,14 @@ public: bool gridEnabled(); /** @brief Read out data from a curve */ - int data(QString key, double* r_x, double* r_y, int maxSize); + int data(const QString &key, double* r_x, double* r_y, int maxSize); public slots: /** @brief Append one data point */ - void appendData(QString key, double x, double y); + void appendData(const QString &key, double x, double y); /** @brief Append multiple data points */ - void appendData(QString key, double* x, double* y, int size); + void appendData(const QString &key, double* x, double* y, int size); /** @brief Reset the plot scaling to the default value */ void resetScaling(); @@ -109,7 +109,7 @@ public slots: void showGrid(bool show); /** @brief Set new plot style */ - void setStyleText(QString style); + void setStyleText(const QString &style); /** @brief Set symmetric axis scaling mode */ void setSymmetric(bool symmetric); From 8538e1a8da14e251eb3423221a705b9db0d7d0e6 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Thu, 10 Oct 2013 13:32:23 +0100 Subject: [PATCH 07/13] LinechartWidget - Make the scaling log button a propper toggle button --- src/ui/linechart/LinechartWidget.cc | 40 +++++++++++++++++-------------------- src/ui/linechart/LinechartWidget.h | 4 +--- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 53dcac3..459022c 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -225,23 +225,14 @@ void LinechartWidget::createLayout() layout->setRowStretch(0, 10); layout->setRowStretch(1, 1); - // Linear scaling button - scalingLinearButton = createButton(this); - scalingLinearButton->setDefaultAction(setScalingLinear); - scalingLinearButton->setCheckable(true); - scalingLinearButton->setToolTip(tr("Set linear scale for Y axis")); - scalingLinearButton->setWhatsThis(tr("Set linear scale for Y axis")); - layout->addWidget(scalingLinearButton, 1, 0); - layout->setColumnStretch(0, 0); - // Logarithmic scaling button scalingLogButton = createButton(this); - scalingLogButton->setDefaultAction(setScalingLogarithmic); + scalingLogButton->setText(tr("LOG")); scalingLogButton->setCheckable(true); scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis")); scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis")); - layout->addWidget(scalingLogButton, 1, 1); - layout->setColumnStretch(1, 0); + layout->addWidget(scalingLogButton, 1, 0); + layout->setColumnStretch(0, 0); // Averaging spin box averageSpinBox = new QSpinBox(this); @@ -251,8 +242,8 @@ void LinechartWidget::createLayout() averageSpinBox->setValue(200); setAverageWindow(200); averageSpinBox->setMaximum(9999); - layout->addWidget(averageSpinBox, 1, 2); - layout->setColumnStretch(2, 0); + layout->addWidget(averageSpinBox, 1, 1); + layout->setColumnStretch(1, 0); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); // Log Button @@ -260,8 +251,8 @@ void LinechartWidget::createLayout() logButton->setToolTip(tr("Start to log curve data into a CSV or TXT file")); logButton->setWhatsThis(tr("Start to log curve data into a CSV or TXT file")); logButton->setText(tr("Start Logging")); - layout->addWidget(logButton, 1, 3); - layout->setColumnStretch(3, 0); + layout->addWidget(logButton, 1, 2); + layout->setColumnStretch(2, 0); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); // Ground time button @@ -269,8 +260,8 @@ void LinechartWidget::createLayout() timeButton->setText(tr("Ground Time")); 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.")); - layout->addWidget(timeButton, 1, 4); - layout->setColumnStretch(4, 0); + layout->addWidget(timeButton, 1, 3); + layout->setColumnStretch(3, 0); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); @@ -294,8 +285,15 @@ void LinechartWidget::createLayout() connect(this, SIGNAL(plotWindowPositionUpdated(quint64)), activePlot, SLOT(setWindowPosition(quint64))); // Set scaling - connect(scalingLinearButton, SIGNAL(clicked()), activePlot, SLOT(setLinearScaling())); - connect(scalingLogButton, SIGNAL(clicked()), activePlot, SLOT(setLogarithmicScaling())); + connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool))); +} + +void LinechartWidget::toggleLogarithmicScaling(bool checked) +{ + if(checked) + activePlot->setLogarithmicScaling(); + else + activePlot->setLinearScaling(); } void LinechartWidget::appendData(int uasId, const QString& curve, const QString& unit, qint8 value, quint64 usec) @@ -626,8 +624,6 @@ void LinechartWidget::setAverageWindow(int windowSize) void LinechartWidget::createActions() { - setScalingLogarithmic = new QAction("LOG", this); - setScalingLinear = new QAction("LIN", this); } /** diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index a775c30..e9caf11 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -96,6 +96,7 @@ public slots: /** @brief Append double data to the given curve. */ void appendData(int uasId, const QString& curve, const QString& unit, double value, quint64 usec); + void toggleLogarithmicScaling(bool toggled); void takeButtonClick(bool checked); void setPlotWindowPosition(int scrollBarValue); void setPlotWindowPosition(quint64 position); @@ -152,14 +153,11 @@ protected: QScrollBar* scrollbar; ///< The plot window scroll bar QSpinBox* averageSpinBox; ///< Spin box to setup average window filter size - QAction* setScalingLogarithmic; ///< Set logarithmic scaling - QAction* setScalingLinear; ///< Set linear scaling QAction* addNewCurve; ///< Add curve candidate to the active curves QMenu* curveMenu; QGridLayout* mainLayout; - QToolButton* scalingLinearButton; QToolButton* scalingLogButton; QToolButton* logButton; QPointer timeButton; From d046a5f2fd0f526ce208b08f610cf887b8dbb723 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Fri, 11 Oct 2013 17:43:06 +0100 Subject: [PATCH 08/13] Linechart - Make it possible to change time axis range --- src/ui/linechart/LinechartPlot.cc | 28 +++++++++++++++---- src/ui/linechart/LinechartWidget.cc | 56 ++++++++++++++++++++++++++----------- src/ui/linechart/LinechartWidget.h | 6 +++- 3 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 9a6c995..4b64564 100644 --- a/src/ui/linechart/LinechartPlot.cc +++ b/src/ui/linechart/LinechartPlot.cc @@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval() **/ void LinechartPlot::setPlotInterval(int interval) { - plotInterval = interval; - QMap::iterator j; - for(j = data.begin(); j != data.end(); ++j) - { - TimeSeriesData* d = data.value(j.key()); - d->setInterval(interval); + //Only ever increase the amount of stored data, + // so that we allow the user to change between + // different intervals without constantly losing + // data points + if((unsigned)interval > plotInterval) { + + QMap::iterator j; + for(j = data.begin(); j != data.end(); ++j) + { + TimeSeriesData* d = data.value(j.key()); + d->setInterval(interval); + } } + plotInterval = interval; + if(plotInterval > 5*60*1000) //If the interval is longer than 4 minutes, change the time scale step to 2 minutes + timeScaleStep = 2*60*1000; + else if(plotInterval >= 4*60*1000) //If the interval is longer than 4 minutes, change the time scale step to 1 minutes + timeScaleStep = 1*60*1000; + else if(plotInterval >= 60*1000) //If the interval is longer than a minute, change the time scale step to 30 seconds + timeScaleStep = 30*1000; + else + timeScaleStep = DEFAULT_SCALE_INTERVAL; + } /** diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 459022c..1c154f9 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -207,10 +207,9 @@ void LinechartWidget::createLayout() createActions(); // Setup the plot group box area layout - QGridLayout* layout = new QGridLayout(ui.diagramGroupBox); - mainLayout = layout; - layout->setSpacing(4); - layout->setMargin(2); + QVBoxLayout* vlayout = new QVBoxLayout(ui.diagramGroupBox); + vlayout->setSpacing(4); + vlayout->setMargin(2); // Create plot container widget activePlot = new LinechartPlot(this, sysid); @@ -221,9 +220,10 @@ void LinechartWidget::createLayout() // activePlot = getPlot(0); // plotContainer->setPlot(activePlot); - layout->addWidget(activePlot, 0, 0, 1, 6); - layout->setRowStretch(0, 10); - layout->setRowStretch(1, 1); + vlayout->addWidget(activePlot); + + QHBoxLayout *hlayout = new QHBoxLayout; + vlayout->addLayout(hlayout); // Logarithmic scaling button scalingLogButton = createButton(this); @@ -231,8 +231,7 @@ void LinechartWidget::createLayout() scalingLogButton->setCheckable(true); scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis")); scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis")); - layout->addWidget(scalingLogButton, 1, 0); - layout->setColumnStretch(0, 0); + hlayout->addWidget(scalingLogButton); // Averaging spin box averageSpinBox = new QSpinBox(this); @@ -242,8 +241,7 @@ void LinechartWidget::createLayout() averageSpinBox->setValue(200); setAverageWindow(200); averageSpinBox->setMaximum(9999); - layout->addWidget(averageSpinBox, 1, 1); - layout->setColumnStretch(1, 0); + hlayout->addWidget(averageSpinBox); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); // Log Button @@ -251,8 +249,7 @@ void LinechartWidget::createLayout() logButton->setToolTip(tr("Start to log curve data into a CSV or TXT file")); logButton->setWhatsThis(tr("Start to log curve data into a CSV or TXT file")); logButton->setText(tr("Start Logging")); - layout->addWidget(logButton, 1, 2); - layout->setColumnStretch(2, 0); + hlayout->addWidget(logButton); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); // Ground time button @@ -260,17 +257,37 @@ void LinechartWidget::createLayout() timeButton->setText(tr("Ground Time")); 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.")); - layout->addWidget(timeButton, 1, 3); - layout->setColumnStretch(3, 0); + hlayout->addWidget(timeButton); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); + hlayout->addStretch(); + + QLabel *timeScaleLabel = new QLabel("Time axis:"); + hlayout->addWidget(timeScaleLabel); + + timeScaleCmb = new QComboBox(this); + timeScaleCmb->addItem("10 seconds", 10); + timeScaleCmb->addItem("20 seconds", 20); + timeScaleCmb->addItem("30 seconds", 30); + timeScaleCmb->addItem("40 seconds", 40); + timeScaleCmb->addItem("50 seconds", 50); + timeScaleCmb->addItem("1 minute", 60); + timeScaleCmb->addItem("2 minutes", 60*2); + timeScaleCmb->addItem("3 minutes", 60*3); + timeScaleCmb->addItem("4 minutes", 60*4); + timeScaleCmb->addItem("5 minutes", 60*5); + timeScaleCmb->addItem("10 minutes", 60*10); + //timeScaleCmb->setSizeAdjustPolicy(QComboBox::AdjustToContents); + timeScaleCmb->setMinimumContentsLength(12); + + hlayout->addWidget(timeScaleCmb); + connect(timeScaleCmb, SIGNAL(currentIndexChanged(int)), this, SLOT(timeScaleChanged(int))); + // 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())); - ui.diagramGroupBox->setLayout(layout); - // Add actions averageSpinBox->setValue(activePlot->getAverageWindow()); @@ -288,6 +305,11 @@ void LinechartWidget::createLayout() connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool))); } +void LinechartWidget::timeScaleChanged(int index) +{ + activePlot->setPlotInterval(timeScaleCmb->itemData(index).toInt()*1000); +} + void LinechartWidget::toggleLogarithmicScaling(bool checked) { if(checked) diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index e9caf11..de090b9 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -123,6 +123,10 @@ public slots: /** @brief Select all curves */ void selectAllCurves(bool all); +private slots: + /** Called when the user changes the time scale combobox. */ + void timeScaleChanged(int index); + protected: void addCurveToList(QString curve); void removeCurveFromList(QString curve); @@ -156,7 +160,7 @@ protected: QAction* addNewCurve; ///< Add curve candidate to the active curves QMenu* curveMenu; - QGridLayout* mainLayout; + QComboBox *timeScaleCmb; QToolButton* scalingLogButton; QToolButton* logButton; From a16f9bdf6ec10dd2e72ab4bbc8c879019c8c8949 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sat, 12 Oct 2013 23:30:09 +0100 Subject: [PATCH 09/13] Improve the UI for editing a text label --- src/ui/designer/QGCTextLabel.cc | 35 ++------- src/ui/designer/QGCTextLabel.h | 1 + src/ui/designer/QGCTextLabel.ui | 160 +++++++++++++++++++--------------------- 3 files changed, 82 insertions(+), 114 deletions(-) diff --git a/src/ui/designer/QGCTextLabel.cc b/src/ui/designer/QGCTextLabel.cc index dd2bbf9..b1b1731 100644 --- a/src/ui/designer/QGCTextLabel.cc +++ b/src/ui/designer/QGCTextLabel.cc @@ -19,13 +19,7 @@ QGCTextLabel::QGCTextLabel(QWidget *parent) : // Hide all edit items ui->editFinishButton->hide(); ui->editNameLabel->hide(); - ui->editTextParam->hide(); - ui->editComponentSpinBox->hide(); ui->editLine1->hide(); - ui->editLine2->hide(); - - // Add commands to combo box - } QGCTextLabel::~QGCTextLabel() @@ -37,13 +31,9 @@ void QGCTextLabel::startEditMode() { // Hide elements ui->nameLabel->hide(); - - ui->editTextParam->show(); ui->editFinishButton->show(); ui->editNameLabel->show(); - ui->editComponentSpinBox->show(); ui->editLine1->show(); - ui->editLine2->show(); // Attempt to undock the dock widget QWidget* p = this; @@ -66,12 +56,8 @@ void QGCTextLabel::startEditMode() void QGCTextLabel::endEditMode() { ui->editFinishButton->hide(); - ui->editTextParam->hide(); ui->editNameLabel->hide(); - ui->editComponentSpinBox->hide(); ui->editLine1->hide(); - ui->editLine2->hide(); - ui->nameLabel->show(); // Write to settings @@ -105,23 +91,17 @@ void QGCTextLabel::writeSettings(QSettings& settings) } void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings) { - ui->editTextParam->setText(settings.value(pre + "QGC_TEXT_SOURCE", "UNKNOWN").toString()); - //ui->editCommandComboBox->setCurrentIndex(settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt()); - if (ui->editTextParam->text() == "NONE") + ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV"); + if (!ui->isMavCommand->isChecked()) { ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString()); ui->nameLabel->setText(ui->editNameLabel->text()); } - else if (ui->editTextParam->text() == "MAV") + else { //MAV command text connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString))); } - - //int commandId = settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt(); - - //ui->editNameLabel->setText(settings.value(pre + "QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); - //ui->nameLabel->setText(settings.value(pre + "QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); } void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message) { @@ -148,17 +128,14 @@ void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, Q void QGCTextLabel::readSettings(const QSettings& settings) { - //ui->editNameLabel->setText(settings.value("QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); - //ui->nameLabel->setText(settings.value("QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); - ui->editTextParam->setText(settings.value("QGC_TEXT_SOURCE", "UNKNOWN").toString()); + ui->isMavCommand->setChecked(settings.value("QGC_TEXT_SOURCE", "NONE").toString() == "MAV"); ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); - //ui->editCommandComboBox->setCurrentIndex(settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt()); - if (ui->editTextParam->text() == "NONE") + if (!ui->isMavCommand->isChecked()) { ui->textLabel->setText(ui->editNameLabel->text()); ui->nameLabel->setText(""); } - else if (ui->editTextParam->text() == "MAV") + else { //MAV command text ui->nameLabel->setText(ui->editNameLabel->text()); diff --git a/src/ui/designer/QGCTextLabel.h b/src/ui/designer/QGCTextLabel.h index 3828d73..f4c23d2 100644 --- a/src/ui/designer/QGCTextLabel.h +++ b/src/ui/designer/QGCTextLabel.h @@ -26,6 +26,7 @@ public slots: void readSettings(const QSettings& settings); void readSettings(const QString& pre,const QVariantMap& settings); void textMessageReceived(int uasid, int componentId, int severity, QString message); + private: int enabledNum; Ui::QGCTextLabel *ui; diff --git a/src/ui/designer/QGCTextLabel.ui b/src/ui/designer/QGCTextLabel.ui index 78ba1dd..24d446e 100644 --- a/src/ui/designer/QGCTextLabel.ui +++ b/src/ui/designer/QGCTextLabel.ui @@ -6,34 +6,36 @@ 0 0 - 1183 - 166 + 554 + 107 Form - - - 6 - - - 3 - - - 6 - - - 3 - - - - - <Label Description Label (in front of text)> - - + + + + + + + + + + Label Description + + + + + + + Mav Command + + + + - + @@ -46,68 +48,56 @@ - - - - - 50 - 0 - - - - Description - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - <Text Param> - - + + + + + + + 50 + 0 + + + + Description + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + + - - - - Done - - - - - - - Component ID: - - - 0 - - - 255 - - - - - - - - 0 - 0 - - - - Qt::Horizontal - - - - - - - TextLabel - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Done + + + + @@ -120,8 +110,8 @@ setText(QString) - 114 - 22 + 280 + 32 114 From 42d68e1d4c3c2f1543b4e62a91677cecee9e478c Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sun, 13 Oct 2013 11:00:02 +0100 Subject: [PATCH 10/13] MainWindow - remove unnecessary static_cast --- src/ui/MainWindow.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 2a5450c..0f4da28 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -450,7 +450,7 @@ void MainWindow::buildCustomWidget() ui.menuTools->addAction(showAction);*/ // Load dock widget location (default is bottom) - Qt::DockWidgetArea location = static_cast (tool->getDockWidgetArea(currentView)); + Qt::DockWidgetArea location = tool->getDockWidgetArea(currentView); //addDockWidget(location, dock); //dock->hide(); From 9143c8c5cbba701c775fe28080895b5d3fd3f73f Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sun, 13 Oct 2013 13:11:51 +0100 Subject: [PATCH 11/13] Improve the UI for editing the Text Label --- src/ui/designer/QGCTextLabel.cc | 71 +++++++++++++++++++++++----------------- src/ui/designer/QGCTextLabel.h | 3 ++ src/ui/designer/QGCTextLabel.ui | 62 ++++++++++++++++++++++++++--------- src/ui/designer/QGCToolWidget.cc | 3 +- 4 files changed, 93 insertions(+), 46 deletions(-) diff --git a/src/ui/designer/QGCTextLabel.cc b/src/ui/designer/QGCTextLabel.cc index b1b1731..ceb645f 100644 --- a/src/ui/designer/QGCTextLabel.cc +++ b/src/ui/designer/QGCTextLabel.cc @@ -7,7 +7,7 @@ #include "UASManager.h" QGCTextLabel::QGCTextLabel(QWidget *parent) : - QGCToolWidgetItem("Command Button", parent), + QGCToolWidgetItem("Text Label", parent), ui(new Ui::QGCTextLabel) { uas = 0; @@ -15,11 +15,15 @@ QGCTextLabel::QGCTextLabel(QWidget *parent) : ui->setupUi(this); connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); + connect(ui->isMavCommand, SIGNAL(toggled(bool)), this, SLOT(update_isMavCommand())); // Hide all edit items ui->editFinishButton->hide(); ui->editNameLabel->hide(); ui->editLine1->hide(); + ui->editLine2->hide(); + ui->isMavCommand->hide(); + ui->textLabel->setText(QString()); } QGCTextLabel::~QGCTextLabel() @@ -30,10 +34,11 @@ QGCTextLabel::~QGCTextLabel() void QGCTextLabel::startEditMode() { // Hide elements - ui->nameLabel->hide(); ui->editFinishButton->show(); ui->editNameLabel->show(); ui->editLine1->show(); + ui->editLine2->show(); + ui->isMavCommand->show(); // Attempt to undock the dock widget QWidget* p = this; @@ -55,10 +60,12 @@ void QGCTextLabel::startEditMode() void QGCTextLabel::endEditMode() { + update_isMavCommand(); ui->editFinishButton->hide(); ui->editNameLabel->hide(); ui->editLine1->hide(); - ui->nameLabel->show(); + ui->editLine2->hide(); + ui->isMavCommand->hide(); // Write to settings emit editingFinished(); @@ -83,25 +90,17 @@ void QGCTextLabel::endEditMode() void QGCTextLabel::writeSettings(QSettings& settings) { - qDebug() << "COMMAND BUTTON WRITING SETTINGS"; - settings.setValue("TYPE", "COMMANDBUTTON"); - settings.setValue("QGC_COMMAND_BUTTON_DESCRIPTION", ui->nameLabel->text()); + settings.setValue("TYPE", "TEXT"); + settings.setValue("QGC_TEXT_TEXT", ui->editNameLabel->text()); + settings.setValue("QGC_TEXT_SOURCE", ui->isMavCommand->isChecked()?"MAV":"NONE"); settings.sync(); } void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings) { + ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString()); ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV"); - if (!ui->isMavCommand->isChecked()) - { - ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString()); - ui->nameLabel->setText(ui->editNameLabel->text()); - } - else - { - //MAV command text - connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString))); - } + update_isMavCommand(); } void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message) { @@ -128,28 +127,40 @@ void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, Q void QGCTextLabel::readSettings(const QSettings& settings) { + ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); //Place this before setting isMavCommand ui->isMavCommand->setChecked(settings.value("QGC_TEXT_SOURCE", "NONE").toString() == "MAV"); - ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); - if (!ui->isMavCommand->isChecked()) - { - ui->textLabel->setText(ui->editNameLabel->text()); - ui->nameLabel->setText(""); - } - else - { - //MAV command text - ui->nameLabel->setText(ui->editNameLabel->text()); - ui->textLabel->setText(""); - connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString))); - } + update_isMavCommand(); } + void QGCTextLabel::enableText(int num) { enabledNum = num; - } void QGCTextLabel::setActiveUAS(UASInterface *uas) { + if(this->uas) + this->uas->disconnect(this); this->uas = uas; + update_isMavCommand(); //Might need to update the signal connections +} + +void QGCTextLabel::update_isMavCommand() +{ + ui->textLabel->setText(""); + if (!ui->isMavCommand->isChecked()) + { + ui->nameLabel->setText(ui->editNameLabel->text()); + if(this->uas) + disconnect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString))); + if(ui->nameLabel->text().isEmpty()) + ui->nameLabel->setText(tr("Text Label")); //Show something, so that we don't end up with just an empty label + } + else + { + //MAV command text + ui->nameLabel->setText(ui->editNameLabel->text()); + if(this->uas) + connect(uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(textMessageReceived(int,int,int,QString))); + } } diff --git a/src/ui/designer/QGCTextLabel.h b/src/ui/designer/QGCTextLabel.h index f4c23d2..a1c1d1d 100644 --- a/src/ui/designer/QGCTextLabel.h +++ b/src/ui/designer/QGCTextLabel.h @@ -27,6 +27,9 @@ public slots: void readSettings(const QString& pre,const QVariantMap& settings); void textMessageReceived(int uasid, int componentId, int severity, QString message); +private slots: + void update_isMavCommand(); + private: int enabledNum; Ui::QGCTextLabel *ui; diff --git a/src/ui/designer/QGCTextLabel.ui b/src/ui/designer/QGCTextLabel.ui index 24d446e..f5f909d 100644 --- a/src/ui/designer/QGCTextLabel.ui +++ b/src/ui/designer/QGCTextLabel.ui @@ -15,6 +15,19 @@ + + + + 0 + 0 + + + + Qt::Horizontal + + + + @@ -28,6 +41,9 @@ + + This is only for advanced use, and allows a label to display the results of a Command Button. + Mav Command @@ -36,19 +52,6 @@ - - - - 0 - 0 - - - - Qt::Horizontal - - - - @@ -59,7 +62,7 @@ - Description + Text Label Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -69,7 +72,7 @@ - TextLabel + mav result @@ -99,6 +102,19 @@ + + + + + 0 + 0 + + + + Qt::Horizontal + + + @@ -119,5 +135,21 @@ + + editNameLabel + returnPressed() + editFinishButton + animateClick() + + + 136 + 20 + + + 498 + 86 + + + diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index 7f976f6..f5302d7 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -296,7 +296,7 @@ void QGCToolWidget::loadSettings(QVariantMap& settings) else if (type == "COMBO") { item = new QGCComboBox(this); - //qDebug() << "CREATED PARAM COMBOBOX"; + //qDebug() << "CREATED COMBOBOX"; } if (item) { @@ -482,6 +482,7 @@ void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event) QMenu menu(this); menu.addAction(addParamAction); menu.addAction(addCommandAction); + menu.addAction(addLabelAction); menu.addSeparator(); menu.addAction(setTitleAction); menu.addAction(exportAction); From ca68c1e93ab7afc9eb51937a177b2b3987cd5b28 Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sun, 13 Oct 2013 13:13:26 +0100 Subject: [PATCH 12/13] Allow user to add a label to a custom widget --- src/ui/designer/QGCToolWidget.cc | 12 ++++++++++++ src/ui/designer/QGCToolWidget.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index f5302d7..df998b8 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -518,6 +518,10 @@ void QGCToolWidget::createActions() addCommandAction->setStatusTip(tr("Add a new action button to the tool")); connect(addCommandAction, SIGNAL(triggered()), this, SLOT(addCommand())); + addLabelAction = new QAction(tr("New &Text Label"), this); + addLabelAction->setStatusTip(tr("Add a new label to the tool")); + connect(addLabelAction, SIGNAL(triggered()), this, SLOT(addLabel())); + setTitleAction = new QAction(tr("Set Widget Title"), this); setTitleAction->setStatusTip(tr("Set the title caption of this tool widget")); connect(setTitleAction, SIGNAL(triggered()), this, SLOT(setTitle())); @@ -591,6 +595,14 @@ void QGCToolWidget::addCommand() button->startEditMode(); } +void QGCToolWidget::addLabel() +{ + QGCTextLabel* label= new QGCTextLabel(this); + connect(label, SIGNAL(destroyed()), this, SLOT(storeSettings())); + toolLayout->addWidget(label); + label->startEditMode(); +} + void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget) { if (ui->hintLabel) diff --git a/src/ui/designer/QGCToolWidget.h b/src/ui/designer/QGCToolWidget.h index c3abb0f..818140e 100644 --- a/src/ui/designer/QGCToolWidget.h +++ b/src/ui/designer/QGCToolWidget.h @@ -74,6 +74,7 @@ protected: QVariantMap settingsMap; QAction* addParamAction; QAction* addCommandAction; + QAction* addLabelAction; QAction* setTitleAction; QAction* deleteAction; QAction* exportAction; @@ -99,6 +100,7 @@ public slots: protected slots: void addParam(); void addCommand(); + void addLabel(); void setTitle(); void setWindowTitle(const QString& title); From 661b9aeb996770623d456db73533e67ad1edfaea Mon Sep 17 00:00:00 2001 From: John Tapsell Date: Sun, 13 Oct 2013 17:47:44 +0100 Subject: [PATCH 13/13] Fix changing the dock window title when not in advanced mode --- qgroundcontrol.pro | 6 +++-- src/ui/MainWindow.cc | 4 ++- src/ui/designer/QGCToolWidget.cc | 57 ++++++++-------------------------------- src/ui/dockwidgeteventfilter.cpp | 21 +++++++++++++++ src/ui/dockwidgeteventfilter.h | 16 +++++++++++ 5 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 src/ui/dockwidgeteventfilter.cpp create mode 100644 src/ui/dockwidgeteventfilter.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 3fb4c02..fcf375d 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -506,7 +506,8 @@ HEADERS += src/MG.h \ src/ui/px4_configuration/QGCPX4AirframeConfig.h \ src/ui/QGCBaseParamWidget.h \ src/ui/px4_configuration/QGCPX4MulticopterConfig.h \ - src/ui/px4_configuration/QGCPX4SensorCalibration.h + src/ui/px4_configuration/QGCPX4SensorCalibration.h \ + src/ui/dockwidgeteventfilter.h # Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h @@ -728,7 +729,8 @@ SOURCES += src/main.cc \ src/ui/px4_configuration/QGCPX4AirframeConfig.cc \ src/ui/QGCBaseParamWidget.cc \ src/ui/px4_configuration/QGCPX4MulticopterConfig.cc \ - src/ui/px4_configuration/QGCPX4SensorCalibration.cc + src/ui/px4_configuration/QGCPX4SensorCalibration.cc \ + src/ui/dockwidgeteventfilter.cpp # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 0f4da28..454c44d 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project #include #include #include "dockwidgettitlebareventfilter.h" +#include "dockwidgeteventfilter.h" #include "QGC.h" #include "MAVLinkSimulationLink.h" #include "SerialLink.h" @@ -895,7 +896,8 @@ void MainWindow::setDockWidgetTitleBar(QDockWidget* widget) { QLabel* label = new QLabel(this); label->setText(widget->windowTitle()); - label->installEventFilter(new DockWidgetTitleBarEventFilter()); + label->installEventFilter(new DockWidgetTitleBarEventFilter()); //Ignore mouse clicks + widget->installEventFilter(new DockWidgetEventFilter()); //Update label if window title changes widget->setTitleBarWidget(label); } // And if nothing should be shown, use an empty widget. diff --git a/src/ui/designer/QGCToolWidget.cc b/src/ui/designer/QGCToolWidget.cc index df998b8..bbd140d 100644 --- a/src/ui/designer/QGCToolWidget.cc +++ b/src/ui/designer/QGCToolWidget.cc @@ -33,26 +33,12 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s } //qDebug() << "WidgetTitle" << widgetTitle; - setObjectName(widgetTitle); createActions(); toolLayout = ui->toolLayout; toolLayout->setAlignment(Qt::AlignTop); toolLayout->setSpacing(8); - QDockWidget* dock = dynamic_cast(this->parentWidget()); - if (dock) { - dock->setWindowTitle(widgetTitle); - dock->setObjectName(widgetTitle+"DOCK"); - } - - // Try with parent - dock = dynamic_cast(parent); - if (dock) { - dock->setWindowTitle(widgetTitle); - dock->setObjectName(widgetTitle+"DOCK"); - } - - this->setWindowTitle(widgetTitle); + this->setTitle(widgetTitle); QList systems = UASManager::instance()->getUASList(); foreach (UASInterface* uas, systems) { @@ -63,7 +49,6 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s } } connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); - if (!instances()->contains(widgetTitle)) instances()->insert(widgetTitle, this); // Enforce storage if this not loaded from settings // is MUST NOT BE SAVED if it was loaded from settings! @@ -80,13 +65,7 @@ QGCToolWidget::~QGCToolWidget() void QGCToolWidget::setParent(QWidget *parent) { QWidget::setParent(parent); - // Try with parent - QDockWidget* dock = dynamic_cast(parent); - if (dock) - { - dock->setWindowTitle(getTitle()); - dock->setObjectName(getTitle()+"DOCK"); - } + setTitle(getTitle()); //Update titles } /** @@ -654,34 +633,20 @@ void QGCToolWidget::setTitle() } } -void QGCToolWidget::setWindowTitle(const QString& title) +void QGCToolWidget::setTitle(const QString& title) { - // Sets title and calls setWindowTitle on QWidget - widgetTitle = title; - QWidget::setWindowTitle(title); -} - -void QGCToolWidget::setTitle(QString title) -{ - // Remove references to old title - /*QSettings settings; - settings.beginGroup(widgetTitle); - settings.remove(""); - settings.endGroup(); - settings.sync();*/ - if (instances()->contains(widgetTitle)) instances()->remove(widgetTitle); + if (!instances()->contains(title)) instances()->insert(title, this); - // Switch to new title + // Sets title and calls setWindowTitle on QWidget widgetTitle = title; - - if (!instances()->contains(title)) instances()->insert(title, this); QWidget::setWindowTitle(title); - QDockWidget* parent = dynamic_cast(this->parentWidget()); - if (parent) parent->setWindowTitle(title); - // Store all widgets - //storeWidgetsToSettings(); - + setObjectName(widgetTitle); + QDockWidget* dock = dynamic_cast(this->parentWidget()); + if (dock) { + dock->setWindowTitle(widgetTitle); + dock->setObjectName(widgetTitle+"DOCK"); + } emit titleChanged(title); if (mainMenuAction) mainMenuAction->setText(title); } diff --git a/src/ui/dockwidgeteventfilter.cpp b/src/ui/dockwidgeteventfilter.cpp new file mode 100644 index 0000000..260e3a5 --- /dev/null +++ b/src/ui/dockwidgeteventfilter.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +#include "dockwidgeteventfilter.h" + +DockWidgetEventFilter::DockWidgetEventFilter(QObject *parent) : QObject(parent) {} + +bool DockWidgetEventFilter::eventFilter(QObject *object,QEvent *event) +{ + if (event->type() == QEvent::WindowTitleChange) + { + QDockWidget *dock = dynamic_cast(object); + if(dock) { + QLabel *label = dynamic_cast(dock->titleBarWidget()); + if(label) + label->setText(dock->windowTitle()); + } + } + return QObject::eventFilter(object,event); +} diff --git a/src/ui/dockwidgeteventfilter.h b/src/ui/dockwidgeteventfilter.h new file mode 100644 index 0000000..60de1e4 --- /dev/null +++ b/src/ui/dockwidgeteventfilter.h @@ -0,0 +1,16 @@ +#ifndef DOCKWIDGETEVENTFILTER_H +#define DOCKWIDGETEVENTFILTER_H + +#include + +/** Event filter to update a QLabel titleBarWidget if the window's title changes */ +class DockWidgetEventFilter : public QObject +{ + Q_OBJECT +public: + DockWidgetEventFilter(QObject *parent = 0); +protected: + virtual bool eventFilter(QObject *object,QEvent *event) override; +}; + +#endif // DOCKWIDGETEVENTFILTER_H