185 @param max_ maximum number of entries (integer) |
185 @param max_ maximum number of entries (integer) |
186 @param parentMenu reference to the parent menu (QMenu) |
186 @param parentMenu reference to the parent menu (QMenu) |
187 @param menu reference to the menu to be populated (QMenu) |
187 @param menu reference to the menu to be populated (QMenu) |
188 """ |
188 """ |
189 if menu is None: |
189 if menu is None: |
190 v = QVariant(parent) |
190 v = parent |
191 |
191 |
192 title = parent.data().toString() |
192 title = parent.data() |
193 modelMenu = self.createBaseMenu() |
193 modelMenu = self.createBaseMenu() |
194 # triggered goes all the way up the menu structure |
194 # triggered goes all the way up the menu structure |
195 self.disconnect(modelMenu, SIGNAL("triggered(QAction*)"), |
195 self.disconnect(modelMenu, SIGNAL("triggered(QAction*)"), |
196 modelMenu.__actionTriggered) |
196 modelMenu.__actionTriggered) |
197 modelMenu.setTitle(title) |
197 modelMenu.setTitle(title) |
198 |
198 |
199 icon = parent.data(Qt.DecorationRole).toPyObject() |
199 icon = parent.data(Qt.DecorationRole) |
200 if icon == NotImplemented or icon is None: |
200 if icon == NotImplemented or icon is None: |
201 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
201 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
202 modelMenu.setIcon(icon) |
202 modelMenu.setIcon(icon) |
203 if parentMenu is not None: |
203 if parentMenu is not None: |
204 parentMenu.addMenu(modelMenu).setData(v) |
204 parentMenu.addMenu(modelMenu).setData(v) |
216 for i in range(end): |
216 for i in range(end): |
217 idx = self.__model.index(i, 0, parent) |
217 idx = self.__model.index(i, 0, parent) |
218 if self.__model.hasChildren(idx): |
218 if self.__model.hasChildren(idx): |
219 self.createMenu(idx, -1, menu) |
219 self.createMenu(idx, -1, menu) |
220 else: |
220 else: |
221 if self.__separatorRole != 0 and idx.data(self.__separatorRole).toBool(): |
221 if self.__separatorRole != 0 and idx.data(self.__separatorRole): |
222 self.addSeparator() |
222 self.addSeparator() |
223 else: |
223 else: |
224 menu.addAction(self.__makeAction(idx)) |
224 menu.addAction(self.__makeAction(idx)) |
225 |
225 |
226 if menu == self and i == self.__firstSeparator - 1: |
226 if menu == self and i == self.__firstSeparator - 1: |
231 Private method to create an action. |
231 Private method to create an action. |
232 |
232 |
233 @param idx index of the item to create an action for (QModelIndex) |
233 @param idx index of the item to create an action for (QModelIndex) |
234 @return reference to the created action (QAction) |
234 @return reference to the created action (QAction) |
235 """ |
235 """ |
236 icon = idx.data(Qt.DecorationRole).toPyObject() |
236 icon = idx.data(Qt.DecorationRole) |
237 if icon == NotImplemented or icon is None: |
237 if icon == NotImplemented or icon is None: |
238 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
238 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
239 action = self.makeAction(icon, idx.data().toString(), self) |
239 action = self.makeAction(icon, idx.data(), self) |
240 action.setStatusTip(idx.data(self.__statusBarTextRole).toString()) |
240 action.setStatusTip(idx.data(self.__statusBarTextRole)) |
241 |
241 |
242 v = QVariant(idx) |
242 v = idx |
243 action.setData(v) |
243 action.setData(v) |
244 |
244 |
245 return action |
245 return action |
246 |
246 |
247 def makeAction(self, icon, text, parent): |
247 def makeAction(self, icon, text, parent): |