aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2016-10-10 11:15:09 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2016-10-10 11:15:09 (GMT)
commitb51ab8575bf37e9fa6d7af272cd93845d3287c1f (patch)
treed8c23f209abae2eed9af71aad5acceb4bb87162c
parent1ce4b332dfb361c90cb41b6376c8ec6b019d895f (diff)
Fix Course Selection On Start
The JS function responsible restoring the last used course was called before the Repeater element holding the data it is relying on was populated. This now avoided by directly reading from the model.
-rw-r--r--src/models/resourcemodel.h1
-rw-r--r--src/qml/CourseSelector.qml35
2 files changed, 16 insertions, 20 deletions
diff --git a/src/models/resourcemodel.h b/src/models/resourcemodel.h
index 0008fc2..bf065d5 100644
--- a/src/models/resourcemodel.h
+++ b/src/models/resourcemodel.h
@@ -46,6 +46,7 @@ public:
IndexRole,
SourceRole
};
+ Q_ENUM(AdditionalRoles)
explicit ResourceModel( QObject* parent = 0);
DataIndex* dataIndex() const;
void setDataIndex(DataIndex* dataIndex);
diff --git a/src/qml/CourseSelector.qml b/src/qml/CourseSelector.qml
index 5747a47..bc25127 100644
--- a/src/qml/CourseSelector.qml
+++ b/src/qml/CourseSelector.qml
@@ -32,17 +32,19 @@ Item {
signal lessonSelected(variant course, variant lesson)
function selectLastUsedCourse() {
- if (!profile)
+ if (!profile) {
return
+ }
+
var courseId = profile.lastUsedCourseId;
- if (courseId == "custom_lessons") {
+ if (courseId === "custom_lessons") {
selectCourse(courseRepeater.count, true)
return
}
- for (var i = 0; i < courseRepeater.count; i++) {
- var dataIndexCourse = courseRepeater.itemAt(i).dataIndexCourse
+ for (var i = 0; i < courseModel.rowCount(); i++) {
+ var dataIndexCourse = courseModel.data(courseModel.index(i, 0), ResourceModel.DataRole);
if (dataIndexCourse.id === courseId) {
selectCourse(i, true)
return
@@ -53,12 +55,14 @@ Item {
}
function selectCourse(index, automaticSelection) {
- if (index === priv.currentIndex)
+ if (index === priv.currentIndex) {
return
+ }
var direction = index > priv.currentIndex? Item.Left: Item.Right
- var dataIndexCourse = index < courseRepeater.count?
- courseRepeater.itemAt(index).dataIndexCourse: null
+ var dataIndexCourse = index < courseModel.rowCount()?
+ courseModel.data(courseModel.index(index, 0), ResourceModel.DataRole):
+ null;
var targetPage = automaticSelection? coursePageContainer.activePage: coursePageContainer.inactivePage
priv.currentIndex = index;
@@ -94,15 +98,6 @@ Item {
}
}
- Repeater {
- id: courseRepeater
- model: courseModel
-
- delegate: Item {
- property DataIndexCourse dataIndexCourse: dataRole
- }
- }
-
QtObject {
id: priv
property int currentIndex: -1
@@ -162,7 +157,7 @@ Item {
anchors.verticalCenter: parent.verticalCenter
iconName: "arrow-left"
enabled: priv.currentIndex > 0
- visible: courseRepeater.count > 0
+ visible: courseModel.rowCount() > 0
onClicked: {
var newIndex = priv.currentIndex - 1
root.selectCourse(newIndex, false)
@@ -172,10 +167,10 @@ Item {
ToolButton {
id: nextButton
iconName: "arrow-right"
- enabled: priv.currentIndex < courseRepeater.count
- visible: courseRepeater.count > 0
+ enabled: priv.currentIndex < courseModel.rowCount()
+ visible: courseModel.rowCount() > 0
onClicked: {
- var newIndex = (priv.currentIndex + 1) % (courseRepeater.count + 1)
+ var newIndex = (priv.currentIndex + 1) % (courseModel.rowCount() + 1)
root.selectCourse(newIndex, false)
}
}