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