Commit 7af96b27 authored by Thomas Gubler's avatar Thomas Gubler

sorted parameters: make search more efficient

parent 61d4bc1c
...@@ -311,6 +311,39 @@ QTreeWidgetItem* QGCParamWidget::getParentWidgetItemForParam(int compId, const Q ...@@ -311,6 +311,39 @@ QTreeWidgetItem* QGCParamWidget::getParentWidgetItemForParam(int compId, const Q
return parentItem; 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) QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString parameterName, QVariant value)
{ {
//qDebug() << "QGCParamWidget::updateParameterDisplay" << parameterName; //qDebug() << "QGCParamWidget::updateParameterDisplay" << parameterName;
...@@ -344,19 +377,10 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para ...@@ -344,19 +377,10 @@ QTreeWidgetItem* QGCParamWidget::updateParameterDisplay(int compId, QString para
paramItem->setFlags(paramItem->flags() | Qt::ItemIsEditable); paramItem->setFlags(paramItem->flags() | Qt::ItemIsEditable);
//Insert alphabetically //Insert alphabetically
bool inserted = false; if (parentItem->childCount() > 0) {
for(int i = 0; i < parentItem->childCount(); i++) { insertParamAlphabetical(0, parentItem->childCount() - 1, parentItem, paramItem);
if (parameterName.compare(parentItem->child(i)->text(0)) < 0 ) } else
{
parentItem->insertChild(i, paramItem);
inserted = true;
break;
}
}
if (!inserted)
{ {
//Insert at the end
parentItem->addChild(paramItem); parentItem->addChild(paramItem);
} }
......
...@@ -83,10 +83,12 @@ public slots: ...@@ -83,10 +83,12 @@ public slots:
virtual void clearOnboardParamDisplay(); virtual void clearOnboardParamDisplay();
virtual void clearPendingParamDisplay(); 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 */ /** @brief Ensure that view of parameter matches data in the model */
QTreeWidgetItem* updateParameterDisplay(int component, QString parameterName, QVariant value); QTreeWidgetItem* updateParameterDisplay(int component, QString parameterName, QVariant value);
/** @brief Update when user changes parameters */ /** @brief Update when user changes parameters */
void parameterItemChanged(QTreeWidgetItem* prev, int column); void parameterItemChanged(QTreeWidgetItem* prev, int column);
......
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