From 1fdeb5deddefcb49ebdef90c852d2a7b3bd91e50 Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 27 Dec 2017 19:17:10 +0100 Subject: Improve archiving pictures Specifically editing mappings. Select and show the source when selecting a mapping result. I know I worked on this a while ago, but never got it right. IIRC I fiddled around with paths and recursion, but that was way too complicated. Just move down the source tree. Fuck recursion :) --- mappingtreewidget.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'mappingtreewidget.cpp') diff --git a/mappingtreewidget.cpp b/mappingtreewidget.cpp index 7ad16a1..8477b0e 100644 --- a/mappingtreewidget.cpp +++ b/mappingtreewidget.cpp @@ -384,6 +384,7 @@ MappingEditWidget::MappingEditWidget(QWidget *parent) : QWidget(parent){ connect(mMappingTree->mappingTreeView(), &MappingTreeView::shiftFocus, this, &MappingEditWidget::shiftFocusResult); connect(mMappingResult, &MappingTreeResultView::shiftFocus, this, &MappingEditWidget::shiftFocusMappings); connect(mMappingResult, &MappingTreeResultView::removeMapping, this, &MappingEditWidget::removeMapping); + connect(mMappingResult->selectionModel(), &QItemSelectionModel::currentChanged, this, &MappingEditWidget::resultSelectionChanged); //buttons mAddMapping = new QPushButton(tr(">>")); @@ -491,6 +492,33 @@ void MappingEditWidget::loadMappings(QString from){ expandAllResults(); } +void MappingEditWidget::resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous){ + Q_UNUSED(previous) + QStringList path; + QModelIndex c = current; + // gather elements from leaf to root + while(c != QModelIndex()){ + path << c.data().toString(); + c = c.parent(); + } + std::reverse(path.begin(), path.end()); + MappingTreeModel *srcModel = mMappingTree->mappingTreeModel(); + QModelIndex srcIdx = srcModel->rootIndex(); + // now search the source tree starting at the top, + // that's why we reversed the QStringList above + for(const QString &p : path){ + srcIdx = srcModel->find(p, 0, srcIdx); + if(!srcIdx.isValid()){ + return; + } + } + // yes, we have a valid index. Map it to the Proxy... + QModelIndex real = mMappingTree->mappingTreeProxy()->mapFromSource(srcIdx); + // select it and make sure it's visible! + mMappingTree->mappingTreeView()->selectionModel()->select(real, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + mMappingTree->mappingTreeView()->scrollTo(real, QAbstractItemView::PositionAtCenter); +} + MappingInputDialog::MappingInputDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ mOk = new QPushButton(tr("Ok")); connect(mOk, &QPushButton::clicked, this, &MappingInputDialog::accept); -- cgit v1.2.3-70-g09d2