From 8409b2bef45d65ca83b4d68f8aedb4a8ffc9edfc Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Tue, 16 Oct 2018 21:18:04 -0700 Subject: [PATCH] populate listview in qml from code --- identities.go | 92 ++++++++++++++++++++++++++++++++++++++++++ main.go | 17 +++++++- qml.qrc | 1 - qml/GroupsColumn.qml | 4 -- qml/MainWindow.qml | 26 ++++++++++-- qml/ProfilesColumn.qml | 13 +++--- qml/main.qml | 5 ++- 7 files changed, 138 insertions(+), 20 deletions(-) create mode 100644 identities.go diff --git a/identities.go b/identities.go new file mode 100644 index 0000000..f4be921 --- /dev/null +++ b/identities.go @@ -0,0 +1,92 @@ +package main + +import ( + "github.com/therecipe/qt/core" +) + +func init() { QIdentityListModel_QmlRegisterType2("CustomQmlTypes", 1, 0, "QIdentityListModel") } + + +const ( + Name = int(core.Qt__UserRole) + 1<qml/LoadingWindow.qml qml/MainWindow.qml qml/ProfilesColumn.qml - assets/open_privacy_logo_white_bg.png qml/main.qml assets/cwtch-logo.png diff --git a/qml/GroupsColumn.qml b/qml/GroupsColumn.qml index 5f153c6..592bbdc 100644 --- a/qml/GroupsColumn.qml +++ b/qml/GroupsColumn.qml @@ -1,10 +1,6 @@ import QtQuick 2.0 Rectangle { - height: parent.height - width: 300 - anchors.top: parent.top - color: "#4a3458" property alias model: list.model diff --git a/qml/MainWindow.qml b/qml/MainWindow.qml index 98e47af..3bef837 100644 --- a/qml/MainWindow.qml +++ b/qml/MainWindow.qml @@ -1,5 +1,6 @@ import QtQuick 2.9 import QtQuick.Window 2.2 +import CustomQmlTypes 1.0 Window { //visible: false @@ -8,25 +9,36 @@ Window { height: 800 title: qsTr("Bulletin") + property alias model: profilesColumn.model + ProfilesColumn { id: profilesColumn - model: profiles + model: identityList + + anchors.top: parent.top + anchors.left: parent.left + height: parent.height + width: 100 } GroupsColumn { id: groupsColumn - anchors.left: profilesColumn.right model: groups + + anchors.top: parent.top + anchors.left: profilesColumn.right + height: parent.height + width: 250 } - ListModel { + /*ListModel { id: profiles ListElement {name: "alice"; onion: "710829b408e8b368273cbc20b07f1c0d"; pcolor: "#ff0000"} ListElement {name: "bob"; onion: "a219b9740fc76367833cbc20b07d1cee"; pcolor: "#00ff00" } ListElement {name: "carol"; onion: "930829b408e8b364563cbc20b07a6560"; pcolor: "#0000ff" } ListElement {name: "+"; onion: "930829b408e8b364563cbc20b07a6560"; pcolor: "#a0a0a0" } - } + }*/ ListModel { id: groups @@ -39,7 +51,13 @@ Window { ListElement {type: "bulletin"; title: "Game Discussions"; groupid: "cc45892408123879273ec2a435cc4234"} } + Connections { + target: cwtchApp + onIdentitiesChanged: { /*ProfilesColumn.model = cwtchApp.identities ; + profilesColumn.update();*/ + } + } } diff --git a/qml/ProfilesColumn.qml b/qml/ProfilesColumn.qml index 44c7a04..f5c10f0 100644 --- a/qml/ProfilesColumn.qml +++ b/qml/ProfilesColumn.qml @@ -1,17 +1,14 @@ import QtQuick 2.0 - +import CustomQmlTypes 1.0 Rectangle { color: "#381F47" - height: parent.height - width: 100 - anchors.top: parent.top - anchors.left: parent.left - property alias model: list.model + Text { color: "white"; text: "length: " + cwtchApp.identities.length } + ListView { id: list @@ -29,8 +26,8 @@ Rectangle { width: 100 Column { - Rectangle { width: 80; height: 80; color: pcolor } - Text { color: "#a0a0a0"; text: name } + Rectangle { width: 80; height: 80; color: Pcolor } + Text { color: "#a0a0a0"; text: Name } } } } diff --git a/qml/main.qml b/qml/main.qml index 6b8bb2e..82a148c 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -2,6 +2,7 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import QtQuick.Window 2.0 +import CustomQmlTypes 1.0 // Root non-graphical object providing window management and other logic. QtObject { @@ -11,6 +12,8 @@ QtObject { onVisibleChanged: if (!visible) Qt.quit() } + property QIdentityListModel model: identityList + property LoadingWindow loadingWindow: LoadingWindow { visible: true } property Timer timer: Timer { @@ -29,7 +32,7 @@ QtObject { target: cwtchApp onTorStatusProgressChanged: { if (cwtchApp.torStatusProgress === 100) { - delay(1000, function() { + delay(500, function() { loadingWindow.visible = false mainWindow.visible = true })