After finishing the keyboard layout editor here in Randa I’ve started working on the last remaining big task of the upcoming new version of KTouch: the summary screen which will be shown after the user has completed a lesson. For that I want to display the user’s learning progress with pretty diagrams. As there are no ready-made components for Qt Quick for that purpose right now, I’ve sat down and started to implement my own:
My QML component to render such graphs is actually pretty generic. Here is the complete code for the screenshot above:
importQtQuick1.1importorg.kde.plasma.core0.1asPlasmaCoreimportorg.kde.plasma.components0.1asPlasmaComponentsimportorg.kde.ktouch.graph0.1asGraphimportktouch1.0Rectangle{width:800height:300anchors.centerIn:parentcolor:"white"Column{anchors{fill:parenttopMargin:2*spacing+legend.heightleftMargin:spacingrightMargin:spacingbottomMargin:spacing}spacing:20Graph.LineGraph{width:parent.widthheight:parent.height-legend.height-parent.spacingmodel:learningProgressModeldimensions:[Graph.Dimension{id:accuracyDimensiondataColumn:5color:"#ffb12d"maximumValue:1.0label:i18n("Accuracy")unit:"%"unitFactor:100},Graph.Dimension{id:charactersPerMinuteDimensiondataColumn:6color:"#38aef4"maximumValue:400label:i18n("Characters per Minute")}]}Row{id:legendanchors.horizontalCenter:parent.horizontalCenterspacing:20Graph.LegendItem{dimension:accuracyDimension}Graph.LegendItem{dimension:charactersPerMinuteDimension}}}}
The model used as the data source for the graph—learningProgressModel—is just a normal QAbstractTableModel descendant.