Finished up foodplan Display:

- now using QAbstractItem model
- added error handling so the app doesn't crash anymore when the data is invalid
This commit is contained in:
Dorian Zedler 2018-12-23 21:07:10 +01:00
parent 99fd686c65
commit c6e1e12cfe
19 changed files with 719 additions and 980 deletions

View file

@ -22,12 +22,12 @@ SOURCES += \
sources/serverconn.cpp \
sources/main.cpp \
sources/appsettings.cpp \
sources/eventform.cpp
sources/foodplanmodel.cpp
HEADERS += \
headers/serverconn.h \
headers/appsettings.h \
headers/eventform.h
headers/foodplanmodel.h
RESOURCES += \
qml/qml.qrc \

View file

@ -1,17 +0,0 @@
#ifndef EVENTFORM_H
#define EVENTFORM_H
#include <QObject>
class EventForm : public QObject
{
Q_OBJECT
public:
explicit EventForm(QObject *parent = nullptr);
signals:
public slots:
};
#endif // EVENTFORM_H

45
headers/foodplanmodel.h Normal file
View file

@ -0,0 +1,45 @@
#ifndef FOODPLANMODEL_H
#define FOODPLANMODEL_H
#include <QAbstractListModel>
#include <QtDebug>
#include "serverconn.h"
class FoodPlanModel : public QAbstractListModel
{
Q_OBJECT
public:
explicit FoodPlanModel(QObject *parent = nullptr);
~FoodPlanModel();
enum DishRole {
CookteamRole = Qt::DisplayRole,
DateRole,
MainDishRole,
MainDishVegRole,
GarnishRole,
DessertRole
};
Q_ENUM(DishRole)
int rowCount(const QModelIndex & = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE QVariantMap get(int row) const;
private:
struct Dish {
QString cookteam;
QString date;
QString mainDish;
QString mainDishVeg;
QString garnish;
QString dessert;
};
QList<Dish> m_foodPlan;
public slots:
};
#endif // FOODPLANMODEL_H

View file

@ -48,6 +48,8 @@ public:
Q_INVOKABLE int getEventCount();
ReturnData_t senddata(QUrl serviceUrl, QUrlQuery postData);
QList<QList<QString>> m_weekplan;
signals:
public slots:
@ -55,19 +57,9 @@ public slots:
private:
struct Day
{
QString Cookteam;
QString Date;
QString Main;
QString Main_veg;
QString Salad;
QString Dessert;
};
QList<QList<QString>> m_weekplan;
QList<QStringList> m_eventlist;
};
extern ServerConn * pGlobalServConn;
#endif // SERVERCONN_H

View file

@ -4,7 +4,6 @@ import QtQuick.Controls 2.4
Item {
id: control
ScrollView {
id:scroll
anchors.fill: parent
@ -94,30 +93,5 @@ Item {
}
}
Rectangle {
id: errorRect
anchors {
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
margins: parent.width * 0.15
}
radius: height * 0.5
height: width
color: "transparent"
border.width: 5
border.color: "red"
visible: _cppServerConn.getEventCount() === 0
Label {
anchors.centerIn: parent
text: "keine Daten..."
}
}
}

View file

