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