-
Notifications
You must be signed in to change notification settings - Fork 4
/
sublayersdialog.py
95 lines (80 loc) · 3.46 KB
/
sublayersdialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtWidgets import QTreeWidgetItem, QDialog, QAbstractItemView
from .ui_sublayersdialog import Ui_SublayersDialog
class SortTreeWidgetItem(QTreeWidgetItem):
def __init__(self, tree):
QTreeWidgetItem.__init__(self, tree)
def __init__(self, tree, stringlist):
QTreeWidgetItem.__init__(self, tree, stringlist)
def __lt__(self, otherItem):
sortColumn = self.treeWidget().sortColumn()
if sortColumn == 0 or sortColumn == 2:
if otherItem.text(sortColumn).toInt() > self.text(
sortColumn).toInt():
return True
else:
return False
else:
if otherItem.text(sortColumn) > self.text(sortColumn):
return True
else:
return False
class SublayersDialog(QDialog, Ui_SublayersDialog):
def __init__(self):
QDialog.__init__(self, None)
self.setupUi(self)
self.mSublayersTreeWidget.setSelectionMode(
QAbstractItemView.ExtendedSelection)
def setupLayerList(self, layerList):
self.mSublayersTreeWidget.setHeaderLabels(["Layer"])
self.mSublayersTreeWidget.setSortingEnabled(False)
for layer in layerList:
newItem = QTreeWidgetItem(self.mSublayersTreeWidget, [layer])
self.mSublayersTreeWidget.addTopLevelItem(newItem)
def setupSublayerList(self, sublayerStringList):
# Create header
headerLabels = []
headerLabels.append("Layer ID")
headerLabels.append("Layer name")
headerLabels.append("Features")
headerLabels.append("Geometry type")
self.mSublayersTreeWidget.setHeaderLabels(headerLabels)
self.mSublayersTreeWidget.setSortingEnabled(True)
# insert sublayer information into mSublayersTreeWidget
for sublayerString in sublayerStringList:
entryStringList = sublayerString.split(":")
if len(entryStringList) < 4:
continue
idString = entryStringList[0]
featureString = entryStringList[len(entryStringList) - 2]
geometryTypeString = entryStringList[len(entryStringList) - 1]
nameString = ""
# the name could also contain ':'
for j in range(1, len(entryStringList) - 2):
if j > 1:
nameString += ":"
nameString += entryStringList[j]
newEntryStringList = []
newEntryStringList.append(idString)
newEntryStringList.append(nameString)
newEntryStringList.append(featureString)
newEntryStringList.append(geometryTypeString)
newItem = SortTreeWidgetItem(
self.mSublayersTreeWidget, newEntryStringList)
newItem.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
self.mSublayersTreeWidget.addTopLevelItem(newItem)
# sort layer name per default
self.mSublayersTreeWidget.sortItems(1, Qt. AscendingOrder)
def layerNames(self):
result = []
for item in self.mSublayersTreeWidget.selectedItems():
result.append(item.text(0))
return result
# go through all the selected entries and return a QStringList with the
# sublayer names
def subLayerNames(self):
result = []
for item in self.mSublayersTreeWidget.selectedItems():
result.append(item.text(1))
return result