84 Private slot to handle the addition of a project to the multi project. |
88 Private slot to handle the addition of a project to the multi project. |
85 |
89 |
86 @param project reference to the project data dictionary |
90 @param project reference to the project data dictionary |
87 """ |
91 """ |
88 self.__addProject(project) |
92 self.__addProject(project) |
89 self.sortItems() |
93 self.sortItems(0, Qt.AscendingOrder) |
90 |
94 |
91 def __projectRemoved(self, project): |
95 def __projectRemoved(self, project): |
92 """ |
96 """ |
93 Private slot to handle the removal of a project from the multi project. |
97 Private slot to handle the removal of a project from the multi project. |
94 |
98 |
95 @param project reference to the project data dictionary |
99 @param project reference to the project data dictionary |
96 """ |
100 """ |
97 row = self.__findProjectItem(project) |
101 itm = self.__findProjectItem(project) |
98 if row > -1: |
102 if itm: |
99 itm = self.takeItem(row) |
103 parent = itm.parent() |
|
104 parent.removeChild(itm) |
100 del itm |
105 del itm |
|
106 if parent.childCount() == 0: |
|
107 top = self.takeTopLevelItem(self.indexOfTopLevelItem(parent)) |
|
108 del top |
101 |
109 |
102 def __projectDataChanged(self, project): |
110 def __projectDataChanged(self, project): |
103 """ |
111 """ |
104 Private slot to handle the change of a project of the multi project. |
112 Private slot to handle the change of a project of the multi project. |
105 |
113 |
106 @param project reference to the project data dictionary |
114 @param project reference to the project data dictionary |
107 """ |
115 """ |
108 row = self.__findProjectItem(project) |
116 itm = self.__findProjectItem(project) |
109 if row > -1: |
117 if itm: |
110 self.__setItemData(self.item(row), project) |
118 parent = itm.parent() |
|
119 if parent.text(0) != project["category"]: |
|
120 self.__projectRemoved(project) |
|
121 self.__addProject(project) |
|
122 else: |
|
123 self.__setItemData(itm, project) |
111 |
124 |
112 self.sortItems() |
125 self.sortItems(0, Qt.AscendingOrder) |
113 |
126 |
114 def __projectOpened(self, projectfile): |
127 def __projectOpened(self, projectfile): |
115 """ |
128 """ |
116 Private slot to handle the opening of a project. |
129 Private slot to handle the opening of a project. |
117 |
130 |
120 project = { |
133 project = { |
121 'name': "", |
134 'name': "", |
122 'file': projectfile, |
135 'file': projectfile, |
123 'master': False, |
136 'master': False, |
124 'description': "", |
137 'description': "", |
|
138 'category': "", |
125 } |
139 } |
126 row = self.__findProjectItem(project) |
140 itm = self.__findProjectItem(project) |
127 if row > -1: |
141 if itm: |
128 self.item(row).setSelected(True) |
142 itm.setSelected(True) |
129 |
143 |
130 def __contextMenuRequested(self, coord): |
144 def __contextMenuRequested(self, coord): |
131 """ |
145 """ |
132 Private slot to show the context menu. |
146 Private slot to show the context menu. |
133 |
147 |
134 @param coord the position of the mouse pointer (QPoint) |
148 @param coord the position of the mouse pointer (QPoint) |
135 """ |
149 """ |
136 itm = self.itemAt(coord) |
150 itm = self.itemAt(coord) |
137 if itm is None: |
151 if itm is None or itm.parent() is None: |
138 self.__backMenu.popup(self.mapToGlobal(coord)) |
152 self.__backMenu.popup(self.mapToGlobal(coord)) |
139 else: |
153 else: |
140 self.__menu.popup(self.mapToGlobal(coord)) |
154 self.__menu.popup(self.mapToGlobal(coord)) |
141 |
155 |
142 def __openItem(self, itm=None): |
156 def __openItem(self, itm=None): |
143 """ |
157 """ |
144 Private slot to open a project. |
158 Private slot to open a project. |
145 |
159 |
146 @param itm reference to the project item to be opened (QListWidgetItem) |
160 @param itm reference to the project item to be opened (QTreeWidgetItem) |
147 """ |
161 """ |
148 if itm is None: |
162 if itm is None: |
149 itm = self.currentItem() |
163 itm = self.currentItem() |
150 if itm is None: |
164 if itm is None or itm.parent() is None: |
151 return |
165 return |
152 |
166 |
153 if not self.__openingProject: |
167 if not self.__openingProject: |
154 filename = itm.data(Qt.UserRole) |
168 filename = itm.data(0, Qt.UserRole) |
155 if filename: |
169 if filename: |
156 self.__openingProject = True |
170 self.__openingProject = True |
157 self.multiProject.openProject(filename) |
171 self.multiProject.openProject(filename) |
158 self.__openingProject = False |
172 self.__openingProject = False |
159 |
173 |
160 ########################################################################### |
174 ########################################################################### |
161 ## Private methods below |
175 ## Private methods below |
162 ########################################################################### |
176 ########################################################################### |
163 |
177 |
|
178 def __findCategoryItem(self, category): |
|
179 """ |
|
180 Private method to find the item for a category. |
|
181 |
|
182 @param category category to search for (string) |
|
183 @return reference to the category item or None, if there is |
|
184 no such item (QTreeWidgetItem or None) |
|
185 """ |
|
186 if category == "": |
|
187 category = self.tr("Not categorized") |
|
188 for index in range(self.topLevelItemCount()): |
|
189 itm = self.topLevelItem(index) |
|
190 if itm.text(0) == category: |
|
191 return itm |
|
192 |
|
193 return None |
|
194 |
164 def __addProject(self, project): |
195 def __addProject(self, project): |
165 """ |
196 """ |
166 Private method to add a project to the list. |
197 Private method to add a project to the list. |
167 |
198 |
168 @param project reference to the project data dictionary |
199 @param project reference to the project data dictionary |
169 """ |
200 """ |
170 itm = QListWidgetItem(self) |
201 parent = self.__findCategoryItem(project['category']) |
|
202 if parent is None: |
|
203 if project['category']: |
|
204 parent = QTreeWidgetItem(self, [project['category']]) |
|
205 else: |
|
206 parent = QTreeWidgetItem(self, [self.tr("Not categorized")]) |
|
207 parent.setExpanded(True) |
|
208 itm = QTreeWidgetItem(parent) |
171 self.__setItemData(itm, project) |
209 self.__setItemData(itm, project) |
172 |
210 |
173 def __setItemData(self, itm, project): |
211 def __setItemData(self, itm, project): |
174 """ |
212 """ |
175 Private method to set the data of a project item. |
213 Private method to set the data of a project item. |
176 |
214 |
177 @param itm reference to the item to be set (QListWidgetItem) |
215 @param itm reference to the item to be set (QTreeWidgetItem) |
178 @param project reference to the project data dictionary |
216 @param project reference to the project data dictionary |
179 """ |
217 """ |
180 itm.setText(project['name']) |
218 itm.setText(0, project['name']) |
181 if project['master']: |
219 if project['master']: |
182 itm.setIcon(UI.PixmapCache.getIcon("masterProject.png")) |
220 itm.setIcon(0, UI.PixmapCache.getIcon("masterProject.png")) |
183 else: |
221 else: |
184 itm.setIcon(UI.PixmapCache.getIcon("empty.png")) |
222 itm.setIcon(0, UI.PixmapCache.getIcon("empty.png")) |
185 itm.setToolTip(project['file']) |
223 itm.setToolTip(0, project['file']) |
186 itm.setData(Qt.UserRole, project['file']) |
224 itm.setData(0, Qt.UserRole, project['file']) |
187 |
225 |
188 def __findProjectItem(self, project): |
226 def __findProjectItem(self, project): |
189 """ |
227 """ |
190 Private method to search a specific project item. |
228 Private method to search a specific project item. |
191 |
229 |
192 @param project reference to the project data dictionary |
230 @param project reference to the project data dictionary |
193 @return row number of the project, -1 if not found (integer) |
231 @return reference to the item (QTreeWidgetItem) or None |
194 """ |
232 """ |
195 row = 0 |
233 for topIndex in range(self.topLevelItemCount()): |
196 while row < self.count(): |
234 topItm = self.topLevelItem(topIndex) |
197 itm = self.item(row) |
235 for childIndex in range(topItm.childCount()): |
198 data = itm.data(Qt.UserRole) |
236 itm = topItm.child(childIndex) |
199 if data == project['file']: |
237 data = itm.data(0, Qt.UserRole) |
200 return row |
238 if data == project['file']: |
201 row += 1 |
239 return itm |
202 |
240 |
203 return -1 |
241 return None |
204 |
242 |
205 def __removeProject(self): |
243 def __removeProject(self): |
206 """ |
244 """ |
207 Private method to handle the Remove context menu entry. |
245 Private method to handle the Remove context menu entry. |
208 """ |
246 """ |
209 itm = self.currentItem() |
247 itm = self.currentItem() |
210 if itm is not None: |
248 if itm is not None and itm.parent() is not None: |
211 filename = itm.data(Qt.UserRole) |
249 filename = itm.data(0, Qt.UserRole) |
212 if filename: |
250 if filename: |
213 self.multiProject.removeProject(filename) |
251 self.multiProject.removeProject(filename) |
214 |
252 |
215 def __showProjectProperties(self): |
253 def __showProjectProperties(self): |
216 """ |
254 """ |
217 Private method to show the data of a project entry. |
255 Private method to show the data of a project entry. |
218 """ |
256 """ |
219 itm = self.currentItem() |
257 itm = self.currentItem() |
220 if itm is not None: |
258 if itm is not None and itm.parent() is not None: |
221 filename = itm.data(Qt.UserRole) |
259 filename = itm.data(0, Qt.UserRole) |
222 if filename: |
260 if filename: |
223 project = self.multiProject.getProject(filename) |
261 project = self.multiProject.getProject(filename) |
224 if project is not None: |
262 if project is not None: |
225 from .AddProjectDialog import AddProjectDialog |
263 from .AddProjectDialog import AddProjectDialog |
226 dlg = AddProjectDialog(self, project=project) |
264 dlg = AddProjectDialog( |
|
265 self, project=project, |
|
266 categories=self.multiProject.getCategories()) |
227 if dlg.exec_() == QDialog.Accepted: |
267 if dlg.exec_() == QDialog.Accepted: |
228 name, filename, isMaster, description = dlg.getData() |
268 name, filename, isMaster, description, category = \ |
|
269 dlg.getData() |
229 project = { |
270 project = { |
230 'name': name, |
271 'name': name, |
231 'file': filename, |
272 'file': filename, |
232 'master': isMaster, |
273 'master': isMaster, |
233 'description': description, |
274 'description': description, |
|
275 'category': category, |
234 } |
276 } |
235 self.multiProject.changeProjectProperties(project) |
277 self.multiProject.changeProjectProperties(project) |
236 |
278 |
237 def __addNewProject(self): |
279 def __addNewProject(self): |
238 """ |
280 """ |