From 73973f145ae2a572084474be181ba6eb05d86404 Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 24 Jun 2018 09:23:10 +0200 Subject: [PATCH] Frotschritte beim Speiseplan --- fannyapp.pro.user | 534 +++++++++++++++++++++--------------------- headers/serverconn.h | 20 +- qml/FoodPlanForm.qml | 56 +++-- qml/MainPage.qml | 9 + source/serverconn.cpp | 103 +++++--- 5 files changed, 404 insertions(+), 318 deletions(-) diff --git a/fannyapp.pro.user b/fannyapp.pro.user index 4f5b87a..7c47319 100644 --- a/fannyapp.pro.user +++ b/fannyapp.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -58,6 +58,271 @@ ProjectExplorer.Project.Target.0 + + Desktop Qt 5.10.1 GCC 64bit + Desktop Qt 5.10.1 GCC 64bit + qt.qt5.5101.gcc_64_kit + 0 + 0 + 0 + + /home/dorian/Documents/builds/Qt/fanny-app + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + fannyapp + fannyapp2 + Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/Documents/gitlab/fanny-app/fannyapp.pro + true + + fannyapp.pro + false + + /home/dorian/Documents/builds/Qt/fanny-app + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 Android for armeabi-v7a (GCC 4.9, Qt 5.10.1 for Android armv7) Android for armeabi-v7a (GCC 4.9, Qt 5.10.1 for Android armv7) @@ -375,271 +640,6 @@ 1 - - ProjectExplorer.Project.Target.1 - - Desktop Qt 5.10.1 GCC 64bit - Desktop Qt 5.10.1 GCC 64bit - qt.qt5.5101.gcc_64_kit - 0 - 0 - 0 - - /home/dorian/Documents/builds/Qt/fanny-app - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - /home/dorian/Documents/Fanny App/build-fannyapp-Desktop_Qt_5_10_1_GCC_64bit-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - true - - false - true - false - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - -w - -r - - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy Configuration - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - fannyapp - fannyapp2 - Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/Documents/gitlab/fanny-app/fannyapp.pro - true - - fannyapp.pro - false - - /home/dorian/Documents/builds/Qt/fanny-app - 3768 - false - true - false - false - true - - 1 - - ProjectExplorer.Project.TargetCount 2 diff --git a/headers/serverconn.h b/headers/serverconn.h index e524d7f..69cdc6d 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -17,11 +17,6 @@ typedef struct strReturnData{ QString text; }ReturnData_t; -typedef struct Weekplan{ - QString Cookteam; - QString date; -}ReturnData_t; - class ServerConn : public QObject { Q_OBJECT @@ -41,6 +36,7 @@ public: Q_INVOKABLE int checkConn(); Q_INVOKABLE float getProgress(); Q_INVOKABLE QString getFoodPlan(); + Q_INVOKABLE QVariantMap getFoodPlanData(int index); ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData); signals: @@ -48,6 +44,20 @@ signals: public slots: void updateProgress(qint64 read, qint64 total); +private: + +struct Day +{ + QString Cookteam; + QString Date; + QString Main; + QString Main_veg; + QString Salad; + QString Dessert; +}; + +QList> m_weekplan; + }; #endif // SERVERCONN_H diff --git a/qml/FoodPlanForm.qml b/qml/FoodPlanForm.qml index c565386..a9f3d07 100644 --- a/qml/FoodPlanForm.qml +++ b/qml/FoodPlanForm.qml @@ -5,24 +5,50 @@ Page { anchors.fill: parent title: qsTr("Speiseplanplan") + property bool loaded: false - Label { - id: laWelcome - text: "Hier kannst du dir den Vertretungsplan des Fannys anschauen" - font.pixelSize: 20 - wrapMode: Label.Wrap - width: window.width / 1.2 - - anchors { - top: parent.top + Timer { + id: firstLoadTimer + interval: 1; + running: true + repeat: false + onTriggered: { + _cppServerConn.getFoodPlan() + loaded = true } } - Button { - id: butt - text: "load" - onClicked: { - var ret = _cppServerConn.getFoodPlan(); - laWelcome.text = ret + + ScrollView { + anchors.fill: parent + + ListView { + enabled: loaded + width: parent.width + model: 8 + delegate: ItemDelegate { + //text: getText(index, "cookteam") + width: parent.width + Label { + anchors.left: parent.left + anchors.top: parent.top + id: cookteam + text: _cppServerConn.getFoodPlanData(index).cookteam + } + Label { + anchors.left: parent.left + anchors.bottom: parent.bottom + id: date + text: _cppServerConn.getFoodPlanData(index).date + } + } } + + } + function getText(indexvar, type){ + if(!loaded){ + _cppServerConn.getFoodPlan() + loaded = true + } + //console.log(_cppServerConn.getFoodPlanData(indexvar)) } } diff --git a/qml/MainPage.qml b/qml/MainPage.qml index 3a5b7cc..8f3e874 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -26,6 +26,15 @@ Page { text: stackView.currentItem.title anchors.centerIn: parent } + Button { + id: butt + text: "load" + anchors.right: parent.right + visible: stackView.currentItem.title === "Speiseplanplan" + onClicked: { + var ret = _cppServerConn.getFoodPlan(); + } + } } Drawer { diff --git a/source/serverconn.cpp b/source/serverconn.cpp index dc4f269..41ff037 100644 --- a/source/serverconn.cpp +++ b/source/serverconn.cpp @@ -207,29 +207,48 @@ QString ServerConn::getFoodPlan() //get the status code QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); - ret.text = QString::fromUtf8(reply->readAll()); - ret.text.replace("\n",""); + if(status_code != 200){ + return(status_code.toString()); + } + + //initialize the weekplan to store information to it + m_weekplan.empty(); //empty the weekplan + //m_weekplan is a list, that contains a list for each day, which contains: cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. + + ret.text = QString::fromUtf8(reply->readAll()); //read the whole website + ret.text.replace("\n",""); //remove unnecessary stuff ret.text.replace("\r",""); ret.text.replace("\t",""); - QStringList stringlist_0 = ret.text.split( "" ); + QStringList stringlist_0 = ret.text.split( "
" ); //split the + + //prepare the table of the first week QString table1 = stringlist_0[1]; - QStringList stringlist_1 = table1.split( "
" ); + QStringList stringlist_1 = table1.split( "" ); //remove everything after "" table1 = stringlist_1[0]; + table1.remove(0,71); //remove "" at the beginning + table1 = table1.left(table1.length() - 13); //remove "" at the end + QStringList table1list = table1.split(""); //split at the days to get a list of all days + table1list.takeFirst(); //remove the first item, as it is empty + + //prepare the table of the second week + QString table2 = stringlist_0[2]; + QStringList stringlist_2 = table2.split( "" ); //remove everything after "" + table2 = stringlist_2[0]; + table2.remove(0,39); //remove "" at the beginning + table2.remove(table2.length() - 13, table2.length()); //remove "" at the end + QStringList table2list = table2.split(""); //split at the days to get a list of all days + table2list.takeFirst(); //remove the first item, as it is empty - table1.remove(0,71); - table1 = table1.left(table1.length() - 13); - //qDebug() << table1; - - QStringList table1list = table1.split(""); - - qDebug() << table1list; + QStringList weeklist = table1list + table2list; //put both weeks into one big list + qDebug() << weeklist; + //qDebug() << table1list; qDebug() << " "; - for (int i = 1; i <=4; i ++){ - QString temp = table1list[i]; //store item temporarly to edit it - table1list[i] = temp.left(temp.length()-5); //remove "" at the and of the Item - temp = table1list[i]; + for (int i = 0; i <=7; i ++){ + QString temp = weeklist[i]; //store item temporarly to edit it + weeklist[i] = temp.left(temp.length()-5); //remove "" at the and of the Item + temp = weeklist[i]; //table list[i] looks now like: //Red Hot Chili Peppers //
@@ -245,31 +264,53 @@ QString ServerConn::getFoodPlan() for (int i = 0; i <=2; i ++){ temp += templist[i]; //convert the list to a big string } + temp.replace("
",""); templist = temp.split(""); - QStringList Weekplan[0][i]; - Weekplan[0][i][0] = templist[0]; //store the cookteam in the weeklist - Weekplan[0][i][1] = templist[1]; //store the date in the weeklist + m_weekplan.append({templist[0], templist[1]}); //store cookteam and date + temp = templist[2]; //store information in temp (looks like: "
Gulasch mit Kartoffeln
Pellkartoffeln mit Quark
Gemischter Salat
Eaton Mess ( Erdbeer-Nachtisch )") + templist = temp.split("
"); //seperate the information + templist.takeFirst(); //remove first item + + m_weekplan[i].append(templist); } - QString table2 = stringlist_0[2]; - QStringList stringlist_2 = table2.split( "" ); - table2 = stringlist_2[0]; - -// QString fulltable = "" + stringlist_1[0] + stringlist_2[0] + "
"; -// fulltable.replace("\n",""); -// fulltable.replace("\r",""); -// fulltable.replace("\t",""); -// qDebug() << fulltable; -// return(fulltable); - - - //qDebug() << ret.text; + qDebug() << m_weekplan; return(""); } +QVariantMap ServerConn::getFoodPlanData(int index) +{ + //cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert. + QString cookteam; + QString date; + QString main_dish; + QString main_dish_veg; + QString garnish; + QString Dessert; + + QStringList ret; //list to return + qDebug() << index; + for(int i=0;i<=5;i++){ + qDebug() << i << m_weekplan.size(); + if(m_weekplan.size() > index){ + if(m_weekplan.at(index).size() > i){ + ret.append(m_weekplan[index][i]); + } + else { + ret.append(NULL); + } + } + else { + ret.append(NULL); + } + } + return { {"cookteam", ret[0]}, {"date", ret[1]}, {"main", ret[2]}, {"main_veg", ret[3]}, {"garnish", ret[4]}, {"dessert", ret[5]} }; + +} + ReturnData_t ServerConn::senddata(QUrl serviceUrl, QUrlQuery pdata) {