@ -1,211 +1,154 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import QtQuick.Layouts 1.3
import Backend 1.0
Item {
id: control
ScrollView {
id:scroll
ListView {
id: foodList
anchors.fill: parent
visible: _cppServerConn.getFoodPlanData(0).cookteam !== ""
anchors.margins: 10
ListView {
id: listView
//width: 514
model: 8
spacing: 0
property var today: new Date
anchors {
right: parent.right
left: parent.left
top: parent.top
bottom: parent.bottom
leftMargin: 5
rightMargin: 5
topMargin: 3
}
delegate: Button {
width: listView.width
id: delegate
height: visible ? cookteam.height + date.height + main_dish.height + main_dish_veg.height + garnish.height + dessert.height + spacer.height + cust_spacing*9 + 5:0
visible: listView.isDayVisible(index)
property int cust_spacing: 5
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 10
font.bold: true
id: cookteam
text: _cppServerConn.getFoodPlanData(index).cookteam
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: cookteam.bottom
font.bold: true
id: date
text: listView.getDateString(index)
width: parent.width - 10
wrapMode: Label.Wrap
}
Rectangle {
anchors.top: date.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
anchors.right: parent.right
anchors.rightMargin: 10
height: 2
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: date.bottom
anchors.topMargin: cust_spacing * 2
width: parent.width - 10
wrapMode: Label.Wrap
id: main_dish
text: _cppServerConn.getFoodPlanData(index).main_dish
height: text!=""? undefined:0
}
Rectangle {
anchors.top: main_dish.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: main_dish_veg.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: main_dish.bottom
anchors.topMargin: cust_spacing * 2
id: main_dish_veg
text: _cppServerConn.getFoodPlanData(index).main_dish_veg
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Rectangle {
anchors.top: main_dish_veg.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: garnish.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: main_dish_veg.bottom
anchors.topMargin: cust_spacing * 2
id: garnish
text: _cppServerConn.getFoodPlanData(index).garnish
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Rectangle {
anchors.top: garnish.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: dessert.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: garnish.bottom
anchors.topMargin: cust_spacing * 2
id: dessert
text: _cppServerConn.getFoodPlanData(index).dessert
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: dessert.bottom
anchors.topMargin: cust_spacing
id: spacer
text: ""
}
}
function getDateString(index){
var date = _cppServerConn.getFoodPlanData(index).date
console.log(date.getTime())
console.log(today.getTime())
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)*/){
return("Morgen")
}
else {
return(Qt.formatDateTime(_cppServerConn.getFoodPlanData(index).date, "dddd, d.M.yy"))
}
}
function isDayVisible(index){
var date = _cppServerConn.getFoodPlanData(index).date
// console.warn(date.getTime())
// console.warn(today.getTime())
// console.log("")
return( date.getTime() > today.getTime() || date.getDate() === today.getDate()/*(date.getDate() >= today.getDate() && date.getMonth() >= today.getMonth()) || (date.getDate() < today.getDate() && date.getMonth() >= today.getMonth())*/)
}
}
}
Rectangle {
id: errorRect
anchors {
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
margins: parent.width * 0.15
model: FoodPlanModel {
id: foodPlanModel
}
radius: height * 0.5
height: width
delegate: Button {
color: "transparent"
border.width: 5
border.color: "red"
width: foodList.width
id: delegate
height: visible ? cookteamLa.height + dateLa.height + mainDishLa.height + mainDishVegLa.height + garnishLa.height + dessertLa.height + spacer.height + cust_spacing*9 + 5:0
visible: true//listView.isDayVisible(index)
visible: _cppServerConn.getFoodPlanData(0).cookteam === ""
property int cust_spacing: 5
Label {
anchors.centerIn: parent
text: "keine Daten..."
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 10
font.bold: true
id: cookteamLa
text: cookteam
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: cookteamLa.bottom
font.bold: true
id: dateLa
text: date
width: parent.width - 10
wrapMode: Label.Wrap
}
Rectangle {
anchors.top: dateLa.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
anchors.right: parent.right
anchors.rightMargin: 10
height: 2
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: dateLa.bottom
anchors.topMargin: cust_spacing * 2
width: parent.width - 10
wrapMode: Label.Wrap
id: mainDishLa
text: mainDish
height: text!=""? undefined:0
}
Rectangle {
anchors.top: mainDishLa.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: mainDishVegLa.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: mainDishLa.bottom
anchors.topMargin: cust_spacing * 2
id: mainDishVegLa
text: mainDishVeg
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Rectangle {
anchors.top: mainDishVegLa.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: garnishLa.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: mainDishVegLa.bottom
anchors.topMargin: cust_spacing * 2
id: garnishLa
text: garnish
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Rectangle {
anchors.top: garnishLa.bottom
anchors.topMargin: cust_spacing
anchors.left: parent.left
anchors.leftMargin: 10
width: parent.width / 10
height: dessertLa.text!=""? 1:0
color: "grey"
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: garnishLa.bottom
anchors.topMargin: cust_spacing * 2
id: dessertLa
text: dessert
width: parent.width - 10
wrapMode: Label.Wrap
height: text!=""? undefined:0
}
Label {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: dessertLa.bottom
anchors.topMargin: cust_spacing
id: spacer
text: ""
}
}
}
}

View file

@ -0,0 +1,71 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
Item {
id: infoArea
property int alertLevel: app.getErrorInfo(infoArea.errorCode)[0]
property int errorCode: -1
height: childrenRect.height
Rectangle {
// 0 - ok
// 1 - info
// 2 - error
radius: height * 0.5
width: parent.width
height: width
color: "transparent"
border.width: 5
border.color: infoArea.alertLevel > 0 ? infoArea.alertLevel > 1 ? "red":"grey" : "green"
opacity: infoArea.errorCode !== 200 && infoArea.errorCode !== (-1) ? 1:0
Behavior on opacity {
NumberAnimation {
duration: 500
}
}
Label {
anchors.centerIn: parent
font.pixelSize: parent.height * 0.8
text: infoArea.alertLevel > 1 ? "!":"i"
color: infoArea.alertLevel > 0 ? infoArea.alertLevel > 1 ? "red":"grey" : "green"
}
Label {
id: errorShortDescription
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.bottom
margins: parent.height * 0.1
}
font.pixelSize: errorLongDescription.font.pixelSize * 2
text: app.getErrorInfo(infoArea.errorCode)[1]
}
Label {
id: errorLongDescription
anchors {
horizontalCenter: parent.horizontalCenter
top: errorShortDescription.bottom
margins: parent.height * 0.1
}
width: parent.width
wrapMode: Label.Wrap
horizontalAlignment: Label.AlignHCenter
text: app.getErrorInfo(infoArea.errorCode)[2]
}
}
}

View file

@ -1,6 +1,7 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import "../Components"
Page {
id: root
@ -9,6 +10,7 @@ Page {
title: qsTr("Vertretungsplan")
property string icon: "qrc:/graphics/FannyLogo_small.png"
property string link: "http://www.fanny-leicht.de/j34"
property int status: -1
signal opened()
@ -56,8 +58,22 @@ Page {
running: true
repeat: false
onTriggered: {
_cppServerConn.getEvents(day);
status = _cppServerConn.getEvents(day);
pageLoader.source = "../Components/EventDisplay.qml"
}
}
InfoArea {
id: infoArea
anchors {
left: parent.left
right: parent.right
top: parent.top
margins: app.landscape() ? parent.width * 0.4:parent.width * 0.3
topMargin: parent.height/2 - height * 0.8
}
errorCode: status
}
}

View file

@ -1,6 +1,7 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import QtGraphicalEffects 1.0
import "../Components"
Page {
id:root
@ -9,6 +10,7 @@ Page {
title: qsTr("Speiseplan")
property string icon: "qrc:/graphics/images/TreffpunktFannyLogo.png"
property string link: "http://www.treffpunkt-fanny.de"
property int status: -1
signal opened()
@ -57,10 +59,22 @@ Page {
running: true
repeat: false
onTriggered: {
_cppServerConn.getFoodPlan()
root.status = _cppServerConn.getFoodPlan()
pageLoader.source = "../Components/FoodPlanDisplay.qml"
}
}
InfoArea {
id: infoArea
anchors {
left: parent.left
right: parent.right
top: parent.top
margins: app.landscape() ? parent.width * 0.4:parent.width * 0.3
topMargin: parent.height/2 - height * 0.8
}
errorCode: status
}
}

View file

@ -1,210 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
import "../Components"
Page {
//anchors.fill: parent
title: qsTr("Vertretungsplan")
property string icon: "qrc:/graphics/images/FannyLogo_small.png"
property string link: "http://www.fanny-leicht.de/j34"
// Image{
// source: "qrc:/graphics/chat_background.jpg";
// height: parent.height
// width: parent.width
// fillMode: Image.Tile
// horizontalAlignment: Image.AlignLeft
// verticalAlignment: Image.AlignTop
// }
// LinearGradient {
// anchors.fill: parent
// start: Qt.point(0, 0)
// end: Qt.point(0, parent.height)
// gradient: Gradient {
// GradientStop { position: 0.0; color: "#4db2b3" }
// GradientStop { position: 1.0; color: "#8f4dae" }
// }
// }
Label {
id: laWelcome
text: "Hier kannst du dir den Vertretungsplan des Fannys anschauen"
font.pixelSize: 20
wrapMode: Label.Wrap
width: window.width / 1.2
color: app.text_color
anchors {
top: parent.top
topMargin: window.height / 8 - laWelcome.height / 2
horizontalCenter: parent.horizontalCenter
}
}
Button {
id:buttToday
enabled: window.is_error === false
anchors {
left: parent.left
leftMargin: (window.width / 4) - (buttToday.width / 2)
verticalCenter: parent.verticalCenter
}
onClicked: {
verificationDialog.day = "sheute"
verificationDialog.open()
}
onPressed: sheuteImage.scale = 0.9
onReleased: sheuteImage.scale = 1.0
background: Image {
id: sheuteImage
source: "qrc:/graphics/sheute.png"
Behavior on scale {
PropertyAnimation {
duration: 100
}
}
}
}
Button {
id: buttTomorrow
enabled: window.is_error === false
anchors {
right: parent.right
rightMargin: (window.width / 4) - (buttTomorrow.width / 2)
verticalCenter: parent.verticalCenter
}
onClicked: {
verificationDialog.day = "smorgen"
verificationDialog.open()
}
onPressed: smorgenImage.scale = 0.9
onReleased: smorgenImage.scale = 1.0
background: Image {
id: smorgenImage
source: "qrc:/graphics/smorgen.png"
Behavior on scale {
PropertyAnimation {
duration: 100
}
}
}
}
Rectangle {
id: buttonsDisabled
anchors.left: buttToday.left
anchors.right: buttTomorrow.right
anchors.top: buttToday.top
anchors.bottom: buttToday.bottom
color: "white"
opacity: 0.7
visible: app.is_error
}
Dialog {
property string day
id: verificationDialog
modal: true
focus: true
title: "Bedingung"
x: (window.width - width) / 2
y: window.height / 6
width: Math.min(window.width, window.height) / 3 * 2
contentHeight: aboutColumn.height
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
_cppServerConn.updateProgress(0,100)
busyDialog.open()
text.visible = false
var ret = _cppServerConn.getDay(day)
progressCircle.arcEnd = 36000
progress.text = "100%"
busyDialog.close()
text.visible = true
if(ret.startsWith("OK")){
var path = ret.replace("OK_", "");
Qt.openUrlExternally(path);
return
}
else if(ret === "Ungültige Benutzerdaten."){
root.StackView.view.pop()
}
else {
error.text = ret
window.is_error = true
window.error = ret
error.visible = true
}
}
Column {
id: aboutColumn
spacing: 20
Label {
id: text
visible: true
width: verificationDialog.availableWidth
wrapMode: Label.Wrap
text: "Vertretungsplan, vertraulich, nur zum persönlichen Gebrauch, keine Speicherung!"
}
}
}
Dialog {
id: busyDialog
modal: true
closePolicy: "NoAutoClose"
focus: true
//title: "Please wait..."
x: (window.width - width) / 2
y: window.height / 6
//width: Math.min(window.width, window.height) / 3 * 2
height: contentHeight * 1.5
width: contentWidth * 1.5
contentHeight: progressCircle.height
contentWidth: progressCircle.width
ProgressCircle {
id: progressCircle
size: 50
lineWidth: 5
anchors.centerIn: parent
colorCircle: "#FF3333"
colorBackground: "#E6E6E6"
showBackground: true
arcBegin: 0
arcEnd: 0
Label {
id: progress
anchors.centerIn: parent
text: "0%"
}
Timer {
id: refreshTimer
interval: 1;
running: busyDialog.visible
repeat: true
onTriggered: {
var ret = _cppServerConn.getProgress()
progressCircle.arcEnd = 360 * ret * 1.2
progress.text = Math.round( ret * 100 ) + "%"
}
}
}
}
}

View file

@ -1,46 +0,0 @@
import QtQuick 2.2
import QtWebView 1.1
import QtQuick.Controls 2.2
import QtQuick.Controls.Styles 1.2
Page {
id:root
objectName: "WebsitePage";
title: qsTr("Fanny Webseite")
//property string icon: "qrc:/graphics/FannyLogo_small.png"
property string link: "http://www.fanny-leicht.de/j34"
ProgressBar {
id: progress
width: parent.width
anchors {
top: parent.top
}
//z: Qt.platform.os === "android" ? -1 : 1
visible: webView.loadProgress < 100
value: webView.loadProgress === 100 ? 0 : webView.loadProgress / 100
}
WebView {
id: webView
Keys.onBackPressed: webView.goBack()
z: 0
anchors {
top: webView.loadProgress < 100 ? progress.bottom:parent.top
bottom: parent.bottom
left: parent.left
right: parent.right
}
url: link
onLoadingChanged: {
console.log(url)
if (loadRequest.errorString)
console.error(loadRequest.errorString);
}
}
}

View file

@ -1,8 +1,7 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls 2.4
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import "../Components"
import "../Forms"
@ -12,18 +11,103 @@ Page {
Shortcut {
sequences: ["Esc", "Back"]
enabled: stackView.depth > 1
enabled: formStack.depth > 1
onActivated: {
stackView.pop()
formStack.pop()
}
}
header: AppToolBar {
StackView {
id: formStack
property var currPage
property string eventDay: ""
anchors {
top: toolBar.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}
onCurrPageChanged: {
mainStack.replace(currPage)
}
onCurrentItemChanged: {
formStack.currentItem.opened()
}
initialItem: homeForm
Component {
id: homeForm
HomeForm {}
}
Component {
id: foodPlanForm
FoodPlanForm {}
}
Component {
id: eventForm
EventForm {
day: formStack.eventDay
}
}
popEnter: Transition {
XAnimator {
from: (formStack.mirrored ? -1 : 1) * -formStack.width
to: 0
duration: 500
easing.type: Easing.OutCubic
}
}
popExit: Transition {
XAnimator {
from: 0
to: (formStack.mirrored ? -1 : 1) * formStack.width
duration: 500
easing.type: Easing.OutCubic
}
}
pushEnter: Transition {
XAnimator {
from: (formStack.mirrored ? -1 : 1) * formStack.width
to: 0
duration: 500
easing.type: Easing.OutCubic
}
}
pushExit: Transition {
XAnimator {
from: 0
to: (formStack.mirrored ? -1 : 1) * -formStack.width
duration: 500
easing.type: Easing.OutCubic
}
}
}
AppToolBar {
id: toolBar
anchors {
top: parent.top
left: parent.left
right: parent.right
topMargin: -60
}
height: 50
Button {
id:toolButton
enabled: window.is_error === false
enabled: true
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
@ -33,8 +117,8 @@ Page {
width: height
onClicked: {
if (stackView.depth > 1) {
stackView.pop()
if (formStack.depth > 1) {
formStack.pop()
} else {
drawer.open()
}
@ -44,7 +128,7 @@ Page {
onReleased: toolButton.scale = 1.0
background: Image {
source: stackView.depth > 1 ? "qrc:/graphics/icons/back.png" : "qrc:/graphics/icons/drawer.png"
source: formStack.depth > 1 ? "qrc:/graphics/icons/backDark.png" : "qrc:/graphics/icons/drawer.png"
height: parent.height
width: parent.width
Behavior on scale {
@ -56,205 +140,40 @@ Page {
}
Label {
text: stackView.currentItem.title
text: formStack.currentItem.title
anchors {
verticalCenter: parent.verticalCenter
left: toolButton.right
leftMargin: parent.width * 0.02
}
font.bold: true
color: "white"
color: "black"
}
Image {
id: logo
source: stackView.currentItem.icon
anchors.right: parent.right
anchors.rightMargin: parent.width * 0.02
anchors.top: parent.top
height: parent.height
fillMode: Image.PreserveAspectFit
mipmap: true
Behavior on scale {
PropertyAnimation {
duration: 100
}
}
MouseArea {
enabled: stackView.currentItem.link !== undefined && stackView.currentItem.objectName !== "WebsitePage"
anchors.fill: parent
onPressed: logo.scale = 0.9
onReleased: logo.scale = 1.0
onClicked: {
stackView.push("qrc:/WebsitePage.qml",{title: "Web", link: stackView.currentItem.link, icon: stackView.currentItem.icon})
}
Behavior on anchors.topMargin {
NumberAnimation {
duration: 500
easing.type: Easing.OutCubic
}
}
}
Drawer {
id: drawer
width: window.width * 0.66
height: window.height
AppToolBar {
id: header
showErrorBar: false
anchors {
top: parent.top
left: parent.left
right: parent.right
}
Label {
text: "Menü"
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 17
states: [
State {
name: "closed"
when: formStack.depth === 1
PropertyChanges {
target: toolBar
anchors.topMargin: -60
}
font.bold: true
}
}
Column {
anchors {
top: header.bottom
bottom: parent.bottom
left: parent.left
right: parent.right
}
ItemDelegate {
text: qsTr("Fanny Webseite")
width: parent.width
onClicked: {
stackView.push("qrc:/WebsitePage.qml",{title: "Fanny Webseite", link: "http://www.fanny-leicht.de/j34", icon: stackView.currentItem.icon})
drawer.close()
},
State {
name: "open"
when: formStack.depth > 1
PropertyChanges {
target: toolBar
anchors.topMargin: 0
}
}
ItemDelegate {
text: qsTr("Vertretungsplan")
width: parent.width
onClicked: {
busyDialog.open()
var ret = _cppServerConn.getEvents();
drawer.close()
busyDialog.close()
if(ret === 200 || _cppServerConn.getEventData(0).grade !== ""){
stackView.push("qrc:/Forms/EventForm.qml")
}
}
}
ItemDelegate {
text: qsTr("Speiseplan")
width: parent.width
onClicked: {
busyDialog.open()
var ret = _cppServerConn.getFoodPlan();
drawer.close()
busyDialog.close()
if(ret === 200 || _cppServerConn.getFoodPlanData(1).cookteam !== ""){
stackView.push("qrc:/FoodPlanForm.qml")
}
}
}
ItemDelegate {
Label {
text: "abmelden"
color: "red"
anchors {
verticalCenter: parent.verticalCenter
left: parent.left
leftMargin: 17
}
font.bold: true
}
width: parent.width
onClicked: {
confirmationDialog.open()
}
Dialog {
id: confirmationDialog
x: (window.width - width) / 2
y: (window.height - height) / 2
parent: ApplicationWindow.overlay
modal: true
standardButtons: Dialog.Cancel | Dialog.Ok
Column {
spacing: 20
anchors.fill: parent
Label {
text: "Möchtest du dich wirklich abmelden?"
}
}
onAccepted: {
_cppServerConn.logout()
drawer.close()
root.StackView.view.push("qrc:/LoginPage.qml")
}
}
}
}
}
StackView {
id: stackView
initialItem: "qrc:/Forms/HomeForm.qml"
anchors.fill: parent
}
Dialog {
id: busyDialog
modal: true
focus: true
//title: "Please wait..."
x: (window.width - width) / 2
y: window.height / 6
//width: Math.min(window.width, window.height) / 3 * 2
height: contentHeight * 1.5
width: contentWidth * 1.5
contentHeight: progressCircle.height
contentWidth: progressCircle.width
ProgressCircle {
id: progressCircle
size: 50
lineWidth: 5
anchors.centerIn: parent
colorCircle: "#FF3333"
colorBackground: "#E6E6E6"
showBackground: true
arcBegin: 0
arcEnd: 0
Label {
id: progress
anchors.centerIn: parent
text: "0%"
}
Timer {
id: refreshTimer
interval: 1;
running: busyDialog.visible
repeat: true
onTriggered: {
var ret = _cppServerConn.getProgress()
if(ret > 100 || ret < 0){
ret = 0
}
progress.text = Math.round( ret * 100 ) + "%"
progressCircle.arcEnd = 360 * ret
}
}
}
]
}
}

View file

@ -1,179 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.4
import QtGraphicalEffects 1.0
import "../Components"
import "../Forms"
Page {
id: root
objectName: "MainPage"
Shortcut {
sequences: ["Esc", "Back"]
enabled: formStack.depth > 1
onActivated: {
formStack.pop()
}
}
StackView {
id: formStack
property var currPage
property string eventDay: ""
anchors {
top: toolBar.bottom
left: parent.left
right: parent.right
bottom: parent.bottom
}
onCurrPageChanged: {
mainStack.replace(currPage)
}
onCurrentItemChanged: {
formStack.currentItem.opened()
}
initialItem: homeForm
Component {
id: homeForm
HomeForm {}
}
Component {
id: foodPlanForm
FoodPlanForm {}
}
Component {
id: eventForm
EventForm {
day: formStack.eventDay
}
}
popEnter: Transition {
XAnimator {
from: (formStack.mirrored ? -1 : 1) * -formStack.width
to: 0
duration: 500
easing.type: Easing.OutCubic
}
}
popExit: Transition {
XAnimator {
from: 0
to: (formStack.mirrored ? -1 : 1) * formStack.width
duration: 500
easing.type: Easing.OutCubic
}
}
pushEnter: Transition {
XAnimator {
from: (formStack.mirrored ? -1 : 1) * formStack.width
to: 0
duration: 500
easing.type: Easing.OutCubic
}
}
pushExit: Transition {
XAnimator {
from: 0
to: (formStack.mirrored ? -1 : 1) * -formStack.width
duration: 500
easing.type: Easing.OutCubic
}
}
}
AppToolBar {
id: toolBar
anchors {
top: parent.top
left: parent.left
right: parent.right
topMargin: -60
}
height: 50
Button {
id:toolButton
enabled: true
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: parent.width *0.02
}
height: parent.height - parent.height * 0.5
width: height
onClicked: {
if (formStack.depth > 1) {
formStack.pop()
} else {
drawer.open()
}
}
onPressed: toolButton.scale = 0.9
onReleased: toolButton.scale = 1.0
background: Image {
source: formStack.depth > 1 ? "qrc:/graphics/icons/backDark.png" : "qrc:/graphics/icons/drawer.png"
height: parent.height
width: parent.width
Behavior on scale {
PropertyAnimation {
duration: 100
}
}
}
}
Label {
text: formStack.currentItem.title
anchors {
verticalCenter: parent.verticalCenter
left: toolButton.right
leftMargin: parent.width * 0.02
}
font.bold: true
color: "black"
}
Behavior on anchors.topMargin {
NumberAnimation {
duration: 500
easing.type: Easing.OutCubic
}
}
states: [
State {
name: "closed"
when: formStack.depth === 1
PropertyChanges {
target: toolBar
anchors.topMargin: -60
}
},
State {
name: "open"
when: formStack.depth > 1
PropertyChanges {
target: toolBar
anchors.topMargin: 0
}
}
]
}
}

View file

@ -40,7 +40,7 @@ ApplicationWindow {
name: "loggedIn"
PropertyChanges {
target: mainStack
currPage: startPage
currPage: mainPage
}
}
]
@ -131,8 +131,8 @@ ApplicationWindow {
}
Component {
id: startPage
StartPage {}
id: mainPage
MainPage {}
}
}
@ -175,6 +175,42 @@ ApplicationWindow {
}
}
function getErrorInfo(errorCode) {
var infoLevel
var errorString
var errorDescription
switch(errorCode) {
case 0:
infoLevel = 2
errorString = "Keine Verbindung zum Server"
errorDescription = "Bitte überprüfe deine Internetverbindung und versuche es erneut."
break
case 500:
infoLevel = 2
errorString = "Interner Server Fehler"
errorDescription = "Scheinbar kann der Server die Anfrage im Moment nicht verarbeiten, bitte versuche es später erneut."
break
case 900:
infoLevel = 2
errorString = "Interner Verarbeitungsfehler"
errorDescription = "Die Daten, die vom Server übertragen wurden, konnten nicht richtig verarbeitet werden, bitte versuche es später erneut."
break
case 901:
infoLevel = 1
errorString = "Keine Daten"
errorDescription = "Es liegen keine aktuellen Daten vor."
break
default:
infoLevel = 2
errorString = "Unerwarteter Fehler ("+errorCode+")"
errorDescription = "Unbekannter Fehler bei der Verbindung mit dem Server."
}
return([infoLevel, errorString, errorDescription])
}
function landscape(){
return(app.width > app.height)
}

View file

@ -1,19 +1,17 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>Forms/HomeForm[old].qml</file>
<file>Pages/LoginPage.qml</file>
<file>Pages/MainPage.qml</file>
<file>Components/AppToolBar.qml</file>
<file>Forms/WebsiteForm.qml</file>
<file>Forms/FoodPlanForm.qml</file>
<file>Components/ProgressCircle.qml</file>
<file>Forms/EventForm.qml</file>
<file>Pages/StartPage.qml</file>
<file>Pages/MainPage.qml</file>
<file>Components/FancyButton.qml</file>
<file>Forms/HomeForm.qml</file>
<file>Components/FoodPlanDisplay.qml</file>
<file>Forms/LoadingForm.qml</file>
<file>Components/EventDisplay.qml</file>
<file>Components/InfoArea.qml</file>
</qresource>
</RCC>

View file

@ -1,6 +0,0 @@
#include "headers/eventform.h"
EventForm::EventForm(QObject *parent) : QObject(parent)
{
}

59
sources/foodplanmodel.cpp Normal file
View file

@ -0,0 +1,59 @@
#include "headers/foodplanmodel.h"
FoodPlanModel::FoodPlanModel(QObject *parent) : QAbstractListModel(parent)
{
//m_foodPlan.append({ "Angel Hogan", "Chapel St. 368 ", "Clearwater" , "0311 1823993", "uhj", "iuij" });
qDebug() << "foodplan Konstructor";
m_foodPlan.clear();
foreach(QList<QString>day, 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
{
return m_foodPlan.count();
}
QVariant FoodPlanModel::data(const QModelIndex &index, int role) const
{
if (index.row() < rowCount())
switch (role) {
case CookteamRole: return m_foodPlan.at(index.row()).cookteam;
case DateRole: return m_foodPlan.at(index.row()).date;
case MainDishRole: return m_foodPlan.at(index.row()).mainDish;
case MainDishVegRole: return m_foodPlan.at(index.row()).mainDishVeg;
case GarnishRole: return m_foodPlan.at(index.row()).garnish;
case DessertRole: return m_foodPlan.at(index.row()).dessert;
default: return QVariant();
}
return QVariant();
}
QHash<int, QByteArray> FoodPlanModel::roleNames() const
{
static const QHash<int, QByteArray> roles {
{ CookteamRole, "cookteam" },
{ DateRole, "date" },
{ MainDishRole, "mainDish" },
{ MainDishVegRole, "mainDishVeg" },
{ GarnishRole, "garnish" },
{ DessertRole, "dessert" }
};
return roles;
}
QVariantMap FoodPlanModel::get(int row) const
{
const Dish foodPlan = m_foodPlan.value(row);
return { {"cookteam", foodPlan.cookteam}, {"date", foodPlan.date}, {"mainDish", foodPlan.mainDish}, {"mainDishVeg", foodPlan.mainDishVeg}, {"garnish", foodPlan.garnish}, {"dessert", foodPlan.dessert} };
}
FoodPlanModel::~FoodPlanModel(){
}

View file

@ -13,24 +13,23 @@
#include <QScreen>
#include <QQmlApplicationEngine>
#include <QtQml/QQmlContext>
#include <QtWebView/QtWebView>
#include "headers/serverconn.h"
#include "headers/appsettings.h"
#include "headers/foodplanmodel.h"
int main(int argc, char *argv[])
{
ServerConn * pServerConn = new ServerConn;
AppSettings * pAppSettings = new AppSettings();
pGlobalAppSettings = pAppSettings;
ServerConn * pServerConn = new ServerConn();
//pGlobalServConn = pServerConn;
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
//! [0]
QGuiApplication app(argc, argv);
QtWebView::initialize();
//! [0]
qmlRegisterType<FoodPlanModel>("Backend", 1, 0, "FoodPlanModel");
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;

View file

@ -1,11 +1,13 @@
#include "headers/serverconn.h"
ServerConn * pGlobalServConn = nullptr;
ServerConn::ServerConn(QObject *parent) : QObject(parent)
{
qDebug("serverconn konstruktor");
this->networkManager = new QNetworkAccessManager();
this->refreshNetworkManager = new QNetworkAccessManager();
pGlobalServConn = this;
}
ServerConn::~ServerConn()
@ -285,14 +287,13 @@ int ServerConn::getFoodPlan()
{
this->progress = 0;
ReturnData_t ret; //this is a custom type to store the returned data
// Call the webservice
// Call the webservice
QNetworkRequest request(QUrl("http://www.treffpunkt-fanny.de/fuer-schueler-und-lehrer/speiseplan.html"));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
//set ssl configuration
//send a POST request with the given url and data to the server
// send a POST request with the given url and data to the server
QNetworkReply* reply;
QUrlQuery pdata;
@ -300,93 +301,224 @@ int ServerConn::getFoodPlan()
connect(reply, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(updateProgress(qint64, qint64)));
//wait until the request has finished
// wait until the request has finished
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
// quit the loop when the timer times out
loop.connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.connect(this->networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(quit()));
timer.start(2000);
loop.exec();
//get the status code
// get the status code
QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
this->progress = 1;
if(status_code != 200){
return(status_code.toInt());
}
//initialize the weekplan to store information to it
//m_weekplan.empty(); //empty the weekplan
// initialize the weekplan to store information to it
QList<QList<QString>> temp_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.
// 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
// read the whole website
ret.text = QString::fromUtf8(reply->readAll());
// remove unnecessary stuff
ret.text.replace("\n","");
ret.text.replace("\r","");
ret.text.replace("\t","");
ret.text.replace("style=\"width: 25%;\"", "width=\"25%\"");
QStringList stringlist_0 = ret.text.split( "<table class=\"speiseplan\">" ); //split the
// workaround for changing html syntax
ret.text.replace("width=\"25%\"", "style=\"width: 25%;\"");
//prepare the table of the first week
QString table1 = stringlist_0[1];
// split the string at the beginning of the tables
QStringList documentList = ret.text.split( "<table class=\"speiseplan\">" );
QStringList stringlist_1 = table1.split( "</table>" ); //remove everything after "</table>"
table1 = stringlist_1[0];
table1.remove(0,71); //remove "<tbody><tr style=\"border: 1px solid #999;\" align=\"center\" valign=\"top\">" at the beginning
table1 = table1.left(table1.length() - 13); //remove "</tr></tbody>" at the end
// enshure that the data is valid
if(documentList.length() < 2){
return(900);
}
QStringList table1list = table1.split("<td width=\"25%\">"); //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 first week ----------
QString table1 = documentList[1];
//prepare the table of the second week
QString table2 = stringlist_0[2];
// enshure that the data is valid
if(table1.split( "</table>" ).length() < 1){
return(900);
}
QStringList stringlist_2 = table2.split( "</table>" ); //remove everything after "</table>"
table2 = stringlist_2[0];
table2.remove(0,39); //remove "<tbody><tr align=\"center\" valign=\"top\">" at the beginning
table2.remove(table2.length() - 13, table2.length()); //remove "</tr></tbody>" at the end
// remove everything after "</table>"
table1 = table1.split( "</table>" )[0];
// remove "<tbody><tr style=\"border: 1px solid #999;\" align=\"center\" valign=\"top\">" at the beginning
table1.remove(0,71);
//remove "</tr></tbody>" at the end
table1 = table1.left(table1.length() - 13);
QStringList table2list = table2.split("<td width=\"25%\">"); //split at the days to get a list of all days
table2list.takeFirst(); //remove the first item, as it is empty
//split at the days to get a list of all days
QStringList table1list = table1.split("<td width=\"25%\">");
// enshure that the data is valid
if(table1list.length() < 5){
return(900);
}
QStringList weeklist = table1list + table2list; //put both weeks into one big list
//remove the first item, as it is empty
table1list.takeFirst();
//---------- prepare the table of the second week ----------
QString table2 = documentList[2];
// enshure that the data is valid
if(table2.split( "</table>" ).length() < 1){
return(900);
}
//remove everything after "</table>"
table2 = table2.split( "</table>" )[0];
//remove "<tbody><tr align=\"center\" valign=\"top\">" at the beginning
table2.remove(0,39);
//remove "</tr></tbody>" at the end
table2.remove(table2.length() - 13, table2.length());
//split at the days to get a list of all days
QStringList table2list = table2.split("<td width=\"25%\">");
// enshure that the data is valid
if(table2list.length() < 5){
return(900);
}
//remove the first item, as it is empty
table2list.takeFirst();
//---------- put both weeks into one big list ----------
QStringList weeklist = table1list + table2list;
//---------- go through all days and split the day-string into the different types of information ----------
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 "</td>" at the and of the Item
temp = weeklist[i];
//table list[i] looks now like:
//<strong>Red Hot Chili Peppers</strong>
//<br />
//<strong>26.06.2018</strong>
//<hr />Gulasch mit Kartoffeln
//<hr />Pellkartoffeln mit Quark
//<hr />Gemischter Salat
//<hr />Eaton Mess ( Erdbeer-Nachtisch )</td>
QStringList templist = temp.split("<strong>"); //split item at strong, to get the cookteam and the date
//qDebug() << templist << "\n";
temp = "";
for (int i = 0; i <=2; i ++){
temp += templist[i]; //convert the list to a big string
if(i > weeklist.length()){
// if the loop exceeds the length of the wweklist some kind of eror occured
return 900;
}
temp.replace("<br />","");
templist = temp.split("</strong>");
temp_weekplan.append({templist[0], templist[1]}); //store cookteam and date
temp = templist[2]; //store information in temp (looks like: "<hr />Gulasch mit Kartoffeln<hr />Pellkartoffeln mit Quark<hr />Gemischter Salat<hr />Eaton Mess ( Erdbeer-Nachtisch )")
templist = temp.split("<hr />"); //seperate the information
templist.takeFirst(); //remove first item
// store item temporarly to edit it
QString day = weeklist[i];
// remove "</td>" at the and of the Item
day = day.left(day.length()-5);
temp_weekplan[i].append(templist);
// table list[i] looks now like: | clould be:
// <strong>cookteam</strong> | <strong>Red Hot Chili Peppers</strong>
// <br /> | <br />
// <strong>date</strong> | <strong>26.06.2018</strong>
// <hr />mainDish | <hr />Gulasch mit Kartoffeln
// <hr />mainDishVeg | <hr />Pellkartoffeln mit Quark
// <hr />garnish | <hr />Gemischter Salat
// <hr />dessert</td> | <hr />Eaton Mess ( Erdbeer-Nachtisch )</td>
// split item at strong, to get the cookteam and the date
QStringList daylist = day.split("<strong>");
day = "";
// convert the list to a big string
for (int i = 0; i <= 2; i ++){
if(i <= daylist.length()){
day += daylist[i];
}
}
day.replace("<br />","");
daylist = day.split("</strong>");
// store cookteam and date in the temp_weekplan
//temp_weekplan.append({daylist[0], daylist[1]});
// store information in day
// (looks like: "<hr />MainDish<hr />MainDishVeg<hr />Garnish<hr />Dessert")
// (could be: "<hr />Gulasch mit Kartoffeln<hr />Pellkartoffeln mit Quark<hr />Gemischter Salat<hr />Eaton Mess ( Erdbeer-Nachtisch )")
day = daylist.takeLast();
// seperate the information
daylist.append(day.split("<hr />"));
// remove the item that is emplty from the list
daylist.removeAt(2);
//---------- check if the day is aleady over ----------
// get the datestring
QString dateString = daylist[1];
// convert it to a valid QDate
QDateTime date = QDateTime::fromString(dateString,"dd.MM.yyyy");
// get the current date and time
QDateTime currentDateTime = QDateTime::currentDateTimeUtc();
// check if the given day is still in the future or today (then it is valid)
if(date.toTime_t() > currentDateTime.toTime_t() || date.date() == currentDateTime.date()){
// add the rest of the information to the temp_weekplan
qDebug() << "day valid:" << daylist;
//---------- convert the date to a readable string ----------
QString readableDateString;
if(date.date() == currentDateTime.date()){
// the given day is today
readableDateString = "Heute";
}
else if (date.toTime_t() < ( currentDateTime.toTime_t() + ( 24 * 60 * 60 ))) {
// the given day is tomorrow
readableDateString = "Morgen";
}
else {
readableDateString = date.toString("dddd, d.M.yy");
}
qDebug() << readableDateString;
// insert the redable tring into the daylist
daylist[1] = readableDateString;
// append the day to the weeklist
temp_weekplan.append({daylist[0], daylist[1], daylist[2], daylist[3], daylist[4], daylist[5]});
}
/*
function getDateString(index){
var date = _cppServerConn.getFoodPlanData(index).date
console.log(date.getTime())
console.log(today.getTime())
if(date.getDate() === today.getDate()){
return("Heute")
}
else if(date.getTime() < (today.getTime() + (24 * 60 * 60 * 1000) )){
return("Morgen")
}
else {
return(Qt.formatDateTime(_cppServerConn.getFoodPlanData(index).date, "dddd, d.M.yy"))
}
}
function isDayVisible(index){
var date = _cppServerConn.getFoodPlanData(index).date
// console.warn(date.getTime())
// console.warn(today.getTime())
// console.log("")
return( date.getTime() > today.getTime() || date.getDate() === today.getDate())
}
}
}
*/
}
//qDebug() << temp_weekplan;
this->m_weekplan = temp_weekplan; //write changes to global foodplan
qDebug() << temp_weekplan;
if(this->m_weekplan.isEmpty()){
return(901);
}
return(200);
}
@ -395,30 +527,29 @@ QVariantMap ServerConn::getFoodPlanData(int index)
{
//cookteam, date, main dish, vagi main dish, garnish(Beilage) and Dessert.
QStringList ret; //list to return
//qDebug() << index;
for(int i=0;i<=5;i++){
// QStringList ret; //list to return
// //qDebug() << index;
// for(int i=0;i<=5;i++){
// if(m_weekplan.size() > index){
// //qDebug() << i << m_weekplan[index].size();
// if(m_weekplan[index].size() > i){
// ret.append(m_weekplan[index][i]);
// //qDebug() << i << m_weekplan[index][i];
// }
// else {
// ret.append(nullptr);
// }
// }
// else {
// ret.append(nullptr);
// }
// }
if(m_weekplan.size() > index){
//qDebug() << i << m_weekplan[index].size();
if(m_weekplan[index].size() > i){
ret.append(m_weekplan[index][i]);
//qDebug() << i << m_weekplan[index][i];
}
else {
ret.append(nullptr);
}
}
else {
ret.append(nullptr);
}
}
QString date_string_on_db = ret[1];
QDate Date = QDate::fromString(date_string_on_db,"dd.MM.yyyy");
//date_string_on_db
qDebug() << Date;
qDebug() << ret;
return { {"cookteam", ret[0]}, {"date", Date}, {"main_dish", ret[2]}, {"main_dish_veg", ret[3]}, {"garnish", ret[4]}, {"dessert", ret[5]} };
//qDebug() << Date;
//qDebug() << ret;
//return { {"cookteam", ret[0]}, {"date", Date}, {"main_dish", ret[2]}, {"main_dish_veg", ret[3]}, {"bgarnish", ret[4]}, {"dessert", ret[5]} };
}