Unverified Commit 40708809 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #5987 from DonLakeFlyer/ParameterCategories

Parameter Editor Category->Group hierarchy support
parents ce0e3ad0 b0f60168
...@@ -497,6 +497,16 @@ int Fact::decimalPlaces(void) const ...@@ -497,6 +497,16 @@ int Fact::decimalPlaces(void) const
} }
} }
QString Fact::category(void) const
{
if (_metaData) {
return _metaData->category();
} else {
qWarning() << kMissingMetadata << name();
return QString();
}
}
QString Fact::group(void) const QString Fact::group(void) const
{ {
if (_metaData) { if (_metaData) {
......
...@@ -48,6 +48,7 @@ public: ...@@ -48,6 +48,7 @@ public:
Q_PROPERTY(QStringList enumStrings READ enumStrings NOTIFY enumsChanged) Q_PROPERTY(QStringList enumStrings READ enumStrings NOTIFY enumsChanged)
Q_PROPERTY(QString enumStringValue READ enumStringValue WRITE setEnumStringValue NOTIFY valueChanged) Q_PROPERTY(QString enumStringValue READ enumStringValue WRITE setEnumStringValue NOTIFY valueChanged)
Q_PROPERTY(QVariantList enumValues READ enumValues NOTIFY enumsChanged) Q_PROPERTY(QVariantList enumValues READ enumValues NOTIFY enumsChanged)
Q_PROPERTY(QString category READ category CONSTANT)
Q_PROPERTY(QString group READ group CONSTANT) Q_PROPERTY(QString group READ group CONSTANT)
Q_PROPERTY(QString longDescription READ longDescription CONSTANT) Q_PROPERTY(QString longDescription READ longDescription CONSTANT)
Q_PROPERTY(QVariant max READ cookedMax CONSTANT) Q_PROPERTY(QVariant max READ cookedMax CONSTANT)
...@@ -91,6 +92,7 @@ public: ...@@ -91,6 +92,7 @@ public:
QStringList enumStrings (void) const; QStringList enumStrings (void) const;
QString enumStringValue (void); // This is not const, since an unknown value can modify the enum lists QString enumStringValue (void); // This is not const, since an unknown value can modify the enum lists
QVariantList enumValues (void) const; QVariantList enumValues (void) const;
QString category (void) const;
QString group (void) const; QString group (void) const;
QString longDescription (void) const; QString longDescription (void) const;
QVariant rawMax (void) const; QVariant rawMax (void) const;
......
...@@ -32,6 +32,9 @@ const qreal FactMetaData::UnitConsts_s::milesToMeters = 1609.344; ...@@ -32,6 +32,9 @@ const qreal FactMetaData::UnitConsts_s::milesToMeters = 1609.344;
const qreal FactMetaData::UnitConsts_s::feetToMeters = 0.3048; const qreal FactMetaData::UnitConsts_s::feetToMeters = 0.3048;
const qreal FactMetaData::UnitConsts_s::inchesToCentimeters = 2.54; const qreal FactMetaData::UnitConsts_s::inchesToCentimeters = 2.54;
const QString FactMetaData::defaultCategory = tr("Other");
const QString FactMetaData::defaultGroup = tr("Misc");
// Built in translations for all Facts // Built in translations for all Facts
const FactMetaData::BuiltInTranslation_s FactMetaData::_rgBuiltInTranslations[] = { const FactMetaData::BuiltInTranslation_s FactMetaData::_rgBuiltInTranslations[] = {
{ "centi-degrees", "deg", FactMetaData::_centiDegreesToDegrees, FactMetaData::_degreesToCentiDegrees }, { "centi-degrees", "deg", FactMetaData::_centiDegreesToDegrees, FactMetaData::_degreesToCentiDegrees },
...@@ -76,43 +79,45 @@ const char* FactMetaData::_maxJsonKey = "max"; ...@@ -76,43 +79,45 @@ const char* FactMetaData::_maxJsonKey = "max";
const char* FactMetaData::_hasControlJsonKey = "control"; const char* FactMetaData::_hasControlJsonKey = "control";
FactMetaData::FactMetaData(QObject* parent) FactMetaData::FactMetaData(QObject* parent)
: QObject(parent) : QObject (parent)
, _type(valueTypeInt32) , _type (valueTypeInt32)
, _decimalPlaces(unknownDecimalPlaces) , _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue(0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _group("*Default Group") , _category (defaultCategory)
, _rawMax(_maxForType()) , _group (defaultGroup)
, _maxIsDefaultForType(true) , _rawMax (_maxForType())
, _rawMin(_minForType()) , _maxIsDefaultForType (true)
, _minIsDefaultForType(true) , _rawMin (_minForType())
, _rawTranslator(_defaultTranslator) , _minIsDefaultForType (true)
, _cookedTranslator(_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _rebootRequired(false) , _cookedTranslator (_defaultTranslator)
, _increment(std::numeric_limits<double>::quiet_NaN()) , _rebootRequired (false)
, _hasControl(true) , _increment (std::numeric_limits<double>::quiet_NaN())
, _readOnly(false) , _hasControl (true)
, _readOnly (false)
{ {
} }
FactMetaData::FactMetaData(ValueType_t type, QObject* parent) FactMetaData::FactMetaData(ValueType_t type, QObject* parent)
: QObject(parent) : QObject (parent)
, _type(type) , _type (type)
, _decimalPlaces(unknownDecimalPlaces) , _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue(0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _group("*Default Group") , _category (defaultCategory)
, _rawMax(_maxForType()) , _group (defaultGroup)
, _maxIsDefaultForType(true) , _rawMax (_maxForType())
, _rawMin(_minForType()) , _maxIsDefaultForType (true)
, _minIsDefaultForType(true) , _rawMin (_minForType())
, _rawTranslator(_defaultTranslator) , _minIsDefaultForType (true)
, _cookedTranslator(_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _rebootRequired(false) , _cookedTranslator (_defaultTranslator)
, _increment(std::numeric_limits<double>::quiet_NaN()) , _rebootRequired (false)
, _hasControl(true) , _increment (std::numeric_limits<double>::quiet_NaN())
, _readOnly(false) , _hasControl (true)
, _readOnly (false)
{ {
} }
...@@ -124,23 +129,24 @@ FactMetaData::FactMetaData(const FactMetaData& other, QObject* parent) ...@@ -124,23 +129,24 @@ FactMetaData::FactMetaData(const FactMetaData& other, QObject* parent)
} }
FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent) FactMetaData::FactMetaData(ValueType_t type, const QString name, QObject* parent)
: QObject(parent) : QObject (parent)
, _type(type) , _type (type)
, _decimalPlaces(unknownDecimalPlaces) , _decimalPlaces (unknownDecimalPlaces)
, _rawDefaultValue(0) , _rawDefaultValue (0)
, _defaultValueAvailable(false) , _defaultValueAvailable(false)
, _group("*Default Group") , _category (defaultCategory)
, _rawMax(_maxForType()) , _group (defaultGroup)
, _maxIsDefaultForType(true) , _rawMax (_maxForType())
, _rawMin(_minForType()) , _maxIsDefaultForType (true)
, _minIsDefaultForType(true) , _rawMin (_minForType())
, _name(name) , _minIsDefaultForType (true)
, _rawTranslator(_defaultTranslator) , _name (name)
, _cookedTranslator(_defaultTranslator) , _rawTranslator (_defaultTranslator)
, _rebootRequired(false) , _cookedTranslator (_defaultTranslator)
, _increment(std::numeric_limits<double>::quiet_NaN()) , _rebootRequired (false)
, _hasControl(true) , _increment (std::numeric_limits<double>::quiet_NaN())
, _readOnly(false) , _hasControl (true)
, _readOnly (false)
{ {
} }
...@@ -154,6 +160,7 @@ const FactMetaData& FactMetaData::operator=(const FactMetaData& other) ...@@ -154,6 +160,7 @@ const FactMetaData& FactMetaData::operator=(const FactMetaData& other)
_bitmaskValues = other._bitmaskValues; _bitmaskValues = other._bitmaskValues;
_enumStrings = other._enumStrings; _enumStrings = other._enumStrings;
_enumValues = other._enumValues; _enumValues = other._enumValues;
_category = other._category;
_group = other._group; _group = other._group;
_longDescription = other._longDescription; _longDescription = other._longDescription;
_rawMax = other._rawMax; _rawMax = other._rawMax;
......
...@@ -84,6 +84,7 @@ public: ...@@ -84,6 +84,7 @@ public:
QVariantList bitmaskValues (void) const { return _bitmaskValues; } QVariantList bitmaskValues (void) const { return _bitmaskValues; }
QStringList enumStrings (void) const { return _enumStrings; } QStringList enumStrings (void) const { return _enumStrings; }
QVariantList enumValues (void) const { return _enumValues; } QVariantList enumValues (void) const { return _enumValues; }
QString category (void) const { return _category; }
QString group (void) const { return _group; } QString group (void) const { return _group; }
QString longDescription (void) const { return _longDescription;} QString longDescription (void) const { return _longDescription;}
QVariant rawMax (void) const { return _rawMax; } QVariant rawMax (void) const { return _rawMax; }
...@@ -118,6 +119,7 @@ public: ...@@ -118,6 +119,7 @@ public:
void setRawDefaultValue (const QVariant& rawDefaultValue); void setRawDefaultValue (const QVariant& rawDefaultValue);
void setBitmaskInfo (const QStringList& strings, const QVariantList& values); void setBitmaskInfo (const QStringList& strings, const QVariantList& values);
void setEnumInfo (const QStringList& strings, const QVariantList& values); void setEnumInfo (const QStringList& strings, const QVariantList& values);
void setCategory (const QString& category) { _category = category; }
void setGroup (const QString& group) { _group = group; } void setGroup (const QString& group) { _group = group; }
void setLongDescription (const QString& longDescription) { _longDescription = longDescription;} void setLongDescription (const QString& longDescription) { _longDescription = longDescription;}
void setRawMax (const QVariant& rawMax); void setRawMax (const QVariant& rawMax);
...@@ -158,6 +160,9 @@ public: ...@@ -158,6 +160,9 @@ public:
static ValueType_t stringToType(const QString& typeString, bool& unknownType); static ValueType_t stringToType(const QString& typeString, bool& unknownType);
static size_t typeToSize(ValueType_t type); static size_t typeToSize(ValueType_t type);
static const QString defaultCategory;
static const QString defaultGroup;
private: private:
QVariant _minForType(void) const; QVariant _minForType(void) const;
QVariant _maxForType(void) const; QVariant _maxForType(void) const;
...@@ -217,6 +222,7 @@ private: ...@@ -217,6 +222,7 @@ private:
QVariantList _bitmaskValues; QVariantList _bitmaskValues;
QStringList _enumStrings; QStringList _enumStrings;
QVariantList _enumValues; QVariantList _enumValues;
QString _category;
QString _group; QString _group;
QString _longDescription; QString _longDescription;
QVariant _rawMax; QVariant _rawMax;
......
...@@ -325,7 +325,7 @@ void ParameterManager::_parameterUpdate(int vehicleId, int componentId, QString ...@@ -325,7 +325,7 @@ void ParameterManager::_parameterUpdate(int vehicleId, int componentId, QString
// When we are getting the very last component param index, reset the group maps to update for the // When we are getting the very last component param index, reset the group maps to update for the
// new params. By handling this here, we can pick up components which finish up later than the default // new params. By handling this here, we can pick up components which finish up later than the default
// component param set. // component param set.
_setupGroupMap(); _setupCategoryMap();
} }
if (_prevWaitingWriteParamNameCount != 0 && waitingWriteParamNameCount == 0) { if (_prevWaitingWriteParamNameCount != 0 && waitingWriteParamNameCount == 0) {
...@@ -511,22 +511,20 @@ QStringList ParameterManager::parameterNames(int componentId) ...@@ -511,22 +511,20 @@ QStringList ParameterManager::parameterNames(int componentId)
return names; return names;
} }
void ParameterManager::_setupGroupMap(void) void ParameterManager::_setupCategoryMap(void)
{ {
// Must be able to handle being called multiple times // Must be able to handle being called multiple times
_mapGroup2ParameterName.clear(); _categoryMap.clear();
foreach (int componentId, _mapParameterName2Variant.keys()) { foreach (const QString &name, _mapParameterName2Variant[_vehicle->defaultComponentId()].keys()) {
foreach (const QString &name, _mapParameterName2Variant[componentId].keys()) { Fact* fact = _mapParameterName2Variant[_vehicle->defaultComponentId()][name].value<Fact*>();
Fact* fact = _mapParameterName2Variant[componentId][name].value<Fact*>(); _categoryMap[fact->category()][fact->group()] += name;
_mapGroup2ParameterName[componentId][fact->group()] += name;
}
} }
} }
const QMap<int, QMap<QString, QStringList> >& ParameterManager::getGroupMap(void) const QMap<QString, QMap<QString, QStringList> >& ParameterManager::getCategoryMap(void)
{ {
return _mapGroup2ParameterName; return _categoryMap;
} }
/// Requests missing index based parameters from the vehicle. /// Requests missing index based parameters from the vehicle.
...@@ -1349,7 +1347,7 @@ void ParameterManager::_loadOfflineEditingParams(void) ...@@ -1349,7 +1347,7 @@ void ParameterManager::_loadOfflineEditingParams(void)
} }
_addMetaDataToDefaultComponent(); _addMetaDataToDefaultComponent();
_setupGroupMap(); _setupCategoryMap();
_parametersReady = true; _parametersReady = true;
_initialLoadComplete = true; _initialLoadComplete = true;
} }
......
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
/// @param name Parameter name /// @param name Parameter name
Fact* getParameter(int componentId, const QString& name); Fact* getParameter(int componentId, const QString& name);
const QMap<int, QMap<QString, QStringList> >& getGroupMap(void); const QMap<QString, QMap<QString, QStringList> >& getCategoryMap(void);
/// Returns error messages from loading /// Returns error messages from loading
QString readParametersFromStream(QTextStream& stream); QString readParametersFromStream(QTextStream& stream);
...@@ -137,7 +137,7 @@ protected: ...@@ -137,7 +137,7 @@ protected:
private: private:
static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool failOk = false); static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool failOk = false);
int _actualComponentId(int componentId); int _actualComponentId(int componentId);
void _setupGroupMap(void); void _setupCategoryMap(void);
void _readParameterRaw(int componentId, const QString& paramName, int paramIndex); void _readParameterRaw(int componentId, const QString& paramName, int paramIndex);
void _writeParameterRaw(int componentId, const QString& paramName, const QVariant& value); void _writeParameterRaw(int componentId, const QString& paramName, const QVariant& value);
void _writeLocalParamCache(int vehicleId, int componentId); void _writeLocalParamCache(int vehicleId, int componentId);
...@@ -160,9 +160,8 @@ private: ...@@ -160,9 +160,8 @@ private:
QMap<int, QMap<int, QString> > _mapParameterId2Name; QMap<int, QMap<int, QString> > _mapParameterId2Name;
/// First mapping is by component id // Category map of default component parameters
/// Second mapping is group name, to Fact QMap<QString /* category */, QMap<QString /* group */, QStringList /* parameter names */> > _categoryMap;
QMap<int, QMap<QString, QStringList> > _mapGroup2ParameterName;
double _loadProgress; ///< Parameter load progess, [0.0,1.0] double _loadProgress; ///< Parameter load progess, [0.0,1.0]
bool _parametersReady; ///< true: parameter load complete bool _parametersReady; ///< true: parameter load complete
......
...@@ -233,14 +233,18 @@ void APMParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData ...@@ -233,14 +233,18 @@ void APMParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData
QString group = name.split('_').first(); QString group = name.split('_').first();
group = group.remove(QRegExp("[0-9]*$")); // remove any numbers from the end group = group.remove(QRegExp("[0-9]*$")); // remove any numbers from the end
QString category = xml.attributes().value("user").toString();
if (category.isEmpty()) {
category = QStringLiteral("Advanced");
}
QString shortDescription = xml.attributes().value("humanName").toString(); QString shortDescription = xml.attributes().value("humanName").toString();
QString longDescription = xml.attributes().value("documentation").toString(); QString longDescription = xml.attributes().value("documentation").toString();
QString userLevel = xml.attributes().value("user").toString();
qCDebug(APMParameterMetaDataVerboseLog) << "Found parameter name:" << name qCDebug(APMParameterMetaDataVerboseLog) << "Found parameter name:" << name
<< "short Desc:" << shortDescription << "short Desc:" << shortDescription
<< "longDescription:" << longDescription << "longDescription:" << longDescription
<< "user level: " << userLevel << "category: " << category
<< "group: " << group; << "group: " << group;
Q_ASSERT(!rawMetaData); Q_ASSERT(!rawMetaData);
...@@ -254,6 +258,7 @@ void APMParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData ...@@ -254,6 +258,7 @@ void APMParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData
} }
qCDebug(APMParameterMetaDataVerboseLog) << "inserting metadata for field" << name; qCDebug(APMParameterMetaDataVerboseLog) << "inserting metadata for field" << name;
rawMetaData->name = name; rawMetaData->name = name;
rawMetaData->category = category;
rawMetaData->group = group; rawMetaData->group = group;
rawMetaData->shortDescription = shortDescription; rawMetaData->shortDescription = shortDescription;
rawMetaData->longDescription = longDescription; rawMetaData->longDescription = longDescription;
...@@ -301,7 +306,7 @@ void APMParameterMetaData::correctGroupMemberships(ParameterNametoFactMetaDataMa ...@@ -301,7 +306,7 @@ void APMParameterMetaData::correctGroupMemberships(ParameterNametoFactMetaDataMa
foreach(const QString& groupName, groupMembers.keys()) { foreach(const QString& groupName, groupMembers.keys()) {
if (groupMembers[groupName].count() == 1) { if (groupMembers[groupName].count() == 1) {
foreach(const QString& parameter, groupMembers.value(groupName)) { foreach(const QString& parameter, groupMembers.value(groupName)) {
parameterToFactMetaDataMap[parameter]->group = "others"; parameterToFactMetaDataMap[parameter]->group = FactMetaData::defaultGroup;
} }
} }
} }
...@@ -434,6 +439,7 @@ void APMParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType) ...@@ -434,6 +439,7 @@ void APMParameterMetaData::addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType)
} }
metaData->setName(rawMetaData->name); metaData->setName(rawMetaData->name);
metaData->setCategory(rawMetaData->category);
metaData->setGroup(rawMetaData->group); metaData->setGroup(rawMetaData->group);
metaData->setRebootRequired(rawMetaData->rebootRequired); metaData->setRebootRequired(rawMetaData->rebootRequired);
......
...@@ -32,6 +32,7 @@ public: ...@@ -32,6 +32,7 @@ public:
{ } { }
QString name; QString name;
QString category;
QString group; QString group;
QString shortDescription; QString shortDescription;
QString longDescription; QString longDescription;
......
...@@ -181,6 +181,11 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData ...@@ -181,6 +181,11 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData
QString type = xml.attributes().value("type").toString(); QString type = xml.attributes().value("type").toString();
QString strDefault = xml.attributes().value("default").toString(); QString strDefault = xml.attributes().value("default").toString();
QString category = xml.attributes().value("category").toString();
if (category.isEmpty()) {
category = QStringLiteral("Standard");
}
qCDebug(PX4ParameterMetaDataLog) << "Found parameter name:" << name << " type:" << type << " default:" << strDefault; qCDebug(PX4ParameterMetaDataLog) << "Found parameter name:" << name << " type:" << type << " default:" << strDefault;
// Convert type from string to FactMetaData::ValueType_t // Convert type from string to FactMetaData::ValueType_t
...@@ -196,7 +201,7 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData ...@@ -196,7 +201,7 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData
metaData = new FactMetaData(foundType); metaData = new FactMetaData(foundType);
Q_CHECK_PTR(metaData); Q_CHECK_PTR(metaData);
if (_mapParameterName2FactMetaData.contains(name)) { if (_mapParameterName2FactMetaData.contains(name)) {
// We can't trust the meta dafa since we have dups // We can't trust the meta data since we have dups
qCWarning(PX4ParameterMetaDataLog) << "Duplicate parameter found:" << name; qCWarning(PX4ParameterMetaDataLog) << "Duplicate parameter found:" << name;
badMetaData = true; badMetaData = true;
// Reset to default meta data // Reset to default meta data
...@@ -204,6 +209,7 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData ...@@ -204,6 +209,7 @@ void PX4ParameterMetaData::loadParameterFactMetaDataFile(const QString& metaData
} else { } else {
_mapParameterName2FactMetaData[name] = metaData; _mapParameterName2FactMetaData[name] = metaData;
metaData->setName(name); metaData->setName(name);
metaData->setCategory(category);
metaData->setGroup(factGroup); metaData->setGroup(factGroup);
if (xml.attributes().hasAttribute("default") && !strDefault.isEmpty()) { if (xml.attributes().hasAttribute("default") && !strDefault.isEmpty()) {
......
...@@ -47,7 +47,8 @@ FocusScope { ...@@ -47,7 +47,8 @@ FocusScope {
QGCLabel { QGCLabel {
id: label id: label
Layout.fillWidth: true anchors.left: parent.left
anchors.right: parent.right
QGCColoredImage { QGCColoredImage {
id: image id: image
......
...@@ -7,13 +7,10 @@ ...@@ -7,13 +7,10 @@
* *
****************************************************************************/ ****************************************************************************/
/// @file
/// @author Don Gagne <don@thegagnes.com>
import QtQuick 2.3 import QtQuick 2.3
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2 import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.2
import QGroundControl 1.0 import QGroundControl 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
...@@ -44,6 +41,8 @@ QGCView { ...@@ -44,6 +41,8 @@ QGCView {
} }
} }
ExclusiveGroup { id: sectionGroup }
QGCViewPanel { QGCViewPanel {
id: panel id: panel
anchors.fill: parent anchors.fill: parent
...@@ -158,47 +157,57 @@ QGCView { ...@@ -158,47 +157,57 @@ QGCView {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
clip: true clip: true
pixelAligned: true pixelAligned: true
contentHeight: groupedViewComponentColumn.height contentHeight: groupedViewCategoryColumn.height
contentWidth: groupedViewComponentColumn.width
flickableDirection: Flickable.VerticalFlick flickableDirection: Flickable.VerticalFlick
visible: !_searchFilter visible: !_searchFilter
Column { ColumnLayout {
id: groupedViewComponentColumn id: groupedViewCategoryColumn
anchors.left: parent.left
anchors.right: parent.right
spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25) spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25)
Repeater { Repeater {
model: controller.componentIds model: controller.categories
Column { Column {
id: componentColumn Layout.fillWidth: true
spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25) spacing: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.25)
readonly property int componentId: modelData readonly property string category: modelData
QGCLabel { SectionHeader {
text: qsTr("Component #: %1").arg(componentId.toString()) id: categoryHeader
font.family: ScreenTools.demiboldFontFamily text: category
anchors.horizontalCenter: parent.horizontalCenter checked: controller.currentCategory == text
exclusiveGroup: sectionGroup
onCheckedChanged: {
if (checked) {
controller.currentCategory = category
controller.currentGroup = controller.getGroupsForCategory(category)[0]
}
}
} }
ExclusiveGroup { id: groupGroup } ExclusiveGroup { id: buttonGroup }
Repeater { Repeater {
model: controller.getGroupsForComponent(componentId) model: categoryHeader.checked ? controller.getGroupsForCategory(category) : 0
QGCButton { QGCButton {
width: ScreenTools.defaultFontPixelWidth * 25 width: ScreenTools.defaultFontPixelWidth * 25
text: groupName text: groupName
height: _rowHeight height: _rowHeight
exclusiveGroup: setupButtonGroup checked: controller.currentGroup == text
exclusiveGroup: buttonGroup
readonly property string groupName: modelData readonly property string groupName: modelData
onClicked: { onClicked: {
checked = true checked = true
_rowWidth = 10 _rowWidth = 10
controller.currentComponentId = componentId controller.currentCategory = category
controller.currentGroup = groupName controller.currentGroup = groupName
} }
} }
......
...@@ -27,22 +27,23 @@ ...@@ -27,22 +27,23 @@
/// @Brief Constructs a new ParameterEditorController Widget. This widget is used within the PX4VehicleConfig set of screens. /// @Brief Constructs a new ParameterEditorController Widget. This widget is used within the PX4VehicleConfig set of screens.
ParameterEditorController::ParameterEditorController(void) ParameterEditorController::ParameterEditorController(void)
: _currentComponentId(_vehicle->defaultComponentId()) : _currentCategory("Standard") // FIXME: firmware specific
, _parameters(new QmlObjectListModel(this)) , _parameters(new QmlObjectListModel(this))
{ {
const QMap<int, QMap<QString, QStringList> >& groupMap = _vehicle->parameterManager()->getGroupMap(); const QMap<QString, QMap<QString, QStringList> >& categoryMap = _vehicle->parameterManager()->getCategoryMap();
foreach (int componentId, groupMap.keys()) { _categories = categoryMap.keys();
_componentIds += QString("%1").arg(componentId);
} // Move default category to front
_categories.removeOne(_currentCategory);
_categories.prepend(_currentCategory);
// Be careful about no parameters // Be careful about no parameters
if (groupMap.contains(_currentComponentId) && groupMap[_currentComponentId].size() != 0) { if (categoryMap.contains(_currentCategory) && categoryMap[_currentCategory].size() != 0) {
_currentGroup = groupMap[_currentComponentId].keys()[0]; _currentGroup = categoryMap[_currentCategory].keys()[0];
} }
_updateParameters(); _updateParameters();
connect(this, &ParameterEditorController::searchTextChanged, this, &ParameterEditorController::_updateParameters); connect(this, &ParameterEditorController::searchTextChanged, this, &ParameterEditorController::_updateParameters);
connect(this, &ParameterEditorController::currentComponentIdChanged, this, &ParameterEditorController::_updateParameters);
connect(this, &ParameterEditorController::currentGroupChanged, this, &ParameterEditorController::_updateParameters); connect(this, &ParameterEditorController::currentGroupChanged, this, &ParameterEditorController::_updateParameters);
} }
...@@ -51,29 +52,29 @@ ParameterEditorController::~ParameterEditorController() ...@@ -51,29 +52,29 @@ ParameterEditorController::~ParameterEditorController()
} }
QStringList ParameterEditorController::getGroupsForComponent(int componentId) QStringList ParameterEditorController::getGroupsForCategory(const QString& category)
{ {
const QMap<int, QMap<QString, QStringList> >& groupMap = _vehicle->parameterManager()->getGroupMap(); const QMap<QString, QMap<QString, QStringList> >& categoryMap = _vehicle->parameterManager()->getCategoryMap();
return groupMap[componentId].keys(); return categoryMap[category].keys();
} }
QStringList ParameterEditorController::getParametersForGroup(int componentId, QString group) QStringList ParameterEditorController::getParametersForGroup(const QString& category, const QString& group)
{ {
const QMap<int, QMap<QString, QStringList> >& groupMap = _vehicle->parameterManager()->getGroupMap(); const QMap<QString, QMap<QString, QStringList> >& categoryMap = _vehicle->parameterManager()->getCategoryMap();
return groupMap[componentId][group]; return categoryMap[category][group];
} }
QStringList ParameterEditorController::searchParametersForComponent(int componentId, const QString& searchText, bool searchInName, bool searchInDescriptions) QStringList ParameterEditorController::searchParameters(const QString& searchText, bool searchInName, bool searchInDescriptions)
{ {
QStringList list; QStringList list;
foreach(const QString &paramName, _vehicle->parameterManager()->parameterNames(componentId)) { foreach(const QString &paramName, _vehicle->parameterManager()->parameterNames(_vehicle->defaultComponentId())) {
if (searchText.isEmpty()) { if (searchText.isEmpty()) {
list += paramName; list += paramName;
} else { } else {
Fact* fact = _vehicle->parameterManager()->getParameter(componentId, paramName); Fact* fact = _vehicle->parameterManager()->getParameter(_vehicle->defaultComponentId(), paramName);
if (searchInName && fact->name().contains(searchText, Qt::CaseInsensitive)) { if (searchInName && fact->name().contains(searchText, Qt::CaseInsensitive)) {
list += paramName; list += paramName;
...@@ -161,9 +162,9 @@ void ParameterEditorController::_updateParameters(void) ...@@ -161,9 +162,9 @@ void ParameterEditorController::_updateParameters(void)
QStringList searchItems = _searchText.split(' ', QString::SkipEmptyParts); QStringList searchItems = _searchText.split(' ', QString::SkipEmptyParts);
if (searchItems.isEmpty()) { if (searchItems.isEmpty()) {
const QMap<int, QMap<QString, QStringList> >& groupMap = _vehicle->parameterManager()->getGroupMap(); const QMap<QString, QMap<QString, QStringList> >& categoryMap = _vehicle->parameterManager()->getCategoryMap();
foreach (const QString& parameter, groupMap[_currentComponentId][_currentGroup]) { foreach (const QString& parameter, categoryMap[_currentCategory][_currentGroup]) {
newParameterList.append(_vehicle->parameterManager()->getParameter(_currentComponentId, parameter)); newParameterList.append(_vehicle->parameterManager()->getParameter(_vehicle->defaultComponentId(), parameter));
} }
} else { } else {
foreach(const QString &parameter, _vehicle->parameterManager()->parameterNames(_vehicle->defaultComponentId())) { foreach(const QString &parameter, _vehicle->parameterManager()->parameterNames(_vehicle->defaultComponentId())) {
......
...@@ -31,14 +31,14 @@ public: ...@@ -31,14 +31,14 @@ public:
~ParameterEditorController(); ~ParameterEditorController();
Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged) Q_PROPERTY(QString searchText MEMBER _searchText NOTIFY searchTextChanged)
Q_PROPERTY(int currentComponentId MEMBER _currentComponentId NOTIFY currentComponentIdChanged) Q_PROPERTY(QString currentCategory MEMBER _currentCategory NOTIFY currentCategoryChanged)
Q_PROPERTY(QString currentGroup MEMBER _currentGroup NOTIFY currentGroupChanged) Q_PROPERTY(QString currentGroup MEMBER _currentGroup NOTIFY currentGroupChanged)
Q_PROPERTY(QmlObjectListModel* parameters MEMBER _parameters CONSTANT) Q_PROPERTY(QmlObjectListModel* parameters MEMBER _parameters CONSTANT)
Q_PROPERTY(QVariantList componentIds MEMBER _componentIds CONSTANT) Q_PROPERTY(QStringList categories MEMBER _categories CONSTANT)
Q_INVOKABLE QStringList getGroupsForComponent(int componentId); Q_INVOKABLE QStringList getGroupsForCategory(const QString& category);
Q_INVOKABLE QStringList getParametersForGroup(int componentId, QString group); Q_INVOKABLE QStringList getParametersForGroup(const QString& category, const QString& group);
Q_INVOKABLE QStringList searchParametersForComponent(int componentId, const QString& searchText, bool searchInName=true, bool searchInDescriptions=true); Q_INVOKABLE QStringList searchParameters(const QString& searchText, bool searchInName=true, bool searchInDescriptions=true);
Q_INVOKABLE void clearRCToParam(void); Q_INVOKABLE void clearRCToParam(void);
Q_INVOKABLE void saveToFile(const QString& filename); Q_INVOKABLE void saveToFile(const QString& filename);
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
signals: signals:
void searchTextChanged(QString searchText); void searchTextChanged(QString searchText);
void currentComponentIdChanged(int componentId); void currentCategoryChanged(QString category);
void currentGroupChanged(QString group); void currentGroupChanged(QString group);
void showErrorMessage(const QString& errorMsg); void showErrorMessage(const QString& errorMsg);
...@@ -59,9 +59,9 @@ private slots: ...@@ -59,9 +59,9 @@ private slots:
void _updateParameters(void); void _updateParameters(void);
private: private:
QVariantList _componentIds; QStringList _categories;
QString _searchText; QString _searchText;
int _currentComponentId; QString _currentCategory;
QString _currentGroup; QString _currentGroup;
QmlObjectListModel* _parameters; QmlObjectListModel* _parameters;
}; };
......
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