diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 3fb4c0281041756f61383f9dee6c3331d81e074c..fcf375d399d2fe112f6ea55d17a8d4911f4853c8 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/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 099c28f46453d6bad16149269f71a62d97ec0dc3..462f1c42cbb61c8960ef6d3e96b7b4f5b3f6fb69 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -55,23 +55,17 @@ 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; // 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 ui.connectionType->setEnabled(false); - ui.linkType->setEnabled(false); ui.protocolGroupBox->setVisible(false); ui.protocolTypeGroupBox->setVisible(false); @@ -83,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 @@ -140,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 @@ -161,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 @@ -172,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))); } @@ -188,9 +188,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 + connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(linkCurrentIndexChanged(int))); // Open details pane for MAVLink if necessary MAVLinkProtocol* mavlink = dynamic_cast(protocol); @@ -220,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()) { @@ -237,7 +240,7 @@ void CommConfigurationWindow::setLinkType(int linktype) switch(linktype) { #ifdef XBEELINK - case 4: + case QGC_LINK_XBEE: { XbeeLink *xbee = new XbeeLink(); tmpLink = xbee; @@ -245,7 +248,7 @@ void CommConfigurationWindow::setLinkType(int linktype) break; } #endif // XBEELINK - case 1: + case QGC_LINK_UDP: { UDPLink *udp = new UDPLink(); tmpLink = udp; @@ -254,7 +257,7 @@ void CommConfigurationWindow::setLinkType(int linktype) } #ifdef OPAL_RT - case 3: + case QGC_LINK_OPAL: { OpalLink* opal = new OpalLink(); tmpLink = opal; @@ -265,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 4333e5ad622c3864f976bd3c0f524e6246660370..47e2b4c8ff50bc7c5732d107ae5b4328eb79b268 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" @@ -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 { @@ -62,7 +64,7 @@ enum qgc_protocol_t { /** * @brief Configuration window for communication links */ -class CommConfigurationWindow : public QWidget +class CommConfigurationWindow : public QDialog { Q_OBJECT @@ -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 73b4d76efc1878c425e67d49f1dc961a966a8510..e04678c17aa92ae77e776d74776813402c00bbbb 100644 --- a/src/ui/CommSettings.ui +++ b/src/ui/CommSettings.ui @@ -14,6 +14,23 @@ Form + + + + + + Link &Type: + + + linkType + + + + + + + + @@ -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 + diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index 354c73b4b1d9bd2931bb3b0fb1554d73bfeccdf4..454c44d9d2b382fdd478eebda7fc9b68c1d3fcf9 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" @@ -450,7 +451,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(); @@ -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. @@ -1683,7 +1685,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(); diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 02dc9d1721d4c5888a3d29464eae02a9efbd646d..4a24151a1452bbad9b537ba968580390191bce4f 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 diff --git a/src/ui/designer/QGCTextLabel.cc b/src/ui/designer/QGCTextLabel.cc index dd2bbf940ce97afeaeee45e1859ab56e1d7bfee8..ceb645ffcf27ac3189103e9f0d709c8cd2432ef3 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,17 +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->editTextParam->hide(); - ui->editComponentSpinBox->hide(); ui->editLine1->hide(); ui->editLine2->hide(); - - // Add commands to combo box - + ui->isMavCommand->hide(); + ui->textLabel->setText(QString()); } QGCTextLabel::~QGCTextLabel() @@ -36,14 +34,11 @@ QGCTextLabel::~QGCTextLabel() 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(); + ui->isMavCommand->show(); // Attempt to undock the dock widget QWidget* p = this; @@ -65,14 +60,12 @@ void QGCTextLabel::startEditMode() void QGCTextLabel::endEditMode() { + update_isMavCommand(); ui->editFinishButton->hide(); - ui->editTextParam->hide(); ui->editNameLabel->hide(); - ui->editComponentSpinBox->hide(); ui->editLine1->hide(); ui->editLine2->hide(); - - ui->nameLabel->show(); + ui->isMavCommand->hide(); // Write to settings emit editingFinished(); @@ -97,31 +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->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->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString()); - ui->nameLabel->setText(ui->editNameLabel->text()); - } - else if (ui->editTextParam->text() == "MAV") - { - //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()); + ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString()); + ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV"); + update_isMavCommand(); } void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message) { @@ -148,31 +127,40 @@ 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->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") - { - ui->textLabel->setText(ui->editNameLabel->text()); - ui->nameLabel->setText(""); - } - else if (ui->editTextParam->text() == "MAV") - { - //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))); - } + 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"); + 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 3828d734fc7fd9a0462e7766fc65199ce768e073..a1c1d1d6cbf46931a1a73542a6aca857727e4c87 100644 --- a/src/ui/designer/QGCTextLabel.h +++ b/src/ui/designer/QGCTextLabel.h @@ -26,6 +26,10 @@ 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 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 78ba1dda55884e0df0c0dca04935d8808d11b4fb..f5f909d1fb5d60b271a5ccaf5b8f8bc1bdf79efb 100644 --- a/src/ui/designer/QGCTextLabel.ui +++ b/src/ui/designer/QGCTextLabel.ui @@ -6,34 +6,15 @@ 0 0 - 1183 - 166 + 554 + 107 Form - - - 6 - - - 3 - - - 6 - - - 3 - - - - - <Label Description Label (in front of text)> - - - - + + @@ -46,50 +27,82 @@ - - - - - 50 - 0 - - - - Description - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + + + + + Label Description + + + + + + + This is only for advanced use, and allows a label to display the results of a Command Button. + + + Mav Command + + + + - - - - <Text Param> - - + + + + + + + 50 + 0 + + + + Text Label + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + mav result + + + + - - - - Done - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Done + + + + - - - - Component ID: - - - 0 - - - 255 - - - - + @@ -102,13 +115,6 @@ - - - - TextLabel - - - @@ -120,8 +126,8 @@ setText(QString) - 114 - 22 + 280 + 32 114 @@ -129,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 7f976f68ae28352ac4a640f3b95a5b7d2df3061b..bbd140d5a7aa35a25c681c0a5744e32cd16588f9 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 } /** @@ -296,7 +275,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 +461,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); @@ -517,6 +497,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())); @@ -590,6 +574,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) @@ -641,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/designer/QGCToolWidget.h b/src/ui/designer/QGCToolWidget.h index c3abb0faf240834ddb16f57315d54e8db2c1e542..818140e80f53444bdeda2f2d4d7df7b304a7e716 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); diff --git a/src/ui/dockwidgeteventfilter.cpp b/src/ui/dockwidgeteventfilter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..260e3a5466614e1eb81f9827f6feb55a0ddfa238 --- /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 0000000000000000000000000000000000000000..60de1e4002bb942f609cb2fe859c8d18b82d9d24 --- /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 diff --git a/src/ui/linechart/ChartPlot.cc b/src/ui/linechart/ChartPlot.cc index 665ff5233674f633c6cf324359ae4681020c9620..a1741f85cfb8df5c7a1bf7f9506d75a12ec7e1cf 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 74a232039ed2ca9bf9be9c2e09a51cd7d0d13c6c..c5196ae8b506e3ba2cbd7efd8d3b32e80bd75c8b 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 d227105c4978e76e162b424b175fa49ee600853a..6a5e13f4de9c553cc2cec6266e2055f049c54ef0 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 06dee02ff04e90449343b0392e326d39ecc81c84..0b7f2d3b4f3a381cbfcb13e4c9e0a67561ab223f 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); diff --git a/src/ui/linechart/LinechartPlot.cc b/src/ui/linechart/LinechartPlot.cc index 9a6c995fef8eb6dbe966e4a8349d2061e5be6bd5..4b645645977beb16367d961b2d3fac5e1d6b7094 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 53dcac360cb7fe268483dfc9abc80c845d2708f6..1c154f98121ea468a985062c35360c3f7634213d 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,27 +220,18 @@ 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); - // 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); + QHBoxLayout *hlayout = new QHBoxLayout; + vlayout->addLayout(hlayout); // 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); + hlayout->addWidget(scalingLogButton); // Averaging spin box averageSpinBox = new QSpinBox(this); @@ -251,8 +241,7 @@ void LinechartWidget::createLayout() averageSpinBox->setValue(200); setAverageWindow(200); averageSpinBox->setMaximum(9999); - layout->addWidget(averageSpinBox, 1, 2); - layout->setColumnStretch(2, 0); + hlayout->addWidget(averageSpinBox); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); // Log Button @@ -260,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, 3); - layout->setColumnStretch(3, 0); + hlayout->addWidget(logButton); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); // Ground time button @@ -269,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, 4); - layout->setColumnStretch(4, 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()); @@ -294,8 +302,20 @@ 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::timeScaleChanged(int index) +{ + activePlot->setPlotInterval(timeScaleCmb->itemData(index).toInt()*1000); +} + +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 +646,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 a775c303f182764f4e5b25432de8ae37769ad63f..de090b92fd2bdd17cd698f0bea7cbc898d3b6ef3 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); @@ -122,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); @@ -152,14 +157,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; + QComboBox *timeScaleCmb; - QToolButton* scalingLinearButton; QToolButton* scalingLogButton; QToolButton* logButton; QPointer timeButton;