Commit d403e613 authored by Lorenz Meier's avatar Lorenz Meier

Merge pull request #393 from johnflux/config

Various improvements to DataPlot and Communication configuration window
parents 6cf29b5f 661b9aeb
...@@ -506,7 +506,8 @@ HEADERS += src/MG.h \ ...@@ -506,7 +506,8 @@ HEADERS += src/MG.h \
src/ui/px4_configuration/QGCPX4AirframeConfig.h \ src/ui/px4_configuration/QGCPX4AirframeConfig.h \
src/ui/QGCBaseParamWidget.h \ src/ui/QGCBaseParamWidget.h \
src/ui/px4_configuration/QGCPX4MulticopterConfig.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 # 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 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 \ ...@@ -728,7 +729,8 @@ SOURCES += src/main.cc \
src/ui/px4_configuration/QGCPX4AirframeConfig.cc \ src/ui/px4_configuration/QGCPX4AirframeConfig.cc \
src/ui/QGCBaseParamWidget.cc \ src/ui/QGCBaseParamWidget.cc \
src/ui/px4_configuration/QGCPX4MulticopterConfig.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 # 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 macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
......
...@@ -55,23 +55,17 @@ This file is part of the QGROUNDCONTROL project ...@@ -55,23 +55,17 @@ This file is part of the QGROUNDCONTROL project
#include "LinkManager.h" #include "LinkManager.h"
#include "MainWindow.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; this->link = link;
// Setup the user interface according to link type // Setup the user interface according to link type
ui.setupUi(this); ui.setupUi(this);
// Center the window on the screen.
QRect position = frameGeometry();
position.moveCenter(QDesktopWidget().availableGeometry().center());
move(position.topLeft());
// Initialize basic ui state // Initialize basic ui state
// Do not allow changes here unless advanced is checked // Do not allow changes here unless advanced is checked
ui.connectionType->setEnabled(false); ui.connectionType->setEnabled(false);
ui.linkType->setEnabled(false);
ui.protocolGroupBox->setVisible(false); ui.protocolGroupBox->setVisible(false);
ui.protocolTypeGroupBox->setVisible(false); ui.protocolTypeGroupBox->setVisible(false);
...@@ -83,14 +77,19 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -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.advancedOptionsCheckBox,SLOT(setChecked(bool)));
connect(ui.advCheckBox,SIGNAL(clicked(bool)),ui.protocolTypeGroupBox,SLOT(setVisible(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.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))); connect(ui.advCheckBox, SIGNAL(clicked(bool)), ui.protocolGroupBox, SLOT(setVisible(bool)));
// add link types // add link types
ui.linkType->addItem(tr("Serial"), QGC_LINK_SERIAL); ui.linkType->addItem(tr("Serial"), QGC_LINK_SERIAL);
ui.linkType->addItem(tr("UDP"), QGC_LINK_UDP); ui.linkType->addItem(tr("UDP"), QGC_LINK_UDP);
ui.linkType->addItem(tr("Simulation"), QGC_LINK_SIMULATION); if(dynamic_cast<MAVLinkSimulationLink*>(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); ui.linkType->addItem(tr("Opal-RT Link"), QGC_LINK_OPAL);
#endif
#ifdef XBEELINK #ifdef XBEELINK
ui.linkType->addItem(tr("Xbee API"),QGC_LINK_XBEE); ui.linkType->addItem(tr("Xbee API"),QGC_LINK_XBEE);
#endif // XBEELINK #endif // XBEELINK
...@@ -140,18 +139,19 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -140,18 +139,19 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
QWidget* conf = new SerialConfigurationWindow(serial, this); QWidget* conf = new SerialConfigurationWindow(serial, this);
ui.linkScrollArea->setWidget(conf); ui.linkScrollArea->setWidget(conf);
ui.linkGroupBox->setTitle(tr("Serial Link")); ui.linkGroupBox->setTitle(tr("Serial Link"));
ui.linkType->setCurrentIndex(0); ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_SERIAL));
} }
UDPLink* udp = dynamic_cast<UDPLink*>(link); UDPLink* udp = dynamic_cast<UDPLink*>(link);
if (udp != 0) { if (udp != 0) {
QWidget* conf = new QGCUDPLinkConfiguration(udp, this); QWidget* conf = new QGCUDPLinkConfiguration(udp, this);
ui.linkScrollArea->setWidget(conf); ui.linkScrollArea->setWidget(conf);
ui.linkGroupBox->setTitle(tr("UDP Link")); ui.linkGroupBox->setTitle(tr("UDP Link"));
ui.linkType->setCurrentIndex(1); ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_UDP));
} }
MAVLinkSimulationLink* sim = dynamic_cast<MAVLinkSimulationLink*>(link); MAVLinkSimulationLink* sim = dynamic_cast<MAVLinkSimulationLink*>(link);
if (sim != 0) { 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")); ui.linkGroupBox->setTitle(tr("MAVLink Simulation Link"));
} }
#ifdef OPAL_RT #ifdef OPAL_RT
...@@ -161,7 +161,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -161,7 +161,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight, ui.linkGroupBox); QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight, ui.linkGroupBox);
layout->addWidget(conf); layout->addWidget(conf);
ui.linkGroupBox->setLayout(layout); ui.linkGroupBox->setLayout(layout);
ui.linkType->setCurrentIndex(3); ui.linkType->setCurrentIndex(ui.linkType->findData(QGC_LINK_OPAL));
ui.linkGroupBox->setTitle(tr("Opal-RT Link")); ui.linkGroupBox->setTitle(tr("Opal-RT Link"));
} }
#endif #endif
...@@ -172,7 +172,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -172,7 +172,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
QWidget* conf = new XbeeConfigurationWindow(xbee,this); QWidget* conf = new XbeeConfigurationWindow(xbee,this);
ui.linkScrollArea->setWidget(conf); ui.linkScrollArea->setWidget(conf);
ui.linkGroupBox->setTitle(tr("Xbee Link")); 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(tryConnectBegin(bool)),ui.actionConnect,SLOT(setDisabled(bool)));
connect(xbee,SIGNAL(tryConnectEnd(bool)),ui.actionConnect,SLOT(setEnabled(bool))); connect(xbee,SIGNAL(tryConnectEnd(bool)),ui.actionConnect,SLOT(setEnabled(bool)));
} }
...@@ -188,9 +188,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ...@@ -188,9 +188,7 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn
qDebug() << "Link is NOT a known link, can't open configuration window"; qDebug() << "Link is NOT a known link, can't open configuration window";
} }
#ifdef XBEELINK connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(linkCurrentIndexChanged(int)));
connect(ui.linkType,SIGNAL(currentIndexChanged(int)),this,SLOT(setLinkType(int)));
#endif // XBEELINK
// Open details pane for MAVLink if necessary // Open details pane for MAVLink if necessary
MAVLinkProtocol* mavlink = dynamic_cast<MAVLinkProtocol*>(protocol); MAVLinkProtocol* mavlink = dynamic_cast<MAVLinkProtocol*>(protocol);
...@@ -220,7 +218,12 @@ QAction* CommConfigurationWindow::getAction() ...@@ -220,7 +218,12 @@ QAction* CommConfigurationWindow::getAction()
return action; return action;
} }
void CommConfigurationWindow::setLinkType(int linktype) void CommConfigurationWindow::linkCurrentIndexChanged(int currentIndex)
{
setLinkType(static_cast<qgc_link_t>(ui.linkType->itemData(currentIndex).toInt()));
}
void CommConfigurationWindow::setLinkType(qgc_link_t linktype)
{ {
if(link->isConnected()) if(link->isConnected())
{ {
...@@ -237,7 +240,7 @@ void CommConfigurationWindow::setLinkType(int linktype) ...@@ -237,7 +240,7 @@ void CommConfigurationWindow::setLinkType(int linktype)
switch(linktype) switch(linktype)
{ {
#ifdef XBEELINK #ifdef XBEELINK
case 4: case QGC_LINK_XBEE:
{ {
XbeeLink *xbee = new XbeeLink(); XbeeLink *xbee = new XbeeLink();
tmpLink = xbee; tmpLink = xbee;
...@@ -245,7 +248,7 @@ void CommConfigurationWindow::setLinkType(int linktype) ...@@ -245,7 +248,7 @@ void CommConfigurationWindow::setLinkType(int linktype)
break; break;
} }
#endif // XBEELINK #endif // XBEELINK
case 1: case QGC_LINK_UDP:
{ {
UDPLink *udp = new UDPLink(); UDPLink *udp = new UDPLink();
tmpLink = udp; tmpLink = udp;
...@@ -254,7 +257,7 @@ void CommConfigurationWindow::setLinkType(int linktype) ...@@ -254,7 +257,7 @@ void CommConfigurationWindow::setLinkType(int linktype)
} }
#ifdef OPAL_RT #ifdef OPAL_RT
case 3: case QGC_LINK_OPAL:
{ {
OpalLink* opal = new OpalLink(); OpalLink* opal = new OpalLink();
tmpLink = opal; tmpLink = opal;
...@@ -265,7 +268,7 @@ void CommConfigurationWindow::setLinkType(int linktype) ...@@ -265,7 +268,7 @@ void CommConfigurationWindow::setLinkType(int linktype)
default: default:
{ {
} }
case 0: case QGC_LINK_SERIAL:
{ {
SerialLink *serial = new SerialLink(); SerialLink *serial = new SerialLink();
tmpLink = serial; tmpLink = serial;
......
...@@ -33,7 +33,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -33,7 +33,7 @@ This file is part of the QGROUNDCONTROL project
#define _COMMCONFIGURATIONWINDOW_H_ #define _COMMCONFIGURATIONWINDOW_H_
#include <QObject> #include <QObject>
#include <QWidget> #include <QDialog>
#include <QAction> #include <QAction>
#include "LinkInterface.h" #include "LinkInterface.h"
#include "ProtocolInterface.h" #include "ProtocolInterface.h"
...@@ -47,7 +47,9 @@ enum qgc_link_t { ...@@ -47,7 +47,9 @@ enum qgc_link_t {
#ifdef XBEELINK #ifdef XBEELINK
QGC_LINK_XBEE, QGC_LINK_XBEE,
#endif #endif
#ifdef OPAL_RT
QGC_LINK_OPAL QGC_LINK_OPAL
#endif
}; };
enum qgc_protocol_t { enum qgc_protocol_t {
...@@ -62,7 +64,7 @@ enum qgc_protocol_t { ...@@ -62,7 +64,7 @@ enum qgc_protocol_t {
/** /**
* @brief Configuration window for communication links * @brief Configuration window for communication links
*/ */
class CommConfigurationWindow : public QWidget class CommConfigurationWindow : public QDialog
{ {
Q_OBJECT Q_OBJECT
...@@ -71,9 +73,12 @@ public: ...@@ -71,9 +73,12 @@ public:
~CommConfigurationWindow(); ~CommConfigurationWindow();
QAction* getAction(); QAction* getAction();
void setLinkType(qgc_link_t linktype);
private slots:
void linkCurrentIndexChanged(int currentIndex);
public slots: public slots:
void setLinkType(int linktype);
/** @brief Set the protocol for this link */ /** @brief Set the protocol for this link */
void setProtocol(int protocol); void setProtocol(int protocol);
void setConnection(); void setConnection();
......
...@@ -14,6 +14,23 @@ ...@@ -14,6 +14,23 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Link &amp;Type:</string>
</property>
<property name="buddy">
<cstring>linkType</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="linkType"/>
</item>
</layout>
</item>
<item> <item>
<widget class="QGroupBox" name="linkGroupBox"> <widget class="QGroupBox" name="linkGroupBox">
<property name="title"> <property name="title">
...@@ -23,7 +40,16 @@ ...@@ -23,7 +40,16 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
...@@ -36,8 +62,8 @@ ...@@ -36,8 +62,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>292</width> <width>298</width>
<height>81</height> <height>90</height>
</rect> </rect>
</property> </property>
</widget> </widget>
...@@ -49,7 +75,7 @@ ...@@ -49,7 +75,7 @@
<item> <item>
<widget class="QCheckBox" name="advCheckBox"> <widget class="QCheckBox" name="advCheckBox">
<property name="text"> <property name="text">
<string>Show Advanced Protocol Options</string> <string>&amp;Show Advanced Protocol Options</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -61,34 +87,27 @@ ...@@ -61,34 +87,27 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Link Type</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="linkType"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="connectionType"> <widget class="QComboBox" name="connectionType">
<property name="currentIndex"> <property name="currentIndex">
<number>-1</number> <number>-1</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="0" column="0">
<widget class="QCheckBox" name="advancedOptionsCheckBox"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>Advanced Options</string> <string>&amp;Protocol:</string>
</property>
<property name="buddy">
<cstring>connectionType</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="1">
<widget class="QLabel" name="label_5"> <widget class="QCheckBox" name="advancedOptionsCheckBox">
<property name="text"> <property name="text">
<string>Protocol</string> <string>&amp;Advanced Options</string>
</property> </property>
</widget> </widget>
</item> </item>
...@@ -113,7 +132,16 @@ ...@@ -113,7 +132,16 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
...@@ -126,8 +154,8 @@ ...@@ -126,8 +154,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>292</width> <width>298</width>
<height>81</height> <height>90</height>
</rect> </rect>
</property> </property>
</widget> </widget>
...@@ -217,7 +245,20 @@ ...@@ -217,7 +245,20 @@
<zorder>connectionStatusLabel</zorder> <zorder>connectionStatusLabel</zorder>
<zorder>advCheckBox</zorder> <zorder>advCheckBox</zorder>
<zorder>protocolTypeGroupBox</zorder> <zorder>protocolTypeGroupBox</zorder>
<zorder>linkType</zorder>
<zorder>label</zorder>
</widget> </widget>
<tabstops>
<tabstop>linkType</tabstop>
<tabstop>linkScrollArea</tabstop>
<tabstop>advCheckBox</tabstop>
<tabstop>connectionType</tabstop>
<tabstop>advancedOptionsCheckBox</tabstop>
<tabstop>protocolScrollArea</tabstop>
<tabstop>connectButton</tabstop>
<tabstop>deleteButton</tabstop>
<tabstop>closeButton</tabstop>
</tabstops>
<resources/> <resources/>
<connections> <connections>
<connection> <connection>
......
...@@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project ...@@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project
#include <QGCHilFlightGearConfiguration.h> #include <QGCHilFlightGearConfiguration.h>
#include <QDeclarativeView> #include <QDeclarativeView>
#include "dockwidgettitlebareventfilter.h" #include "dockwidgettitlebareventfilter.h"
#include "dockwidgeteventfilter.h"
#include "QGC.h" #include "QGC.h"
#include "MAVLinkSimulationLink.h" #include "MAVLinkSimulationLink.h"
#include "SerialLink.h" #include "SerialLink.h"
...@@ -450,7 +451,7 @@ void MainWindow::buildCustomWidget() ...@@ -450,7 +451,7 @@ void MainWindow::buildCustomWidget()
ui.menuTools->addAction(showAction);*/ ui.menuTools->addAction(showAction);*/
// Load dock widget location (default is bottom) // Load dock widget location (default is bottom)
Qt::DockWidgetArea location = static_cast <Qt::DockWidgetArea>(tool->getDockWidgetArea(currentView)); Qt::DockWidgetArea location = tool->getDockWidgetArea(currentView);
//addDockWidget(location, dock); //addDockWidget(location, dock);
//dock->hide(); //dock->hide();
...@@ -895,7 +896,8 @@ void MainWindow::setDockWidgetTitleBar(QDockWidget* widget) ...@@ -895,7 +896,8 @@ void MainWindow::setDockWidgetTitleBar(QDockWidget* widget)
{ {
QLabel* label = new QLabel(this); QLabel* label = new QLabel(this);
label->setText(widget->windowTitle()); 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); widget->setTitleBarWidget(label);
} }
// And if nothing should be shown, use an empty widget. // And if nothing should be shown, use an empty widget.
...@@ -1683,7 +1685,7 @@ void MainWindow::addLink(LinkInterface *link) ...@@ -1683,7 +1685,7 @@ void MainWindow::addLink(LinkInterface *link)
if (!found) if (!found)
{ {
CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, NULL); CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
commsWidgetList.append(commWidget); commsWidgetList.append(commWidget);
connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*))); connect(commWidget,SIGNAL(destroyed(QObject*)),this,SLOT(commsWidgetDestroyed(QObject*)));
QAction* action = commWidget->getAction(); QAction* action = commWidget->getAction();
......
...@@ -120,6 +120,8 @@ void QGCDataPlot2D::savePlot() ...@@ -120,6 +120,8 @@ void QGCDataPlot2D::savePlot()
fileName = QFileDialog::getSaveFileName( fileName = QFileDialog::getSaveFileName(
this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)"); "PDF Documents (*.pdf);;SVG Images (*.svg)");
if (fileName.isEmpty())
return;
if (!fileName.contains(".")) { if (!fileName.contains(".")) {
// .pdf is default extension // .pdf is default extension
...@@ -138,6 +140,8 @@ void QGCDataPlot2D::savePlot() ...@@ -138,6 +140,8 @@ void QGCDataPlot2D::savePlot()
fileName = QFileDialog::getSaveFileName( fileName = QFileDialog::getSaveFileName(
this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), this, "Export File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation),
"PDF Documents (*.pdf);;SVG Images (*.svg)"); "PDF Documents (*.pdf);;SVG Images (*.svg)");
if (fileName.isEmpty())
return; //Abort if cancelled
} }
if (fileName.endsWith(".pdf")) { if (fileName.endsWith(".pdf")) {
...@@ -689,6 +693,8 @@ void QGCDataPlot2D::saveCsvLog() ...@@ -689,6 +693,8 @@ void QGCDataPlot2D::saveCsvLog()
fileName = QFileDialog::getSaveFileName( fileName = QFileDialog::getSaveFileName(
this, "Export CSV File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation), this, "Export CSV File Name", QDesktopServices::storageLocation(QDesktopServices::DesktopLocation),
"CSV file (*.csv);;Text file (*.txt)"); "CSV file (*.csv);;Text file (*.txt)");
if (fileName.isEmpty())
return; //User cancelled
if (!fileName.contains(".")) { if (!fileName.contains(".")) {
// .csv is default extension // .csv is default extension
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "UASManager.h" #include "UASManager.h"
QGCTextLabel::QGCTextLabel(QWidget *parent) : QGCTextLabel::QGCTextLabel(QWidget *parent) :
QGCToolWidgetItem("Command Button", parent), QGCToolWidgetItem("Text Label", parent),
ui(new Ui::QGCTextLabel) ui(new Ui::QGCTextLabel)
{ {
uas = 0; uas = 0;
...@@ -15,17 +15,15 @@ QGCTextLabel::QGCTextLabel(QWidget *parent) : ...@@ -15,17 +15,15 @@ QGCTextLabel::QGCTextLabel(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode())); connect(ui->editFinishButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
connect(ui->isMavCommand, SIGNAL(toggled(bool)), this, SLOT(update_isMavCommand()));
// Hide all edit items // Hide all edit items
ui->editFinishButton->hide(); ui->editFinishButton->hide();
ui->editNameLabel->hide(); ui->editNameLabel->hide();
ui->editTextParam->hide();
ui->editComponentSpinBox->hide();
ui->editLine1->hide(); ui->editLine1->hide();
ui->editLine2->hide(); ui->editLine2->hide();
ui->isMavCommand->hide();
// Add commands to combo box ui->textLabel->setText(QString());
} }
QGCTextLabel::~QGCTextLabel() QGCTextLabel::~QGCTextLabel()
...@@ -36,14 +34,11 @@ QGCTextLabel::~QGCTextLabel() ...@@ -36,14 +34,11 @@ QGCTextLabel::~QGCTextLabel()
void QGCTextLabel::startEditMode() void QGCTextLabel::startEditMode()
{ {
// Hide elements // Hide elements
ui->nameLabel->hide();
ui->editTextParam->show();
ui->editFinishButton->show(); ui->editFinishButton->show();
ui->editNameLabel->show(); ui->editNameLabel->show();
ui->editComponentSpinBox->show();
ui->editLine1->show(); ui->editLine1->show();
ui->editLine2->show(); ui->editLine2->show();
ui->isMavCommand->show();
// Attempt to undock the dock widget // Attempt to undock the dock widget
QWidget* p = this; QWidget* p = this;
...@@ -65,14 +60,12 @@ void QGCTextLabel::startEditMode() ...@@ -65,14 +60,12 @@ void QGCTextLabel::startEditMode()
void QGCTextLabel::endEditMode() void QGCTextLabel::endEditMode()
{ {
update_isMavCommand();
ui->editFinishButton->hide(); ui->editFinishButton->hide();
ui->editTextParam->hide();
ui->editNameLabel->hide(); ui->editNameLabel->hide();
ui->editComponentSpinBox->hide();
ui->editLine1->hide(); ui->editLine1->hide();
ui->editLine2->hide(); ui->editLine2->hide();
ui->isMavCommand->hide();
ui->nameLabel->show();
// Write to settings // Write to settings
emit editingFinished(); emit editingFinished();
...@@ -97,31 +90,17 @@ void QGCTextLabel::endEditMode() ...@@ -97,31 +90,17 @@ void QGCTextLabel::endEditMode()
void QGCTextLabel::writeSettings(QSettings& settings) void QGCTextLabel::writeSettings(QSettings& settings)
{ {
qDebug() << "COMMAND BUTTON WRITING SETTINGS"; settings.setValue("TYPE", "TEXT");
settings.setValue("TYPE", "COMMANDBUTTON"); settings.setValue("QGC_TEXT_TEXT", ui->editNameLabel->text());
settings.setValue("QGC_COMMAND_BUTTON_DESCRIPTION", ui->nameLabel->text()); settings.setValue("QGC_TEXT_SOURCE", ui->isMavCommand->isChecked()?"MAV":"NONE");
settings.sync(); settings.sync();
} }
void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings) void QGCTextLabel::readSettings(const QString& pre,const QVariantMap& settings)
{ {
ui->editTextParam->setText(settings.value(pre + "QGC_TEXT_SOURCE", "UNKNOWN").toString()); ui->editNameLabel->setText(settings.value(pre + "QGC_TEXT_TEXT","").toString());
//ui->editCommandComboBox->setCurrentIndex(settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt()); ui->isMavCommand->setChecked(settings.value(pre + "QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
if (ui->editTextParam->text() == "NONE") update_isMavCommand();
{
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());
} }
void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, QString message) 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 ...@@ -148,31 +127,40 @@ void QGCTextLabel::textMessageReceived(int uasid, int component, int severity, Q
void QGCTextLabel::readSettings(const QSettings& settings) void QGCTextLabel::readSettings(const QSettings& settings)
{ {
//ui->editNameLabel->setText(settings.value("QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); ui->editNameLabel->setText(settings.value("QGC_TEXT_TEXT","").toString()); //Place this before setting isMavCommand
//ui->nameLabel->setText(settings.value("QGC_COMMAND_BUTTON_DESCRIPTION", "ERROR LOADING BUTTON").toString()); ui->isMavCommand->setChecked(settings.value("QGC_TEXT_SOURCE", "NONE").toString() == "MAV");
ui->editTextParam->setText(settings.value("QGC_TEXT_SOURCE", "UNKNOWN").toString()); update_isMavCommand();
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)));
}
} }
void QGCTextLabel::enableText(int num) void QGCTextLabel::enableText(int num)
{ {
enabledNum = num; enabledNum = num;
} }
void QGCTextLabel::setActiveUAS(UASInterface *uas) void QGCTextLabel::setActiveUAS(UASInterface *uas)
{ {
if(this->uas)
this->uas->disconnect(this);
this->uas = uas; 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)));
}
} }
...@@ -26,6 +26,10 @@ public slots: ...@@ -26,6 +26,10 @@ public slots:
void readSettings(const QSettings& settings); void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings); void readSettings(const QString& pre,const QVariantMap& settings);
void textMessageReceived(int uasid, int componentId, int severity, QString message); void textMessageReceived(int uasid, int componentId, int severity, QString message);
private slots:
void update_isMavCommand();
private: private:
int enabledNum; int enabledNum;
Ui::QGCTextLabel *ui; Ui::QGCTextLabel *ui;
......
...@@ -6,34 +6,15 @@ ...@@ -6,34 +6,15 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1183</width> <width>554</width>
<height>166</height> <height>107</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,0,0"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin"> <item>
<number>6</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="2" column="0" colspan="2">
<widget class="QLineEdit" name="editNameLabel">
<property name="text">
<string>&lt;Label Description Label (in front of text)&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="Line" name="editLine1"> <widget class="Line" name="editLine1">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
...@@ -46,50 +27,82 @@ ...@@ -46,50 +27,82 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2"> <item>
<widget class="QLabel" name="nameLabel"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="minimumSize"> <item>
<size> <widget class="QLineEdit" name="editNameLabel">
<width>50</width> <property name="text">
<height>0</height> <string/>
</size> </property>
</property> <property name="placeholderText">
<property name="text"> <string>Label Description</string>
<string>Description</string> </property>
</property> </widget>
<property name="alignment"> </item>
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <item>
</property> <widget class="QCheckBox" name="isMavCommand">
</widget> <property name="toolTip">
<string>This is only for advanced use, and allows a label to display the results of a Command Button.</string>
</property>
<property name="text">
<string>Mav Command</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="2" column="2"> <item>
<widget class="QLineEdit" name="editTextParam"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="text"> <item>
<string>&lt;Text Param&gt;</string> <widget class="QLabel" name="nameLabel">
</property> <property name="minimumSize">
</widget> <size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Text Label</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel">
<property name="text">
<string>mav result</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="6" column="2"> <item>
<widget class="QPushButton" name="editFinishButton"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="text"> <item>
<string>Done</string> <spacer name="horizontalSpacer">
</property> <property name="orientation">
</widget> <enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="5" column="0"> <item>
<widget class="QSpinBox" name="editComponentSpinBox">
<property name="prefix">
<string>Component ID: </string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item row="7" column="0" colspan="3">
<widget class="Line" name="editLine2"> <widget class="Line" name="editLine2">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
...@@ -102,13 +115,6 @@ ...@@ -102,13 +115,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2">
<widget class="QLabel" name="textLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>
...@@ -120,8 +126,8 @@ ...@@ -120,8 +126,8 @@
<slot>setText(QString)</slot> <slot>setText(QString)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>114</x> <x>280</x>
<y>22</y> <y>32</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>114</x> <x>114</x>
...@@ -129,5 +135,21 @@ ...@@ -129,5 +135,21 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>editNameLabel</sender>
<signal>returnPressed()</signal>
<receiver>editFinishButton</receiver>
<slot>animateClick()</slot>
<hints>
<hint type="sourcelabel">
<x>136</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>498</x>
<y>86</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>
...@@ -33,26 +33,12 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s ...@@ -33,26 +33,12 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s
} }
//qDebug() << "WidgetTitle" << widgetTitle; //qDebug() << "WidgetTitle" << widgetTitle;
setObjectName(widgetTitle);
createActions(); createActions();
toolLayout = ui->toolLayout; toolLayout = ui->toolLayout;
toolLayout->setAlignment(Qt::AlignTop); toolLayout->setAlignment(Qt::AlignTop);
toolLayout->setSpacing(8); toolLayout->setSpacing(8);
QDockWidget* dock = dynamic_cast<QDockWidget*>(this->parentWidget()); this->setTitle(widgetTitle);
if (dock) {
dock->setWindowTitle(widgetTitle);
dock->setObjectName(widgetTitle+"DOCK");
}
// Try with parent
dock = dynamic_cast<QDockWidget*>(parent);
if (dock) {
dock->setWindowTitle(widgetTitle);
dock->setObjectName(widgetTitle+"DOCK");
}
this->setWindowTitle(widgetTitle);
QList<UASInterface*> systems = UASManager::instance()->getUASList(); QList<UASInterface*> systems = UASManager::instance()->getUASList();
foreach (UASInterface* uas, systems) foreach (UASInterface* uas, systems)
{ {
...@@ -63,7 +49,6 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s ...@@ -63,7 +49,6 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s
} }
} }
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*))); 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 // Enforce storage if this not loaded from settings
// is MUST NOT BE SAVED if it was loaded from settings! // is MUST NOT BE SAVED if it was loaded from settings!
...@@ -80,13 +65,7 @@ QGCToolWidget::~QGCToolWidget() ...@@ -80,13 +65,7 @@ QGCToolWidget::~QGCToolWidget()
void QGCToolWidget::setParent(QWidget *parent) void QGCToolWidget::setParent(QWidget *parent)
{ {
QWidget::setParent(parent); QWidget::setParent(parent);
// Try with parent setTitle(getTitle()); //Update titles
QDockWidget* dock = dynamic_cast<QDockWidget*>(parent);
if (dock)
{
dock->setWindowTitle(getTitle());
dock->setObjectName(getTitle()+"DOCK");
}
} }
/** /**
...@@ -296,7 +275,7 @@ void QGCToolWidget::loadSettings(QVariantMap& settings) ...@@ -296,7 +275,7 @@ void QGCToolWidget::loadSettings(QVariantMap& settings)
else if (type == "COMBO") else if (type == "COMBO")
{ {
item = new QGCComboBox(this); item = new QGCComboBox(this);
//qDebug() << "CREATED PARAM COMBOBOX"; //qDebug() << "CREATED COMBOBOX";
} }
if (item) if (item)
{ {
...@@ -482,6 +461,7 @@ void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event) ...@@ -482,6 +461,7 @@ void QGCToolWidget::contextMenuEvent (QContextMenuEvent* event)
QMenu menu(this); QMenu menu(this);
menu.addAction(addParamAction); menu.addAction(addParamAction);
menu.addAction(addCommandAction); menu.addAction(addCommandAction);
menu.addAction(addLabelAction);
menu.addSeparator(); menu.addSeparator();
menu.addAction(setTitleAction); menu.addAction(setTitleAction);
menu.addAction(exportAction); menu.addAction(exportAction);
...@@ -517,6 +497,10 @@ void QGCToolWidget::createActions() ...@@ -517,6 +497,10 @@ void QGCToolWidget::createActions()
addCommandAction->setStatusTip(tr("Add a new action button to the tool")); addCommandAction->setStatusTip(tr("Add a new action button to the tool"));
connect(addCommandAction, SIGNAL(triggered()), this, SLOT(addCommand())); 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 = new QAction(tr("Set Widget Title"), this);
setTitleAction->setStatusTip(tr("Set the title caption of this tool widget")); setTitleAction->setStatusTip(tr("Set the title caption of this tool widget"));
connect(setTitleAction, SIGNAL(triggered()), this, SLOT(setTitle())); connect(setTitleAction, SIGNAL(triggered()), this, SLOT(setTitle()));
...@@ -590,6 +574,14 @@ void QGCToolWidget::addCommand() ...@@ -590,6 +574,14 @@ void QGCToolWidget::addCommand()
button->startEditMode(); 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) void QGCToolWidget::addToolWidget(QGCToolWidgetItem* widget)
{ {
if (ui->hintLabel) if (ui->hintLabel)
...@@ -641,34 +633,20 @@ void QGCToolWidget::setTitle() ...@@ -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(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; widgetTitle = title;
if (!instances()->contains(title)) instances()->insert(title, this);
QWidget::setWindowTitle(title); QWidget::setWindowTitle(title);
QDockWidget* parent = dynamic_cast<QDockWidget*>(this->parentWidget()); setObjectName(widgetTitle);
if (parent) parent->setWindowTitle(title); QDockWidget* dock = dynamic_cast<QDockWidget*>(this->parentWidget());
// Store all widgets if (dock) {
//storeWidgetsToSettings(); dock->setWindowTitle(widgetTitle);
dock->setObjectName(widgetTitle+"DOCK");
}
emit titleChanged(title); emit titleChanged(title);
if (mainMenuAction) mainMenuAction->setText(title); if (mainMenuAction) mainMenuAction->setText(title);
} }
......
...@@ -74,6 +74,7 @@ protected: ...@@ -74,6 +74,7 @@ protected:
QVariantMap settingsMap; QVariantMap settingsMap;
QAction* addParamAction; QAction* addParamAction;
QAction* addCommandAction; QAction* addCommandAction;
QAction* addLabelAction;
QAction* setTitleAction; QAction* setTitleAction;
QAction* deleteAction; QAction* deleteAction;
QAction* exportAction; QAction* exportAction;
...@@ -99,6 +100,7 @@ public slots: ...@@ -99,6 +100,7 @@ public slots:
protected slots: protected slots:
void addParam(); void addParam();
void addCommand(); void addCommand();
void addLabel();
void setTitle(); void setTitle();
void setWindowTitle(const QString& title); void setWindowTitle(const QString& title);
......
#include <QDockWidget>
#include <QEvent>
#include <QLabel>
#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<QDockWidget *>(object);
if(dock) {
QLabel *label = dynamic_cast<QLabel *>(dock->titleBarWidget());
if(label)
label->setText(dock->windowTitle());
}
}
return QObject::eventFilter(object,event);
}
#ifndef DOCKWIDGETEVENTFILTER_H
#define DOCKWIDGETEVENTFILTER_H
#include <QObject>
/** 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
...@@ -70,7 +70,7 @@ QColor ChartPlot::getNextColor() ...@@ -70,7 +70,7 @@ QColor ChartPlot::getNextColor()
return colors[nextColorIndex++]; return colors[nextColorIndex++];
} }
QColor ChartPlot::getColorForCurve(QString id) QColor ChartPlot::getColorForCurve(const QString &id)
{ {
return curves.value(id)->pen().color(); return curves.value(id)->pen().color();
} }
......
...@@ -17,7 +17,7 @@ public: ...@@ -17,7 +17,7 @@ public:
QColor getNextColor(); QColor getNextColor();
/** @brief Get color for curve id */ /** @brief Get color for curve id */
QColor getColorForCurve(QString id); QColor getColorForCurve(const QString &id);
/** @brief Reset color map */ /** @brief Reset color map */
void shuffleColors(); void shuffleColors();
......
...@@ -155,7 +155,7 @@ void IncrementalPlot::showLegend(bool show) ...@@ -155,7 +155,7 @@ void IncrementalPlot::showLegend(bool show)
* *
* @param style Formatting string for line/data point style * @param style Formatting string for line/data point style
*/ */
void IncrementalPlot::setStyleText(QString style) void IncrementalPlot::setStyleText(const QString &style)
{ {
foreach (QwtPlotCurve* curve, curves) { foreach (QwtPlotCurve* curve, curves) {
// Style of datapoints // Style of datapoints
...@@ -250,12 +250,12 @@ void IncrementalPlot::updateScale() ...@@ -250,12 +250,12 @@ void IncrementalPlot::updateScale()
zoomer->setZoomBase(true); 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); 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; CurveData* data;
QwtPlotCurve* curve; QwtPlotCurve* curve;
...@@ -349,7 +349,7 @@ void IncrementalPlot::appendData(QString key, double *x, double *y, int size) ...@@ -349,7 +349,7 @@ void IncrementalPlot::appendData(QString key, double *x, double *y, int size)
/** /**
* @return Number of copied data points, 0 on failure * @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; int result = 0;
if (d_data.contains(key)) { if (d_data.contains(key)) {
......
...@@ -84,14 +84,14 @@ public: ...@@ -84,14 +84,14 @@ public:
bool gridEnabled(); bool gridEnabled();
/** @brief Read out data from a curve */ /** @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: public slots:
/** @brief Append one data point */ /** @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 */ /** @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 */ /** @brief Reset the plot scaling to the default value */
void resetScaling(); void resetScaling();
...@@ -109,7 +109,7 @@ public slots: ...@@ -109,7 +109,7 @@ public slots:
void showGrid(bool show); void showGrid(bool show);
/** @brief Set new plot style */ /** @brief Set new plot style */
void setStyleText(QString style); void setStyleText(const QString &style);
/** @brief Set symmetric axis scaling mode */ /** @brief Set symmetric axis scaling mode */
void setSymmetric(bool symmetric); void setSymmetric(bool symmetric);
......
...@@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval() ...@@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval()
**/ **/
void LinechartPlot::setPlotInterval(int interval) void LinechartPlot::setPlotInterval(int interval)
{ {
plotInterval = interval; //Only ever increase the amount of stored data,
QMap<QString, TimeSeriesData*>::iterator j; // so that we allow the user to change between
for(j = data.begin(); j != data.end(); ++j) // different intervals without constantly losing
{ // data points
TimeSeriesData* d = data.value(j.key()); if((unsigned)interval > plotInterval) {
d->setInterval(interval);
QMap<QString, TimeSeriesData*>::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;
} }
/** /**
......
...@@ -207,10 +207,9 @@ void LinechartWidget::createLayout() ...@@ -207,10 +207,9 @@ void LinechartWidget::createLayout()
createActions(); createActions();
// Setup the plot group box area layout // Setup the plot group box area layout
QGridLayout* layout = new QGridLayout(ui.diagramGroupBox); QVBoxLayout* vlayout = new QVBoxLayout(ui.diagramGroupBox);
mainLayout = layout; vlayout->setSpacing(4);
layout->setSpacing(4); vlayout->setMargin(2);
layout->setMargin(2);
// Create plot container widget // Create plot container widget
activePlot = new LinechartPlot(this, sysid); activePlot = new LinechartPlot(this, sysid);
...@@ -221,27 +220,18 @@ void LinechartWidget::createLayout() ...@@ -221,27 +220,18 @@ void LinechartWidget::createLayout()
// activePlot = getPlot(0); // activePlot = getPlot(0);
// plotContainer->setPlot(activePlot); // plotContainer->setPlot(activePlot);
layout->addWidget(activePlot, 0, 0, 1, 6); vlayout->addWidget(activePlot);
layout->setRowStretch(0, 10);
layout->setRowStretch(1, 1);
// Linear scaling button QHBoxLayout *hlayout = new QHBoxLayout;
scalingLinearButton = createButton(this); vlayout->addLayout(hlayout);
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 // Logarithmic scaling button
scalingLogButton = createButton(this); scalingLogButton = createButton(this);
scalingLogButton->setDefaultAction(setScalingLogarithmic); scalingLogButton->setText(tr("LOG"));
scalingLogButton->setCheckable(true); scalingLogButton->setCheckable(true);
scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis")); scalingLogButton->setToolTip(tr("Set logarithmic scale for Y axis"));
scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis")); scalingLogButton->setWhatsThis(tr("Set logarithmic scale for Y axis"));
layout->addWidget(scalingLogButton, 1, 1); hlayout->addWidget(scalingLogButton);
layout->setColumnStretch(1, 0);
// Averaging spin box // Averaging spin box
averageSpinBox = new QSpinBox(this); averageSpinBox = new QSpinBox(this);
...@@ -251,8 +241,7 @@ void LinechartWidget::createLayout() ...@@ -251,8 +241,7 @@ void LinechartWidget::createLayout()
averageSpinBox->setValue(200); averageSpinBox->setValue(200);
setAverageWindow(200); setAverageWindow(200);
averageSpinBox->setMaximum(9999); averageSpinBox->setMaximum(9999);
layout->addWidget(averageSpinBox, 1, 2); hlayout->addWidget(averageSpinBox);
layout->setColumnStretch(2, 0);
connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int))); connect(averageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setAverageWindow(int)));
// Log Button // Log Button
...@@ -260,8 +249,7 @@ void LinechartWidget::createLayout() ...@@ -260,8 +249,7 @@ void LinechartWidget::createLayout()
logButton->setToolTip(tr("Start to log curve data into a CSV or TXT file")); 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->setWhatsThis(tr("Start to log curve data into a CSV or TXT file"));
logButton->setText(tr("Start Logging")); logButton->setText(tr("Start Logging"));
layout->addWidget(logButton, 1, 3); hlayout->addWidget(logButton);
layout->setColumnStretch(3, 0);
connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging())); connect(logButton, SIGNAL(clicked()), this, SLOT(startLogging()));
// Ground time button // Ground time button
...@@ -269,17 +257,37 @@ void LinechartWidget::createLayout() ...@@ -269,17 +257,37 @@ void LinechartWidget::createLayout()
timeButton->setText(tr("Ground Time")); 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->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.")); 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); hlayout->addWidget(timeButton);
layout->setColumnStretch(4, 0);
connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool))); connect(timeButton, SIGNAL(clicked(bool)), activePlot, SLOT(enforceGroundTime(bool)));
connect(timeButton, SIGNAL(clicked()), this, SLOT(writeSettings())); 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 // Initialize the "Show units" checkbox. This is configured in the .ui file, so all
// we do here is attach the clicked() signal. // we do here is attach the clicked() signal.
connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings())); connect(ui.showUnitsCheckBox, SIGNAL(clicked()), this, SLOT(writeSettings()));
ui.diagramGroupBox->setLayout(layout);
// Add actions // Add actions
averageSpinBox->setValue(activePlot->getAverageWindow()); averageSpinBox->setValue(activePlot->getAverageWindow());
...@@ -294,8 +302,20 @@ void LinechartWidget::createLayout() ...@@ -294,8 +302,20 @@ void LinechartWidget::createLayout()
connect(this, SIGNAL(plotWindowPositionUpdated(quint64)), activePlot, SLOT(setWindowPosition(quint64))); connect(this, SIGNAL(plotWindowPositionUpdated(quint64)), activePlot, SLOT(setWindowPosition(quint64)));
// Set scaling // Set scaling
connect(scalingLinearButton, SIGNAL(clicked()), activePlot, SLOT(setLinearScaling())); connect(scalingLogButton, SIGNAL(toggled(bool)), this, SLOT(toggleLogarithmicScaling(bool)));
connect(scalingLogButton, SIGNAL(clicked()), activePlot, SLOT(setLogarithmicScaling())); }
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) void LinechartWidget::appendData(int uasId, const QString& curve, const QString& unit, qint8 value, quint64 usec)
...@@ -626,8 +646,6 @@ void LinechartWidget::setAverageWindow(int windowSize) ...@@ -626,8 +646,6 @@ void LinechartWidget::setAverageWindow(int windowSize)
void LinechartWidget::createActions() void LinechartWidget::createActions()
{ {
setScalingLogarithmic = new QAction("LOG", this);
setScalingLinear = new QAction("LIN", this);
} }
/** /**
......
...@@ -96,6 +96,7 @@ public slots: ...@@ -96,6 +96,7 @@ public slots:
/** @brief Append double data to the given curve. */ /** @brief Append double data to the given curve. */
void appendData(int uasId, const QString& curve, const QString& unit, double value, quint64 usec); void appendData(int uasId, const QString& curve, const QString& unit, double value, quint64 usec);
void toggleLogarithmicScaling(bool toggled);
void takeButtonClick(bool checked); void takeButtonClick(bool checked);
void setPlotWindowPosition(int scrollBarValue); void setPlotWindowPosition(int scrollBarValue);
void setPlotWindowPosition(quint64 position); void setPlotWindowPosition(quint64 position);
...@@ -122,6 +123,10 @@ public slots: ...@@ -122,6 +123,10 @@ public slots:
/** @brief Select all curves */ /** @brief Select all curves */
void selectAllCurves(bool all); void selectAllCurves(bool all);
private slots:
/** Called when the user changes the time scale combobox. */
void timeScaleChanged(int index);
protected: protected:
void addCurveToList(QString curve); void addCurveToList(QString curve);
void removeCurveFromList(QString curve); void removeCurveFromList(QString curve);
...@@ -152,14 +157,11 @@ protected: ...@@ -152,14 +157,11 @@ protected:
QScrollBar* scrollbar; ///< The plot window scroll bar QScrollBar* scrollbar; ///< The plot window scroll bar
QSpinBox* averageSpinBox; ///< Spin box to setup average window filter size 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 QAction* addNewCurve; ///< Add curve candidate to the active curves
QMenu* curveMenu; QMenu* curveMenu;
QGridLayout* mainLayout; QComboBox *timeScaleCmb;
QToolButton* scalingLinearButton;
QToolButton* scalingLogButton; QToolButton* scalingLogButton;
QToolButton* logButton; QToolButton* logButton;
QPointer<QCheckBox> timeButton; QPointer<QCheckBox> timeButton;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment