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:
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

View file

@ -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: {

View file

@ -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)
}
}
}
}
}

View file

@ -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<mainStack.depth; i++){
if(i > 1){
titleString += " > "
function getText(){
var 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"
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 {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

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

View file

@ -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