diff options
author | Arno <arno@disconnect.de> | 2017-12-27 19:17:10 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-12-27 19:38:03 +0100 |
commit | 1fdeb5deddefcb49ebdef90c852d2a7b3bd91e50 (patch) | |
tree | 3202482ab68ab4bfc79e5f65f72c12191aa18c74 | |
parent | 3106d58f45ebfd3a0fda56acaa5e9bfabab99981 (diff) | |
download | SheMov-1fdeb5deddefcb49ebdef90c852d2a7b3bd91e50.tar.gz SheMov-1fdeb5deddefcb49ebdef90c852d2a7b3bd91e50.tar.bz2 SheMov-1fdeb5deddefcb49ebdef90c852d2a7b3bd91e50.zip |
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 :)
-rw-r--r-- | mappingtreewidget.cpp | 28 | ||||
-rw-r--r-- | mappingtreewidget.h | 3 |
2 files changed, 31 insertions, 0 deletions
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); diff --git a/mappingtreewidget.h b/mappingtreewidget.h index 44a43e3..baf9fb1 100644 --- a/mappingtreewidget.h +++ b/mappingtreewidget.h @@ -33,6 +33,8 @@ class MappingTreeWidget : public QWidget { QList<MappingData> selectedTree() const; QList<MappingData> selectedTreeRecursive(const QModelIndex &start) const; MappingTreeView *mappingTreeView() const { return mTree; } + MappingTreeModel *mappingTreeModel() const { return mModel; } + MappingTreeProxy *mappingTreeProxy() const { return mProxy; } public slots: void addChild(); @@ -121,6 +123,7 @@ class MappingEditWidget : public QWidget { void shiftFocusMappings(); void saveMappings(QString where); void loadMappings(QString from); + void resultSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); private: MappingTreeWidget *mMappingTree; |