Commit d7137bbe authored by tstellanova's avatar tstellanova

refactor QGCUASParamManager to be Controller-only (no View code)

parent 09a26af9
......@@ -471,7 +471,8 @@ HEADERS += src/MG.h \
src/ui/configuration/ApmFirmwareConfig.h \
src/uas/UASParameterDataModel.h \
src/uas/UASParameterCommsMgr.h \
src/ui/QGCPendingParamWidget.h
src/ui/QGCPendingParamWidget.h \
src/ui/QGCBaseParamWidget.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
......@@ -689,7 +690,8 @@ SOURCES += src/main.cc \
src/ui/configuration/ApmFirmwareConfig.cc \
src/uas/UASParameterDataModel.cc \
src/uas/UASParameterCommsMgr.cc \
src/ui/QGCPendingParamWidget.cc
src/ui/QGCPendingParamWidget.cc \
src/ui/QGCBaseParamWidget.cc
# 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
......
......@@ -2,28 +2,46 @@
#include <QApplication>>
#include <QDir>
#include <QMessageBox>
#include "UASInterface.h"
#include "UASParameterCommsMgr.h"
QGCUASParamManager::QGCUASParamManager(UASInterface* uas, QWidget *parent) :
QWidget(parent),
QGCUASParamManager::QGCUASParamManager(QObject *parent, UASInterface* uas) :
QObject(parent),
mav(uas),
paramDataModel(NULL),
paramDataModel(this),
paramCommsMgr(NULL)
{
paramDataModel = uas->getParamDataModel();
paramCommsMgr = uas->getParamCommsMgr();
mav->setParamManager(this);
paramCommsMgr = new UASParameterCommsMgr(this,mav);
// Load default values and tooltips
loadParamMetaInfoCSV();
connectToCommsMgr();
}
void QGCUASParamManager::connectToCommsMgr()
{
// Pass along comms mgr status msgs
connect(paramCommsMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
this, SIGNAL(parameterStatusMsgUpdated(QString,int)));
connect(paramCommsMgr, SIGNAL(parameterListUpToDate()),
this, SIGNAL(parameterListUpToDate()));
}
bool QGCUASParamManager::getParameterValue(int component, const QString& parameter, QVariant& value) const
{
return paramDataModel->getOnboardParamValue(component,parameter,value);
return paramDataModel.getOnboardParamValue(component,parameter,value);
}
......@@ -42,29 +60,31 @@ void QGCUASParamManager::requestParameterUpdate(int component, const QString& pa
*/
void QGCUASParamManager::requestParameterList()
{
if (!mav) {
return;
if (mav) {
emit parameterStatusMsgUpdated(tr("Requested param list.. waiting"), UASParameterCommsMgr::ParamCommsStatusLevel_OK);
paramCommsMgr->requestParameterList();
}
setParameterStatusMsg(tr("Requested param list.. waiting"));
paramCommsMgr->requestParameterList();
}
void QGCUASParamManager::setParameterStatusMsg(const QString& msg)
void QGCUASParamManager::requestParameterListIfEmpty()
{
qDebug() << "parameterStatusMsg: " << msg;
parameterStatusMsg = msg;
if (mav) {
int totalOnboard = paramDataModel.countOnboardParams();
if (totalOnboard < 2) { //TODO arbitrary constant, maybe 0 is OK?
requestParameterList();
}
}
}
void QGCUASParamManager::setParamDescriptions(const QMap<QString,QString>& paramInfo) {
paramDataModel->setParamDescriptions(paramInfo);
paramDataModel.setParamDescriptions(paramInfo);
}
void QGCUASParamManager::setParameter(int compId, QString paramName, QVariant value)
{
//paramCommsMgr->setParameter(compId,paramName,value);
paramDataModel->updatePendingParamWithValue(compId,paramName,value);
paramDataModel.updatePendingParamWithValue(compId,paramName,value);
}
void QGCUASParamManager::sendPendingParameters()
......@@ -74,7 +94,7 @@ void QGCUASParamManager::sendPendingParameters()
void QGCUASParamManager::setPendingParam(int compId, QString& paramName, const QVariant& value)
{
paramDataModel->updatePendingParamWithValue(compId,paramName,value);
paramDataModel.updatePendingParamWithValue(compId,paramName,value);
}
......@@ -97,16 +117,59 @@ void QGCUASParamManager::loadParamMetaInfoCSV()
}
QTextStream in(&paramMetaFile);
paramDataModel->loadParamMetaInfoFromStream(in);
paramDataModel.loadParamMetaInfoFromStream(in);
paramMetaFile.close();
}
/**
* @return The MAV of this mgr. Unless the MAV object has been destroyed, this
* pointer is never zero.
*/
UASInterface* QGCUASParamManager::getUAS()
{
return mav;
}
UASParameterDataModel* QGCUASParamManager::dataModel()
{
return &paramDataModel;
}
void QGCUASParamManager::writeOnboardParamsToStream(QTextStream &stream, const QString& uasName)
{
paramDataModel.writeOnboardParamsToStream(stream,uasName);
}
void QGCUASParamManager::readPendingParamsFromStream(QTextStream &stream)
{
paramDataModel.readUpdateParamsFromStream(stream);
}
void QGCUASParamManager::copyVolatileParamsToPersistent()
{
int changedParamCount = paramDataModel.countPendingParams();
if (changedParamCount > 0) {
QMessageBox msgBox;
msgBox.setText(tr("There are locally changed parameters. Please transmit them first (<TRANSMIT>) or update them with the onboard values (<REFRESH>) before storing onboard from RAM to ROM."));
msgBox.exec();
}
else {
paramCommsMgr->writeParamsToPersistentStorage();
}
}
void QGCUASParamManager::copyPersistentParamsToVolatile()
{
if (mav) {
mav->readParametersFromStorage(); //TODO use comms mgr instead?
}
}
void QGCUASParamManager::requestRcCalibrationParamsUpdate() {
paramCommsMgr->requestRcCalibrationParamsUpdate();
}
......@@ -6,16 +6,18 @@
#include <QTimer>
#include <QVariant>
#include "UASParameterDataModel.h"
//forward declarations
class QTextStream;
class UASInterface;
class UASParameterCommsMgr;
class UASParameterDataModel;
class QGCUASParamManager : public QWidget
class QGCUASParamManager : public QObject
{
Q_OBJECT
public:
QGCUASParamManager(UASInterface* uas, QWidget *parent = 0);
QGCUASParamManager(QObject* parent = 0,UASInterface* uas = 0);
/** @brief Get the known, confirmed value of a parameter */
virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const;
......@@ -28,16 +30,23 @@ public:
*/
UASInterface* getUAS();
/** @return The data model managed by this class */
virtual UASParameterDataModel* dataModel();
protected:
//TODO decouple this UI message display further?
virtual void setParameterStatusMsg(const QString& msg);
/** @brief Load parameter meta information from appropriate CSV file */
virtual void loadParamMetaInfoCSV();
void connectToCommsMgr();
signals:
void parameterChanged(int component, QString parameter, QVariant value);
void parameterChanged(int component, int parameterIndex, QVariant value);
/** @brief We updated the parameter status message */
void parameterStatusMsgUpdated(QString msg, int level);
/** @brief We have received a complete list of all parameters onboard the MAV */
void parameterListUpToDate();
public slots:
/** @brief Send one parameter to the MAV: changes value in transient memory of MAV */
......@@ -49,25 +58,32 @@ public slots:
/** @brief Request list of parameters from MAV */
virtual void requestParameterList();
/** @brief Request a list of params onboard the MAV if the onboard param list we have is empty */
virtual void requestParameterListIfEmpty();
virtual void setPendingParam(int componentId, QString& key, const QVariant& value);
/** @brief Request a single parameter by name from the MAV */
virtual void requestParameterUpdate(int component, const QString& parameter);
virtual void handleParameterUpdate(int component, const QString& parameterName, QVariant value) = 0;
virtual void handleParameterListUpToDate() = 0;
virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName);
virtual void readPendingParamsFromStream(QTextStream &stream);
virtual void requestRcCalibrationParamsUpdate();
/** @brief Copy the current parameters in volatile RAM to persistent storage (EEPROM/HDD) */
virtual void copyVolatileParamsToPersistent();
/** @brief Copy the parameters from persistent storage to volatile RAM */
virtual void copyPersistentParamsToVolatile();
protected:
// Parameter data model
UASInterface* mav; ///< The MAV this manager is controlling
UASParameterDataModel* paramDataModel;///< Shared data model of parameters
UASParameterDataModel paramDataModel;///< Shared data model of parameters
UASParameterCommsMgr* paramCommsMgr; ///< Shared comms mgr for parameters
// Status
QString parameterStatusMsg;
};
#endif // QGCUASPARAMMANAGER_H
This diff is collapsed.
......@@ -492,9 +492,7 @@ protected: //COMMENTS FOR TEST UNIT
/// PARAMETERS
QMap<int, QMap<QString, QVariant>* > parameters; ///< All parameters
bool paramsOnceRequested; ///< If the parameter list has been read at least once
QGCUASParamManager* paramManager; ///< Parameter manager class
UASParameterDataModel* paramDataModel; ///< The parameter data model for this UAS
UASParameterCommsMgr* paramCommsMgr;
QGCUASParamManager paramManager; ///< Parameter manager for this UAS
/// SIMULATION
QGCHilLink* simulation; ///< Hardware in the loop simulation link
......@@ -515,36 +513,22 @@ public:
/** @brief Check if vehicle is armed */
bool isArmed() const { return systemIsArmed; }
/** @brief Get reference to the waypoint manager **/
UASWaypointManager* getWaypointManager() {
return &waypointManager;
}
/** @brief Get reference to the param manager **/
QGCUASParamManager* getParamManager() const {
return paramManager;
}
/** @brief Get reference to the parameter data model (same one shared with the parameter manager) **/
UASParameterDataModel* getParamDataModel() {
return paramDataModel;
}
UASParameterCommsMgr* getParamCommsMgr() {
return paramCommsMgr;
/** @brief Get reference to the param manager **/
virtual QGCUASParamManager* getParamManager() {
return &paramManager;
}
/** @brief Get the HIL simulation */
QGCHilLink* getHILSimulation() const {
return simulation;
}
// TODO Will be removed
/** @brief Set reference to the param manager **/
void setParamManager(QGCUASParamManager* manager) {
paramManager = manager;
}
int getSystemType();
/**
......@@ -953,6 +937,8 @@ protected:
/** @brief Get the UNIX timestamp in milliseconds, ignore attitudeStamped mode */
quint64 getUnixReferenceTime(quint64 time);
virtual void processParamValueMsg(mavlink_message_t& msg, const QString& paramName,const mavlink_param_value_t& rawValue, mavlink_param_union_t& paramValue);
int componentID[256];
bool componentMulti[256];
bool connectionLost; ///< Flag indicates a timed out connection
......
......@@ -154,18 +154,8 @@ public:
/** @brief Get reference to the waypoint manager **/
virtual UASWaypointManager* getWaypointManager(void) = 0;
/** @brief Access the parameter data model for this UAS (sans widget). This is the same parameter data model used by the parameter manager. **/
virtual UASParameterDataModel* getParamDataModel() = 0;
virtual UASParameterCommsMgr* getParamCommsMgr() = 0;
/** @brief Get reference to the param manager **/
virtual QGCUASParamManager* getParamManager() const = 0;
// TODO Will be removed
/** @brief Set reference to the param manager **/
virtual void setParamManager(QGCUASParamManager* manager) = 0;
virtual QGCUASParamManager* getParamManager() = 0;
/* COMMUNICATION FLAGS */
......
......@@ -18,7 +18,7 @@ UASParameterCommsMgr::UASParameterCommsMgr(QObject *parent, UASInterface *uas) :
rewriteTimeout(1000),
retransmissionBurstRequestSize(5)
{
paramDataModel = mav->getParamDataModel();
paramDataModel = mav->getParamManager()->dataModel();
loadParamCommsSettings();
......@@ -60,15 +60,6 @@ void UASParameterCommsMgr::loadParamCommsSettings()
}
void UASParameterCommsMgr::requestParameterListIfEmpty()
{
int totalOnboard = paramDataModel->countOnboardParams();
if (totalOnboard < 2) { //TODO arbitrary constant, maybe 0 is OK?
requestParameterList();
}
}
/**
* Send a request to deliver the list of onboard parameters
......
......@@ -72,8 +72,6 @@ public slots:
/** @brief Request list of parameters from MAV */
virtual void requestParameterList();
/** @brief Request a list of params onboard the MAV if the onboard param list we have is empty */
virtual void requestParameterListIfEmpty();
/** @brief Check for missing parameters */
virtual void retransmissionGuardTick();
......
......@@ -97,14 +97,15 @@ void ParameterInterface::addUAS(UASInterface* uas)
return;
}
QGCParamWidget* param = new QGCParamWidget(uas, this);
param->init();
QGCParamWidget* paramWidget = new QGCParamWidget(this);
paramWidget = (QGCParamWidget*)paramWidget->initWithUAS(uas);
QString ptrStr;
ptrStr.sprintf("QGCParamWidget %8p (parent %8p)", param,this);
ptrStr.sprintf("QGCParamWidget %8p (parent %8p)", paramWidget,this);
qDebug() << "Created " << ptrStr << " for UAS id: " << uasId << " count: " << paramWidgets->count();
paramWidgets->insert(uasId, param);
m_ui->stackedWidget->addWidget(param);
paramWidgets->insert(uasId, paramWidget);
m_ui->stackedWidget->addWidget(paramWidget);
QGCSensorSettingsWidget* sensor = NULL;
......@@ -119,7 +120,7 @@ void ParameterInterface::addUAS(UASInterface* uas)
// Clear
if (m_ui->sensorSettings && sensor)
m_ui->sensorSettings->setCurrentWidget(sensor);
m_ui->stackedWidget->setCurrentWidget(param);
m_ui->stackedWidget->setCurrentWidget(paramWidget);
curr = 0;
}
}
......
#include "QGCBaseParamWidget.h"
#include <QFileDialog>
#include <QFile>
#include <QVariant>
#include <QTextStream>>
#include "QGCUASParamManager.h"
#include "UASInterface.h"
QGCBaseParamWidget::QGCBaseParamWidget(QWidget *parent) :
QWidget(parent),
mav(NULL),
paramMgr(NULL),
updatingParamNameLock("")
{
}
QGCBaseParamWidget* QGCBaseParamWidget::initWithUAS(UASInterface *uas)
{
setUAS(uas);
layoutWidget();
return this;
}
void QGCBaseParamWidget::setUAS(UASInterface* uas)
{
if (mav) {
//TODO disconnect any connections as needed
disconnectViewSignalsAndSlots();
disconnectFromParamManager();
clearOnboardParamDisplay();
clearPendingParamDisplay();
}
mav = uas;
connectToParamManager();
connectViewSignalsAndSlots();
paramMgr->requestParameterListIfEmpty();
}
void QGCBaseParamWidget::connectToParamManager()
{
//TODO route via paramManager instead?
// Listen to updated param signals from the data model
connect(paramMgr->dataModel(), SIGNAL(parameterUpdated(int, QString , QVariant )),
this, SLOT(handleOnboardParamUpdate(int,QString,QVariant)));
connect(paramMgr->dataModel(), SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
this, SLOT(handlePendingParamUpdate(int , const QString& , QVariant, bool )));
// Listen for param list reload finished
connect(paramMgr, SIGNAL(parameterListUpToDate()),
this, SLOT(handleOnboardParameterListUpToDate()));
// Listen to communications status messages so we can display them
connect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
this, SLOT(handleParamStatusMsgUpdate(QString , int )));
}
void QGCBaseParamWidget::disconnectFromParamManager()
{
disconnect(paramMgr->dataModel(), SIGNAL(parameterUpdated(int, QString , QVariant )),
this, SLOT(handleOnboardParamUpdate(int,QString,QVariant)));
disconnect(paramMgr->dataModel(), SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
this, SLOT(handlePendingParamUpdate(int , const QString& , QVariant, bool )));
disconnect(paramMgr, SIGNAL(parameterListUpToDate()),
this, SLOT(handleOnboardParameterListUpToDate()));
// Listen to communications status messages so we can display them
disconnect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
this, SLOT(handleParamStatusMsgUpdate(QString , int )));
}
void QGCBaseParamWidget::requestOnboardParamsUpdate()
{
paramMgr->requestParameterList();
}
void QGCBaseParamWidget::saveParametersToFile()
{
if (!mav)
return;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "./parameters.txt", tr("Parameter File (*.txt)"));
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
}
QTextStream outstream(&file);
paramMgr->writeOnboardParamsToStream(outstream,mav->getUASName());
file.close();
}
void QGCBaseParamWidget::loadParametersFromFile()
{
if (!mav)
return;
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), ".", tr("Parameter file (*.txt)"));
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
paramMgr->readPendingParamsFromStream(in);
file.close();
}
#ifndef QGCBASEPARAMWIDGET_H
#define QGCBASEPARAMWIDGET_H
#include <QVariant>
#include <QWidget>
//forward declarations
class QGCUASParamManager;
class UASInterface;
class QGCBaseParamWidget : public QWidget
{
Q_OBJECT
public:
explicit QGCBaseParamWidget(QWidget *parent = 0);
virtual QGCBaseParamWidget* initWithUAS(UASInterface* uas);///< Two-stage construction: initialize this object
virtual void setUAS(UASInterface* uas);///< Allows swapping the underlying UAS
protected:
virtual void setParameterStatusMsg(const QString& msg) = 0;
virtual void layoutWidget() = 0;///< Layout the appearance of this widget
virtual void connectViewSignalsAndSlots() = 0;///< Connect view signals/slots as needed
virtual void disconnectViewSignalsAndSlots() = 0;///< Disconnect view signals/slots as needed
virtual void connectToParamManager(); ///>Connect to any required param manager signals
virtual void disconnectFromParamManager(); ///< Disconnect from any connected param manager signals
signals:
public slots:
virtual void handleOnboardParamUpdate(int component,const QString& parameterName, QVariant value) = 0;
virtual void handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending) = 0;
virtual void handleOnboardParameterListUpToDate() = 0;
virtual void handleParamStatusMsgUpdate(QString msg, int level) = 0;
/** @brief Clear the rendering of onboard parameters */
virtual void clearOnboardParamDisplay() = 0;
/** @brief Clear the rendering of pending parameters */
virtual void clearPendingParamDisplay() = 0;
/** @brief Request list of parameters from MAV */
virtual void requestOnboardParamsUpdate();
/** @brief Store parameters to a file */
virtual void saveParametersToFile();
/** @brief Load parameters from a file */
virtual void loadParametersFromFile();
protected:
QGCUASParamManager* paramMgr;
UASInterface* mav;
QString updatingParamNameLock; ///< Name of param currently being updated-- used for reducing echo on param change
};
#endif // QGCBASEPARAMWIDGET_H
......@@ -84,7 +84,7 @@ QGCPX4VehicleConfig::QGCPX4VehicleConfig(QWidget *parent) :
//connect(ui->setTrimButton, SIGNAL(clicked()), this, SLOT(setTrimPositions()));
//TODO connect buttons here to save/clear actions?
ui->pendingCommitsWidget->init();
ui->pendingCommitsWidget->initWithUAS(this->mav);
ui->pendingCommitsWidget->update();
//TODO the following methods are not yet implemented
......@@ -798,11 +798,11 @@ void QGCPX4VehicleConfig::loadConfig()
}
if (!paramTooltips.isEmpty()) {
mav->getParamManager()->setParamDescriptions(paramTooltips);
paramMgr->setParamDescriptions(paramTooltips);
}
doneLoadingConfig = true;
//Config is finished, lets do a parameter request to ensure none are missed if someone else started requesting before we were finished.
paramCommsMgr->requestParameterListIfEmpty();
paramMgr->requestParameterListIfEmpty();
}
void QGCPX4VehicleConfig::setActiveUAS(UASInterface* active)
......@@ -828,6 +828,7 @@ void QGCPX4VehicleConfig::setActiveUAS(UASInterface* active)
if (mav)
{
// Disconnect old system
disconnect(mav, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
......@@ -835,7 +836,7 @@ void QGCPX4VehicleConfig::setActiveUAS(UASInterface* active)
disconnect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
disconnect(ui->refreshButton,SIGNAL(clicked()),
paramCommsMgr,SLOT(requestParameterList()));
paramMgr,SLOT(requestParameterList()));
// Delete all children from all fixed tabs.
foreach(QWidget* child, ui->generalLeftContents->findChildren<QWidget*>()) {
......@@ -868,22 +869,23 @@ void QGCPX4VehicleConfig::setActiveUAS(UASInterface* active)
// Connect new system
mav = active;
paramCommsMgr = mav->getParamCommsMgr();
paramMgr = mav->getParamManager();
// Reset current state
resetCalibrationRC();
requestCalibrationRC();
//TODO eliminate the separate RC_TYPE call
mav->requestParameter(0, "RC_TYPE");
chanCount = 0;
//TODO get parameter changes via Param Mgr instead
// Connect new system
connect(mav, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
connect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
connect(ui->refreshButton, SIGNAL(clicked()),
paramCommsMgr,SLOT(requestParameterList()));
paramMgr,SLOT(requestParameterList()));
if (systemTypeToParamMap.contains(mav->getSystemTypeName())) {
paramToWidgetMap = systemTypeToParamMap[mav->getSystemTypeName()];
......@@ -978,9 +980,7 @@ void QGCPX4VehicleConfig::writeCalibrationRC()
void QGCPX4VehicleConfig::requestCalibrationRC()
{
if (paramCommsMgr) {
paramCommsMgr->requestRcCalibrationParamsUpdate();
}
paramMgr->requestRcCalibrationParamsUpdate();
}
void QGCPX4VehicleConfig::writeParameters()
......
......@@ -161,7 +161,7 @@ protected slots:
protected:
bool doneLoadingConfig;
UASInterface* mav; ///< The current MAV
UASParameterCommsMgr* paramCommsMgr; ///< param comms mgr for the mav
QGCUASParamManager* paramMgr; ///< params mgr for the mav
static const unsigned int chanMax = 8; ///< Maximum number of channels
unsigned int chanCount; ///< Actual channels
int rcType; ///< Type of the remote control
......
This diff is collapsed.
......@@ -37,64 +37,54 @@ This file is part of the QGROUNDCONTROL project
#include <QLabel>
#include <QTimer>
#include "QGCUASParamManager.h"
#include "UASInterface.h"
#include "QGCBaseParamWidget.h"
//forward declarations
class UASInterface;
/**
* @brief Widget to read/set onboard parameters
*/
class QGCParamWidget : public QGCUASParamManager
class QGCParamWidget : public QGCBaseParamWidget
{
Q_OBJECT
public:
QGCParamWidget(UASInterface* uas, QWidget *parent = 0);
virtual void init(); ///< Two-stage construction: initialize the object
QGCParamWidget(QWidget *parent = 0);
protected:
virtual void setParameterStatusMsg(const QString& msg);
virtual void layoutWidget();///< Layout the appearance of this widget
virtual void connectSignalsAndSlots();///< Connect signals/slots as needed
virtual void connectViewSignalsAndSlots();///< Connect view signals/slots as needed
virtual void disconnectViewSignalsAndSlots();///< Connect view signals/slots as needed
virtual QTreeWidgetItem* getParentWidgetItemForParam(int compId, const QString& paramName);
virtual QTreeWidgetItem* findChildWidgetItemForParam(QTreeWidgetItem* parentItem, const QString& paramName);
signals:
public slots:
/** @brief Add a component to the list
/** @brief Add a component item as a child of this widget
* @param compId Component id of the component
* @param compName Human friendly name of the component
*/
void addComponentItem(int compId, QString compName);
signals:
virtual void handleParameterUpdate(int component,const QString& parameterName, QVariant value);
virtual void handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending);
virtual void handleParameterListUpToDate();
public slots:
virtual void handleOnboardParamUpdate(int component,const QString& parameterName, QVariant value);
virtual void handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending);
virtual void handleOnboardParameterListUpToDate();
virtual void handleParamStatusMsgUpdate(QString msg, int level);
virtual void clearOnboardParamDisplay();
virtual void clearPendingParamDisplay();
/** @brief Ensure that view of parameter matches data in the model */
QTreeWidgetItem* updateParameterDisplay(int component, QString parameterName, QVariant value);
/** @brief Request list of parameters from MAV */
void requestAllParamsUpdate();
/** @brief Write the current parameters to permanent storage (EEPROM/HDD) */
void writeParameters();
/** @brief Read the parameters from permanent storage to RAM */
void readParameters();
/** @brief Clear the parameter list */
void clear();
/** @brief Update when user changes parameters */
void parameterItemChanged(QTreeWidgetItem* prev, int column);
/** @brief Store parameters to a file */
void saveParametersToFile();
/** @brief Load parameters from a file */
void loadParametersFromFile();
/** @brief Update when user changes parameters */
void parameterItemChanged(QTreeWidgetItem* prev, int column);
protected:
......@@ -102,7 +92,6 @@ protected:
QLabel* statusLabel; ///< User-facing parameter status label
QMap<int, QTreeWidgetItem*>* componentItems; ///< The tree of component items, stored by component ID
QMap<int, QMap<QString, QTreeWidgetItem*>* > paramGroups; ///< Parameter groups to organize component items
QString updatingParamNameLock; ///< Name of param currently being updated-- used for reducing echo on param change
};
......
......@@ -5,31 +5,48 @@
QGCPendingParamWidget::QGCPendingParamWidget(QObject *parent) :
QGCParamWidget(UASManager::instance()->getActiveUAS(),(QWidget*)parent)
QGCParamWidget((QWidget*)parent)
{
}
void QGCPendingParamWidget::init()
void QGCPendingParamWidget::connectToParamManager()
{
//we override a lot of the super's init methods
layoutWidget();
connectSignalsAndSlots();
//TODO route via paramManager instead?
// Listen to updated param signals from the data model
connect(paramMgr->dataModel(), SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
this, SLOT(handlePendingParamUpdate(int , const QString& , QVariant, bool )));
//don't request update params here...assume that everything we need is in the data model
// Listen to communications status messages so we can display them
connect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
this, SLOT(handleParamStatusMsgUpdate(QString , int )));
}
void QGCPendingParamWidget::connectSignalsAndSlots()
void QGCPendingParamWidget::disconnectFromParamManager()
{
// Listing for pending list update
connect(paramDataModel, SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
//TODO route via paramManager instead?
// Listen to updated param signals from the data model
disconnect(paramMgr->dataModel(), SIGNAL(pendingParamUpdate(int , const QString&, QVariant , bool )),
this, SLOT(handlePendingParamUpdate(int , const QString& , QVariant, bool )));
// Listen to communications status messages so we can display them
connect(paramCommsMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
disconnect(paramMgr, SIGNAL(parameterStatusMsgUpdated(QString,int)),
this, SLOT(handleParamStatusMsgUpdate(QString , int )));
}
void QGCPendingParamWidget::disconnectViewSignalsAndSlots()
{
//we ignore edits from the tree view
}
void QGCPendingParamWidget::connectViewSignalsAndSlots()
{
//we ignore edits from the tree view
}
void QGCPendingParamWidget::handlePendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending)
{
// qDebug() << "handlePendingParamUpdate:" << paramName << "with updatingParamNameLock:" << updatingParamNameLock;
......
......@@ -10,11 +10,13 @@ class QGCPendingParamWidget : public QGCParamWidget
public:
explicit QGCPendingParamWidget(QObject* parent);
virtual void init(); ///< Two-stage construction: initialize the object
protected:
virtual void connectSignalsAndSlots();
virtual void connectToParamManager();
virtual void disconnectFromParamManager();
virtual void connectViewSignalsAndSlots();
virtual void disconnectViewSignalsAndSlots();
signals:
......
......@@ -788,10 +788,12 @@ void QGCVehicleConfig::loadConfig()
xml.readNext();
}
mav->getParamManager()->setParamDescriptions(paramTooltips);
if (!paramTooltips.isEmpty()) {
paramMgr->setParamDescriptions(paramTooltips);
}
doneLoadingConfig = true;
//Config is finished, lets do a parameter request to ensure none are missed if someone else started requesting before we were finished.
mav->getParamCommsMgr()->requestParameterListIfEmpty();
paramMgr->requestParameterListIfEmpty();
}
void QGCVehicleConfig::setActiveUAS(UASInterface* active)
......@@ -862,6 +864,7 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active)
// Connect new system
mav = active;
paramMgr = mav->getParamManager();
// Reset current state
resetCalibrationRC();
......@@ -977,15 +980,14 @@ void QGCVehicleConfig::writeCalibrationRC()
void QGCVehicleConfig::requestCalibrationRC()
{
if (mav) {
mav->getParamCommsMgr()->requestRcCalibrationParamsUpdate();
}
paramMgr->requestRcCalibrationParamsUpdate();
}
void QGCVehicleConfig::writeParameters()
{
updateStatus(tr("Writing all onboard parameters."));
writeCalibrationRC();
mav->writeParametersToStorage();
}
......
......@@ -158,6 +158,7 @@ protected slots:
protected:
bool doneLoadingConfig;
UASInterface* mav; ///< The current MAV
QGCUASParamManager* paramMgr; ///< params mgr for the mav
static const unsigned int chanMax = 8; ///< Maximum number of channels
unsigned int chanCount; ///< Actual channels
int rcType; ///< Type of the remote control
......
......@@ -17,7 +17,7 @@ QGCComboBox::QGCComboBox(QWidget *parent) :
parameterScalingFactor(0.0),
parameterMin(0.0f),
parameterMax(0.0f),
component(0),
componentId(0),
ui(new Ui::QGCComboBox)
{
ui->setupUi(this);
......@@ -56,7 +56,7 @@ QGCComboBox::QGCComboBox(QWidget *parent) :
//connect(ui->intValueSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setParamValue(int)));
connect(ui->editNameLabel, SIGNAL(textChanged(QString)), ui->nameLabel, SLOT(setText(QString)));
connect(ui->readButton, SIGNAL(clicked()), this, SLOT(requestParameter()));
connect(ui->editRefreshParamsButton, SIGNAL(clicked()), this, SLOT(refreshParamList()));
connect(ui->editRefreshParamsButton, SIGNAL(clicked()), this, SLOT(refreshParameter()));
connect(ui->editInfoCheckBox, SIGNAL(clicked(bool)), this, SLOT(showInfo(bool)));
// connect to self
connect(ui->infoLabel, SIGNAL(released()), this, SLOT(showTooltip()));
......@@ -82,14 +82,13 @@ void QGCComboBox::showTooltip()
}
}
void QGCComboBox::refreshParamList()
void QGCComboBox::refreshParameter()
{
ui->editSelectParamComboBox->setEnabled(true);
ui->editSelectComponentComboBox->setEnabled(true);
if (uas)
{
uas->getParamManager()->requestParameterList();
ui->editStatusLabel->setText(tr("Parameter list updating.."));
if (uas && !parameterName.isEmpty()) {
uas->getParamManager()->requestParameterUpdate(componentId,parameterName);
ui->editStatusLabel->setText(tr("Requesting refresh..."));
}
}
......@@ -105,11 +104,12 @@ void QGCComboBox::setActiveUAS(UASInterface* activeUas)
// Connect buttons and signals
connect(activeUas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(setParameterValue(int,int,int,int,QString,QVariant)), Qt::UniqueConnection);
uas = activeUas;
paramMgr = uas->getParamManager();
// Update current param value
//requestParameter();
// Set param info
QString text = uas->getParamDataModel()->getParamDescription(parameterName);
QString text = paramMgr->dataModel()->getParamDescription(parameterName);
if (!text.isEmpty()) {
ui->infoLabel->setToolTip(text);
ui->infoLabel->show();
......@@ -125,7 +125,7 @@ void QGCComboBox::requestParameter()
{
if (!parameterName.isEmpty() && uas)
{
uas->getParamManager()->requestParameterUpdate(this->component, this->parameterName);
paramMgr->requestParameterUpdate(this->componentId, this->parameterName);
}
}
......@@ -137,7 +137,7 @@ void QGCComboBox::showInfo(bool enable)
void QGCComboBox::selectComponent(int componentIndex)
{
this->component = ui->editSelectComponentComboBox->itemData(componentIndex).toInt();
this->componentId = ui->editSelectComponentComboBox->itemData(componentIndex).toInt();
}
void QGCComboBox::selectParameter(int paramIndex)
......@@ -147,7 +147,7 @@ void QGCComboBox::selectParameter(int paramIndex)
// Update min and max values if available
if (uas) {
UASParameterDataModel* dataModel = uas->getParamDataModel();
UASParameterDataModel* dataModel = paramMgr->dataModel();
if (dataModel) {
// Minimum
if (dataModel->isParamMinKnown(parameterName)) {
......@@ -236,7 +236,7 @@ void QGCComboBox::endEditMode()
void QGCComboBox::setParamPending()
{
if (uas) {
uas->getParamManager()->setPendingParam(component, parameterName, parameterValue);
uas->getParamManager()->setPendingParam(componentId, parameterName, parameterValue);
}
else {
qWarning() << __FILE__ << __LINE__ << "NO UAS SET, DOING NOTHING";
......@@ -292,7 +292,7 @@ void QGCComboBox::setParameterValue(int uas, int component, int paramCount, int
{
if (visibleVal == value.toInt())
{
this->uas->requestParameter(this->component,this->parameterName);
this->uas->requestParameter(this->componentId,this->parameterName);
visibleEnabled = true;
this->show();
}
......@@ -307,7 +307,7 @@ void QGCComboBox::setParameterValue(int uas, int component, int paramCount, int
}
}
}
if (component == this->component && parameterName == this->parameterName)
if (component == this->componentId && parameterName == this->parameterName)
{
if (!visibleEnabled)
{
......@@ -350,7 +350,7 @@ void QGCComboBox::writeSettings(QSettings& settings)
settings.setValue("QGC_PARAM_COMBOBOX_DESCRIPTION", ui->nameLabel->text());
//settings.setValue("QGC_PARAM_COMBOBOX_BUTTONTEXT", ui->actionButton->text());
settings.setValue("QGC_PARAM_COMBOBOX_PARAMID", parameterName);
settings.setValue("QGC_PARAM_COMBOBOX_COMPONENTID", component);
settings.setValue("QGC_PARAM_COMBOBOX_COMPONENTID", componentId);
settings.setValue("QGC_PARAM_COMBOBOX_DISPLAY_INFO", ui->editInfoCheckBox->isChecked());
settings.setValue("QGC_PARAM_COMBOBOX_COUNT", ui->editOptionComboBox->count());
......@@ -364,7 +364,7 @@ void QGCComboBox::writeSettings(QSettings& settings)
void QGCComboBox::readSettings(const QString& pre,const QVariantMap& settings)
{
parameterName = settings.value(pre + "QGC_PARAM_COMBOBOX_PARAMID").toString();
component = settings.value(pre + "QGC_PARAM_COMBOBOX_COMPONENTID").toInt();
componentId = settings.value(pre + "QGC_PARAM_COMBOBOX_COMPONENTID").toInt();
ui->nameLabel->setText(settings.value(pre + "QGC_PARAM_COMBOBOX_DESCRIPTION").toString());
ui->editNameLabel->setText(settings.value(pre + "QGC_PARAM_COMBOBOX_DESCRIPTION").toString());
//settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text());
......
......@@ -7,6 +7,8 @@
#include "QGCToolWidgetItem.h"
class QGCUASParamManager;
namespace Ui
{
class QGCComboBox;
......@@ -26,11 +28,12 @@ public slots:
/** @brief Queue parameter for sending to the MAV (add to pending list)*/
void setParamPending();
/** @brief Update the UI with the new parameter value */
void setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, const QVariant value);
void setParameterValue(int uas, int componentId, int paramCount, int paramIndex, QString parameterName, const QVariant value);
void writeSettings(QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void readSettings(const QSettings& settings);
void refreshParamList();
/** @brief request that the parameter for this widget be refreshed */
void refreshParameter();
void setActiveUAS(UASInterface *uas);
void selectComponent(int componentIndex);
void selectParameter(int paramIndex);
......@@ -49,6 +52,7 @@ protected slots:
/** @brief Updates current parameter based on new combobox value */
void comboBoxIndexChanged(QString val);
protected:
QGCUASParamManager *paramMgr; ///< Access to parameter manager
bool visibleEnabled;
QString visibleParam;
int visibleVal;
......@@ -61,7 +65,7 @@ protected:
float parameterMin;
bool isDisabled;
float parameterMax;
int component; ///< ID of the MAV component to address
int componentId; ///< ID of the MAV component to address
//double scaledInt;
void changeEvent(QEvent *e);
......
......@@ -116,7 +116,7 @@ void QGCParamSlider::setActiveUAS(UASInterface* activeUas)
}
if (uas && !parameterName.isEmpty()) {
QString text = uas->getParamDataModel()->getParamDescription(parameterName);
QString text = uas->getParamManager()->dataModel()->getParamDescription(parameterName);
if (!text.isEmpty()) {
ui->infoLabel->setToolTip(text);
ui->infoLabel->show();
......@@ -190,7 +190,7 @@ void QGCParamSlider::selectParameter(int paramIndex)
// Update min and max values if available
if (uas) {
UASParameterDataModel* dataModel = uas->getParamDataModel();
UASParameterDataModel* dataModel = uas->getParamManager()->dataModel();
if (dataModel) {
// Minimum
if (dataModel->isParamMinKnown(parameterName)) {
......
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