diff --git a/fannyapp.pro b/fannyapp.pro index e0f63df..dfb9636 100644 --- a/fannyapp.pro +++ b/fannyapp.pro @@ -22,12 +22,14 @@ SOURCES += \ sources/serverconn.cpp \ sources/main.cpp \ sources/appsettings.cpp \ - sources/foodplanmodel.cpp + sources/foodplanmodel.cpp \ + sources/eventmodel.cpp HEADERS += \ headers/serverconn.h \ headers/appsettings.h \ - headers/foodplanmodel.h + headers/foodplanmodel.h \ + headers/eventmodel.h RESOURCES += \ qml/qml.qrc \ diff --git a/headers/eventmodel.h b/headers/eventmodel.h new file mode 100644 index 0000000..a12c7a6 --- /dev/null +++ b/headers/eventmodel.h @@ -0,0 +1,46 @@ +#ifndef EVENTMODEL_H +#define EVENTMODEL_H + +#include +#include +#include "headers/serverconn.h" + +class EventModel : public QAbstractListModel +{ + Q_OBJECT +public: + EventModel(QObject *parent = nullptr); + ~EventModel(); + + enum DayRole { + GradeRole = Qt::DisplayRole, + HourRole, + ReplaceRole, + SubjectRole, + RoomRole, + ToRole, + TextRole + }; + Q_ENUM(DayRole) + + int rowCount(const QModelIndex & = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QHash roleNames() const; + + Q_INVOKABLE QVariantMap get(int row) const; + +private: + struct Day { + QString grade; + QString hour; + QString replace; + QString subject; + QString room; + QString to; + QString text; + }; + + QList m_events; +}; + +#endif // EVENTMODEL_H diff --git a/headers/foodplanmodel.h b/headers/foodplanmodel.h index 4179b88..13d64b6 100644 --- a/headers/foodplanmodel.h +++ b/headers/foodplanmodel.h @@ -11,6 +11,7 @@ class FoodPlanModel : public QAbstractListModel public: explicit FoodPlanModel(QObject *parent = nullptr); ~FoodPlanModel(); + enum DishRole { CookteamRole = Qt::DisplayRole, DateRole, @@ -38,8 +39,6 @@ private: }; QList m_foodPlan; - -public slots: }; #endif // FOODPLANMODEL_H diff --git a/headers/serverconn.h b/headers/serverconn.h index b8028a0..e68787a 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -48,16 +48,13 @@ public: ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); QList> m_weekplan; + QList m_events; signals: public slots: Q_INVOKABLE void updateProgress(qint64 read, qint64 total); -private: - -QList m_eventlist; - }; extern ServerConn * pGlobalServConn; diff --git a/qml/Components/EventDisplay.qml b/qml/Components/EventDisplay.qml index 8e183ea..8ff3c75 100644 --- a/qml/Components/EventDisplay.qml +++ b/qml/Components/EventDisplay.qml @@ -1,9 +1,10 @@ import QtQuick 2.9 import QtQuick.Controls 2.4 +import Backend 1.0 Item { id: control - +/* ScrollView { id:scroll anchors.fill: parent @@ -79,7 +80,7 @@ Item { if(date.getDate() === today.getDate()){ return("Heute") } - else if(date.getTime() < (today.getTime() + (24 * 60 * 60 * 1000) )/*date.getDate() === today.getDate() + 1 || (date.getDate() === 1 && date.getMonth() === today.getMonth() + 1)*/){ + else if(date.getTime() < (today.getTime() + (24 * 60 * 60 * 1000) )){ return("Morgen") } else { @@ -92,6 +93,64 @@ Item { } } } +*/ + ListView { + id: eventList + + anchors.fill: parent + anchors.margins: 10 + + model: EventModel { + id: foodPlanModel + } + + delegate: Button { + width: listView.width + id: delegate + height: visible ? cookteam.height + date.height + text.height + cust_spacing*9 + 5:0 + visible: listView.isDayVisible(index) + + property int cust_spacing: 5 + + Label { + id: cookteam + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: parent.top + anchors.topMargin: 10 + font.bold: true + font.pixelSize: date.font.pixelSize * 1.5 + text: _cppServerConn.getEventData(index).grade + width: parent.width - 10 + wrapMode: Label.Wrap + height: text!==""? undefined:0 + } + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: cookteam.bottom + id: date + text: _cppServerConn.getEventData(index).hour + " | " + + _cppServerConn.getEventData(index).replace + " | " + + _cppServerConn.getEventData(index).subject + " | " + + _cppServerConn.getEventData(index).room + " | " + + width: parent.width - 10 + wrapMode: Label.Wrap + } + + Label { + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.top: date.bottom + anchors.topMargin: cust_spacing + font.pixelSize: date.font.pixelSize * 2 + font.bold: true + id: text + text: _cppServerConn.getEventData(index).to + " " + _cppServerConn.getEventData(index).text + } + } + } } diff --git a/qml/Components/FoodPlanDisplay.qml b/qml/Components/FoodPlanDisplay.qml index a206d7d..1a87eb0 100644 --- a/qml/Components/FoodPlanDisplay.qml +++ b/qml/Components/FoodPlanDisplay.qml @@ -150,6 +150,7 @@ Item { } } + } diff --git a/qml/Forms/EventForm.qml b/qml/Forms/EventForm.qml index 75bea67..6fde6f6 100644 --- a/qml/Forms/EventForm.qml +++ b/qml/Forms/EventForm.qml @@ -58,7 +58,7 @@ Page { running: true repeat: false onTriggered: { - status = _cppServerConn.getEvents(day); + status = _cppServerConn.getEvents(day) pageLoader.source = "../Components/EventDisplay.qml" } } diff --git a/sources/eventmodel.cpp b/sources/eventmodel.cpp new file mode 100644 index 0000000..f879e92 --- /dev/null +++ b/sources/eventmodel.cpp @@ -0,0 +1,61 @@ +#include "headers/eventmodel.h" + +EventModel::EventModel(QObject *parent) : QAbstractListModel(parent) +{ + // foodplan constructor + // is called when the Foodplan Display is loaded + + // list + m_events.clear(); + + // convert the stringlist from the serverconn to a Dish-list + foreach(QListday, pGlobalServConn->m_events){ + m_events.append({day[0], day[1], day[2], day[3], day[4], day[5], day[6]}); + } +} + +int EventModel::rowCount(const QModelIndex &) const +{ + return m_events.count(); +} + +QVariant EventModel::data(const QModelIndex &index, int role) const +{ + if (index.row() < rowCount()) + switch (role) { + case GradeRole: return m_events.at(index.row()).grade; + case HourRole: return m_events.at(index.row()).hour; + case ReplaceRole: return m_events.at(index.row()).replace; + case SubjectRole: return m_events.at(index.row()).subject; + case RoomRole: return m_events.at(index.row()).room; + case ToRole: return m_events.at(index.row()).to; + case TextRole: return m_events.at(index.row()).text; + default: return QVariant(); + } + return QVariant(); +} + +QHash EventModel::roleNames() const +{ + static const QHash roles { + { GradeRole, "grade" }, + { HourRole, "hour" }, + { ReplaceRole, "replace" }, + { SubjectRole, "subject" }, + { RoomRole, "room" }, + { ToRole, "to" }, + { TextRole, "text" } + }; + return roles; +} + +QVariantMap EventModel::get(int row) const +{ + const Day foodPlan = m_events.value(row); + return { {"grade", foodPlan.grade}, {"hour", foodPlan.hour}, {"replace", foodPlan.replace}, {"subject", foodPlan.subject}, {"room", foodPlan.room}, {"to", foodPlan.to}, {"text", foodPlan.text} }; +} + +EventModel::~EventModel() +{ + +} diff --git a/sources/foodplanmodel.cpp b/sources/foodplanmodel.cpp index ed30932..da62404 100644 --- a/sources/foodplanmodel.cpp +++ b/sources/foodplanmodel.cpp @@ -2,16 +2,16 @@ FoodPlanModel::FoodPlanModel(QObject *parent) : QAbstractListModel(parent) { - //m_foodPlan.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993", "uhj", "iuij" }); - qDebug() << "foodplan Konstructor"; + // foodplan constructor + // is called when the Foodplan Display is loaded + // list m_foodPlan.clear(); + + // convert the stringlist from the serverconn to a Dish-list foreach(QListday, pGlobalServConn->m_weekplan){ m_foodPlan.append({day[0], day[1], day[2], day[3], day[4], day[5]}); } - - qDebug() << "end1"; - //qDebug() << pGlobalServConn->m_weekplan; } int FoodPlanModel::rowCount(const QModelIndex &) const diff --git a/sources/main.cpp b/sources/main.cpp index 6fe72c8..85f7da5 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -16,6 +16,7 @@ #include "headers/serverconn.h" #include "headers/appsettings.h" #include "headers/foodplanmodel.h" +#include "headers/eventmodel.h" int main(int argc, char *argv[]) { @@ -30,6 +31,7 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); qmlRegisterType("Backend", 1, 0, "FoodPlanModel"); + qmlRegisterType("Backend", 1, 0, "EventModel"); QQuickStyle::setStyle("Material"); QQmlApplicationEngine engine; diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index dc4c2b4..2439e53 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -123,20 +123,20 @@ QString ServerConn::getDay(QString day) QUrl url = QUrl::fromLocalFile(path + "/.fannyapp-tmp/" + day + ".pdf"); // QDesktopServices::openUrl(url); - return("OK_" + url.toString()); - } - else if(status_code == 401){ - return("Ungültige Benutzerdaten."); - } - else if(status_code == 0){ - return("Keine Verbindung zum Server."); - } - else { - QString ret = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toChar(); - ret = ret + " (" + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toChar() + ")"; - return(ret); - } + return("OK_" + url.toString()); } + else if(status_code == 401){ + return("Ungültige Benutzerdaten."); + } + else if(status_code == 0){ + return("Keine Verbindung zum Server."); + } + else { + QString ret = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toChar(); + ret = ret + " (" + reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toChar() + ")"; + return(ret); + } +} int ServerConn::checkConn() @@ -184,7 +184,7 @@ float ServerConn::getProgress() } int ServerConn::getEvents(QString day){ - + /* this->progress = 0; ReturnData_t ret; //this is a custom type to store the returned data // Call the webservice @@ -214,73 +214,113 @@ int ServerConn::getEvents(QString day){ } QString eventString = reply->readAll(); - +*/ qDebug() << "reading xml file"; -// QFile * xmlFile = new QFile(":/samplehtml/Download File.xml"); -// if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) { -// qDebug() << "Load XML File Problem Couldn't open xmlfile.xml to load settings for download"; -// return 900; -// } + QFile * xmlFile = new QFile(":/samplehtml/Download File.xml"); + if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "Load XML File Problem Couldn't open xmlfile.xml to load settings for download"; + return 900; + } - QXmlStreamReader * xmlReader = new QXmlStreamReader(eventString); + //QXmlStreamReader * xmlReader = new QXmlStreamReader(eventString); + QXmlStreamReader * xmlReader = new QXmlStreamReader(xmlFile); //qDebug() << xmlFile->readAll(); QList tmpEvents; QStringList dayList; int currTop = 0; + /* + 8a + 1 - 2 + Ei + Ch + --- + Entfall + KEINE KA + */ + + #define eventXmlPosGrade 3 + #define eventXmlPosHour 55 + #define eventXmlPosReplace 123 + #define eventXmlPosSubject 178 + #define eventXmlPosRoom 233 + #define eventXmlPosTo 275 + #define eventXmlPosText 391 + //Parse the XML until we reach end of it while(!xmlReader->atEnd()) { - if (xmlReader->readNextStartElement()) { - if (xmlReader->name().toString() == "text"){ - QXmlStreamAttributes attributes = xmlReader->attributes(); - QString attribute_value; - int top; + if (xmlReader->readNextStartElement()) { + // read next element - if(attributes.hasAttribute("font")){ - attribute_value = attributes.value("font").toString(); + if (xmlReader->name().toString() == "text"){ + // text element found + QXmlStreamAttributes attributes = xmlReader->attributes(); + QString attribute_value; + int top; + + if(attributes.hasAttribute("font")){ + attribute_value = attributes.value("font").toString(); + } + + if(attributes.hasAttribute("top")){ + // get the y-Position of the text + + top = attributes.value("top").toInt(); + + if(abs(top - currTop) > 3){ + // new line started + + if(currTop > 175){ + // ignore the header + qDebug() << dayList; + tmpEvents.append(dayList); + } + + dayList.clear(); + while (dayList.length() < 7) { + dayList.append(""); + } + currTop = top; } + else { + // no new line - if(attributes.hasAttribute("top")){ - top = attributes.value("top").toInt(); - if(abs(top - currTop) > 3){ - //next line started - if(currTop > 175){ - // ignore the header - tmpEvents.append(dayList); + if(attributes.hasAttribute("left")){ + int left = attributes.value("left").toInt(); + QString text = xmlReader->readElementText(QXmlStreamReader::IncludeChildElements); + if(abs(left - eventXmlPosGrade) < 3){ + // position tells the text is the grade + dayList[0] = text; + } + else if (abs(left - eventXmlPosHour) < 3) { + // position tells the text is the grade + dayList[1] = text; } - - dayList.clear(); - currTop = top; } } - - QString text = xmlReader->readElementText(QXmlStreamReader::IncludeChildElements); - dayList.append(text); - - - - qDebug() << qPrintable(xmlReader->name().toString()) << text << attribute_value << dayList; } } + + //qDebug() << qPrintable(xmlReader->name().toString()) << text << attribute_value << dayList; + } } +} - tmpEvents.takeFirst(); +qDebug() << tmpEvents; - qDebug() << tmpEvents; +this->m_events = tmpEvents; - this->m_eventlist = tmpEvents; +if(xmlReader->hasError()) { + qDebug() << "xmlFile.xml Parse Error" << xmlReader->errorString(); + //return(900); +} - if(xmlReader->hasError()) { - qDebug() << "xmlFile.xml Parse Error" << xmlReader->errorString(); - //return(500); - } +//close reader and flush file +xmlReader->clear(); +//xmlFile->close(); - //close reader and flush file - xmlReader->clear(); - //xmlFile->close(); - - return(200); +return(200); } int ServerConn::getFoodPlan() @@ -507,18 +547,18 @@ QVariantMap ServerConn::getEventData(int index) //qDebug() << index; for(int i=0;i<=6;i++){ - if(m_eventlist.size() > index){ + if(m_events.size() > index){ //qDebug() << i << m_weekplan[index].size(); - if(m_eventlist[index].size() > i){ - ret.append(m_eventlist[index][i]); + if(m_events[index].size() > i){ + ret.append(m_events[index][i]); //qDebug() << i << m_weekplan[index][i]; } else { - ret.append(NULL); + ret.append(nullptr); } } else { - ret.append(NULL); + ret.append(nullptr); } } if(ret.length() < 7){ @@ -533,7 +573,7 @@ QVariantMap ServerConn::getEventData(int index) } int ServerConn::getEventCount(){ - return (m_eventlist.length()); + return (m_events.length()); } ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata)