diff options
Diffstat (limited to 'application/widgets')
-rw-r--r-- | application/widgets/VersionSelectWidget.cpp | 25 | ||||
-rw-r--r-- | application/widgets/VersionSelectWidget.h | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/application/widgets/VersionSelectWidget.cpp b/application/widgets/VersionSelectWidget.cpp index 1696d9d1..2a7cbfb7 100644 --- a/application/widgets/VersionSelectWidget.cpp +++ b/application/widgets/VersionSelectWidget.cpp @@ -41,6 +41,11 @@ VersionSelectWidget::VersionSelectWidget(BaseVersionList* vlist, QWidget* parent QMetaObject::connectSlotsByName(this); } +void VersionSelectWidget::setCurrentVersion(const QString& version) +{ + m_currentVersion = version; +} + void VersionSelectWidget::setEmptyString(QString emptyString) { listView->setEmptyString(emptyString); @@ -134,15 +139,33 @@ void VersionSelectWidget::preselect() { if(preselectedAlready) return; - preselectedAlready = true; + selectCurrent(); + if(preselectedAlready) + return; selectRecommended(); } +void VersionSelectWidget::selectCurrent() +{ + if(m_currentVersion.isEmpty()) + { + return; + } + auto idx = m_proxyModel->getVersion(m_currentVersion); + if(idx.isValid()) + { + preselectedAlready = true; + listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); + listView->scrollTo(idx, QAbstractItemView::PositionAtCenter); + } +} + void VersionSelectWidget::selectRecommended() { auto idx = m_proxyModel->getRecommended(); if(idx.isValid()) { + preselectedAlready = true; listView->selectionModel()->setCurrentIndex(idx,QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); listView->scrollTo(idx, QAbstractItemView::PositionAtCenter); } diff --git a/application/widgets/VersionSelectWidget.h b/application/widgets/VersionSelectWidget.h index 66e512ac..0840e27a 100644 --- a/application/widgets/VersionSelectWidget.h +++ b/application/widgets/VersionSelectWidget.h @@ -40,13 +40,14 @@ public: bool hasVersions() const; BaseVersionPtr selectedVersion() const; void selectRecommended(); + void selectCurrent(); + void setCurrentVersion(const QString & version); void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter); void setExactFilter(BaseVersionList::ModelRoles role, QString filter); void setEmptyString(QString emptyString); void setEmptyErrorString(QString emptyErrorString); void setResizeOn(int column); - void setUseLatest(const bool useLatest); signals: void selectedVersionChanged(BaseVersionPtr version); @@ -64,6 +65,7 @@ private: void preselect(); private: + QString m_currentVersion; BaseVersionList *m_vlist = nullptr; VersionProxyModel *m_proxyModel = nullptr; int resizeOnColumn = 0; |