diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.cpp b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.cpp index cd2f87587..40f710c26 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.cpp @@ -55,6 +55,17 @@ void UAVObjectBrowser::loadConfiguration(IUAVGadgetConfiguration *config) m_widget->setSplitterState(m->splitterState()); } +void UAVObjectBrowser::saveState(QSettings &settings) const +{ + m_widget->saveState(settings); +} + + +void UAVObjectBrowser::restoreState(QSettings &settings) +{ + m_widget->restoreState(settings); +} + void UAVObjectBrowser::viewOptionsChangedSlot(bool categorized, bool scientific, bool metadata, bool description) { if (m_config) { diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.h b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.h index d84891a95..d8e0c7adf 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.h +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowser.h @@ -51,6 +51,9 @@ public: } void loadConfiguration(IUAVGadgetConfiguration *config); + void saveState(QSettings &settings) const; + void restoreState(QSettings &settings); + private slots: void viewOptionsChangedSlot(bool categorized, bool scientific, bool metadata, bool description); void splitterChanged(QByteArray state); diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp index 2b6f24c0e..a18c2ce0d 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.cpp @@ -422,6 +422,68 @@ void UAVObjectBrowserWidget::searchLineChanged(QString searchText) } } +QString UAVObjectBrowserWidget::indexToPath(const QModelIndex &index) const +{ + QString path = index.data(Qt::DisplayRole).toString(); + + QModelIndex parent = index.parent(); + + while (parent.isValid()) { + path = parent.data(Qt::DisplayRole).toString() + "/" + path; + parent = parent.parent(); + } + return path; +} + +QModelIndex UAVObjectBrowserWidget::indexFromPath(const QString &path) const +{ + QStringList list = path.split("/"); + + QModelIndex index = m_modelProxy->index(0, 0); + + foreach(QString name, list) { + QModelIndexList items = m_modelProxy->match(index, Qt::DisplayRole, name, 1, Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive)); + + if (!items.isEmpty()) { + index = items.first(); + } else { + // bail out + return QModelIndex(); + } + } + return index; +} + +void UAVObjectBrowserWidget::saveState(QSettings &settings) const +{ + QStringList list; + + // prepare list + foreach(QModelIndex index, m_modelProxy->getPersistentIndexList()) { + if (m_browser->treeView->isExpanded(index)) { + QString path = indexToPath(index); + list << path; + } + } + + // save list + settings.setValue("expandedItems", QVariant::fromValue(list)); +} + +void UAVObjectBrowserWidget::restoreState(QSettings &settings) +{ + // get list + QStringList list = settings.value("expandedItems").toStringList(); + + foreach(QString path, list) { + QModelIndex index = indexFromPath(path); + + if (index.isValid()) { + m_browser->treeView->setExpanded(index, true); + } + } +} + void UAVObjectBrowserWidget::searchTextCleared() { m_browser->searchLine->clear(); diff --git a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h index 73b010afc..bcf8a7ac5 100644 --- a/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h +++ b/ground/gcs/src/plugins/uavobjectbrowser/uavobjectbrowserwidget.h @@ -46,6 +46,12 @@ class TreeSortFilterProxyModel : public QSortFilterProxyModel { public: TreeSortFilterProxyModel(QObject *parent); +public: + QModelIndexList getPersistentIndexList() const + { + return persistentIndexList(); + } + protected: bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const; @@ -87,6 +93,12 @@ public: void setViewOptions(bool showCategories, bool showMetadata, bool useScientificNotation, bool showDescription); void setSplitterState(QByteArray state); + void saveState(QSettings &settings) const; + void restoreState(QSettings &settings); + + QString indexToPath(const QModelIndex &index) const; + QModelIndex indexFromPath(const QString &path) const; + public slots: void showDescription(bool show);