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

Reenable course switching by languages

parent 1f8ddf5d
......@@ -126,6 +126,25 @@ void EditorSession::setCourse(IEditableCourse *course)
emit courseChanged();
}
void EditorSession::setCourseByLanguage(Language *language)
{
if (!skeletonMode() || m_skeleton == nullptr) {
qDebug() << "Course selection by language is only available in skeleton mode";
return;
}
if (language == nullptr || m_repository == nullptr) {
return;
}
IEditableCourse *newCourse{ nullptr };
for (auto course : m_repository->editableCourses()) {
if (course->foreignId() == m_skeleton->id() && course->language()->id() == language->id()) {
newCourse = course;
break;
}
}
setCourse(newCourse);
}
IEditableCourse * EditorSession::displayedCourse() const
{
IEditableCourse * course{ nullptr };
......
......@@ -83,6 +83,11 @@ public:
Language * language() const;
IEditableCourse * course() const;
void setCourse(IEditableCourse *course);
/**
* @brief Open course resource by specifying the language
* @param language the target language
*/
Q_INVOKABLE void setCourseByLanguage(Language *language);
IEditableCourse * displayedCourse() const;
Unit * unit() const;
void setUnit(Unit *unit);
......
......@@ -113,30 +113,21 @@ Item {
text: i18n("Language:")
}
ComboBox {
id: languageSelectionComboBox
Layout.minimumWidth: 200
Layout.fillWidth: true
enabled: !buttonEditSkeleton.checked
model: languageModel
textRole: "i18nTitle"
onCurrentIndexChanged: {
// g_editorSession.language = languageModel.language(currentIndex)
//FIXME language selection shall not change the language but the course
g_editorSession.setCourseByLanguage(languageModel.language(currentIndex))
}
}
}
RowLayout {
id: courseRow
id: createNewCourseRow
visible: {
if (buttonEditSkeleton.checked) {
return false
}
if (g_editorSession.skeletonMode && g_editorSession.course !== null) {
return false
}
if (!g_editorSession.skeletonMode
&& g_editorSession.language !== null
&& g_editorSession.course !== null
) {
if (buttonEditSkeleton.checked || g_editorSession.displayedCourse !== null) {
return false
}
return true
......@@ -147,18 +138,18 @@ Item {
}
ComboBox { // course selection only necessary when we do not edit skeleton derived course
id: comboCourse
enabled: !g_editorSession.skeletonMode
visible: !g_editorSession.skeletonMode
Layout.fillWidth: true
model: courseModel
textRole: "title"
onCurrentIndexChanged: {
if (courseModel.course(currentIndex)) {
g_editorSession.course = courseModel.course(currentIndex)
g_editorSession.course = courseModel.course(languageSelectionComboBox.currentIndex)
}
}
onVisibleChanged: {
if (visible && courseModel.course(currentIndex)) {
g_editorSession.course = courseModel.course(currentIndex)
g_editorSession.course = courseModel.course(languageSelectionComboBox.currentIndex)
}
}
}
......@@ -166,14 +157,14 @@ Item {
text: i18n("Create Course")
icon.name: "journal-new"
onClicked: {
g_editorSession.course = g_repository.createCourse(g_editorSession.language, g_editorSession.skeleton)
g_editorSession.course = g_repository.createCourse(languageModel.language(languageSelectionComboBox.currentIndex), g_editorSession.skeleton)
}
}
Item { Layout.fillHeight: true } //dummy
}
RowLayout {
id: mainRow
visible: g_editorSession.course !== null
visible: g_editorSession.course !== null && createNewCourseRow.visible === false
Layout.fillHeight: true
ColumnLayout {
ScrollView {
......
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