adding another list element now works

This commit is contained in:
lordwelch 2016-05-11 09:17:22 -07:00
parent 636e3e42ed
commit 3569a7d502
6 changed files with 230 additions and 169 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*.o *.o
*.a *.a
*.so *.so
PresentationApp
# Folders # Folders
_obj _obj

17
main.go
View File

@ -92,6 +92,16 @@ func run() error {
return err return err
} }
qlst, err := engine.LoadFile(path + "/lst/tst.qml")
if err != nil {
return err
}
qlstEle, err := engine.LoadFile(path + "/lst/lstEle.qml")
if err != nil {
return err
}
window = mainQml.CreateWindow(engine.Context()) window = mainQml.CreateWindow(engine.Context())
window2 = edtQml.CreateWindow(engine.Context()) window2 = edtQml.CreateWindow(engine.Context())
@ -104,7 +114,12 @@ func run() error {
//image is ready for imageprovider //image is ready for imageprovider
imgready = true imgready = true
tstlst :=qlst.Create(engine.Context())
tstlst.Set("parent", window.ObjectByName("data1"))
tstLlst := qlstEle.Create(engine.Context())
tstLlst.Call("get1")
//fmt.Println(tstLlst.Property("id1"))
tstlst.Call("addLst") //.Call("get1") //).(qml.Object).Create(engine.Context()).Set("parent", qlst.ObjectByName("nestedModel"))
window.Show() window.Show()
window2.Show() window2.Show()
edtQmlShow() edtQmlShow()

5
qml.go
View File

@ -2,7 +2,6 @@
package main package main
import ( import (
"fmt"
"image" "image"
"path/filepath" "path/filepath"
"runtime/debug" "runtime/debug"
@ -171,8 +170,8 @@ func setSignals() {
} }
func edtQmlShow() { func edtQmlShow() {
slc := window2.ObjectByName("fontPicker").Property("model") //slc := window2.ObjectByName("fontPicker").Property("model")
fmt.Println(slc) //fmt.Println(slc)
} }
//imgProvider() for preview images in QML //imgProvider() for preview images in QML

28
qml/lst/lstEle.qml Normal file
View File

@ -0,0 +1,28 @@
import QtQuick 2.4
ListModel {
id: nestedModel
objectName: "nestedModel"
function get1() {
console.log(get(0))
return get(0)
}
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "tst"
},
ListElement {
itemName: "Tota"
},
ListElement {
itemName: "vy"
},
ListElement {
itemName: "Audio Adrenaline"
}
]
}
}

180
qml/lst/tst.qml Normal file
View File

@ -0,0 +1,180 @@
//https://gist.github.com/elpuri/3753756
import QtQuick 2.4
Item {
id: tst4
height: 50 + ((tst3.count - 1) * 50) + (tst3.subCount * 40)
width: 200
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
Component.onCompleted: {
addLst()
}
function addLst() {
var tstm
tstm = nestedModel.get(0)
tstm.subItems = [ { itemName: "test" }, { itemName: "notest" } ]
nestedModel.append(tstm)
}
ListView {
id: tst3
anchors.fill: parent
property int subCount: 0
model: nestedModel
delegate: Component {
id: categoryDelegate
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedModel.setProperty(index, "collapsed", !collapsed)
if (!nestedModel.get(index).collapsed) {
tst3.subCount = tst3.subCount + subItemLoader.subItemModel.count
} else {
tst3.subCount = tst3.subCount - subItemLoader.subItemModel.count
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subItems
sourceComponent: subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDelegate
Column {
property alias model: subItemRepeater.model
width: tst4.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
ListModel {
id: nestedModel
objectName: "nestedModel"
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nisan"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissa"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissan"
},
ListElement {
itemName: "Toota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
}
}

View File

@ -195,168 +195,6 @@ ApplicationWindow {
clip: true clip: true
height: data1.childrenRect.height height: data1.childrenRect.height
Item {
id: tst4
height: 50 + ((tst3.count-1)*50) + (tst3.subCount * 40)
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
ListView {
id: tst3
anchors.fill: parent
property int subCount: 0
model: ListModel {
id: nestedModel
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissan"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissan"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
ListElement {
categoryName: "Cars"
collapsed: true
subItems: [
ListElement {
itemName: "Nissan"
},
ListElement {
itemName: "Toyota"
},
ListElement {
itemName: "Chevy"
},
ListElement {
itemName: "Audi"
}
]
}
}
delegate: Component {
id: categoryDelegate
Column {
anchors.right: parent.right
anchors.left: parent.left
//width: 200
Rectangle {
id: categoryItem
anchors.right: parent.right
anchors.left: parent.left
border.color: "black"
border.width: 5
color: "white"
height: 50
//width: 200
Text {
anchors.verticalCenter: parent.verticalCenter
x: 15
font.pixelSize: 24
text: categoryName
}
Rectangle {
color: "red"
width: 30
height: 30
anchors.right: parent.right
anchors.rightMargin: 15
anchors.verticalCenter: parent.verticalCenter
MouseArea {
anchors.fill: parent
// Toggle the 'collapsed' property
onClicked: {
nestedModel.setProperty(index, "collapsed", !collapsed)
if (!nestedModel.get(index).collapsed) {
tst3.subCount = tst3.subCount + subItemLoader.subItemModel.count
} else {
tst3.subCount = tst3.subCount - subItemLoader.subItemModel.count
}
}
}
}
}
Loader {
id: subItemLoader
// This is a workaround for a bug/feature in the Loader element. If sourceComponent is set to null
// the Loader element retains the same height it had when sourceComponent was set. Setting visible
// to false makes the parent Column treat it as if it's height was 0.
visible: !collapsed
property variant subItemModel: subItems
sourceComponent: collapsed ? null : subItemColumnDelegate
onStatusChanged: if (status == Loader.Ready)
item.model = subItemModel
}
}
}
}
Component {
id: subItemColumnDelegate
Column {
property alias model: subItemRepeater.model
width: tst4.width
Repeater {
id: subItemRepeater
delegate: Rectangle {
color: "#cccccc"
height: 40
anchors.right: parent.right
anchors.left: parent.left
//width: 200
border.color: "black"
border.width: 2
Text {
anchors.verticalCenter: parent.verticalCenter
x: 30
font.pixelSize: 18
text: itemName
}
}
}
}
}
}
} }
} }
@ -402,15 +240,15 @@ ApplicationWindow {
Button { Button {
id: button2 id: button2
x: 8 x: 8
y: 39 y: 43
text: qsTr("Button ") + tst4.height text: qsTr("Button ")
objectName: "btnRem" objectName: "btnRem"
} }
Button { Button {
id: button3 id: button3
x: 8 x: 8
y: 70 y: 78
text: qsTr("Button ") text: qsTr("Button ")
objectName: "btnMem" objectName: "btnMem"
} }