added year selector

This commit is contained in:
Dorian Zedler 2019-04-21 18:35:28 +02:00
parent 9dbad425df
commit 5faa8c0617
7 changed files with 210 additions and 108 deletions

View file

@ -26,7 +26,7 @@ signals:
public slots: public slots:
void refreshFoodplan(); 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); QVariant getRanking(int competitionId, int categoryId, bool registrationData = false, const int routeNumber = -2);
// functions for qml // functions for qml

View file

@ -134,31 +134,7 @@ DataListView {
width: parent.width / ( boulderResRep.model ) width: parent.width / ( boulderResRep.model )
height: parent.height 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 { Canvas {
id: boulderResCv id: boulderResCv
@ -166,7 +142,7 @@ DataListView {
anchors.centerIn: parent anchors.centerIn: parent
height: parent.height * 1.1 height: parent.height > parent.width ? parent.width * 0.9:parent.height * 0.9
width: height width: height
onPaint: { onPaint: {

View file

@ -9,26 +9,87 @@ Page {
title: "calendar" title: "calendar"
property string nation: "" property Component headerComponent: Item {
property int status: -1 anchors.fill: parent
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
Component.onCompleted: {
loadData(root.nation)
} }
function loadData(nation) { 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
}
}
}
}
}
}
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 root.status = 905
loadingDl.open() loadingDl.open()
var ret = serverConn.getCalendar(nation) var ret = serverConn.getCalendar(nation, year)
if(ret["status"] === 200){ if(ret["status"] === 200){
root.status = 200 root.status = 200
root.calendarData = ret["data"]
calendarList.listData = ret["data"]["competitions"] calendarList.listData = ret["data"]["competitions"]
} }
else { else {
root.status = ret["status"] root.status = parseInt(ret["status"])
calendarList.listData = {} calendarList.listData = {}
root.calendarData = {}
} }
loadingDl.close() loadingDl.close()
} }
@ -47,7 +108,7 @@ Page {
status: root.status status: root.status
onRefresh: { onRefresh: {
root.loadData(root.nation) root.loadData(root.nation, root.year)
} }
delegate: ItemDelegate { 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)
}
}
}
}
} }

View file

@ -112,15 +112,26 @@ Window {
height: 50 height: 50
Row {
anchors.fill: parent
spacing: width * 0.02
Item {
id: spacer
width: 1
height: parent.height
}
Button { Button {
id:toolButton id:toolButton
enabled: true
anchors { anchors {
left: parent.left
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
leftMargin: parent.width *0.02
} }
height: parent.height - parent.height * 0.5
height: parent.height * 0.5
width: height width: height
onClicked: { onClicked: {
@ -134,8 +145,10 @@ Window {
background: Image { background: Image {
source: "qrc:/icons/backDark.png" source: "qrc:/icons/backDark.png"
height: parent.height height: parent.height
width: parent.width width: height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
Behavior on scale { Behavior on scale {
PropertyAnimation { PropertyAnimation {
@ -145,18 +158,16 @@ Window {
} }
} }
Column {
anchors.verticalCenter: parent.verticalCenter
height: childrenRect.height
width: parent.width * 0.7
Label { Label {
id: toolBarTitleLa id: toolBarTitleLa
anchors {
verticalCenter: parent.verticalCenter
verticalCenterOffset: -toolBarSubTitleLa.anchors.verticalCenterOffset
left: toolButton.right
leftMargin: parent.width * 0.02
right: parent.right
}
elide: "ElideRight" elide: "ElideRight"
font.bold: true font.bold: true
@ -188,14 +199,6 @@ Window {
Label { Label {
id: toolBarSubTitleLa 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" elide: "ElideRight"
font.bold: false font.bold: false
@ -215,6 +218,24 @@ Window {
} }
} }
}
Loader {
id: extraComponentLoader
height: parent.height
width: parent.width * 0.2 - toolButton.width
anchors {
top: parent.top
bottom: parent.bottom
}
sourceComponent: mainStack.currentItem.headerComponent
}
}
Behavior on anchors.topMargin { Behavior on anchors.topMargin {
NumberAnimation { NumberAnimation {
duration: 500 duration: 500

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -5,5 +5,6 @@
<file>icons/sac.png</file> <file>icons/sac.png</file>
<file>icons/back.png</file> <file>icons/back.png</file>
<file>icons/backDark.png</file> <file>icons/backDark.png</file>
<file>icons/calendar.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -23,8 +23,8 @@ void ServerConn::refreshFoodplan() {
emit this->foodplanChanged(); emit this->foodplanChanged();
} }
QVariant ServerConn::getCalendar(QString nation){ QVariant ServerConn::getCalendar(QString nation, int year){
QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=2019&nation=" + nation)); QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=" + QString::number(year) + "&nation=" + nation));
if(ret["status"] != 200){ if(ret["status"] != 200){
// request was a failure // request was a failure