aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Cord-Landwehr <[email protected]>2015-09-08 16:51:40 +0200
committerAndreas Cord-Landwehr <[email protected]>2015-09-08 16:51:40 +0200
commitfa61cbb1ec4a13aa4ec26049516ad529592b5d6c (patch)
tree41ceea8b49722239f00cd1d2a5f58e69499f67f9
parent7a32548e294010b0f2437d4d29a8b0d2c3b11708 (diff)
Expand units if phrase therein is selected.
-rw-r--r--src/models/phrasemodel.cpp10
-rw-r--r--src/models/phrasemodel.h3
-rw-r--r--src/qml/Editor.qml3
3 files changed, 13 insertions, 3 deletions
diff --git a/src/models/phrasemodel.cpp b/src/models/phrasemodel.cpp
index 124361e..d77e5ae 100644
--- a/src/models/phrasemodel.cpp
+++ b/src/models/phrasemodel.cpp
@@ -180,7 +180,7 @@ QModelIndex PhraseModel::index(int row, int column, const QModelIndex &parent) c
return QModelIndex();
}
-QModelIndex PhraseModel::index(Phrase *phrase) const
+QModelIndex PhraseModel::indexPhrase(Phrase *phrase) const
{
if (!phrase) {
return QModelIndex();
@@ -189,6 +189,14 @@ QModelIndex PhraseModel::index(Phrase *phrase) const
return createIndex(unit->phraseList().indexOf(phrase), 0, unit);
}
+QModelIndex PhraseModel::indexUnit(Unit *unit) const
+{
+ if (!unit) {
+ return QModelIndex();
+ }
+ return createIndex(m_course->unitList().indexOf(unit), 0);
+}
+
void PhraseModel::onPhraseAboutToBeAdded(Phrase *phrase, int index)
{
int unitIndex = m_course->unitList().indexOf(phrase->unit());
diff --git a/src/models/phrasemodel.h b/src/models/phrasemodel.h
index 18bfcba..d1c0409 100644
--- a/src/models/phrasemodel.h
+++ b/src/models/phrasemodel.h
@@ -50,7 +50,8 @@ public:
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const Q_DECL_OVERRIDE;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
Q_INVOKABLE Phrase * phrase(const QModelIndex &index) const;
- Q_INVOKABLE QModelIndex index(Phrase *phrase) const;
+ Q_INVOKABLE QModelIndex indexPhrase(Phrase *phrase) const;
+ Q_INVOKABLE QModelIndex indexUnit(Unit *unit) const;
Q_SIGNALS:
void phraseChanged(int index);
diff --git a/src/qml/Editor.qml b/src/qml/Editor.qml
index 9fda39f..267c1f1 100644
--- a/src/qml/Editor.qml
+++ b/src/qml/Editor.qml
@@ -193,8 +193,9 @@ Item
Connections {
target: editorSession
onPhraseChanged: {
+ phraseTree.expand(phraseModel.indexUnit(editorSession.phrase.unit))
phraseTree.selection.setCurrentIndex(
- phraseModel.index(editorSession.phrase),
+ phraseModel.indexPhrase(editorSession.phrase),
ItemSelectionModel.ClearAndSelect)
}
}