Commit a905b65e authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Revisit basic switching behavior for skeletons in editor

parent 51b49bf7
......@@ -31,7 +31,11 @@
EditorSession::EditorSession(QObject *parent)
: QObject(parent)
{
connect(this, &EditorSession::skeletonChanged, this, &EditorSession::displayedCourseChanged);
connect(this, &EditorSession::courseChanged, this, &EditorSession::displayedCourseChanged);
connect(this, &EditorSession::editSkeletonChanged, this, &EditorSession::displayedCourseChanged);
connect(this, &EditorSession::displayedCourseChanged, this, &EditorSession::updateDisplayedUnit);
connect(this, &EditorSession::courseChanged, this, &EditorSession::skeletonModeChanged);
}
void EditorSession::setRepository(IEditableRepository *repository)
......@@ -41,7 +45,7 @@ void EditorSession::setRepository(IEditableRepository *repository)
bool EditorSession::skeletonMode() const
{
return m_skeletonMode;
return m_skeleton != nullptr;
}
void EditorSession::setEditSkeleton(bool enabled)
......@@ -50,13 +54,6 @@ void EditorSession::setEditSkeleton(bool enabled)
return;
}
m_editSkeleton = enabled;
if (enabled) {
m_tmpCourseWhileSkeletonEditing = m_course;
// setCourse(m_skeleton); //FIXME port skeleton for this
} else {
setCourse(m_tmpCourseWhileSkeletonEditing);
m_tmpCourseWhileSkeletonEditing = nullptr;
}
emit editSkeletonChanged();
}
......@@ -77,10 +74,6 @@ void EditorSession::setSkeleton(IEditableCourse *skeleton)
}
m_skeleton = skeleton;
if (m_skeletonMode != true) {
m_skeletonMode = true;
emit skeletonModeChanged();
}
IEditableCourse *newCourse{ nullptr };
if (m_skeleton && m_repository) {
for (const auto &course : m_repository->editableCourses()) {
......@@ -91,7 +84,6 @@ void EditorSession::setSkeleton(IEditableCourse *skeleton)
}
}
setCourse(newCourse);
emit skeletonChanged();
}
......@@ -111,29 +103,48 @@ void EditorSession::setCourse(IEditableCourse *course)
return;
}
m_course = course;
if (m_skeleton == nullptr || m_skeleton->id() != course->foreignId()) {
for (const auto &skeleton : m_repository->skeletons()) {
if (skeleton->id() == course->foreignId()) {
m_skeleton = skeleton;
emit skeletonChanged();
break;
}
}
}
if (m_course != nullptr) {
// update skeleton
IEditableCourse * newSkeleton{ nullptr };
if (m_skeleton == nullptr || m_skeleton->id() != course->foreignId()) {
for (const auto &skeleton : m_repository->skeletons()) {
if (skeleton->id() == course->foreignId()) {
newSkeleton = skeleton;
break;
}
}
m_skeleton = newSkeleton;
emit skeletonChanged();
}
// update language
m_language = m_course->language();
} else {
m_language = nullptr;
}
emit languageChanged();
emit courseChanged();
}
IEditableCourse * EditorSession::displayedCourse() const
{
IEditableCourse * course{ nullptr };
if (m_editSkeleton) {
course = m_skeleton;
} else {
course = m_course;
}
return course;
}
if (m_course && !m_course->unitList().isEmpty()) {
setUnit(m_course->unitList().constFirst());
void EditorSession::updateDisplayedUnit()
{
auto course = displayedCourse();
if (course && !course->unitList().isEmpty()) {
setUnit(course->unitList().constFirst());
} else {
setUnit(nullptr);
}
emit courseChanged();
}
Unit * EditorSession::unit() const
......
......@@ -58,8 +58,14 @@ class ARTIKULATECORE_EXPORT EditorSession : public QObject
Q_PROPERTY(bool skeletonMode READ skeletonMode NOTIFY skeletonModeChanged)
Q_PROPERTY(bool editSkeleton READ isEditSkeleton WRITE setEditSkeleton NOTIFY editSkeletonChanged)
Q_PROPERTY(IEditableCourse *skeleton READ skeleton WRITE setSkeleton NOTIFY skeletonChanged)
Q_PROPERTY(Language *language READ language NOTIFY languageChanged)
Q_PROPERTY(IEditableCourse *course READ course WRITE setCourse NOTIFY courseChanged)
// editor elements depending on curently selected mode, skeleton and course
/**
* @brief the displayed course (skeleton or course) depending on the user selection
*/
Q_PROPERTY(IEditableCourse *displayedCourse READ displayedCourse NOTIFY displayedCourseChanged)
Q_PROPERTY(Language *language READ language NOTIFY languageChanged)
Q_PROPERTY(Unit *unit READ unit WRITE setUnit NOTIFY unitChanged)
Q_PROPERTY(Phrase *phrase READ phrase WRITE setPhrase NOTIFY phraseChanged)
Q_PROPERTY(bool hasNextPhrase READ hasNextPhrase NOTIFY phraseChanged)
......@@ -77,6 +83,7 @@ public:
Language * language() const;
IEditableCourse * course() const;
void setCourse(IEditableCourse *course);
IEditableCourse * displayedCourse() const;
Unit * unit() const;
void setUnit(Unit *unit);
Phrase * phrase() const;
......@@ -89,6 +96,9 @@ public:
Q_INVOKABLE void switchToNextPhrase();
Q_INVOKABLE void updateCourseFromSkeleton();
private Q_SLOTS:
void updateDisplayedUnit();
private:
Phrase * nextPhrase() const;
Phrase * previousPhrase() const;
......@@ -99,18 +109,17 @@ Q_SIGNALS:
void skeletonChanged();
void languageChanged();
void courseChanged();
void displayedCourseChanged();
void unitChanged();
void phraseChanged();
private:
Q_DISABLE_COPY(EditorSession)
IEditableRepository * m_repository{ nullptr };
bool m_skeletonMode{ false };
bool m_editSkeleton{ false };
IEditableCourse *m_skeleton{ nullptr };
Language *m_language{ nullptr };
IEditableCourse *m_course{ nullptr };
IEditableCourse *m_tmpCourseWhileSkeletonEditing{ nullptr };
Unit *m_unit{ nullptr };
Phrase *m_phrase{ nullptr };
};
......
......@@ -53,7 +53,7 @@ Item {
}
UnitModel {
id: selectedUnitModel
course: g_editorSession.course
course: g_editorSession.displayedCourse
}
ColumnLayout {
......@@ -89,6 +89,7 @@ Item {
text: i18n("Edit Prototype")
icon.name: "code-class"
checkable: true
enabled: g_editorSession.skeletonMode
onClicked: g_editorSession.editSkeleton = checked
}
Item { Layout.fillWidth: true }
......@@ -104,15 +105,6 @@ Item {
ToolTip.text: i18n("Update the course with elements from prototype.")
onClicked: g_editorSession.updateCourseFromSkeleton()
}
CheckBox {
Layout.alignment: Qt.AlignRight
enabled: false//FIXME for now deactivating non-skeleton mode
text: i18n("Prototype Mode")
checked: g_editorSession.skeletonMode
onClicked: {
g_editorSession.skeletonMode = !g_editorSession.skeletonMode
}
}
}
RowLayout {
......@@ -127,7 +119,8 @@ Item {
model: languageModel
textRole: "i18nTitle"
onCurrentIndexChanged: {
g_editorSession.language = languageModel.language(currentIndex)
// g_editorSession.language = languageModel.language(currentIndex)
//FIXME language selection shall not change the language but the course
}
}
}
......@@ -154,7 +147,7 @@ Item {
}
ComboBox { // course selection only necessary when we do not edit skeleton derived course
id: comboCourse
visible: !g_editorSession.skeletonMode
enabled: !g_editorSession.skeletonMode
Layout.fillWidth: true
model: courseModel
textRole: "title"
......@@ -200,7 +193,7 @@ Item {
}
model: PhraseModel {
id: phraseModel
course: g_editorSession.course
course: g_editorSession.displayedCourse
}
selection: ItemSelectionModel {
model: phraseTree.model
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment