Set parents for all QObjects

This commit is contained in:
miruka 2019-04-22 14:24:45 -04:00
parent 6664fc29e3
commit 34d2bd233d
10 changed files with 25 additions and 25 deletions

View File

@ -2,16 +2,15 @@
- Merge login page
- Refactoring
- Set Qt parents for all QObject
- Migrate more JS functions to their own files / Implement in Python instead
- Don't bake in size properties for components
- Better names and organization for the Message components
- Bug fixes
- Graphic bug when resizing window vertically for side pane?
- Fix tooltip hide()
- ![A picture](https://picsum.photos/256/256) not clickable?
- Icons aren't reloaded
- Bug when resizing window being tiled (i3), can't figure it out
- UI
- Use HRowLayout and its totalSpacing wherever possible

View File

@ -13,8 +13,8 @@ from .pyqt_future import futurize
class Backend(QObject):
def __init__(self) -> None:
super().__init__()
def __init__(self, parent: QObject) -> None:
super().__init__(parent)
self.pool: ThreadPoolExecutor = ThreadPoolExecutor(max_workers=6)
self._queried_displaynames: Dict[str, str] = {}
@ -24,8 +24,8 @@ class Backend(QObject):
from .client_manager import ClientManager
self._client_manager: ClientManager = ClientManager(self)
self._models: QMLModels = QMLModels()
self._html_filter: HtmlFilter = HtmlFilter()
self._models: QMLModels = QMLModels(self)
self._html_filter: HtmlFilter = HtmlFilter(self)
from .signal_manager import SignalManager
self._signal_manager: SignalManager = SignalManager(self)

View File

@ -1,7 +1,6 @@
# Copyright 2018 miruka
# This file is part of harmonyqt, licensed under GPLv3.
import hashlib
import json
import os
import platform

View File

@ -20,8 +20,8 @@ class HtmlFilter(QObject):
]]
def __init__(self) -> None:
super().__init__()
def __init__(self, parent: QObject) -> None:
super().__init__(parent)
self._sanitizer = sanitizer.Sanitizer(self.sanitizer_settings)
# The whitespace remover doesn't take <pre> into account

View File

@ -19,9 +19,9 @@ class ListModel(QAbstractListModel):
countChanged = pyqtSignal(int)
def __init__(self,
parent: QObject,
initial_data: Optional[List[NewItem]] = None,
container: Callable[..., MutableSequence] = list,
parent: Optional[QObject] = None) -> None:
container: Callable[..., MutableSequence] = list) -> None:
super().__init__(parent)
self._data: MutableSequence[ListItem] = container()

View File

@ -6,9 +6,11 @@ from .list_model import ListModel
class ListModelMap(QObject):
def __init__(self, models_container: Callable[..., MutableSequence] = list
def __init__(self,
parent: QObject,
models_container: Callable[..., MutableSequence] = list
) -> None:
super().__init__()
super().__init__(parent)
# Set the parent to prevent item garbage-collection on the C++ side
self.dict: DefaultDict[Any, ListModel] = \

View File

@ -10,11 +10,12 @@ from .list_model_map import ListModelMap
class QMLModels(QObject):
def __init__(self) -> None:
super().__init__()
self._accounts: ListModel = ListModel()
self._rooms: ListModelMap = ListModelMap()
self._room_events: ListModelMap = ListModelMap(models_container=Deque)
def __init__(self, parent: QObject) -> None:
super().__init__(parent)
self._accounts: ListModel = ListModel(parent)
self._rooms: ListModelMap = ListModelMap(parent)
self._room_events: ListModelMap = ListModelMap(parent,
models_container=Deque)
@pyqtProperty(ListModel, constant=True)

View File

@ -19,7 +19,6 @@ Controls1.SplitView {
pageStack.replace(
"chat/Root.qml", { userId: userId, roomId: roomId }
)
console.log("replaced")
}
id: pageStack

View File

@ -9,6 +9,8 @@ ColumnLayout {
readonly property var roomInfo:
Backend.models.rooms.get(userId).getWhere("roomId", roomId)
Component.onCompleted: console.log("replaced")
id: chatPage
spacing: 0

View File

@ -4,12 +4,11 @@
import logging
import sys
from pathlib import Path
from typing import Generator, Optional
from typing import Generator
from PyQt5.QtCore import QFileSystemWatcher, QObject, QTimer
from PyQt5.QtQml import QQmlApplicationEngine
from .__about__ import __doc__
from .app import Application
from .backend.backend import Backend
@ -19,11 +18,10 @@ from .backend.backend import Backend
class Engine(QQmlApplicationEngine):
def __init__(self,
app: Application,
debug: bool = False,
parent: Optional[QObject] = None) -> None:
super().__init__(parent)
debug: bool = False) -> None:
super().__init__(app)
self.app = app
self.backend = Backend()
self.backend = Backend(self)
self.app_dir = Path(sys.argv[0]).resolve().parent
# Set QML properties