Begin yet another model refactor

Use native ListModel which require a lot of changes, but should be
much faster than the old way which exponentially slowed down to a crawl.
Also fix some popup bugs (leave/forget).

Not working yet: side pane keyboard controls, proper highlight,
room & member filtering, local echo replacement
This commit is contained in:
miruka
2019-12-02 16:29:29 -04:00
parent 2ce5e20efa
commit 9990fecc74
49 changed files with 826 additions and 781 deletions

View File

@@ -1,6 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import ".."
import "../.."
QtObject {
function onExitRequested(exitCode) {
@@ -16,10 +18,10 @@ QtObject {
function onCoroutineDone(uuid, result, error, traceback) {
let onSuccess = py.privates.pendingCoroutines[uuid].onSuccess
let onError = py.privates.pendingCoroutines[uuid].onError
let onSuccess = Globals.pendingCoroutines[uuid].onSuccess
let onError = Globals.pendingCoroutines[uuid].onError
delete py.privates.pendingCoroutines[uuid]
delete Globals.pendingCoroutines[uuid]
if (error) {
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
@@ -74,14 +76,29 @@ QtObject {
}
function onModelUpdated(syncId, data, serializedSyncId) {
if (serializedSyncId === "Account" || serializedSyncId[0] === "Room") {
py.callCoro("get_flat_mainpane_data", [], data => {
window.mainPaneModelSource = data
})
}
function onModelItemInserted(syncId, index, item) {
// print("insert", syncId, index, item)
ModelStore.get(syncId).insert(index, item)
}
window.modelSources[serializedSyncId] = data
window.modelSourcesChanged()
function onModelItemFieldChanged(syncId, oldIndex, newIndex, field, value){
// print("change", syncId, oldIndex, newIndex, field, value)
const model = ModelStore.get(syncId)
model.setProperty(oldIndex, field, value)
if (oldIndex !== newIndex) model.move(oldIndex, newIndex, 1)
}
function onModelItemDeleted(syncId, index) {
// print("del", syncId, index)
ModelStore.get(syncId).remove(index)
}
function onModelCleared(syncId) {
// print("clear", syncId)
ModelStore.get(syncId).clear()
}
}

View File

@@ -0,0 +1,8 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
pragma Singleton
import QtQuick 2.12
QtObject {
readonly property var pendingCoroutines: ({})
}

View File

@@ -0,0 +1 @@
singleton Globals 0.1 Globals.qml

View File

@@ -3,41 +3,16 @@
import QtQuick 2.12
import io.thp.pyotherside 1.5
import CppUtils 0.1
import "Privates"
Python {
id: py
Component.onCompleted: {
for (var func in privates.eventHandlers) {
if (! privates.eventHandlers.hasOwnProperty(func)) continue
setHandler(func.replace(/^on/, ""), privates.eventHandlers[func])
}
addImportPath("src")
addImportPath("qrc:/src")
importNames("backend.qml_bridge", ["BRIDGE"], () => {
loadSettings(() => {
callCoro("saved_accounts.any_saved", [], any => {
if (any) { py.callCoro("load_saved_accounts", []) }
py.startupAnyAccountsSaved = any
py.ready = true
})
})
})
}
property bool ready: false
property bool startupAnyAccountsSaved: false
readonly property QtObject privates: QtObject {
readonly property var pendingCoroutines: ({})
readonly property EventHandlers eventHandlers: EventHandlers {}
function makeFuture(callback) {
return Qt.createComponent("Future.qml")
.createObject(py, {bridge: py})
.createObject(py, { bridge: py })
}
}
@@ -47,15 +22,10 @@ Python {
}
function callSync(name, args=[]) {
return call_sync("BRIDGE.backend." + name, args)
}
function callCoro(name, args=[], onSuccess=null, onError=null) {
let uuid = name + "." + CppUtils.uuid()
privates.pendingCoroutines[uuid] = {onSuccess, onError}
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
let future = privates.makeFuture()
@@ -75,7 +45,7 @@ Python {
callCoro("get_client", [accountId], () => {
let uuid = accountId + "." + name + "." + CppUtils.uuid()
privates.pendingCoroutines[uuid] = {onSuccess, onError}
Globals.pendingCoroutines[uuid] = {onSuccess, onError}
let call_args = [accountId, name, uuid, args]

View File

@@ -0,0 +1,33 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import "Privates"
PythonBridge {
Component.onCompleted: {
for (var func in eventHandlers) {
if (! eventHandlers.hasOwnProperty(func)) continue
setHandler(func.replace(/^on/, ""), eventHandlers[func])
}
addImportPath("src")
addImportPath("qrc:/src")
importNames("backend.qml_bridge", ["BRIDGE"], () => {
loadSettings(() => {
callCoro("saved_accounts.any_saved", [], any => {
if (any) { callCoro("load_saved_accounts", []) }
startupAnyAccountsSaved = any
ready = true
})
})
})
}
property bool ready: false
property bool startupAnyAccountsSaved: false
readonly property EventHandlers eventHandlers: EventHandlers {}
}