From 5faa8c0617f5274b8f4d77b4f2f881bca65e8ed6 Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 21 Apr 2019 18:35:28 +0200 Subject: [PATCH] added year selector --- headers/serverconn.h | 2 +- resources/qml/Components/RankingView.qml | 26 +-- .../qml/Pages/CompetitionCalendarPage.qml | 120 ++++++++++++- resources/qml/main.qml | 165 ++++++++++-------- resources/shared/icons/calendar.png | Bin 0 -> 1132 bytes resources/shared/shared.qrc | 1 + sources/serverconn.cpp | 4 +- 7 files changed, 210 insertions(+), 108 deletions(-) create mode 100644 resources/shared/icons/calendar.png diff --git a/headers/serverconn.h b/headers/serverconn.h index c0ed1c2..56810c2 100644 --- a/headers/serverconn.h +++ b/headers/serverconn.h @@ -26,7 +26,7 @@ signals: public slots: void refreshFoodplan(); - QVariant getCalendar(QString nation); + QVariant getCalendar(QString nation, int year); QVariant getRanking(int competitionId, int categoryId, bool registrationData = false, const int routeNumber = -2); // functions for qml diff --git a/resources/qml/Components/RankingView.qml b/resources/qml/Components/RankingView.qml index eb3c0f2..c563592 100644 --- a/resources/qml/Components/RankingView.qml +++ b/resources/qml/Components/RankingView.qml @@ -134,31 +134,7 @@ DataListView { width: parent.width / ( boulderResRep.model ) height: parent.height -/* - Rectangle { - anchors { - left: parent.left - } - width: 1 - height: parent.height - - visible: index === 0 - - color: "grey" - } - - Rectangle { - anchors { - right: parent.right - } - - width: 1 - height: parent.height - - color: "grey" - } -*/ Canvas { id: boulderResCv @@ -166,7 +142,7 @@ DataListView { anchors.centerIn: parent - height: parent.height * 1.1 + height: parent.height > parent.width ? parent.width * 0.9:parent.height * 0.9 width: height onPaint: { diff --git a/resources/qml/Pages/CompetitionCalendarPage.qml b/resources/qml/Pages/CompetitionCalendarPage.qml index 29be6ec..6cca235 100644 --- a/resources/qml/Pages/CompetitionCalendarPage.qml +++ b/resources/qml/Pages/CompetitionCalendarPage.qml @@ -9,26 +9,87 @@ Page { title: "calendar" - property string nation: "" - property int status: -1 + property Component headerComponent: Item { + anchors.fill: parent - Component.onCompleted: { - loadData(root.nation) + Row { + anchors.fill: parent + + spacing: width * 0.05 + + Label { + anchors.verticalCenter: parent.verticalCenter + + width: parent.width - toolButton.width - parent.spacing + height: parent.height * 0.6 + + fontSizeMode: Text.Fit + font.pixelSize: height + minimumPixelSize: 0 + + text: root.year + + } + + Button { + id:toolButton + + anchors { + verticalCenter: parent.verticalCenter + } + + height: parent.height * 0.5 + width: height + + onClicked: { + yearSelectPu.open() + } + + onPressed: toolButton.scale = 0.9 + onReleased: toolButton.scale = 1.0 + + background: Image { + source: "qrc:/icons/calendar.png" + + height: parent.height + width: height + + fillMode: Image.PreserveAspectFit + Behavior on scale { + PropertyAnimation { + duration: 100 + } + } + } + } + + } } - function loadData(nation) { + property string nation: "" + property int year: new Date().getFullYear() + property int status: -1 + property var calendarData + + Component.onCompleted: { + loadData(root.nation, root.year) + } + + function loadData(nation, year) { root.status = 905 loadingDl.open() - var ret = serverConn.getCalendar(nation) + var ret = serverConn.getCalendar(nation, year) if(ret["status"] === 200){ root.status = 200 + root.calendarData = ret["data"] calendarList.listData = ret["data"]["competitions"] } else { - root.status = ret["status"] + root.status = parseInt(ret["status"]) calendarList.listData = {} + root.calendarData = {} } loadingDl.close() } @@ -47,7 +108,7 @@ Page { status: root.status onRefresh: { - root.loadData(root.nation) + root.loadData(root.nation, root.year) } delegate: ItemDelegate { @@ -179,4 +240,47 @@ Page { } + Dialog { + id: yearSelectPu + + property var yearList: root.calendarData["years"] + + x: root.width / 2 - width / 2 + y: root.height / 2 - height / 2 + + width: root.width * 0.8 + height: root.height * 0.6 + + modal: true + focus: true + + title: qsTr("select year") + + contentItem: ListView { + id: yearsLv + + width: parent.width + height: root.height * 0.6 + + model: yearSelectPu.yearList.length + + delegate: Button { + id: yearBt + + width: parent.width + + flat: true + + text: yearSelectPu.yearList[index] + + onClicked: { + yearSelectPu.close() + root.year = yearSelectPu.yearList[index] + root.loadData(root.nation, root.year) + } + } + } + + } + } diff --git a/resources/qml/main.qml b/resources/qml/main.qml index 3ed7586..d69995a 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -112,107 +112,128 @@ Window { 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 + Row { - onClicked: { - if(!mainStack.currentItem.locked){ - mainStack.pop() - } - } + anchors.fill: parent - onPressed: toolButton.scale = 0.9 - onReleased: toolButton.scale = 1.0 + spacing: width * 0.02 - background: Image { - source: "qrc:/icons/backDark.png" + Item { + id: spacer + width: 1 height: parent.height - width: parent.width - fillMode: Image.PreserveAspectFit - Behavior on scale { - PropertyAnimation { - duration: 100 + } + + Button { + id:toolButton + + anchors { + verticalCenter: parent.verticalCenter + } + + height: parent.height * 0.5 + width: height + + onClicked: { + if(!mainStack.currentItem.locked){ + mainStack.pop() + } + } + + onPressed: toolButton.scale = 0.9 + onReleased: toolButton.scale = 1.0 + + background: Image { + source: "qrc:/icons/backDark.png" + + height: parent.height + width: height + + fillMode: Image.PreserveAspectFit + Behavior on scale { + PropertyAnimation { + duration: 100 + } } } } - } - Label { - id: toolBarTitleLa + Column { + anchors.verticalCenter: parent.verticalCenter - anchors { - verticalCenter: parent.verticalCenter - verticalCenterOffset: -toolBarSubTitleLa.anchors.verticalCenterOffset - left: toolButton.right - leftMargin: parent.width * 0.02 - right: parent.right - } + height: childrenRect.height + width: parent.width * 0.7 - elide: "ElideRight" + Label { + id: toolBarTitleLa - font.bold: true + elide: "ElideRight" - color: "black" + font.bold: true - text: getText() + color: "black" - function getText(){ - var titleString = ""; + text: getText() - if(!mainStack.currentItem.titleIsPageTitle){ - for(var i=1; i 1){ - titleString += " > " + function getText(){ + var titleString = ""; + + if(!mainStack.currentItem.titleIsPageTitle){ + for(var i=1; i 1){ + titleString += " > " + } + + titleString += mainStack.get(i).title + } + } + else { + titleString = mainStack.currentItem.title } - titleString += mainStack.get(i).title + return(titleString) } } - else { - titleString = mainStack.currentItem.title + + Label { + id: toolBarSubTitleLa + + elide: "ElideRight" + + font.bold: false + + color: "black" + + text: getText() + + function getText(){ + var titleString = ""; + + if(mainStack.currentItem.subTitle !== undefined){ + titleString = mainStack.currentItem.subTitle + } + + return(titleString) + } } - return(titleString) - } - } - - Label { - id: toolBarSubTitleLa - - anchors { - verticalCenter: parent.verticalCenter - verticalCenterOffset: toolBarSubTitleLa.text !== "" ? height/2:0 - left: toolButton.right - leftMargin: parent.width * 0.02 - right: parent.right } - elide: "ElideRight" + Loader { + id: extraComponentLoader - font.bold: false + height: parent.height + width: parent.width * 0.2 - toolButton.width - color: "black" - - text: getText() - - function getText(){ - var titleString = ""; - - if(mainStack.currentItem.subTitle !== undefined){ - titleString = mainStack.currentItem.subTitle + anchors { + top: parent.top + bottom: parent.bottom } - return(titleString) + sourceComponent: mainStack.currentItem.headerComponent } + } Behavior on anchors.topMargin { diff --git a/resources/shared/icons/calendar.png b/resources/shared/icons/calendar.png new file mode 100644 index 0000000000000000000000000000000000000000..a1c99521d2cb05528caf72b2f46c416d3e312525 GIT binary patch literal 1132 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGojKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucHH@Avjv*CsZ*MyG$+$|eKHSG%!7d|r_@YAs zAH!8;?pCjbJuhF*3)1^HVV|$>-Xg8ke4Fk5FYa%sE=#**XKnI!-rSkn&hz>1PETL< zcC+*4cQCdPLj8+VmeuX&Zd!+1rN6&mS)Km0?)ZNBI=ekz zA3yAG-up-H`5RfFOw7wUd!3)Znfram{hxo|<;U;0|FNR@8{gc`b``PP!+WndqyP6}LZdHOm;@f}U|MOq}|D4{8sPuBTnWR%IHt~jTTX@PW z9^osb-5{D#3y?dtoZc)IRF!!5`MgUZO$9y|M7K&&#Dfz!HMN)78&qol`;+016f;{Qv*} literal 0 HcmV?d00001 diff --git a/resources/shared/shared.qrc b/resources/shared/shared.qrc index aabd3de..8439a11 100644 --- a/resources/shared/shared.qrc +++ b/resources/shared/shared.qrc @@ -5,5 +5,6 @@ icons/sac.png icons/back.png icons/backDark.png + icons/calendar.png diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index ce68541..d2128f8 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -23,8 +23,8 @@ void ServerConn::refreshFoodplan() { emit this->foodplanChanged(); } -QVariant ServerConn::getCalendar(QString nation){ - QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=2019&nation=" + nation)); +QVariant ServerConn::getCalendar(QString nation, int year){ + QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=" + QString::number(year) + "&nation=" + nation)); if(ret["status"] != 200){ // request was a failure