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:
104
src/gui/PythonBridge/Privates/EventHandlers.qml
Normal file
104
src/gui/PythonBridge/Privates/EventHandlers.qml
Normal file
@@ -0,0 +1,104 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
import QtQuick 2.12
|
||||
import ".."
|
||||
import "../.."
|
||||
|
||||
QtObject {
|
||||
function onExitRequested(exitCode) {
|
||||
Qt.exit(exitCode)
|
||||
}
|
||||
|
||||
|
||||
function onAlertRequested() {
|
||||
if (Qt.application.state !== Qt.ApplicationActive) {
|
||||
window.alert(window.settings.alertOnMessageForMsec)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onCoroutineDone(uuid, result, error, traceback) {
|
||||
let onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
||||
let onError = Globals.pendingCoroutines[uuid].onError
|
||||
|
||||
delete Globals.pendingCoroutines[uuid]
|
||||
|
||||
if (error) {
|
||||
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||
const args = py.getattr(error, "args")
|
||||
|
||||
if (type === "CancelledError") {
|
||||
console.warn(`python: cancelled: ${uuid}`)
|
||||
return
|
||||
}
|
||||
|
||||
if (onError) {
|
||||
onError(type, args, error, traceback)
|
||||
return
|
||||
}
|
||||
|
||||
console.error(`python: ${uuid}\n${traceback}`)
|
||||
|
||||
if (window.hideErrorTypes.has(type)) {
|
||||
console.warn(
|
||||
"Not showing error popup for this type due to user choice"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
utils.makePopup(
|
||||
"Popups/UnexpectedErrorPopup.qml",
|
||||
window,
|
||||
{ errorType: type, traceback },
|
||||
)
|
||||
}
|
||||
|
||||
if (onSuccess) onSuccess(result)
|
||||
}
|
||||
|
||||
|
||||
function onLoopException(message, error, traceback) {
|
||||
// No need to log these here, the asyncio exception handler does it
|
||||
const type = py.getattr(py.getattr(error, "__class__"), "__name__")
|
||||
|
||||
if (window.hideErrorTypes.has(type)) {
|
||||
console.warn(
|
||||
"Not showing error popup for this type due to user choice"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
utils.makePopup(
|
||||
"Popups/UnexpectedErrorPopup.qml",
|
||||
window,
|
||||
{ errorType: type, message, traceback },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
function onModelItemInserted(syncId, index, item) {
|
||||
// print("insert", syncId, index, item)
|
||||
ModelStore.get(syncId).insert(index, item)
|
||||
}
|
||||
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
8
src/gui/PythonBridge/Privates/Globals.qml
Normal file
8
src/gui/PythonBridge/Privates/Globals.qml
Normal file
@@ -0,0 +1,8 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
pragma Singleton
|
||||
import QtQuick 2.12
|
||||
|
||||
QtObject {
|
||||
readonly property var pendingCoroutines: ({})
|
||||
}
|
||||
1
src/gui/PythonBridge/Privates/qmldir
Normal file
1
src/gui/PythonBridge/Privates/qmldir
Normal file
@@ -0,0 +1 @@
|
||||
singleton Globals 0.1 Globals.qml
|
||||
Reference in New Issue
Block a user