1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-1590 Added TabBar Toolbuttons with menus to copy/reset/restore/swap settings.

Still needs actual implementation.
This commit is contained in:
m_thread 2014-11-03 01:33:45 +01:00
parent a55aff2723
commit 0428cdfadc
6 changed files with 139 additions and 2 deletions

View File

@ -3,7 +3,6 @@
<file>images/help2.png</file>
<file>images/ahrs-calib.svg</file>
<file>images/multirotor-shapes.svg</file>
<!-- these are different from the files in /setupwiz/resources -->
<file>images/fixedwing-shapes.svg</file>
<file>images/ccpm_setup.svg</file>
<file>images/PipXtreme.png</file>
@ -47,5 +46,6 @@
<file>images/calibration/empty.png</file>
<file>images/calibration/plane-swd.png</file>
<file>images/calibration/board-swd.png</file>
<file>images/gear.png</file>
</qresource>
</RCC>

View File

@ -37,6 +37,9 @@
#include <QList>
#include <QTabBar>
#include <QMessageBox>
#include <QToolButton>
#include <QMenu>
#include <QAction>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/generalsettings.h>
@ -49,7 +52,10 @@
#include "qwt/src/qwt_scale_widget.h"
ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTaskWidget(parent),
boardModel(0), m_pidBankCount(0), m_currentPIDBank(0)
boardModel(0), m_pidBankCount(0), m_currentPIDBank(0),
m_PIDCopyFromSignalMapper(new QSignalMapper()),
m_PIDCopyToSignalMapper(new QSignalMapper()),
m_PIDSwapSignalMapper(new QSignalMapper())
{
ui = new Ui_StabilizationWidget();
ui->setupUi(this);
@ -64,10 +70,67 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
// Set up fake tab widget stuff for pid banks support
m_pidTabBars.append(ui->basicPIDBankTabBar);
m_pidTabBars.append(ui->advancedPIDBankTabBar);
m_defaultPIDMenuAction = new QAction(QIcon(":configgadget/images/gear.png"), QString(), this);
QAction *restoreAllAction = new QAction(tr("Restore all to saved"), this);
connect(restoreAllAction, SIGNAL(triggered()), this, SLOT(restoreAllPIDBanks()));
QAction *resetAllAction = new QAction(tr("Reset all to default"), this);
connect(resetAllAction, SIGNAL(triggered()), this, SLOT(resetAllPIDBanks()));
QAction *restoreCurrentAction = new QAction(tr("Restore to saved"), this);
connect(restoreCurrentAction, SIGNAL(triggered()), this, SLOT(restoreCurrentAction()));
QAction *resetCurrentAction = new QAction(tr("Reset to default"), this);
connect(resetCurrentAction, SIGNAL(triggered()), this, SLOT(resetCurrentPIDBank()));
QAction *copyCurrentAction = new QAction(tr("Copy to others"), this);
connect(copyCurrentAction, SIGNAL(triggered()), this, SLOT(copyCurrentPIDBank()));
connect(m_PIDCopyFromSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyFromBankToCurrent(int)));
connect(m_PIDCopyToSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyToBankFromCurrent(int)));
connect(m_PIDSwapSignalMapper, SIGNAL(mapped(int)), this, SLOT(swapBankAndCurrent(int)));
foreach(QTabBar * tabBar, m_pidTabBars) {
for (int i = 0; i < m_pidBankCount; i++) {
tabBar->addTab(tr("Settings Bank %1").arg(i + 1));
tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1));
QToolButton *tabButton = new QToolButton();
connect(this, SIGNAL(enableControlsChanged(bool)), tabButton, SLOT(setEnabled(bool)));
tabButton->setDefaultAction(m_defaultPIDMenuAction);
tabButton->setAutoRaise(true);
tabButton->setPopupMode(QToolButton::MenuButtonPopup);
QMenu *tabMenu = new QMenu();
QMenu *restoreMenu = new QMenu(tr("Restore"));
QMenu *resetMenu = new QMenu(tr("Reset"));
QMenu *copyMenu = new QMenu(tr("Copy"));
QMenu *swapMenu = new QMenu(tr("Swap"));
QAction *menuAction;
for (int j = 0; j < m_pidBankCount; j++) {
if (j == i) {
restoreMenu->addAction(restoreCurrentAction);
resetMenu->addAction(resetCurrentAction);
copyMenu->addAction(copyCurrentAction);
} else {
menuAction = new QAction(tr("Copy from %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), m_PIDCopyFromSignalMapper, SLOT(map()));
m_PIDCopyFromSignalMapper->setMapping(menuAction, j + 1);
copyMenu->addAction(menuAction);
menuAction = new QAction(tr("Copy to %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), m_PIDCopyToSignalMapper, SLOT(map()));
m_PIDCopyToSignalMapper->setMapping(menuAction, j + 1);
copyMenu->addAction(menuAction);
menuAction = new QAction(tr("Swap with %1").arg(j + 1), this);
connect(menuAction, SIGNAL(triggered()), m_PIDSwapSignalMapper, SLOT(map()));
m_PIDSwapSignalMapper->setMapping(menuAction, j + 1);
swapMenu->addAction(menuAction);
}
}
restoreMenu->addAction(restoreAllAction);
resetMenu->addAction(resetAllAction);
tabMenu->addMenu(copyMenu);
tabMenu->addMenu(swapMenu);
tabMenu->addMenu(resetMenu);
tabMenu->addMenu(restoreMenu);
tabButton->setMenu(tabMenu);
tabBar->setTabButton(i, QTabBar::RightSide, tabButton);
}
tabBar->setExpanding(false);
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(pidBankChanged(int)));
@ -163,6 +226,18 @@ ConfigStabilizationWidget::ConfigStabilizationWidget(QWidget *parent) : ConfigTa
ConfigStabilizationWidget::~ConfigStabilizationWidget()
{
// Do nothing
if (m_PIDCopyFromSignalMapper) {
delete m_PIDCopyFromSignalMapper;
m_PIDCopyFromSignalMapper = NULL;
}
if (m_PIDCopyToSignalMapper) {
delete m_PIDCopyToSignalMapper;
m_PIDCopyToSignalMapper = NULL;
}
if (m_PIDSwapSignalMapper) {
delete m_PIDSwapSignalMapper;
m_PIDSwapSignalMapper = NULL;
}
}
void ConfigStabilizationWidget::refreshWidgetsValues(UAVObject *o)
@ -338,6 +413,46 @@ void ConfigStabilizationWidget::replotExpoYaw(int value)
replotExpo(value, m_expoPlotCurveYaw);
}
void ConfigStabilizationWidget::restoreAllPIDBanks()
{
qDebug() << "restoreAllPIDBanks";
}
void ConfigStabilizationWidget::resetAllPIDBanks()
{
qDebug() << "resetAllPIDBanks";
}
void ConfigStabilizationWidget::restoreCurrentAction()
{
qDebug() << "restoreCurrentAction";
}
void ConfigStabilizationWidget::resetCurrentPIDBank()
{
qDebug() << "resetCurrentPIDBank";
}
void ConfigStabilizationWidget::copyCurrentPIDBank()
{
qDebug() << "copyCurrentPIDBank";
}
void ConfigStabilizationWidget::copyFromBankToCurrent(int bank)
{
qDebug() << "copyFromBankToCurrent" << bank;
}
void ConfigStabilizationWidget::copyToBankFromCurrent(int bank)
{
qDebug() << "copyToBankFromCurrent" << bank;
}
void ConfigStabilizationWidget::swapBankAndCurrent(int bank)
{
qDebug() << "swapBankAndCurrent" << bank;
}
void ConfigStabilizationWidget::realtimeUpdatesSlot(bool value)
{
ui->realTimeUpdates_6->setChecked(value);

View File

@ -35,6 +35,7 @@
#include "stabilizationsettings.h"
#include <QWidget>
#include <QTimer>
#include <QSignalMapper>
#include "qwt/src/qwt_plot_curve.h"
#include "qwt/src/qwt_plot_grid.h"
@ -51,6 +52,7 @@ private:
QTimer *realtimeUpdates;
QList<QTabBar *> m_pidTabBars;
QString m_stabilizationObjectsString;
QAction *m_defaultPIDMenuAction;
// Milliseconds between automatic 'Instant Updates'
static const int AUTOMATIC_UPDATE_RATE = 500;
@ -66,6 +68,9 @@ private:
QwtPlotCurve m_expoPlotCurvePitch;
QwtPlotCurve m_expoPlotCurveYaw;
QwtPlotGrid m_plotGrid;
QSignalMapper *m_PIDCopyFromSignalMapper;
QSignalMapper *m_PIDCopyToSignalMapper;
QSignalMapper *m_PIDSwapSignalMapper;
void updateThrottleCurveFromObject();
void updateObjectFromThrottleCurve();
@ -89,5 +94,15 @@ private slots:
void replotExpoRoll(int value);
void replotExpoPitch(int value);
void replotExpoYaw(int value);
void restoreAllPIDBanks();
void resetAllPIDBanks();
void restoreCurrentAction();
void resetCurrentPIDBank();
void copyCurrentPIDBank();
void copyFromBankToCurrent(int bank);
void copyToBankFromCurrent(int bank);
void swapBankAndCurrent(int bank);
};
#endif // ConfigStabilizationWidget_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -31,6 +31,7 @@
#include <QWidget>
#include <QLineEdit>
#include <QToolButton>
ConfigTaskWidget::ConfigTaskWidget(QWidget *parent) : QWidget(parent), m_currentBoardId(-1), m_isConnected(false), m_isWidgetUpdatesAllowed(true),
m_saveButton(NULL), m_isDirty(false), m_outOfLimitsStyle("background-color: rgb(255, 0, 0);"), m_realtimeUpdateTimer(NULL)
@ -361,6 +362,7 @@ void ConfigTaskWidget::enableControls(bool enable)
}
}
}
emit enableControlsChanged(enable);
}
bool ConfigTaskWidget::shouldObjectBeSaved(UAVObject *object)
@ -809,6 +811,8 @@ void ConfigTaskWidget::connectWidgetUpdatesToSlot(QWidget *widget, const char *f
connect(cb, SIGNAL(stateChanged(int)), this, function, Qt::UniqueConnection);
} else if (QPushButton * cb = qobject_cast<QPushButton *>(widget)) {
connect(cb, SIGNAL(clicked()), this, function, Qt::UniqueConnection);
} else if (QToolButton * cb = qobject_cast<QToolButton *>(widget)) {
connect(cb, SIGNAL(clicked()), this, function, Qt::UniqueConnection);
} else {
qDebug() << __FUNCTION__ << "widget binding not implemented" << widget->metaObject()->className();
}
@ -837,6 +841,8 @@ void ConfigTaskWidget::disconnectWidgetUpdatesToSlot(QWidget *widget, const char
disconnect(cb, SIGNAL(stateChanged(int)), this, function);
} else if (QPushButton * cb = qobject_cast<QPushButton *>(widget)) {
disconnect(cb, SIGNAL(clicked()), this, function);
} else if (QToolButton * cb = qobject_cast<QToolButton *>(widget)) {
disconnect(cb, SIGNAL(clicked()), this, function);
} else {
qDebug() << __FUNCTION__ << "widget binding not implemented" << widget->metaObject()->className();
}

View File

@ -173,6 +173,7 @@ signals:
// fired when the autopilot disconnects
void autoPilotDisconnected();
void defaultRequested(int group);
void enableControlsChanged(bool enable);
private slots:
void objectUpdated(UAVObject *object);