Browse Source

Merge pull request #441 from thomasgubler/params_alphabetical

display parameters in alphabetical order
QGC4.4
Lorenz Meier 12 years ago
parent
commit
e547004f19
  1. 42
      src/ui/QGCParamWidget.cc
  2. 4
      src/ui/QGCParamWidget.h

42
src/ui/QGCParamWidget.cc

@ -311,6 +311,39 @@ QTreeWidgetItem* QGCParamWidget::getParentWidgetItemForParam(int compId, const Q @@ -311,6 +311,39 @@ QTreeWidgetItem* QGCParamWidget::getParentWidgetItemForParam(int compId, const Q
return parentItem;
}
void QGCParamWidget::insertParamAlphabetical(int indexLowerBound, int indexUpperBound, QTreeWidgetItem* parentItem, QTreeWidgetItem* paramItem)
{
if (indexLowerBound >= indexUpperBound)
{
if (paramItem->text(0).compare(parentItem->child(indexLowerBound)->text(0)) < 0) {
parentItem->insertChild(indexLowerBound, paramItem);
}
else
{
if (indexLowerBound < parentItem->childCount() - 1) {
parentItem->insertChild(indexLowerBound + 1, paramItem);
}
else
{
parentItem->addChild(paramItem);
}
}
}
else
{
int midpoint = indexLowerBound + floor(indexUpperBound - indexLowerBound)/2;
if (paramItem->text(0).compare(parentItem->child(midpoint)->text(0)) < 0)
{
insertParamAlphabetical(indexLowerBound, midpoint - 1, parentItem, paramItem);
} else
{
insertParamAlphabetical(midpoint + 1, indexUpperBound, parentItem, paramItem);
}
}
}
QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, QVariant value)
{
//qDebug() << "QGCParamWidget::updateParameterDisplay" << parameterName;
@ -343,8 +376,13 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para @@ -343,8 +376,13 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
}
paramItem->setFlags(paramItem->flags() | Qt::ItemIsEditable);
//TODO insert alphabetically
parentItem->addChild(paramItem);
//Insert alphabetically
if (parentItem->childCount() > 0) {
insertParamAlphabetical(0, parentItem->childCount() - 1, parentItem, paramItem);
} else
{
parentItem->addChild(paramItem);
}
//only add the tooltip when the parameter item is first added
QString paramDesc = paramMgr->dataModel()->getParamDescription(parameterName);

4
src/ui/QGCParamWidget.h

@ -83,10 +83,12 @@ public slots: @@ -83,10 +83,12 @@ public slots:
virtual void clearOnboardParamDisplay();
virtual void clearPendingParamDisplay();
/** @brief Adds parameter at the correct location by a alphapetical comparison of the parameter names */
void insertParamAlphabetical(int indexLowerBound, int indexUpperBound, QTreeWidgetItem* parentItem, QTreeWidgetItem* paramItem);
/** @brief Ensure that view of parameter matches data in the model */
QTreeWidgetItem* updateParameterDisplay(int component, QString parameterName, QVariant value);
/** @brief Update when user changes parameters */
void parameterItemChanged(QTreeWidgetItem* prev, int column);

Loading…
Cancel
Save