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 \
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
......
......@@ -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<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);
#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<UDPLink*>(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<MAVLinkSimulationLink*>(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<MAVLinkProtocol*>(protocol);
......@@ -220,7 +218,12 @@ QAction* CommConfigurationWindow::getAction()
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())
{
......@@ -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;
......
......@@ -33,7 +33,7 @@ This file is part of the QGROUNDCONTROL project
#define _COMMCONFIGURATIONWINDOW_H_
#include <QObject>
#include <QWidget>
#include <QDialog>
#include <QAction>
#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();
......
......@@ -14,6 +14,23 @@
<string>Form</string>
</property>
<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>
<widget class="QGroupBox" name="linkGroupBox">
<property name="title">
......@@ -23,7 +40,16 @@
<property name="spacing">
<number>0</number>
</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>
</property>
<item>
......@@ -36,8 +62,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>292</width>
<height>81</height>
<width>298</width>
<height>90</height>
</rect>
</property>
</widget>
......@@ -49,7 +75,7 @@
<item>
<widget class="QCheckBox" name="advCheckBox">
<property name="text">
<string>Show Advanced Protocol Options</string>
<string>&amp;Show Advanced Protocol Options</string>
</property>
</widget>
</item>
......@@ -61,34 +87,27 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<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">
<widget class="QComboBox" name="linkType"/>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="connectionType">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="advancedOptionsCheckBox">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Advanced Options</string>
<string>&amp;Protocol:</string>
</property>
<property name="buddy">
<cstring>connectionType</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<item row="1" column="1">
<widget class="QCheckBox" name="advancedOptionsCheckBox">
<property name="text">
<string>Protocol</string>
<string>&amp;Advanced Options</string>
</property>
</widget>
</item>
......@@ -113,7 +132,16 @@
<property name="spacing">
<number>0</number>
</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>
</property>
<item>
......@@ -126,8 +154,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>292</width>
<height>81</height>
<width>298</width>
<height>90</height>
</rect>
</property>
</widget>
......@@ -217,7 +245,20 @@
<zorder>connectionStatusLabel</zorder>
<zorder>advCheckBox</zorder>
<zorder>protocolTypeGroupBox</zorder>
<zorder>linkType</zorder>
<zorder>label</zorder>
</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/>
<connections>
<connection>
......
......@@ -40,6 +40,7 @@ This file is part of the QGROUNDCONTROL project
#include <QGCHilFlightGearConfiguration.h>
#include <QDeclarativeView>
#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 <Qt::DockWidgetArea>(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();
......
......@@ -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
......
......@@ -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)));
}
}
......@@ -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;
......
......@@ -6,34 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>1183</width>
<height>166</height>
<width>554</width>
<height>107</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="100,0,0">
<property name="leftMargin">
<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">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="Line" name="editLine1">
<property name="minimumSize">
<size>
......@@ -46,50 +27,82 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Description</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="editNameLabel">
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Label Description</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="isMavCommand">
<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 row="2" column="2">
<widget class="QLineEdit" name="editTextParam">
<property name="text">
<string>&lt;Text Param&gt;</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="nameLabel">
<property name="minimumSize">
<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 row="6" column="2">
<widget class="QPushButton" name="editFinishButton">
<property name="text">
<string>Done</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<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 row="5" column="0">
<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">
<item>
<widget class="Line" name="editLine2">
<property name="minimumSize">
<size>
......@@ -102,13 +115,6 @@
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="textLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
......@@ -120,8 +126,8 @@
<slot>setText(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>114</x>
<y>22</y>
<x>280</x>
<y>32</y>
</hint>
<hint type="destinationlabel">
<x>114</x>
......@@ -129,5 +135,21 @@
</hint>
</hints>
</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>
</ui>
......@@ -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<QDockWidget*>(this->parentWidget());
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);
this->setTitle(widgetTitle);
QList<UASInterface*> 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<QDockWidget*>(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<QDockWidget*>(this->parentWidget());
if (parent) parent->setWindowTitle(title);
// Store all widgets
//storeWidgetsToSettings();
setObjectName(widgetTitle);
QDockWidget* dock = dynamic_cast<QDockWidget*>(this->parentWidget());
if (dock) {
dock->setWindowTitle(widgetTitle);
dock->setObjectName(widgetTitle+"DOCK");
}
emit titleChanged(title);
if (mainMenuAction) mainMenuAction->setText(title);
}
......
......@@ -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);
......
#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()
return colors[nextColorIndex++];
}
QColor ChartPlot::getColorForCurve(QString id)
QColor ChartPlot::getColorForCurve(const QString &id)
{
return curves.value(id)->pen().color();
}
......
......@@ -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();
......
......@@ -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)) {
......
......@@ -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);
......
......@@ -566,13 +566,29 @@ quint64 LinechartPlot::getPlotInterval()
**/
void LinechartPlot::setPlotInterval(int interval)
{
plotInterval = interval;
QMap<QString, TimeSeriesData*>::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<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()
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);
}
/**
......
......@@ -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<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