From 9dbad425dfe88dc88b5d90a13ce7b228b4dfc98f Mon Sep 17 00:00:00 2001 From: dorian Date: Sun, 21 Apr 2019 12:35:11 +0200 Subject: [PATCH] added rectangles like on dr website for boulder ranking --- DigitalRockRanking.pro.user | 18 +- resources/qml/Components/DataListView.qml | 24 ++- resources/qml/Components/RankingView.qml | 180 +++++++++++++++++- .../qml/Pages/CompetitionCalendarPage.qml | 33 ++-- resources/qml/Pages/RankingPage.qml | 10 +- resources/qml/main.qml | 5 + sources/serverconn.cpp | 2 +- 7 files changed, 230 insertions(+), 42 deletions(-) diff --git a/DigitalRockRanking.pro.user b/DigitalRockRanking.pro.user index 544d316..acb0eea 100644 --- a/DigitalRockRanking.pro.user +++ b/DigitalRockRanking.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -8,7 +8,7 @@ ProjectExplorer.Project.ActiveTarget - 0 + 1 ProjectExplorer.Project.EditorSettings @@ -69,7 +69,7 @@ 0 0 - /home/dorian/builds/build-DigitalRockRanking-Android_for_armeabi_v7a_Clang_Qt_5_11_3_for_Android_ARMv7-Debug + /home/dorian/Documents/git/builds/build-DigitalRockRanking-Android_for_armeabi_v7a_Clang_Qt_5_11_3_for_Android_ARMv7-Debug true @@ -355,8 +355,8 @@ 0 DigitalRockRanking - DigitalRockRanking - Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/DigitalRockRanking/DigitalRockRanking.pro + + Qt4ProjectManager.AndroidRunConfiguration:/home/dorian/Documents/git/digital-rock-ranking/DigitalRockRanking.pro 3768 false @@ -378,7 +378,7 @@ 0 0 - /home/dorian/builds/build-DigitalRockRanking-Desktop_Qt_5_11_3_GCC_64bit-Debug + /home/dorian/Documents/git/builds/build-DigitalRockRanking-Desktop_Qt_5_11_3_GCC_64bit-Debug true @@ -603,8 +603,8 @@ 2 DigitalRockRanking - - Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/DigitalRockRanking/DigitalRockRanking.pro + DigitalRockRanking2 + Qt4ProjectManager.Qt4RunConfiguration:/home/dorian/Documents/git/digital-rock-ranking/DigitalRockRanking.pro DigitalRockRanking.pro 3768 @@ -615,7 +615,7 @@ false true - /home/dorian/builds/build-DigitalRockRanking-Desktop_Qt_5_11_3_GCC_64bit-Debug + /home/dorian/Documents/git/builds/build-DigitalRockRanking-Desktop_Qt_5_11_3_GCC_64bit-Debug 1 diff --git a/resources/qml/Components/DataListView.qml b/resources/qml/Components/DataListView.qml index 0e9ee28..1cfbd45 100644 --- a/resources/qml/Components/DataListView.qml +++ b/resources/qml/Components/DataListView.qml @@ -11,6 +11,11 @@ ListView { anchors.margins: 10 anchors.rightMargin: 14 + + enabled: status === 200 + opacity: enabled ? 1:0 + + ScrollBar.vertical: ScrollBar { parent: control.parent @@ -24,15 +29,30 @@ ListView { width: 8 + visible: control.model > 0 + active: true } onContentYChanged: { - if(contentY < -125){ + if(contentY < -control.height * 0.3 && control.status !== 905){ + contentY = 0 control.refresh() } } + Behavior on opacity { + NumberAnimation { + duration: 200 + } + } + + Behavior on contentY { + NumberAnimation { + duration: 200 + } + } + InfoArea { id: infoArea @@ -44,7 +64,7 @@ ListView { topMargin: control.height*( status === 901 ? 0.6:0.5) - height * 0.8 } - excludedCodes: [200, 902] + excludedCodes: [200, 902, 905] errorCode: control.status } } diff --git a/resources/qml/Components/RankingView.qml b/resources/qml/Components/RankingView.qml index d0af5ce..eb3c0f2 100644 --- a/resources/qml/Components/RankingView.qml +++ b/resources/qml/Components/RankingView.qml @@ -108,6 +108,25 @@ DataListView { model: parseInt(listData[ "route_num_problems" ]) + function getDataForIcon(index){ + var resultString = listData[ "participants" ][partDel.ind]["boulder"+(index+1)] + + var resultList = [] + + if( resultString !== undefined){ + resultString = resultString.replace("t", "") + resultString = resultString.replace("z", "") + resultList = resultString.split(" ") + } + + + while (resultList.length < 2){ + resultList.unshift(0) + } + + return resultList + } + delegate: Item { id: boulderResItm @@ -115,7 +134,7 @@ DataListView { width: parent.width / ( boulderResRep.model ) height: parent.height - +/* Rectangle { anchors { left: parent.left @@ -139,20 +158,161 @@ DataListView { color: "grey" } +*/ + Canvas { + id: boulderResCv + + property var resultData: boulderResRep.getDataForIcon(index) - Label { anchors.centerIn: parent - height: parent.height - width: parent.width * 0.9 + height: parent.height * 1.1 + width: height - fontSizeMode: Text.Fit - font.pixelSize: Math.abs( height * 0.6 ) - minimumPixelSize: 0 - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter + onPaint: { + var width = boulderResCv.width * 0.9 + var height = boulderResCv.height * 0.9 - text: listData[ "participants" ][partDel.ind]["boulder"+(index+1)] === undefined ? "":listData[ "participants" ][partDel.ind]["boulder"+(index+1)] + var radius = width * 0.3 + + var offsetX = width * 0.05 + var offsetY = height * 0.05 + + var context = getContext("2d"); + + context.beginPath(); + + context.moveTo(0 + offsetX + radius, 0 + offsetY); + + // top line + context.lineTo(width - radius + offsetX, 0 + offsetY); + // top right corner + context.arc(width-radius + offsetX, radius + offsetY, radius, 1.5 * Math.PI, 0); + // right line + context.lineTo(width + offsetX, height - radius + offsetY); + // bottom right corner + context.arc(width-radius + offsetX, height - radius + offsetY, radius, 0, 0.5 * Math.PI); + // bottom line + context.lineTo(0 + radius + offsetX, height + offsetY); + // bottom left corner + context.arc(radius + offsetY, height - radius + offsetY, radius, 0.5 * Math.PI, Math.PI); + // left line + context.lineTo(0 + offsetX, radius + offsetY); + // top left corner + context.arc(radius + offsetX, radius + offsetY, radius, Math.PI, 1.5 * Math.PI); + + // fill + context.fillStyle = "#b7b7b7"; + context.fill(); + + // outline + context.lineWidth = 1; + context.strokeStyle = '#424242'; + context.stroke(); + + if(resultData[1] > 0){ + + // the first triangle + context.beginPath(); + + // top right corner + context.arc(width-radius + offsetX, radius + offsetY, radius, 1.75 * Math.PI, 0); + + // right line + context.lineTo(width + offsetX, height - radius + offsetY); + + // bottom right corner + context.arc(width-radius + offsetX, height - radius + offsetY, radius, 0, 0.5 * Math.PI); + + // bottom line + context.lineTo(0 + radius + offsetX, height + offsetY); + // bottom left corner + context.arc(radius + offsetX, height - radius + offsetY, radius, 0.5 * Math.PI, 0.75 * Math.PI); + context.closePath(); + + context.fillStyle = "#44ed38"; + context.fill(); + + // outline + context.lineWidth = 1; + context.strokeStyle = '#424242'; + context.stroke(); + + + if(resultData[0] > 0){ + // the second triangle + context.beginPath(); + // bottom left corner + context.arc(radius + offsetX, height - radius + offsetY, radius, 0.75 * Math.PI, 1 * Math.PI); + // left line + context.lineTo(0 + offsetX, radius + offsetY); + // top left corner + context.arc(radius + offsetX, radius + offsetY, radius, Math.PI, 1.5 * Math.PI); + // top line + context.lineTo(width - radius + offsetX, 0 + offsetY); + // top right corner + context.arc(width-radius + offsetX, radius + offsetY, radius, 1.5 * Math.PI, 1.75 * Math.PI); + + context.closePath(); + + context.fillStyle = "#44ed38"; + context.fill(); + + // outline + context.lineWidth = 1; + context.strokeStyle = '#424242'; + context.stroke(); + } + } + } + + Label { + id: boulderResZoneLa + + anchors { + right: parent.right + bottom: parent.bottom + margins: boulderResCv.height * 0.05 + } + + height: parent.height / 2 + width: parent.width / 2 + + visible: text !== "0" + + fontSizeMode: Text.Fit + font.pixelSize: height + minimumPixelSize: 0 + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + text: boulderResCv.resultData[1] + } + + Label { + id: boulderResTopLa + + anchors { + left: parent.left + top: parent.top + margins: boulderResCv.height * 0.05 + } + + height: parent.height / 2 + width: parent.width / 2 + + visible: text !== "0" + + fontSizeMode: Text.Fit + font.pixelSize: height + minimumPixelSize: 0 + + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + + text: boulderResCv.resultData[0] + } } } diff --git a/resources/qml/Pages/CompetitionCalendarPage.qml b/resources/qml/Pages/CompetitionCalendarPage.qml index b761d14..29be6ec 100644 --- a/resources/qml/Pages/CompetitionCalendarPage.qml +++ b/resources/qml/Pages/CompetitionCalendarPage.qml @@ -13,6 +13,13 @@ Page { property int status: -1 Component.onCompleted: { + loadData(root.nation) + } + + function loadData(nation) { + root.status = 905 + loadingDl.open() + var ret = serverConn.getCalendar(nation) if(ret["status"] === 200){ @@ -23,34 +30,26 @@ Page { root.status = ret["status"] calendarList.listData = {} } + loadingDl.close() } - 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*( status === 901 ? 0.6:0.5) - height * 0.8 - } - - excludedCodes: [200, 902] - errorCode: root.status - } - - ListView { + DataListView { id: calendarList property var listData anchors.fill: parent - boundsBehavior: Flickable.StopAtBounds + //boundsBehavior: Flickable.StopAtBounds model: listData.length + status: root.status + + onRefresh: { + root.loadData(root.nation) + } + delegate: ItemDelegate { id: competitionDel diff --git a/resources/qml/Pages/RankingPage.qml b/resources/qml/Pages/RankingPage.qml index ebeb810..110a5b8 100644 --- a/resources/qml/Pages/RankingPage.qml +++ b/resources/qml/Pages/RankingPage.qml @@ -30,6 +30,7 @@ Page { } function loadData(comp, cat, reg, route){ + root.status = 905 loadingDl.open() console.log("[info][QML] getting ranking data of comp: " + comp + " and cat: " + cat + " reg: " + reg) var ret = serverConn.getRanking(comp, cat, reg, route) @@ -63,7 +64,7 @@ Page { } - if(ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1){ + if((ret["data"][ root.listKey ] === undefined || ret["data"][ root.listKey ].length < 1) && ( root.status === 200 || root.status === 404 ) ){ root.status = 901 } @@ -109,6 +110,9 @@ Page { listData: root.reg ? root.rankingData:({}) + onRefresh: { + root.loadData(root.comId, root.catId, root.reg, root.routeNumber) + } } } @@ -136,8 +140,8 @@ Page { listData: root.reg ? ({}):root.rankingData - onListDataChanged: { - console.log("list data changed") + onRefresh: { + root.loadData(root.comId, root.catId, root.reg, root.routeNumber) } } diff --git a/resources/qml/main.qml b/resources/qml/main.qml index bafbf1f..3ed7586 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -339,6 +339,11 @@ Window { errorString = "Incompatible API" errorDescription = "Please make shure that you are using the latest version of this app and try again." break + case 905: + infoLevel = 1 + errorString = "Loading..." + errorDescription = "Please wait while we're loading some data" + break default: infoLevel = 2 errorString = "Unexpected error ("+errorCode+")" diff --git a/sources/serverconn.cpp b/sources/serverconn.cpp index a4e774e..ce68541 100644 --- a/sources/serverconn.cpp +++ b/sources/serverconn.cpp @@ -24,7 +24,7 @@ void ServerConn::refreshFoodplan() { } QVariant ServerConn::getCalendar(QString nation){ - QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=2018&nation=" + nation)); + QVariantMap ret = this->senddata(QUrl("http://egw.ifsc-climbing.org/egw/ranking/json.php?year=2019&nation=" + nation)); if(ret["status"] != 200){ // request was a failure