Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pgipper committed Nov 12, 2022
1 parent 3b020fe commit 7f827cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 86 deletions.
82 changes: 2 additions & 80 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Any

from PyQt5.QtCore import QAbstractListModel, Qt, QModelIndex, QVariant, QAbstractTableModel, QAbstractItemModel
from PyQt5.QtCore import QAbstractListModel, Qt, QModelIndex
from PyQt5.QtGui import QStandardItemModel, QStandardItem

from qgis.core import QgsMessageLog, Qgis, QgsMapLayerProxyModel, QgsProject, QgsFeatureSource, QgsApplication
from qgis.core import QgsMessageLog, Qgis, QgsProject, QgsFeatureSource, QgsApplication

from .helpers import hasLayerException
from .settings import SUPPORTED_PROVIDERS
Expand Down Expand Up @@ -37,24 +37,6 @@ def removeRows(self, row: int, count: int = 1, parent: QModelIndex = ...) -> boo
return True


def getLayerModel():
model = QStandardItemModel()
for layer in [layerNode.layer() for layerNode in QgsProject.instance().layerTreeRoot().findLayers()]:
item = QStandardItem(layer.name())
item.setData(layer, role=DataRole)
item.setFlags(Qt.ItemIsUserCheckable)
if layer.providerType() in SUPPORTED_PROVIDERS:
item.setEnabled(True)
else:
item.setEnabled(False)
if hasLayerException(layer):
item.setCheckState(Qt.Checked)
else:
item.setCheckState(Qt.Unchecked)
model.appendRow(item)
return model


class LayerModel(QStandardItemModel):
def __init__(self, parent=None):
super(LayerModel, self).__init__(parent)
Expand All @@ -77,63 +59,3 @@ def __init__(self, parent=None):
item.setCheckState(Qt.Unchecked)
self.appendRow(item)


class LayerModel1(QgsMapLayerProxyModel):

def __init__(self, parent=None):
super().__init__(parent)
self.headers = ['Layer', self.tr('Do not filter'), self.tr('Description')]

def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...) -> Any:
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.headers[section]
return QVariant()

def data(self, index: QModelIndex, role: int = ...) -> Any:
if not index.isValid():
return QVariant()
if index.column() == 0:
return super().data(index, role=role)
if index.column() == 1 and role == Qt.DisplayRole:
return 'Checkbox'
if index.column() == 2:
layerIndex = self.index(row=index.row(), column=0)
return super().data(layerIndex, role=Qt.UserRole)
return QVariant()

def columnCount(self, parent: QModelIndex = ...) -> int:
return len(self.headers)


class LayerModel2(QAbstractTableModel):

def __init__(self, parent=None):
super().__init__(parent)
self.layers = list(QgsProject.instance().mapLayers().values())
self.headers = [self.tr('Do not filter'), 'Layer', 'Status']

def headerData(self, section: int, orientation: Qt.Orientation, role: int = ...) -> Any:
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
return self.headers[section]
return QVariant()

def display(self, index):
mapping = {
0: 'checkbox',
1: self.layers[index.row()].name(),
2: 'Layer wird nicht unterstützt' if self.layers[index.row()].providerType() == 'postgres' else '',
}
return mapping[index.column()]

def data(self, index, role=Qt.DisplayRole):
if role == Qt.DisplayRole:
return self.display(index)
elif role == DataRole:
return self.layers[index.row()]
return QVariant()

def rowCount(self, parent=QModelIndex()):
return len(self.layers)

def columnCount(self, parent: QModelIndex = ...) -> int:
return len(self.headers)
10 changes: 4 additions & 6 deletions widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from PyQt5 import uic
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QIcon, QPixmap, QColor, QStandardItemModel, QStandardItem
from PyQt5.QtGui import QIcon, QPixmap, QColor
from PyQt5.QtWidgets import (
QToolBar,
QWidget,
Expand All @@ -20,9 +20,7 @@
from qgis.gui import QgsExtentWidget, QgsRubberBand
from qgis.core import (
QgsApplication,
QgsExpressionContextUtils,
QgsGeometry,
QgsMapLayerProxyModel,
QgsProject,
QgsCoordinateReferenceSystem,
QgsCoordinateTransform,
Expand All @@ -33,7 +31,7 @@

from .helpers import removeFilterFromLayer, setLayerException, hasLayerException, addFilterToLayer
from .controller import FilterController
from .models import FilterModel, LayerModel, getLayerModel, DataRole
from .models import FilterModel, LayerModel, DataRole
from .filters import Predicate, FilterManager, FilterDefinition


Expand Down Expand Up @@ -77,7 +75,7 @@ def __init__(self, controller: FilterController, parent: Optional[QWidget] = Non
super().__init__(parent=parent)
self.controller = controller
self.setObjectName("mLayerExceptionsDialog")
self.setWindowTitle(self.tr("Check layers to exclude from filter"))
self.setWindowTitle(self.tr("Exclude layers from filter"))
self.setupUi()
self.listView.setModel(LayerModel())
self.adjustSize()
Expand Down Expand Up @@ -332,7 +330,7 @@ def startFilterFromExtentDialog(self):

def startLayerExceptionsDialog(self):
dlg = LayerExceptionsDialog(self.controller, parent=self)
dlg.show()
dlg.exec()

def startManageFiltersDialog(self):
dlg = ManageFiltersDialog(self.controller, parent=self)
Expand Down

0 comments on commit 7f827cd

Please sign in to comment.