Move the listView data to the c++ context

This commit is contained in:
Felix Hammer
2015-09-20 14:01:51 +02:00
parent 27b524f52f
commit e053cdcaf6
19 changed files with 8241 additions and 2952 deletions
+28 -10
View File
@@ -1,6 +1,7 @@
import QtQuick 2.0
import QtQuick.Layouts 1.1
import QtQuick 2.5
import QtQuick.Controls 1.2
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import "../js/colors.js" as GlobalColors
import "styles"
@@ -9,7 +10,7 @@ Item {
id: root
anchors.fill: parent
property ListModel selectionModel: ListModel {}
property ListModel internalValuesList: ListModel {}
property string valueFromParent
property string titleString
property string returnValue
@@ -23,9 +24,9 @@ Item {
returnValue = vl; // <-- initial the returnValue with the preselection to prevent a NULL return when pressing Cancel
valueIsIndex = valueIndex;
//fill the model
selectionModel.clear();
for (var i=0; i < list.count; i++) {
selectionModel.append({"valueString": list.get(i).value});
internalValuesList.clear();
for (var i=0; i < list.length; i++) {
internalValuesList.append({"value": list[i]});
}
mySelector.show()
}
@@ -48,22 +49,39 @@ Item {
onButton1Clicked: hide()
container: ScrollView {
id: scrollView
anchors.fill:parent
property int yOfCheckedRadioButton: 0
ListView {
id:listView
anchors.fill: parent
spacing: Math.round(appWindow.height*0.05)
model: selectionModel
model: internalValuesList
delegate: RadioButton {
id: radioBtn
//check of value is index type and do the corresponding checked? test
checked: valueIsIndex ? (parseInt(valueFromParent) == index ? true : false) : (valueFromParent == valueString ? true : false)
checked: valueIsIndex ? (parseInt(valueFromParent) == index ? true : false) : (valueFromParent == value ? true : false)
onClicked: {
root.selected(valueString, index)
root.selected(value, index)
}
style: MyRadioButtonStyle {
myRadioBtn: radioBtn
labelString: valueString
labelString: value
}
Component.onCompleted: {
//set the position of the checked RadioButton to scroll to it later onContentHeightChange
if(checked) {
var checkedRadioBtnPositionY = Math.round((radioBtn.height + listView.spacing) * index - radioBtn.height * 1.5)
if( checkedRadioBtnPositionY > 0)
scrollView.yOfCheckedRadioButton = checkedRadioBtnPositionY
else
scrollView.yOfCheckedRadioButton = 0
}
}
}
onContentHeightChanged: {
//scroll to the checked RadioButton
contentY = scrollView.yOfCheckedRadioButton
}
}
}