summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Gottfried <sebastiangottfried@web.de>2015-06-01 16:33:57 (GMT)
committerSebastian Gottfried <sebastiangottfried@web.de>2015-06-01 16:33:57 (GMT)
commit00d90c30371310cd1aef0c0ac1ecac8d37d504d1 (patch)
treea0936c241d6837f2d4d05f3b59dfd951f69665dd
parent6a2217b2a5d941faa8c14549461a725650d27ec5 (diff)
Qt5: Port main.qml To Qt Quick 2
Also add additional guards in ResourceModel to prevent crash. The parts of `main.qml` referencing other QML files are still commented out. So the app still shows only an empty window, but at least without any error messages.
-rw-r--r--src/models/resourcemodel.cpp21
-rw-r--r--src/qml/main.qml51
2 files changed, 47 insertions, 25 deletions
diff --git a/src/models/resourcemodel.cpp b/src/models/resourcemodel.cpp
index 90fdf5d..1ce0aa2 100644
--- a/src/models/resourcemodel.cpp
+++ b/src/models/resourcemodel.cpp
@@ -89,6 +89,9 @@ QVariant ResourceModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
+ if (!m_dataIndex)
+ return QVariant();
+
if (index.row() > m_dataIndex->courseCount() + m_dataIndex->keyboardLayoutCount())
return QVariant();
@@ -112,6 +115,9 @@ int ResourceModel::rowCount(const QModelIndex &parent) const
if (parent.isValid())
return 0;
+ if (!m_dataIndex)
+ return 0;
+
return m_dataIndex->courseCount() + m_dataIndex->keyboardLayoutCount();
}
@@ -137,6 +143,9 @@ void ResourceModel::onCoursesAboutToBeRemoved(int first, int last)
void ResourceModel::onKeyboardLayoutAboutToBeAdded(DataIndexKeyboardLayout* keyboardLayout, int index)
{
+ if (!m_dataIndex)
+ return;
+
const int offset = m_dataIndex->courseCount();
connectToKeyboardLayout(keyboardLayout);
beginInsertRows(QModelIndex(), index + offset, index + offset);
@@ -144,6 +153,9 @@ void ResourceModel::onKeyboardLayoutAboutToBeAdded(DataIndexKeyboardLayout* keyb
void ResourceModel::onKeyboardLayoutsAboutToBeRemoved(int first, int last)
{
+ if (!m_dataIndex)
+ return;
+
const int offset = m_dataIndex->courseCount();
beginRemoveRows(QModelIndex(), first + offset, last + offset);
}
@@ -168,6 +180,9 @@ void ResourceModel::emitDataChanged(int row)
QVariant ResourceModel::courseData(int row, int role) const
{
+ if (!m_dataIndex)
+ return QVariant();
+
switch(role)
{
case KCategorizedSortFilterProxyModel::CategorySortRole:
@@ -199,6 +214,9 @@ QVariant ResourceModel::courseData(int row, int role) const
QVariant ResourceModel::keyboardLayoutData(int row, int role) const
{
+ if (!m_dataIndex)
+ return QVariant();
+
switch(role)
{
case KCategorizedSortFilterProxyModel::CategorySortRole:
@@ -247,6 +265,9 @@ void ResourceModel::connectToKeyboardLayout(DataIndexKeyboardLayout *keyboardLay
void ResourceModel::updateMappings()
{
+ if (!m_dataIndex)
+ return;
+
for (int i = 0; i < m_dataIndex->courseCount(); i++)
{
m_signalMapper->setMapping(m_dataIndex->course(i), i);
diff --git a/src/qml/main.qml b/src/qml/main.qml
index e326316..02f4112 100644
--- a/src/qml/main.qml
+++ b/src/qml/main.qml
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import QtQuick 1.1
+import QtQuick 2.4
import ktouch 1.0
Item {
@@ -31,25 +31,27 @@ Item {
id: dataAccess
}
- property DataIndex dataIndex: globalDataIndex
+ Text {
+ text: ktouch.globalDataIndex.courseCount
+ }
QtObject {
id: helper
- property string name: keyboardLayoutName
- property int keyboardLayoutCount: dataIndex.keyboardLayoutCount
- property int courseCount: dataIndex.courseCount
+ property string name: ktouch.keyboardLayoutName
+ property int keyboardLayoutCount: ktouch.globalDataIndex.keyboardLayoutCount
+ property int courseCount: ktouch.globalDataIndex.courseCount
onNameChanged: {
keyboardLayout.update()
}
onKeyboardLayoutCountChanged: {
- if (dataIndex.isValid)
+ if (ktouch.globalDataIndex.isValid)
keyboardLayout.update()
}
}
ResourceModel {
id: resourceModel
- dataIndex: main.dataIndex
+ dataIndex: ktouch.globalDataIndex
}
ProfileDataAccess {
@@ -64,20 +66,20 @@ Item {
id: keyboardLayout
Component.onCompleted: {
- if (dataIndex.isValid) {
+ if (ktouch.globalDataIndex.isValid) {
keyboardLayout.update()
}
}
function update() {
isValid = false
- var name = keyboardLayoutName;
+ var name = ktouch.keyboardLayoutName;
// first pass - exact match
- for (var i = 0; i < dataIndex.keyboardLayoutCount; i++)
+ for (var i = 0; i < ktouch.globalDataIndex.keyboardLayoutCount; i++)
{
- var dataIndexLayout = dataIndex.keyboardLayout(i)
+ var dataIndexLayout = ktouch.globalDataIndex.keyboardLayout(i)
if (dataIndexLayout.name === name) {
dataAccess.loadKeyboardLayout(dataIndexLayout, keyboardLayout)
@@ -87,9 +89,9 @@ Item {
// second pass - substring match
- for (var i = 0; i < dataIndex.keyboardLayoutCount; i++)
+ for (var i = 0; i < ktouch.globalDataIndex.keyboardLayoutCount; i++)
{
- var dataIndexLayout = dataIndex.keyboardLayout(i)
+ var dataIndexLayout = ktouch.globalDataIndex.keyboardLayout(i)
if (name.search(dataIndexLayout.name) === 0) {
dataAccess.loadKeyboardLayout(dataIndexLayout, keyboardLayout)
@@ -106,11 +108,16 @@ Item {
keyboardLayoutNameFilter: keyboardLayout.isValid? keyboardLayout.name: keyboardLayoutName
}
- ApplicationBackground {
- id: background
- anchors.fill: parent
+ Course {
+ id: selectedCourse
+ property Lesson selectedLesson
+ }
+
+ Lesson {
+ id: customLessonCopy
}
+ /*
HomeScreen {
id: homeScreen
anchors.fill: parent
@@ -147,15 +154,6 @@ Item {
}
}
- Course {
- id: selectedCourse
- property Lesson selectedLesson
- }
-
- Lesson {
- id: customLessonCopy
- }
-
TrainingScreen {
id: trainingScreen
anchors.fill: parent
@@ -183,6 +181,7 @@ Item {
main.switchScreen(scoreScreen, trainingScreen)
}
}
+ */
Rectangle {
id: curtain
@@ -191,6 +190,7 @@ Item {
opacity: 0
}
+ /*
SequentialAnimation
{
id: switchScreenAnimation
@@ -230,4 +230,5 @@ Item {
}
}
}
+ */
}