Commit 5e03573c authored by Michael Carpenter's avatar Michael Carpenter

Major change to configuration, to allow for loading from APM generated xml

This commit still allows configuration widgets to be loaded from qgc files
assuming that there is no APM generated xml file (arduplane.pdef.xml) in
the files/%autopilorname%/ directory. This filename needs to be
configurable, and selectable at runtime. It is not yet.
parent bc2fc3e5
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -43,6 +43,7 @@ public:
virtual double getParamMax(const QString& param) = 0;
virtual double getParamDefault(const QString& param) = 0;
virtual QString getParamInfo(const QString& param) = 0;
virtual void setParamInfo(const QMap<QString,QString>& param) = 0;
/** @brief Request an update for the parameter list */
void requestParameterListUpdate(int component = 0);
......
......@@ -127,7 +127,6 @@ public:
QList<QAction*> listLinkMenuActions(void);
public slots:
/** @brief Shows a status message on the bottom status bar */
void showStatusMessage(const QString& status, int timeout);
/** @brief Shows a status message on the bottom status bar */
......
......@@ -58,6 +58,7 @@ public:
double getParamMax(const QString& param) { return paramMax.value(param, 0.0f); }
double getParamDefault(const QString& param) { return paramDefault.value(param, 0.0f); }
QString getParamInfo(const QString& param) { return paramToolTips.value(param, ""); }
void setParamInfo(const QMap<QString,QString>& param) { paramToolTips = param; }
signals:
/** @brief A parameter was changed in the widget, NOT onboard */
......
......@@ -9,6 +9,7 @@
#include <QTimer>
#include <QDir>
#include <QXmlStreamReader>
#include "QGCVehicleConfig.h"
#include "UASManager.h"
......@@ -149,46 +150,8 @@ void QGCVehicleConfig::stopCalibrationRC()
ui->rcTypeComboBox->setEnabled(true);
ui->rcCalibrationButton->setText(tr("Start RC Calibration"));
}
void QGCVehicleConfig::setActiveUAS(UASInterface* active)
void QGCVehicleConfig::loadQgcConfig()
{
// Do nothing if system is the same or NULL
if ((active == NULL) || mav == active) return;
if (mav)
{
// Disconnect old system
disconnect(mav, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
disconnect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
foreach (QGCToolWidget* tool, toolWidgets)
{
delete tool;
}
toolWidgets.clear();
}
// Reset current state
resetCalibrationRC();
chanCount = 0;
// Connect new system
mav = active;
connect(active, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
connect(active, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
mav->requestParameters();
QString defaultsDir = qApp->applicationDirPath() + "/files/" + mav->getAutopilotTypeName().toLower() + "/widgets/";
qDebug() << "CALIBRATION!! System Type Name:" << mav->getSystemTypeName();
QGCToolWidget* tool;
QDir autopilotdir(qApp->applicationDirPath() + "/files/" + mav->getAutopilotTypeName().toLower());
QDir generaldir = QDir(autopilotdir.absolutePath() + "/general/widgets");
QDir vehicledir = QDir(autopilotdir.absolutePath() + "/" + mav->getSystemTypeName().toLower() + "/widgets");
......@@ -202,10 +165,8 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active)
//TODO: Throw an error here too, no autopilot specific configuration
qDebug() << "invalid vehicle dir";
}
qDebug() << autopilotdir.absolutePath();
qDebug() << generaldir.absolutePath();
qDebug() << vehicledir.absolutePath();
int left = true;
QGCToolWidget *tool;
bool left = true;
foreach (QString file,generaldir.entryList(QDir::Files | QDir::NoDotAndDotDot))
{
if (file.toLower().endsWith(".qgw")) {
......@@ -335,10 +296,252 @@ void QGCVehicleConfig::setActiveUAS(UASInterface* active)
} else {
delete tool;
}*/
}
updateStatus(QString("Reading from system %1").arg(mav->getUASName()));
void QGCVehicleConfig::loadConfig()
{
QGCToolWidget* tool;
QDir autopilotdir(qApp->applicationDirPath() + "/files/" + mav->getAutopilotTypeName().toLower());
QDir generaldir = QDir(autopilotdir.absolutePath() + "/general/widgets");
QDir vehicledir = QDir(autopilotdir.absolutePath() + "/" + mav->getSystemTypeName().toLower() + "/widgets");
if (!autopilotdir.exists("general"))
{
//TODO: Throw some kind of error here. There is no general configuration directory
qDebug() << "invalid general dir";
}
if (!autopilotdir.exists(mav->getAutopilotTypeName().toLower()))
{
//TODO: Throw an error here too, no autopilot specific configuration
qDebug() << "invalid vehicle dir";
}
qDebug() << autopilotdir.absolutePath();
qDebug() << generaldir.absolutePath();
qDebug() << vehicledir.absolutePath();
QFile xmlfile(autopilotdir.absolutePath() + "/arduplane.pdef.xml");
if (!xmlfile.open(QIODevice::ReadOnly))
{
loadQgcConfig();
return;
}
QXmlStreamReader xml(xmlfile.readAll());
xmlfile.close();
while (!xml.atEnd())
{
if (xml.isStartElement() && xml.name() == "paramfile")
{
//Beginning of the file
xml.readNext();
while ((xml.name() != "paramfile") && !xml.atEnd())
{
QString valuetype = "";
if (xml.isStartElement() && (xml.name() == "vehicles" || xml.name() == "libraries")) //Enter into the vehicles loop
{
valuetype = xml.name().toString();
xml.readNext();
while ((xml.name() != valuetype) && !xml.atEnd())
{
if (xml.isStartElement() && xml.name() == "parameters") //This is a parameter block
{
QString parametersname = "";
if (xml.attributes().hasAttribute("name"))
{
parametersname = xml.attributes().value("name").toString();
}
QVariantMap set;
set["title"] = parametersname;
QString setname = parametersname;
xml.readNext();
int arraycount = 0;
while ((xml.name() != "parameters") && !xml.atEnd())
{
if (xml.isStartElement() && xml.name() == "param")
{
//set.setArrayIndex(arraycount++);
QString humanname = xml.attributes().value("humanName").toString();
QString name = xml.attributes().value("name").toString();
if (name.contains(":"))
{
name = name.split(":")[1];
}
QString docs = xml.attributes().value("documentation").toString();
paramTooltips[name] = name + " - " + docs;
// qDebug() << "Found param:" << name << humanname;
int type = -1; //Type of item
QMap<QString,QString> fieldmap;
xml.readNext();
while ((xml.name() != "param") && !xml.atEnd())
{
if (xml.isStartElement() && xml.name() == "values")
{
type = 1; //1 is a combobox
set[setname + "\\" + QString::number(arraycount) + "\\" + "TYPE"] = "COMBO";
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_DESCRIPTION"] = humanname;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_PARAMID"] = name;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_COMPONENTID"] = 1;
int paramcount = 0;
xml.readNext();
while ((xml.name() != "values") && !xml.atEnd())
{
if (xml.isStartElement() && xml.name() == "value")
{
QString code = xml.attributes().value("code").toString();
QString arg = xml.readElementText();
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(paramcount) + "_TEXT"] = arg;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(paramcount) + "_VAL"] = code.toInt();
paramcount++;
//qDebug() << "Code:" << code << "Arg:" << arg;
}
xml.readNext();
}
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_COMBOBOX_COUNT"] = paramcount;
}
if (xml.isStartElement() && xml.name() == "field")
{
type = 2; //2 is a slider
QString fieldtype = xml.attributes().value("name").toString();
QString text = xml.readElementText();
fieldmap[fieldtype] = text;
// qDebug() << "Field:" << fieldtype << "Text:" << text;
}
xml.readNext();
}
if (type == -1)
{
//Nothing inside! Assume it's a value
type = 2;
QString fieldtype = "Range";
QString text = "0 100";
fieldmap[fieldtype] = text;
}
if (type == 2)
{
set[setname + "\\" + QString::number(arraycount) + "\\" + "TYPE"] = "SLIDER";
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_SLIDER_DESCRIPTION"] = humanname;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_SLIDER_PARAMID"] = name;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_SLIDER_COMPONENTID"] = 1;
if (fieldmap.contains("Range"))
{
float min = 0;
float max = 0;
if (fieldmap["Range"].split(" ").size() > 1)
{
min = fieldmap["Range"].split(" ")[0].trimmed().toFloat();
max = fieldmap["Range"].split(" ")[1].trimmed().toFloat();
}
else if (fieldmap["Range"].split("-").size() > 1)
{
min = fieldmap["Range"].split("-")[0].trimmed().toFloat();
max = fieldmap["Range"].split("-")[1].trimmed().toFloat();
}
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_SLIDER_MIN"] = min;
set[setname + "\\" + QString::number(arraycount) + "\\" + "QGC_PARAM_SLIDER_MAX"] = max;
}
}
arraycount++;
}
xml.readNext();
}
set["count"] = arraycount;
tool = new QGCToolWidget("", this);
tool->setTitle(parametersname);
tool->setObjectName(parametersname);
tool->setSettings(set);
QList<QString> paramlist = tool->getParamList();
for (int i=0;i<paramlist.size();i++)
{
paramToWidgetMap[paramlist[i]] = tool;
}
toolWidgets.append(tool);
QGroupBox *box = new QGroupBox(this);
box->setTitle(tool->objectName());
box->setLayout(new QVBoxLayout());
box->layout()->addWidget(tool);
if (valuetype == "vehicles")
{
ui->leftGeneralLayout->addWidget(box);
}
else if (valuetype == "libraries")
{
ui->rightGeneralLayout->addWidget(box);
}
box->hide();
toolToBoxMap[tool] = box;
}
xml.readNext();
}
}
xml.readNext();
}
}
xml.readNext();
}
if (mav)
{
mav->getParamManager()->setParamInfo(paramTooltips);
}
emit configReady();
}
void QGCVehicleConfig::setActiveUAS(UASInterface* active)
{
// Do nothing if system is the same or NULL
if ((active == NULL) || mav == active) return;
if (mav)
{
// Disconnect old system
disconnect(mav, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
disconnect(mav, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
foreach (QGCToolWidget* tool, toolWidgets)
{
delete tool;
}
toolWidgets.clear();
}
// Reset current state
resetCalibrationRC();
chanCount = 0;
// Connect new system
mav = active;
connect(active, SIGNAL(remoteControlChannelRawChanged(int,float)), this,
SLOT(remoteControlChannelRawChanged(int,float)));
connect(active, SIGNAL(parameterChanged(int,int,QString,QVariant)), this,
SLOT(parameterChanged(int,int,QString,QVariant)));
if (!paramTooltips.isEmpty())
{
mav->getParamManager()->setParamInfo(paramTooltips);
}
mav->requestParameters();
QString defaultsDir = qApp->applicationDirPath() + "/files/" + mav->getAutopilotTypeName().toLower() + "/widgets/";
qDebug() << "CALIBRATION!! System Type Name:" << mav->getSystemTypeName();
//Load configuration after 1ms. This allows it to go into the event loop, and prevents application hangups due to the
//amount of time it actually takes to load the configuration windows.
QTimer::singleShot(1,this,SLOT(loadConfig()));
updateStatus(QString("Reading from system %1").arg(mav->getUASName()));
}
void QGCVehicleConfig::resetCalibrationRC()
{
for (unsigned int i = 0; i < chanMax; ++i)
......@@ -559,6 +762,24 @@ void QGCVehicleConfig::parameterChanged(int uas, int component, QString paramete
Q_UNUSED(uas);
Q_UNUSED(component);
if (paramToWidgetMap.contains(parameterName))
{
paramToWidgetMap[parameterName]->setParameterValue(uas,component,parameterName,value);
if (toolToBoxMap.contains(paramToWidgetMap[parameterName]))
{
qDebug() << "Parameter update:" << parameterName;
toolToBoxMap[paramToWidgetMap[parameterName]]->show();
}
else
{
qDebug() << "ERROR!!!!!!!!!! widget with no box:" << parameterName;
}
}
else
{
qDebug() << "Param with no widget:" << parameterName;
}
// Channel calibration values
QRegExp minTpl("RC?_MIN");
minTpl.setPatternSyntax(QRegExp::Wildcard);
......
......@@ -4,6 +4,7 @@
#include <QWidget>
#include <QTimer>
#include <QList>
#include <QGroupBox>
#include "QGCToolWidget.h"
#include "UASInterface.h"
......@@ -30,7 +31,8 @@ public:
public slots:
/** Set the MAV currently being calibrated */
void setActiveUAS(UASInterface* active);
void loadQgcConfig();
void loadConfig();
/** Start the RC calibration routine */
void startCalibrationRC();
/** Stop the RC calibration routine */
......@@ -169,12 +171,16 @@ protected:
enum RC_MODE rc_mode; ///< Mode of the remote control, according to usual convention
QList<QGCToolWidget*> toolWidgets; ///< Configurable widgets
bool calibrationEnabled; ///< calibration mode on / off
QMap<QString,QGCToolWidget*> paramToWidgetMap;
QMap<QGCToolWidget*,QGroupBox*> toolToBoxMap;
QMap<QString,QString> paramTooltips;
private:
Ui::QGCVehicleConfig *ui;
signals:
void visibilityChanged(bool visible);
void configReady();
};
#endif // QGCVEHICLECONFIG_H
......@@ -11,7 +11,7 @@
QGCComboBox::QGCComboBox(QWidget *parent) :
QGCToolWidgetItem("Slider", parent),
QGCToolWidgetItem("Combo", parent),
parameterName(""),
parameterValue(0.0f),
parameterScalingFactor(0.0),
......@@ -41,10 +41,8 @@ QGCComboBox::QGCComboBox(QWidget *parent) :
ui->itemNameLabel->hide();
ui->editOptionComboBox->setEnabled(false);
isDisabled = true;
ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
//ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
// ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
connect(ui->editDoneButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
connect(ui->editOptionComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(comboBoxIndexChanged(QString)));
connect(ui->editAddItemButton,SIGNAL(clicked()),this,SLOT(addButtonClicked()));
......@@ -64,7 +62,9 @@ QGCComboBox::QGCComboBox(QWidget *parent) :
// connect to self
connect(ui->infoLabel, SIGNAL(released()), this, SLOT(showTooltip()));
// Set the current UAS if present
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
}
QGCComboBox::~QGCComboBox()
......@@ -107,7 +107,7 @@ void QGCComboBox::setActiveUAS(UASInterface* activeUas)
connect(activeUas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(setParameterValue(int,int,int,int,QString,QVariant)), Qt::UniqueConnection);
uas = activeUas;
// Update current param value
requestParameter();
//requestParameter();
// Set param info
QString text = uas->getParamManager()->getParamInfo(parameterName);
ui->infoLabel->setToolTip(text);
......@@ -351,7 +351,34 @@ void QGCComboBox::writeSettings(QSettings& settings)
}
settings.sync();
}
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();
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());
ui->editSelectParamComboBox->addItem(settings.value(pre + "QGC_PARAM_COMBOBOX_PARAMID").toString());
ui->editSelectParamComboBox->setCurrentIndex(ui->editSelectParamComboBox->count()-1);
ui->editSelectComponentComboBox->addItem(tr("Component #%1").arg(settings.value(pre + "QGC_PARAM_COMBOBOX_COMPONENTID").toInt()), settings.value(pre + "QGC_PARAM_COMBOBOX_COMPONENTID").toInt());
showInfo(settings.value(pre + "QGC_PARAM_COMBOBOX_DISPLAY_INFO", true).toBool());
ui->editSelectParamComboBox->setEnabled(true);
ui->editSelectComponentComboBox->setEnabled(true);
int num = settings.value(pre + "QGC_PARAM_COMBOBOX_COUNT").toInt();
for (int i=0;i<num;i++)
{
ui->editOptionComboBox->addItem(settings.value(pre + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT").toString());
//qDebug() << "Adding val:" << settings.value(pre + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT").toString() << settings.value(pre + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_VAL").toInt();
comboBoxTextToValMap[settings.value(pre + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_TEXT").toString()] = settings.value(pre + "QGC_PARAM_COMBOBOX_ITEM_" + QString::number(i) + "_VAL").toInt();
}
setActiveUAS(UASManager::instance()->getActiveUAS());
// Get param value after settings have been loaded
// requestParameter();
}
void QGCComboBox::readSettings(const QSettings& settings)
{
parameterName = settings.value("QGC_PARAM_COMBOBOX_PARAMID").toString();
......@@ -394,7 +421,6 @@ void QGCComboBox::delButtonClicked()
}
void QGCComboBox::comboBoxIndexChanged(QString val)
{
qDebug() << "comboboxchanged:" << comboBoxTextToValMap[val] << val;
switch (parameterValue.type())
{
case QVariant::Char:
......
......@@ -28,6 +28,7 @@ public slots:
/** @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 writeSettings(QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void readSettings(const QSettings& settings);
void refreshParamList();
void setActiveUAS(UASInterface *uas);
......
......@@ -247,11 +247,7 @@
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qgroundcontrol.qrc">
<normaloff>:/files/images/status/dialog-information.svg</normaloff>:/files/images/status/dialog-information.svg</iconset>
<string>?</string>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
......@@ -285,8 +281,6 @@
</item>
</layout>
</widget>
<resources>
<include location="../../../qgroundcontrol.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
......@@ -241,7 +241,58 @@ void QGCCommandButton::writeSettings(QSettings& settings)
settings.setValue("QGC_COMMAND_BUTTON_PARAM7", ui->editParam7SpinBox->value());
settings.sync();
}
void QGCCommandButton::readSettings(const QString& pre,const QVariantMap& settings)
{
ui->editButtonName->setText(settings.value(pre + "QGC_COMMAND_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
ui->editCommandComboBox->setCurrentIndex(settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt());
ui->commandButton->setText(settings.value(pre + "QGC_COMMAND_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
int commandId = settings.value(pre + "QGC_COMMAND_BUTTON_COMMANDID", 0).toInt();
ui->editParam1SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM1", 0.0).toDouble());
ui->editParam2SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM2", 0.0).toDouble());
ui->editParam3SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM3", 0.0).toDouble());
ui->editParam4SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM4", 0.0).toDouble());
ui->editParam5SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM5", 0.0).toDouble());
ui->editParam6SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM6", 0.0).toDouble());
ui->editParam7SpinBox->setValue(settings.value(pre + "QGC_COMMAND_BUTTON_PARAM7", 0.0).toDouble());
ui->editCommandComboBox->setCurrentIndex(0);
// Find combobox entry for this data
for (int i = 0; i < ui->editCommandComboBox->count(); ++i)
{
if (commandId == ui->editCommandComboBox->itemData(i).toInt())
{
ui->editCommandComboBox->setCurrentIndex(i);
}
}
ui->editParamsVisibleCheckBox->setChecked(settings.value(pre + "QGC_COMMAND_BUTTON_PARAMS_VISIBLE").toBool());
if (ui->editParamsVisibleCheckBox->isChecked())
{
ui->editParam1SpinBox->show();
ui->editParam2SpinBox->show();
ui->editParam3SpinBox->show();
ui->editParam4SpinBox->show();
ui->editParam5SpinBox->show();
ui->editParam6SpinBox->show();
ui->editParam7SpinBox->show();
}
else
{
ui->editParam1SpinBox->hide();
ui->editParam2SpinBox->hide();
ui->editParam3SpinBox->hide();
ui->editParam4SpinBox->hide();
ui->editParam5SpinBox->hide();
ui->editParam6SpinBox->hide();
ui->editParam7SpinBox->hide();
}
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 QGCCommandButton::readSettings(const QSettings& settings)
{
ui->editButtonName->setText(settings.value("QGC_COMMAND_BUTTON_BUTTONTEXT", "UNKNOWN").toString());
......
......@@ -25,6 +25,7 @@ public slots:
void endEditMode();
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
private:
Ui::QGCCommandButton *ui;
......
......@@ -40,8 +40,8 @@ QGCParamSlider::QGCParamSlider(QWidget *parent) :
ui->editLine1->hide();
ui->editLine2->hide();
ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
//ui->editLine1->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
//ui->editLine2->setStyleSheet("QWidget { border: 1px solid #66666B; border-radius: 3px; padding: 10px 0px 0px 0px; background: #111122; }");
connect(ui->editDoneButton, SIGNAL(clicked()), this, SLOT(endEditMode()));
......@@ -102,7 +102,7 @@ void QGCParamSlider::setActiveUAS(UASInterface* activeUas)
connect(activeUas, SIGNAL(parameterChanged(int,int,int,int,QString,QVariant)), this, SLOT(setParameterValue(int,int,int,int,QString,QVariant)), Qt::UniqueConnection);
uas = activeUas;
// Update current param value
requestParameter();
//requestParameter();
// Set param info
QString text = uas->getParamManager()->getParamInfo(parameterName);
ui->infoLabel->setToolTip(text);
......@@ -428,6 +428,27 @@ void QGCParamSlider::writeSettings(QSettings& settings)
settings.setValue("QGC_PARAM_SLIDER_DISPLAY_INFO", ui->editInfoCheckBox->isChecked());
settings.sync();
}
void QGCParamSlider::readSettings(const QString& pre,const QVariantMap& settings)
{
parameterName = settings.value(pre + "QGC_PARAM_SLIDER_PARAMID").toString();
component = settings.value(pre + "QGC_PARAM_SLIDER_COMPONENTID").toInt();
ui->nameLabel->setText(settings.value(pre + "QGC_PARAM_SLIDER_DESCRIPTION").toString());
ui->editNameLabel->setText(settings.value(pre + "QGC_PARAM_SLIDER_DESCRIPTION").toString());
//settings.setValue("QGC_PARAM_SLIDER_BUTTONTEXT", ui->actionButton->text());
ui->editSelectParamComboBox->addItem(settings.value(pre + "QGC_PARAM_SLIDER_PARAMID").toString());
ui->editSelectParamComboBox->setCurrentIndex(ui->editSelectParamComboBox->count()-1);
ui->editSelectComponentComboBox->addItem(tr("Component #%1").arg(settings.value(pre + "QGC_PARAM_SLIDER_COMPONENTID").toInt()), settings.value(pre + "QGC_PARAM_SLIDER_COMPONENTID").toInt());
ui->editMinSpinBox->setValue(settings.value(pre + "QGC_PARAM_SLIDER_MIN").toFloat());
ui->editMaxSpinBox->setValue(settings.value(pre + "QGC_PARAM_SLIDER_MAX").toFloat());
showInfo(settings.value(pre + "QGC_PARAM_SLIDER_DISPLAY_INFO", true).toBool());
ui->editSelectParamComboBox->setEnabled(true);
ui->editSelectComponentComboBox->setEnabled(true);
setActiveUAS(UASManager::instance()->getActiveUAS());
// Get param value after settings have been loaded
//requestParameter();
}
void QGCParamSlider::readSettings(const QSettings& settings)
{
......@@ -448,5 +469,5 @@ void QGCParamSlider::readSettings(const QSettings& settings)
setActiveUAS(UASManager::instance()->getActiveUAS());
// Get param value after settings have been loaded
requestParameter();
//requestParameter();
}
......@@ -31,6 +31,7 @@ public slots:
void setParameterValue(int uas, int component, int paramCount, int paramIndex, QString parameterName, const QVariant value);
void writeSettings(QSettings& settings);
void readSettings(const QSettings& settings);
void readSettings(const QString& pre,const QVariantMap& settings);
void refreshParamList();
void setActiveUAS(UASInterface *uas);
void selectComponent(int componentIndex);
......
......@@ -282,18 +282,12 @@
<item row="2" column="3">
<widget class="QToolButton" name="infoLabel">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../../qgroundcontrol.qrc">
<normaloff>:/files/images/status/dialog-information.svg</normaloff>:/files/images/status/dialog-information.svg</iconset>
<string>?</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../qgroundcontrol.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
......@@ -65,7 +65,7 @@ QGCToolWidget::QGCToolWidget(const QString& title, QWidget *parent, QSettings* s
// Enforce storage if this not loaded from settings
// is MUST NOT BE SAVED if it was loaded from settings!
if (!settings) storeWidgetsToSettings();
//if (!settings) storeWidgetsToSettings();
}
QGCToolWidget::~QGCToolWidget()
......@@ -169,6 +169,130 @@ bool QGCToolWidget::loadSettings(const QString& settings, bool singleinstance)
return false;
}
}
void QGCToolWidget::setSettings(QVariantMap& settings)
{
settingsMap = settings;
QString widgetName = getTitle();
int size = settingsMap["count"].toInt();
for (int j = 0; j < size; j++)
{
QString type = settings.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
if (type == "SLIDER")
{
QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_SLIDER_PARAMID").toString();
paramList.append(checkparam);
}
else if (type == "COMBO")
{
QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_COMBOBOX_PARAMID").toString();
paramList.append(checkparam);
}
}
}
QList<QString> QGCToolWidget::getParamList()
{
return paramList;
}
void QGCToolWidget::setParameterValue(int uas, int component, QString parameterName, const QVariant value)
{
//settings.setValue("QGC_PARAM_SLIDER_PARAMID", parameterName);
//settings.setValue("QGC_PARAM_COMBOBOX_PARAMID", parameterName);
QString widgetName = getTitle();
//settings.beginGroup(widgetName);
//qDebug() << "LOADING FOR" << widgetName;
//int size = settings.beginReadArray("QGC_TOOL_WIDGET_ITEMS");
int size = settingsMap["count"].toInt();
//qDebug() << "CHILDREN SIZE:" << size;
for (int j = 0; j < size; j++)
{
QString type = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
QGCToolWidgetItem* item = NULL;
if (type == "COMMANDBUTTON")
{
return;
//item = new QGCCommandButton(this);
//qDebug() << "CREATED COMMANDBUTTON";
}
else if (type == "SLIDER")
{
QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_SLIDER_PARAMID").toString();
if (checkparam == parameterName)
{
item = new QGCParamSlider(this);
addToolWidget(item);
item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settingsMap);
return;
}
//qDebug() << "CREATED PARAM SLIDER";
}
else if (type == "COMBO")
{
QString checkparam = settingsMap.value(widgetName + "\\" + QString::number(j) + "\\" + "QGC_PARAM_COMBOBOX_PARAMID").toString();
if (checkparam == parameterName)
{
item = new QGCComboBox(this);
addToolWidget(item);
item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settingsMap);
return;
}
//qDebug() << "CREATED PARAM COMBOBOX";
}
}
}
void QGCToolWidget::loadSettings(QVariantMap& settings)
{
QString widgetName = getTitle();
//settings.beginGroup(widgetName);
qDebug() << "LOADING FOR" << widgetName;
//int size = settings.beginReadArray("QGC_TOOL_WIDGET_ITEMS");
int size = settings["count"].toInt();
qDebug() << "CHILDREN SIZE:" << size;
for (int j = 0; j < size; j++)
{
QApplication::processEvents();
//settings.setArrayIndex(j);
QString type = settings.value(widgetName + "\\" + QString::number(j) + "\\" + "TYPE", "UNKNOWN").toString();
if (type != "UNKNOWN")
{
QGCToolWidgetItem* item = NULL;
if (type == "COMMANDBUTTON")
{
item = new QGCCommandButton(this);
//qDebug() << "CREATED COMMANDBUTTON";
}
else if (type == "SLIDER")
{
item = new QGCParamSlider(this);
//qDebug() << "CREATED PARAM SLIDER";
}
else if (type == "COMBO")
{
item = new QGCComboBox(this);
//qDebug() << "CREATED PARAM COMBOBOX";
}
if (item)
{
// Configure and add to layout
addToolWidget(item);
item->readSettings(widgetName + "\\" + QString::number(j) + "\\",settings);
//qDebug() << "Created tool widget";
}
}
else
{
qDebug() << "UNKNOWN TOOL WIDGET TYPE" << type;
}
}
//settings.endArray();
//settings.endGroup();
}
void QGCToolWidget::loadSettings(QSettings& settings)
{
......@@ -480,7 +604,7 @@ void QGCToolWidget::setTitle(QString title)
QDockWidget* parent = dynamic_cast<QDockWidget*>(this->parentWidget());
if (parent) parent->setWindowTitle(title);
// Store all widgets
storeWidgetsToSettings();
//storeWidgetsToSettings();
emit titleChanged(title);
if (mainMenuAction) mainMenuAction->setText(title);
......
......@@ -45,6 +45,7 @@ public slots:
void importWidget();
/** @brief Store all widgets of this type to QSettings */
static void storeWidgetsToSettings(QString settingsFile=QString());
void loadSettings(QVariantMap& settings);
/** @brief Load this widget from a QSettings object */
void loadSettings(QSettings& settings);
/** @brief Load this widget from a settings file */
......@@ -57,11 +58,15 @@ public slots:
void storeSettings();
/** @brief Store the view id and dock widget area */
void setViewVisibilityAndDockWidgetArea(int view, bool visible, Qt::DockWidgetArea area);
void setSettings(QVariantMap& settings);
QList<QString> getParamList();
void setParameterValue(int uas, int component, QString parameterName, const QVariant value);
signals:
void titleChanged(QString);
protected:
QList<QString> paramList;
QVariantMap settingsMap;
QAction* addParamAction;
QAction* addCommandAction;
QAction* setTitleAction;
......@@ -83,12 +88,13 @@ protected:
void addToolWidget(QGCToolWidgetItem* widget);
void hideEvent(QHideEvent* event);
public slots:
void setTitle(QString title);
protected slots:
void addParam();
void addCommand();
void setTitle();
void setTitle(QString title);
void setWindowTitle(const QString& title);
......
......@@ -26,6 +26,7 @@ public slots:
}
virtual void writeSettings(QSettings& settings) = 0;
virtual void readSettings(const QSettings& settings) = 0;
virtual void readSettings(const QString& pre,const QVariantMap& settings) = 0;
virtual void setActiveUAS(UASInterface *uas);
signals:
......
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