Skip to content

Commit

Permalink
avoid repeatedly update ui (#3)
Browse files Browse the repository at this point in the history
- Attribute forms are opened smoother and faster
- Should be checked in QGIS if some updateUi calls could be avoided
  • Loading branch information
domi4484 authored Oct 26, 2021
1 parent abdfdf5 commit 96bab29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ordered_relation_editor/core/ordered_relation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def reloadData(self):
self._related_features = []

if Debug:
print('Debug', self._ordering_field, self._relation.isValid(), self._relation.id(), self._feature.isValid())
QgsMessageLog.logMessage("Reload data: Ordering field='{0}', Relation valid/id={1}/'{2}', Feature valid={3}"
.format(self._ordering_field, self._relation.isValid(), self._relation.id(), self._feature.isValid()))

if len(self._ordering_field) > 0 and self._relation.isValid() and self._feature.isValid():
request = self._relation.getRelatedFeaturesRequest(self._feature)
Expand Down
14 changes: 11 additions & 3 deletions ordered_relation_editor/gui/ordered_relation_editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

from PyQt5.QtQuickWidgets import QQuickWidget
import os
from qgis.PyQt.QtCore import QUrl, QModelIndex
from qgis.PyQt.QtCore import QUrl, QModelIndex, QTimer
from qgis.PyQt.QtWidgets import QVBoxLayout
from qgis.PyQt.uic import loadUiType
from qgis.core import QgsFeature, QgsApplication
from qgis.core import QgsFeature, QgsApplication, QgsMessageLog
from qgis.gui import QgsAbstractRelationEditorWidget, QgsAttributeForm, QgsScrollArea
from ordered_relation_editor.core.ordered_relation_model import OrderedRelationModel

Expand All @@ -25,6 +25,9 @@ class OrderedRelationEditorWidget(QgsAbstractRelationEditorWidget, WidgetUi):

def __init__(self, config, parent):
super().__init__(config, parent)
self.updateUiTimer = QTimer()
self.updateUiTimer.setSingleShot(True)
self.updateUiTimer.timeout.connect(self.updateUiTimeout)
self.setupUi(self)
self.addFeatureToolButton.setIcon(QgsApplication.getThemeIcon('/mActionNewTableRow.svg'))
self.addFeatureToolButton.clicked.connect(self.addFeature)
Expand Down Expand Up @@ -81,7 +84,12 @@ def update_buttons(self):
self.deleteFeatureToolButton.setEnabled(enabled and view_has_selection)

def updateUi(self):
# print('updateUi')
self.updateUiTimer.start(200)

def updateUiTimeout(self):
if Debug:
QgsMessageLog.logMessage("updateUiTimeout()")

self.model.init(self.relation(), self.ordering_field, self.feature(), self.image_path, self.description)

# form view
Expand Down

0 comments on commit 96bab29

Please sign in to comment.