From bbcd468ec3f1eb30eff58d1737d99a6c8d9ae8f9 Mon Sep 17 00:00:00 2001 From: dorian Date: Thu, 4 Jul 2019 23:00:43 +0200 Subject: [PATCH] finished the implementation of speed final flowcharts, everything seems to work fine --- resources/qml/Components/DataListView.qml | 7 +- resources/qml/Components/SpeedFlowChart.qml | 125 +++++++++++++++----- resources/qml/Widgets/ResultWidget.qml | 42 ++++++- resources/qml/main.qml | 9 ++ 4 files changed, 144 insertions(+), 39 deletions(-) diff --git a/resources/qml/Components/DataListView.qml b/resources/qml/Components/DataListView.qml index 07d80a4..38f7c7a 100644 --- a/resources/qml/Components/DataListView.qml +++ b/resources/qml/Components/DataListView.qml @@ -26,6 +26,7 @@ ListView { property bool loading: false property var listData property var emptyProperties: [] + property bool useBuiltInPullRefresher: true signal refresh() @@ -81,13 +82,17 @@ ListView { PullRefresher { target: control + visible: control.useBuiltInPullRefresher + postRefreshDelay: 0 busyIndicator: FancyBusyIndicator {} refreshPosition: height * 1.3 onRefreshRequested: { - control.refresh() + if(control.useBuiltInPullRefresher) { + control.refresh() + } } } } diff --git a/resources/qml/Components/SpeedFlowChart.qml b/resources/qml/Components/SpeedFlowChart.qml index 0e2b6a4..f7755c5 100644 --- a/resources/qml/Components/SpeedFlowChart.qml +++ b/resources/qml/Components/SpeedFlowChart.qml @@ -10,6 +10,9 @@ ListView { property int rounds property int tileSize: app.height / 8 * 0.8 + property int refreshes: 0 + property int roundRefreshes: 1 + anchors.fill: parent anchors.margins: 10 model: rounds + 2 @@ -24,18 +27,55 @@ ListView { } function prepareData() { + if(!control.enabled) + return + /*refreshes += 1 + + if(refreshes > 2){ + roundRefreshes += 1 + } + + console.log("refreshes: " + refreshes + " rounds: " + roundRefreshes) + + // create competition like data (just testing) + for(var part in flowchartData['participants']){ + if(flowchartData['participants'].hasOwnProperty(part)){ + + for(var r = 2 + roundRefreshes; r < 7; r++){ + delete flowchartData['participants'][part]["result"+r] + delete flowchartData['participants'][part]["result_rank"+r] + } + + if(parseInt(flowchartData['participants'][part]["result_rank0"]) > 14 + refreshes) { + delete flowchartData['participants'][part]["result_rank2"] + } + } + } + + + delete flowchartData['route_names'][2] + delete flowchartData['route_names'][3] + delete flowchartData['route_names'][4] + delete flowchartData['route_names'][5] + delete flowchartData['route_names'][6] + */ + + //flowchartData['route_names'] = flowchartData['route_names'].slice(0,) // array to store the restructured data var allData = [] - for(var round in flowchartData['route_names']){ - if(flowchartData['route_names'].hasOwnProperty(round) && parseInt(round) >= 0){ - console.log(round) + //console.log(JSON.stringify(flowchartData['route_names'])) - if(allData.length > 0){ + for(var round in flowchartData['route_names']){ + //console.log(round) + if(flowchartData['route_names'].hasOwnProperty(round) && parseInt(round) >= 0){ + //console.log(round) + + /*if(allData.length > 0){ allData[allData.length-1].push(round) allData[allData.length-1].push(flowchartData['route_names'][round]) - } + }*/ if(parseInt(round) === 0){ // this is the first round @@ -86,7 +126,8 @@ ListView { } // push the first round to all data - + finalFirstRoundPairs.push(2) + finalFirstRoundPairs.push(flowchartData['route_names'][2]) allData.push(finalFirstRoundPairs) } @@ -106,6 +147,10 @@ ListView { var thisLooser var thisWinnerIsFirstOfNewPair = i%2 === 0 + if(thisPair[0] === undefined || thisPair[1] === undefined){ + continue + } + if(thisWinnerIsFirstOfNewPair){ nextRound.push([]) } @@ -117,14 +162,18 @@ ListView { thisWinner = thisPair[0] thisLooser = thisPair[1] } - else { + else if(parseInt(thisPair[0]["result_rank"+round]) > parseInt(thisPair[1]["result_rank"+round])) { thisWinner = thisPair[1] thisLooser = thisPair[0] } + else { + // no result yet!! + thisPair[1]["win"] = thisPair[0]["win"] = false + //console.log("got no winner yet") + continue + } - console.log(thisWinner['firstname']+" has won in round " + round) - //thisWinner.win = false - //thisLooser.win = true + //console.log(thisWinner['firstname']+" has won in round " + round) if(round - control.rounds === 2){ // if we are in the 1/2 final @@ -144,24 +193,30 @@ ListView { // small Final allData.push([smallFinal, parseInt(round)+1]) - break + //break } else { - //nextRound.push(round) - //nextRound.push(flowchartData['route_names'][round]) + nextRound.push(parseInt(round) + 1 ) + nextRound.push(flowchartData['route_names'][parseInt(round) + 1]) allData.push(nextRound) } } } } control.allFlowchartData = allData + //console.log(JSON.stringify(allData)) + } + + function getWinner(part1, part2){ + } delegate: Column { id: roundCol property int thisIndex: index - property int thisRound: control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-2] + property int thisRound: thisRoundIsValid ? control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-2]:-1 + property bool thisRoundIsValid: control.allFlowchartData !== undefined && control.allFlowchartData[roundCol.thisIndex] !== undefined && control.allFlowchartData[roundCol.thisIndex].length > 2 property bool thisIsLastRound: thisIndex === control.model - 1 width: app.width * 0.5 @@ -172,9 +227,13 @@ ListView { Label { id: roundNameLa width: parent.width + height: control.height * 0.05 horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + fontSizeMode: Text.Fit + font.pixelSize: height * 0.6 font.bold: true - text: control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-1] + text: roundCol.thisRoundIsValid && control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-1] !== undefined ? control.allFlowchartData[roundCol.thisIndex][control.allFlowchartData[roundCol.thisIndex].length-1] : "-" } Repeater { @@ -185,18 +244,19 @@ ListView { property bool lowerPart: (index%2 > 0) - property int thisIndex: index - property var thisMatchData: control.allFlowchartData[ thisIsSemifinal ? roundCol.thisIndex+1 : roundCol.thisIndex][matchItm.thisIndex] - property bool thisIsFinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 2 - property bool thisIsSemifinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 1 + property var matchData: roundCol.thisRoundIsValid ? control.allFlowchartData[ thisIsSmallFinal ? roundCol.thisIndex+1 : roundCol.thisIndex][ thisIsSmallFinal ? 0:matchItm.thisIndex]:undefined - Component.onCompleted: { - if(thisIsSemifinal){ - console.log("this is semi final") - console.log(thisMatchData) - } - console.log(thisMatchData) - } + property int thisIndex: index + property int thisRound: parseInt(roundCol.thisRound) - (thisIsSmallFinal ? 1:0) + property var thisMatchData: thisMatchDataIsValid ? matchData:[] + + property bool thisMatchDataIsValid: (matchData !== undefined && matchData !== null && typeof matchData === "object" && matchData.length > 0) + property bool thisMatchIsOver: thisMatchDataIsValid && thisMatchData[0]['result_rank'+thisRound] !== undefined && thisMatchData[1]['result_rank'+thisRound] !== undefined + + property bool thisIsFinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 2 + property bool thisIsSmallFinal: roundCol.thisIsLastRound && thisIndex === rectRep.model - 1 + + property int winnerIndex: thisMatchIsOver ? (parseInt(thisMatchData[0]['result_rank'+thisRound]) < parseInt(thisMatchData[1]['result_rank'+thisRound]) ? 0:1) : -1 height: !roundCol.thisIsLastRound ? (roundCol.height - roundNameLa.height) / rectRep.model - roundCol.spacing : (thisIsFinal ? (roundCol.height - roundNameLa.height) * 0.5 + control.tileSize * 0.5 : (roundCol.height - roundNameLa.height) - (roundCol.height - roundNameLa.height) * 0.5 + control.tileSize * 0.5 ) width: parent.width @@ -255,6 +315,7 @@ ListView { model: 2 delegate: Row { + height: app.landscape() ? parent.height:parent.height / 2 width: app.landscape() ? parent.width / 2 : parent.width @@ -262,28 +323,29 @@ ListView { Label { height: parent.height - width: parent.width * 0.2 + width: parent.width * (app.landscape() ? 0.1 : 0.2) verticalAlignment: Text.AlignVCenter font.pixelSize: height * 0.6 fontSizeMode: Text.Fit minimumPixelSize: 1 - text: matchItm.thisMatchData[index]['result_rank0'] + text: matchItm.thisMatchData[index] !== undefined ? matchItm.thisMatchData[index]['result_rank0']: "" } Label { height: parent.height - width: parent.width * 0.5 + width: parent.width * 0.6 verticalAlignment: Text.AlignVCenter + horizontalAlignment: app.landscape() ? Text.AlignLeft : Text.AlignHCenter font.pixelSize: height * 0.6 fontSizeMode: Text.Fit minimumPixelSize: 1 - color: (parseInt(matchItm.thisMatchData[0]["result_rank" + roundCol.thisRound ]) < parseInt(matchItm.thisMatchData[1]["result_rank" + roundCol.thisRound])) === (index === 0 ? true:false) ? "green":"black" + color: matchItm.winnerIndex === index ? "green":"black" - text: matchItm.thisMatchData[index]['firstname'] + " " + matchItm.thisMatchData[index]['lastname'] + text: matchItm.thisMatchData[index] !== undefined ? matchItm.thisMatchData[index]['firstname'] + " " + matchItm.thisMatchData[index]['lastname'] :"-" } /*Rectangle { @@ -302,7 +364,6 @@ ListView { visible: (parseInt(matchItm.thisMatchData[0]["result_rank" + roundCol.thisRound ]) < parseInt(matchItm.thisMatchData[1]["result_rank" + roundCol.thisRound])) === (index === 0 ? true:false) }*/ - } } } diff --git a/resources/qml/Widgets/ResultWidget.qml b/resources/qml/Widgets/ResultWidget.qml index e6caba5..4207151 100644 --- a/resources/qml/Widgets/ResultWidget.qml +++ b/resources/qml/Widgets/ResultWidget.qml @@ -43,7 +43,9 @@ DataListView { ToolButton { id: flowToolBt - visible: control.widgetData['discipline'] === 'speed' + visible: speedFlowChart.enabled + + enabled: control.widgetData['route_order'] === "-1" && Object.keys(control.widgetData['route_names']).length > 2 onClicked: { if(speedFlowChartBackgroundRect.state === "hidden"){ @@ -154,6 +156,8 @@ DataListView { property int ind: index property var thisData: widgetData[ "participants" ][partDel.ind] + enabled: speedFlowChartBackgroundRect.state === "hidden" + width: parent.width height: 70 @@ -250,13 +254,15 @@ DataListView { id: partDelSecondRow width: parent.width - height: multiResRow.enabled || multiGenResRow.enabled || resultLa.enabled ? parent.height / 2 : 0 + height: multiResRow.active || multiGenResRow.active || resultLa.acitve ? parent.height / 2 : 0 Row { id: multiResRow + property bool active: parseInt(widgetData[ "route_order" ]) > -1 && boulderResRep.model > 0 + height: parent.height - width: enabled ? parent.width * 0.75:0 + width: active ? parent.width * 0.75:0 enabled: parseInt(widgetData[ "route_order" ]) > -1 && boulderResRep.model > 0 @@ -464,8 +470,10 @@ DataListView { Row { id: multiGenResRow + property bool active: ((parseInt(widgetData[ "route_order" ]) === -1) && (generalResRep.model > 0)) ? true:false + height: parent.height - width: enabled ? parent.width - resultLa.width:0 + width: active ? parent.width - resultLa.width:0 enabled: ((parseInt(widgetData[ "route_order" ]) === -1) && (generalResRep.model > 0)) ? true:false @@ -554,6 +562,8 @@ DataListView { Label { id: resultLa + property bool acitve: ( boulderResRep.model > 0 || widgetData["discipline"] !== "boulder" ) && parseInt(widgetData[ "route_order" ]) > -1 + width: enabled ? parent.width * 0.25:0 height: enabled ? parent.height:0 @@ -591,6 +601,8 @@ DataListView { property var tabs: getTabs() property var tabIndexes: [] + enabled: speedFlowChartBackgroundRect.state === "hidden" + anchors { left: parent.left right: parent.right @@ -678,14 +690,18 @@ DataListView { color: Material.background SpeedFlowChart { + id: speedFlowChart + anchors.fill: parent - flowchartData: control.widgetData; + enabled: control.widgetData['discipline'] === 'speed' + + flowchartData: control.widgetData //participants: control.widgetData['participants'].slice() //route_names: control.widgetData['route_names'] - rounds: control.widgetData['route_names'][2].includes("8") ? 2:1 + rounds: Object.keys(control.widgetData['route_names']).length > 2 ? control.widgetData['route_names']["2"].includes("8") ? 2:1 : 0 } states: [ @@ -719,4 +735,18 @@ DataListView { } ] } + + PullRefresher { + target: control + + postRefreshDelay: 0 + + busyIndicator: FancyBusyIndicator {} + refreshPosition: height * 1.3 + + onRefreshRequested: { + control.refresh() + } + } + } diff --git a/resources/qml/main.qml b/resources/qml/main.qml index 7b275b4..626e402 100644 --- a/resources/qml/main.qml +++ b/resources/qml/main.qml @@ -579,6 +579,15 @@ Window { loadingDl.close() } + function defaultString(string, defaultString){ + if(string === undefined || string === null){ + return defaultString + } + else { + return string + } + } + function getErrorInfo(errorCode) { var infoLevel