diff --git a/.gitignore b/.gitignore index bf2bb1d..38b5524 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.o *.a *.so +PresentationApp # Folders _obj diff --git a/main.go b/main.go index c84b931..a5e93b0 100644 --- a/main.go +++ b/main.go @@ -92,6 +92,16 @@ func run() error { 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()) window2 = edtQml.CreateWindow(engine.Context()) @@ -104,7 +114,12 @@ func run() error { //image is ready for imageprovider 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() window2.Show() edtQmlShow() diff --git a/qml.go b/qml.go index c3f699e..405d8ca 100644 --- a/qml.go +++ b/qml.go @@ -2,7 +2,6 @@ package main import ( - "fmt" "image" "path/filepath" "runtime/debug" @@ -171,8 +170,8 @@ func setSignals() { } func edtQmlShow() { - slc := window2.ObjectByName("fontPicker").Property("model") - fmt.Println(slc) + //slc := window2.ObjectByName("fontPicker").Property("model") + //fmt.Println(slc) } //imgProvider() for preview images in QML diff --git a/qml/lst/lstEle.qml b/qml/lst/lstEle.qml new file mode 100644 index 0000000..9765b6f --- /dev/null +++ b/qml/lst/lstEle.qml @@ -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" + } + ] + } +} diff --git a/qml/lst/tst.qml b/qml/lst/tst.qml new file mode 100644 index 0000000..e9d40ad --- /dev/null +++ b/qml/lst/tst.qml @@ -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" + } + ] + } + } +} + diff --git a/qml/main.qml b/qml/main.qml index 16ee5da..8c143e5 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -195,168 +195,6 @@ ApplicationWindow { clip: true 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 { id: button2 x: 8 - y: 39 - text: qsTr("Button ") + tst4.height + y: 43 + text: qsTr("Button ") objectName: "btnRem" } Button { id: button3 x: 8 - y: 70 + y: 78 text: qsTr("Button ") objectName: "btnMem" }