From bcf98edb9d5ddf23774121cd9e39334797871611 Mon Sep 17 00:00:00 2001 From: dorian Date: Fri, 28 Dec 2018 11:37:06 +0100 Subject: [PATCH] fixed issue with filters that made a "no data" error occur, when the user set at least one filter for teacher but none for students and vice versa, even if there was data available. --- headers/filtermodel.h | 6 ++++-- qml/Forms/FilterForm.qml | 8 ++++++-- sources/appsettings.cpp | 21 +++++++++++++++++---- sources/filtermodel.cpp | 14 ++++++++------ sources/serverconn.cpp | 9 +++++++++ 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/headers/filtermodel.h b/headers/filtermodel.h index 3f21f32..5799ae1 100644 --- a/headers/filtermodel.h +++ b/headers/filtermodel.h @@ -13,7 +13,8 @@ public: enum FilterRole { GradeRole = Qt::DisplayRole, - ClassLetterRole + ClassLetterRole, + RoleRole }; Q_ENUM(FilterRole) @@ -22,13 +23,14 @@ public: QHash roleNames() const; Q_INVOKABLE QVariantMap get(int row) const; - Q_INVOKABLE void append(const QString &grade, const QString &classLetter); + Q_INVOKABLE void append(const QString &grade, const QString &classLetter, const QString &role); Q_INVOKABLE void remove(int row); private: struct Filter { QString grade; QString classLetter; + QString role; }; QList m_filters; diff --git a/qml/Forms/FilterForm.qml b/qml/Forms/FilterForm.qml index 21ec335..97742e4 100644 --- a/qml/Forms/FilterForm.qml +++ b/qml/Forms/FilterForm.qml @@ -8,6 +8,8 @@ import "../Components" Page { id: root + property bool teacherMode: _cppAppSettings.loadSetting("teacherMode") === "true" + title: "Vertretungsplan Filter" signal opened() @@ -25,14 +27,14 @@ Page { onFinished: { if(_cppAppSettings.loadSetting("teacherMode") === "true"){ - contactView.model.append(teacherShortcut, "") + contactView.model.append(teacherShortcut, "", "t"); } else { if(parseInt(grade) > 10 || classletter === "alle"){ classletter = "" } - contactView.model.append(grade, classletter) + contactView.model.append(grade, classletter, "s") } } @@ -142,6 +144,8 @@ Page { text: grade + classLetter font.pixelSize: height * 0.4 + enabled: root.teacherMode ? role === "t":role === "s" + Rectangle { anchors { diff --git a/sources/appsettings.cpp b/sources/appsettings.cpp index dd5b819..84159d3 100644 --- a/sources/appsettings.cpp +++ b/sources/appsettings.cpp @@ -63,11 +63,18 @@ QList AppSettings::readFilters() { // array of a single filter QJsonArray filterArray = value.toArray(); - // extract values from array - QString gradeString = filterArray[0].toString(); - QString letterString = filterArray[1].toString(); + QStringList tmpFilterList; - filtersList.append({gradeString, letterString}); + // extract values from array + foreach(const QJsonValue & key, filterArray){ + tmpFilterList.append(key.toString()); + } + + while (tmpFilterList.length() < 3) { + tmpFilterList.append(""); + } + + filtersList.append(tmpFilterList); } return(filtersList); @@ -81,8 +88,14 @@ void AppSettings::writeFilters(QList list) { foreach(QStringList filter, list){ QJsonArray filterArray; + + while (filter.length() < 3) { + filter.append(""); + } + filterArray.append(filter[0]); filterArray.append(filter[1]); + filterArray.append(filter[2]); filtersArray.append(filterArray); } diff --git a/sources/filtermodel.cpp b/sources/filtermodel.cpp index 701e604..1050d88 100644 --- a/sources/filtermodel.cpp +++ b/sources/filtermodel.cpp @@ -7,7 +7,7 @@ FilterModel::FilterModel(QObject *parent ) : QAbstractListModel(parent) QList filtersList = pGlobalAppSettings->readFilters(); foreach(QStringList filterList, filtersList){ - m_filters.append({filterList[0], filterList[1]}); + m_filters.append({filterList[0], filterList[1], filterList[2]}); } } @@ -22,6 +22,7 @@ QVariant FilterModel::data(const QModelIndex &index, int role) const switch (role) { case GradeRole: return m_filters.at(index.row()).grade; case ClassLetterRole: return m_filters.at(index.row()).classLetter; + case RoleRole: return m_filters.at(index.row()).role; default: return QVariant(); } return QVariant(); @@ -32,6 +33,7 @@ QHash FilterModel::roleNames() const static const QHash roles { { GradeRole, "grade" }, { ClassLetterRole, "classLetter" }, + { RoleRole, "role"} }; return roles; } @@ -39,10 +41,10 @@ QHash FilterModel::roleNames() const QVariantMap FilterModel::get(int row) const { const Filter filter = m_filters.value(row); - return { {"grade", filter.grade}, {"classLetter", filter.classLetter} }; + return { {"grade", filter.grade}, {"classLetter", filter.classLetter}, {"role", filter.role} }; } -void FilterModel::append(const QString &grade, const QString &classLetter) +void FilterModel::append(const QString &grade, const QString &classLetter, const QString &role) { foreach(Filter filter, this->m_filters){ @@ -61,14 +63,14 @@ void FilterModel::append(const QString &grade, const QString &classLetter) row++; } beginInsertRows(QModelIndex(), row, row); - m_filters.insert(row, {grade, classLetter}); + m_filters.insert(row, {grade, classLetter, role}); endInsertRows(); QList filtersList; filtersList.clear(); foreach(Filter filter, this->m_filters){ - filtersList.append({filter.grade, filter.classLetter}); + filtersList.append({filter.grade, filter.classLetter, filter.role}); } pGlobalAppSettings->writeFilters(filtersList); @@ -88,7 +90,7 @@ void FilterModel::remove(int row) filtersList.clear(); foreach(Filter filter, this->m_filters){ - filtersList.append({filter.grade, filter.classLetter}); + filtersList.append({filter.grade, filter.classLetter, filter.role}); } pGlobalAppSettings->writeFilters(filtersList); diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index 4c62bae..03ae240 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -298,6 +298,15 @@ int ServerConn::getEvents(QString day){ // get the filers list for later usage QList filtersList = pGlobalAppSettings->readFilters(); + // remove all elements from the filters list, that do not match the current mode ( teacher / student ) of the app + for(int i = 0; i < filtersList.length(); i++){ + QStringList filterList = filtersList[i]; + if( !(pGlobalAppSettings->loadSetting("teacherMode") == "true" ? filterList[2] == "t":filterList[2] == "s") ){ + filtersList.removeAt(i); + i = i-1; + } + } + // go through the list and process every single row for(int x = 0; x < events.length(); x++){ // store the event string