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.
This commit is contained in:
parent
2ff52410d2
commit
bcf98edb9d
5 changed files with 44 additions and 14 deletions
|
@ -13,7 +13,8 @@ public:
|
||||||
|
|
||||||
enum FilterRole {
|
enum FilterRole {
|
||||||
GradeRole = Qt::DisplayRole,
|
GradeRole = Qt::DisplayRole,
|
||||||
ClassLetterRole
|
ClassLetterRole,
|
||||||
|
RoleRole
|
||||||
};
|
};
|
||||||
Q_ENUM(FilterRole)
|
Q_ENUM(FilterRole)
|
||||||
|
|
||||||
|
@ -22,13 +23,14 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
||||||
Q_INVOKABLE QVariantMap get(int row) 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);
|
Q_INVOKABLE void remove(int row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Filter {
|
struct Filter {
|
||||||
QString grade;
|
QString grade;
|
||||||
QString classLetter;
|
QString classLetter;
|
||||||
|
QString role;
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<Filter> m_filters;
|
QList<Filter> m_filters;
|
||||||
|
|
|
@ -8,6 +8,8 @@ import "../Components"
|
||||||
Page {
|
Page {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
property bool teacherMode: _cppAppSettings.loadSetting("teacherMode") === "true"
|
||||||
|
|
||||||
title: "Vertretungsplan Filter"
|
title: "Vertretungsplan Filter"
|
||||||
|
|
||||||
signal opened()
|
signal opened()
|
||||||
|
@ -25,14 +27,14 @@ Page {
|
||||||
|
|
||||||
onFinished: {
|
onFinished: {
|
||||||
if(_cppAppSettings.loadSetting("teacherMode") === "true"){
|
if(_cppAppSettings.loadSetting("teacherMode") === "true"){
|
||||||
contactView.model.append(teacherShortcut, "")
|
contactView.model.append(teacherShortcut, "", "t");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(parseInt(grade) > 10 || classletter === "alle"){
|
if(parseInt(grade) > 10 || classletter === "alle"){
|
||||||
classletter = ""
|
classletter = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
contactView.model.append(grade, classletter)
|
contactView.model.append(grade, classletter, "s")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,6 +144,8 @@ Page {
|
||||||
text: grade + classLetter
|
text: grade + classLetter
|
||||||
font.pixelSize: height * 0.4
|
font.pixelSize: height * 0.4
|
||||||
|
|
||||||
|
enabled: root.teacherMode ? role === "t":role === "s"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
|
|
|
@ -63,11 +63,18 @@ QList<QStringList> AppSettings::readFilters() {
|
||||||
// array of a single filter
|
// array of a single filter
|
||||||
QJsonArray filterArray = value.toArray();
|
QJsonArray filterArray = value.toArray();
|
||||||
|
|
||||||
// extract values from array
|
QStringList tmpFilterList;
|
||||||
QString gradeString = filterArray[0].toString();
|
|
||||||
QString letterString = filterArray[1].toString();
|
|
||||||
|
|
||||||
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);
|
return(filtersList);
|
||||||
|
@ -81,8 +88,14 @@ void AppSettings::writeFilters(QList<QStringList> list) {
|
||||||
|
|
||||||
foreach(QStringList filter, list){
|
foreach(QStringList filter, list){
|
||||||
QJsonArray filterArray;
|
QJsonArray filterArray;
|
||||||
|
|
||||||
|
while (filter.length() < 3) {
|
||||||
|
filter.append("");
|
||||||
|
}
|
||||||
|
|
||||||
filterArray.append(filter[0]);
|
filterArray.append(filter[0]);
|
||||||
filterArray.append(filter[1]);
|
filterArray.append(filter[1]);
|
||||||
|
filterArray.append(filter[2]);
|
||||||
|
|
||||||
filtersArray.append(filterArray);
|
filtersArray.append(filterArray);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ FilterModel::FilterModel(QObject *parent ) : QAbstractListModel(parent)
|
||||||
QList<QStringList> filtersList = pGlobalAppSettings->readFilters();
|
QList<QStringList> filtersList = pGlobalAppSettings->readFilters();
|
||||||
|
|
||||||
foreach(QStringList filterList, filtersList){
|
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) {
|
switch (role) {
|
||||||
case GradeRole: return m_filters.at(index.row()).grade;
|
case GradeRole: return m_filters.at(index.row()).grade;
|
||||||
case ClassLetterRole: return m_filters.at(index.row()).classLetter;
|
case ClassLetterRole: return m_filters.at(index.row()).classLetter;
|
||||||
|
case RoleRole: return m_filters.at(index.row()).role;
|
||||||
default: return QVariant();
|
default: return QVariant();
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -32,6 +33,7 @@ QHash<int, QByteArray> FilterModel::roleNames() const
|
||||||
static const QHash<int, QByteArray> roles {
|
static const QHash<int, QByteArray> roles {
|
||||||
{ GradeRole, "grade" },
|
{ GradeRole, "grade" },
|
||||||
{ ClassLetterRole, "classLetter" },
|
{ ClassLetterRole, "classLetter" },
|
||||||
|
{ RoleRole, "role"}
|
||||||
};
|
};
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
@ -39,10 +41,10 @@ QHash<int, QByteArray> FilterModel::roleNames() const
|
||||||
QVariantMap FilterModel::get(int row) const
|
QVariantMap FilterModel::get(int row) const
|
||||||
{
|
{
|
||||||
const Filter filter = m_filters.value(row);
|
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){
|
foreach(Filter filter, this->m_filters){
|
||||||
|
@ -61,14 +63,14 @@ void FilterModel::append(const QString &grade, const QString &classLetter)
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
m_filters.insert(row, {grade, classLetter});
|
m_filters.insert(row, {grade, classLetter, role});
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
QList<QStringList> filtersList;
|
QList<QStringList> filtersList;
|
||||||
filtersList.clear();
|
filtersList.clear();
|
||||||
|
|
||||||
foreach(Filter filter, this->m_filters){
|
foreach(Filter filter, this->m_filters){
|
||||||
filtersList.append({filter.grade, filter.classLetter});
|
filtersList.append({filter.grade, filter.classLetter, filter.role});
|
||||||
}
|
}
|
||||||
|
|
||||||
pGlobalAppSettings->writeFilters(filtersList);
|
pGlobalAppSettings->writeFilters(filtersList);
|
||||||
|
@ -88,7 +90,7 @@ void FilterModel::remove(int row)
|
||||||
filtersList.clear();
|
filtersList.clear();
|
||||||
|
|
||||||
foreach(Filter filter, this->m_filters){
|
foreach(Filter filter, this->m_filters){
|
||||||
filtersList.append({filter.grade, filter.classLetter});
|
filtersList.append({filter.grade, filter.classLetter, filter.role});
|
||||||
}
|
}
|
||||||
|
|
||||||
pGlobalAppSettings->writeFilters(filtersList);
|
pGlobalAppSettings->writeFilters(filtersList);
|
||||||
|
|
|
@ -298,6 +298,15 @@ int ServerConn::getEvents(QString day){
|
||||||
// get the filers list for later usage
|
// get the filers list for later usage
|
||||||
QList<QStringList> filtersList = pGlobalAppSettings->readFilters();
|
QList<QStringList> 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
|
// go through the list and process every single row
|
||||||
for(int x = 0; x < events.length(); x++){
|
for(int x = 0; x < events.length(); x++){
|
||||||
// store the event string
|
// store the event string
|
||||||
|
|
Reference in a new issue