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
Component.onCompleted: { Row {
loadData(root.nation) 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 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,107 +112,128 @@ Window {
height: 50 height: 50
Button { Row {
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: { anchors.fill: parent
if(!mainStack.currentItem.locked){
mainStack.pop()
}
}
onPressed: toolButton.scale = 0.9 spacing: width * 0.02
onReleased: toolButton.scale = 1.0
background: Image { Item {
source: "qrc:/icons/backDark.png" id: spacer
width: 1
height: parent.height height: parent.height
width: parent.width }
fillMode: Image.PreserveAspectFit
Behavior on scale { Button {
PropertyAnimation { id:toolButton
duration: 100
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 { Column {
id: toolBarTitleLa
anchors.verticalCenter: parent.verticalCenter
anchors { height: childrenRect.height
verticalCenter: parent.verticalCenter width: parent.width * 0.7
verticalCenterOffset: -toolBarSubTitleLa.anchors.verticalCenterOffset
left: toolButton.right
leftMargin: parent.width * 0.02
right: parent.right
}
elide: "ElideRight" Label {
id: toolBarTitleLa
font.bold: true elide: "ElideRight"
color: "black" font.bold: true
text: getText() color: "black"
function getText(){ text: getText()
var titleString = "";
if(!mainStack.currentItem.titleIsPageTitle){ function getText(){
for(var i=1; i<mainStack.depth; i++){ var titleString = "";
if(i > 1){
titleString += " > " if(!mainStack.currentItem.titleIsPageTitle){
for(var i=1; i<mainStack.depth; i++){
if(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" anchors {
top: parent.top
text: getText() bottom: parent.bottom
function getText(){
var titleString = "";
if(mainStack.currentItem.subTitle !== undefined){
titleString = mainStack.currentItem.subTitle
} }
return(titleString) sourceComponent: mainStack.currentItem.headerComponent
} }
} }
Behavior on anchors.topMargin { Behavior on anchors.topMargin {

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