Helpviewer/QtHelpFiltersDialog.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3217
87b8a0745edd
child 3656
441956d8fce5
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
11 11
12 import sqlite3 12 import sqlite3
13 13
14 from PyQt4.QtCore import pyqtSlot, Qt 14 from PyQt4.QtCore import pyqtSlot, Qt
15 from PyQt4.QtGui import QDialog, QTreeWidgetItem, QListWidgetItem, \ 15 from PyQt4.QtGui import QDialog, QTreeWidgetItem, QListWidgetItem, \
16 QInputDialog, QLineEdit 16 QInputDialog, QLineEdit, QItemSelectionModel
17 from PyQt4.QtHelp import QHelpEngineCore 17 from PyQt4.QtHelp import QHelpEngineCore
18
19 from E5Gui import E5MessageBox
18 20
19 from .Ui_QtHelpFiltersDialog import Ui_QtHelpFiltersDialog 21 from .Ui_QtHelpFiltersDialog import Ui_QtHelpFiltersDialog
20 22
21 23
22 class QtHelpFiltersDialog(QDialog, Ui_QtHelpFiltersDialog): 24 class QtHelpFiltersDialog(QDialog, Ui_QtHelpFiltersDialog):
31 @param parent reference to the parent widget (QWidget) 33 @param parent reference to the parent widget (QWidget)
32 """ 34 """
33 super(QtHelpFiltersDialog, self).__init__(parent) 35 super(QtHelpFiltersDialog, self).__init__(parent)
34 self.setupUi(self) 36 self.setupUi(self)
35 37
38 self.removeButton.setEnabled(False)
39 self.removeAttributeButton.setEnabled(False)
40
36 self.__engine = engine 41 self.__engine = engine
37
38 self.attributesList.header().hide()
39 42
40 self.filtersList.clear() 43 self.filtersList.clear()
41 self.attributesList.clear() 44 self.attributesList.clear()
42 45
43 help = QHelpEngineCore(self.__engine.collectionFile()) 46 help = QHelpEngineCore(self.__engine.collectionFile())
55 self.__filterMap[filter] = atts 58 self.__filterMap[filter] = atts
56 59
57 self.filtersList.addItems(sorted(self.__filterMap.keys())) 60 self.filtersList.addItems(sorted(self.__filterMap.keys()))
58 for attr in help.filterAttributes(): 61 for attr in help.filterAttributes():
59 QTreeWidgetItem(self.attributesList, [attr]) 62 QTreeWidgetItem(self.attributesList, [attr])
63 self.attributesList.sortItems(0, Qt.AscendingOrder)
60 64
61 if self.__filterMap: 65 if self.__filterMap:
62 self.filtersList.setCurrentRow(0) 66 self.filtersList.setCurrentRow(0)
63 67
64 @pyqtSlot(QListWidgetItem, QListWidgetItem) 68 @pyqtSlot(QListWidgetItem, QListWidgetItem)
78 if itm.text(0) in checkedList: 82 if itm.text(0) in checkedList:
79 itm.setCheckState(0, Qt.Checked) 83 itm.setCheckState(0, Qt.Checked)
80 else: 84 else:
81 itm.setCheckState(0, Qt.Unchecked) 85 itm.setCheckState(0, Qt.Unchecked)
82 86
87 @pyqtSlot()
88 def on_filtersList_itemSelectionChanged(self):
89 """
90 Private slot handling a change of selected filters.
91 """
92 self.removeButton.setEnabled(
93 len(self.filtersList.selectedItems()) > 0)
94
83 @pyqtSlot(QTreeWidgetItem, int) 95 @pyqtSlot(QTreeWidgetItem, int)
84 def on_attributesList_itemChanged(self, item, column): 96 def on_attributesList_itemChanged(self, item, column):
85 """ 97 """
86 Private slot to handle a change of an attribute. 98 Private slot to handle a change of an attribute.
87 99
101 if itm.checkState(0) == Qt.Checked: 113 if itm.checkState(0) == Qt.Checked:
102 newAtts.append(itm.text(0)) 114 newAtts.append(itm.text(0))
103 self.__filterMap[filter] = newAtts 115 self.__filterMap[filter] = newAtts
104 116
105 @pyqtSlot() 117 @pyqtSlot()
118 def on_attributesList_itemSelectionChanged(self):
119 """
120 Private slot handling the selection of attributes.
121 """
122 self.removeAttributeButton.setEnabled(
123 len(self.attributesList.selectedItems()) != 0)
124
125 @pyqtSlot()
106 def on_addButton_clicked(self): 126 def on_addButton_clicked(self):
107 """ 127 """
108 Private slot to add a new filter. 128 Private slot to add a new filter.
109 """ 129 """
110 filter, ok = QInputDialog.getText( 130 filter, ok = QInputDialog.getText(
111 None, 131 None,
112 self.trUtf8("Add Filter"), 132 self.tr("Add Filter"),
113 self.trUtf8("Filter name:"), 133 self.tr("Filter name:"),
114 QLineEdit.Normal) 134 QLineEdit.Normal)
115 if not filter: 135 if not filter:
116 return 136 return
117 137
118 if filter not in self.__filterMap: 138 if filter not in self.__filterMap:
123 self.filtersList.setCurrentItem(itm) 143 self.filtersList.setCurrentItem(itm)
124 144
125 @pyqtSlot() 145 @pyqtSlot()
126 def on_removeButton_clicked(self): 146 def on_removeButton_clicked(self):
127 """ 147 """
128 Private slot to remove a filter. 148 Private slot to remove the selected filters.
129 """ 149 """
130 row = self.filtersList.currentRow() 150 ok = E5MessageBox.yesNo(
131 itm = self.filtersList.takeItem(row) 151 self,
132 if itm is None: 152 self.tr("Remove Filters"),
133 return 153 self.tr(
134 154 """Do you really want to remove the selected filters """
135 del self.__filterMap[itm.text()] 155 """from the database?"""))
136 self.__removedFilters.append(itm.text()) 156 if not ok:
137 del itm 157 return
158
159 items = self.filtersList.selectedItems()
160 for item in items:
161 itm = self.filtersList.takeItem(self.filtersList.row(item))
162 if itm is None:
163 continue
164
165 del self.__filterMap[itm.text()]
166 self.__removedFilters.append(itm.text())
167 del itm
168
138 if self.filtersList.count(): 169 if self.filtersList.count():
139 self.filtersList.setCurrentRow(row) 170 self.filtersList.setCurrentRow(
171 0, QItemSelectionModel.ClearAndSelect)
140 172
141 @pyqtSlot() 173 @pyqtSlot()
142 def on_removeAttributeButton_clicked(self): 174 def on_removeAttributeButton_clicked(self):
143 """ 175 """
144 Private slot to remove a filter attribute. 176 Private slot to remove the selected filter attributes.
145 """ 177 """
146 itm = self.attributesList.takeTopLevelItem( 178 ok = E5MessageBox.yesNo(
147 self.attributesList.indexOfTopLevelItem( 179 self,
148 self.attributesList.currentItem())) 180 self.tr("Remove Attributes"),
149 if itm is None: 181 self.tr(
150 return 182 """Do you really want to remove the selected attributes """
151 183 """from the database?"""))
152 attr = itm.text(0) 184 if not ok:
153 self.__removedAttributes.append(attr) 185 return
186
187 items = self.attributesList.selectedItems()
188 for item in items:
189 itm = self.attributesList.takeTopLevelItem(
190 self.attributesList.indexOfTopLevelItem(item))
191 if itm is None:
192 continue
193
194 attr = itm.text(0)
195 self.__removedAttributes.append(attr)
196 for filter in self.__filterMap:
197 if attr in self.__filterMap[filter]:
198 self.__filterMap[filter].remove(attr)
199
200 del itm
201
202 @pyqtSlot()
203 def on_unusedAttributesButton_clicked(self):
204 """
205 Private slot to select all unused attributes.
206 """
207 # step 1: determine all used attributes
208 attributes = set()
154 for filter in self.__filterMap: 209 for filter in self.__filterMap:
155 if attr in self.__filterMap[filter]: 210 attributes |= set(self.__filterMap[filter])
156 self.__filterMap[filter].remove(attr) 211
157 212 # step 2: select all unused attribute items
158 del itm 213 self.attributesList.clearSelection()
214 for row in range(self.attributesList.topLevelItemCount()):
215 itm = self.attributesList.topLevelItem(row)
216 if itm.text(0) not in attributes:
217 itm.setSelected(True)
159 218
160 def __removeAttributes(self): 219 def __removeAttributes(self):
161 """ 220 """
162 Private method to remove attributes from the Qt Help database. 221 Private method to remove attributes from the Qt Help database.
163 """ 222 """

eric ide

mercurial