14 |
14 |
15 class E5ModelMenu(QMenu): |
15 class E5ModelMenu(QMenu): |
16 """ |
16 """ |
17 Class implementing a menu populated from a QAbstractItemModel. |
17 Class implementing a menu populated from a QAbstractItemModel. |
18 |
18 |
19 @signal activated(const QModelIndex&) emitted when an action has been triggered |
19 @signal activated(QModelIndex) emitted when an action has been triggered |
20 """ |
20 """ |
|
21 activated = pyqtSignal(QModelIndex) |
|
22 |
21 def __init__(self, parent = None): |
23 def __init__(self, parent = None): |
22 """ |
24 """ |
23 Constructor |
25 Constructor |
24 |
26 |
25 @param parent reference to the parent widget (QWidget) |
27 @param parent reference to the parent widget (QWidget) |
41 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) |
43 self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier) |
42 self.__dropRow = -1 |
44 self.__dropRow = -1 |
43 self.__dropIndex = None |
45 self.__dropIndex = None |
44 |
46 |
45 self.aboutToShow.connect(self.__aboutToShow) |
47 self.aboutToShow.connect(self.__aboutToShow) |
46 self.connect(self, SIGNAL("triggered(QAction*)"), self.__actionTriggered) |
48 self.triggered.connect(self.__actionTriggered) |
47 |
49 |
48 def prePopulated(self): |
50 def prePopulated(self): |
49 """ |
51 """ |
50 Public method to add any actions before the tree. |
52 Public method to add any actions before the tree. |
51 |
53 |
190 v = parent |
192 v = parent |
191 |
193 |
192 title = parent.data() |
194 title = parent.data() |
193 modelMenu = self.createBaseMenu() |
195 modelMenu = self.createBaseMenu() |
194 # triggered goes all the way up the menu structure |
196 # triggered goes all the way up the menu structure |
195 self.disconnect(modelMenu, SIGNAL("triggered(QAction*)"), |
197 modelMenu.triggered.disconnect(modelMenu.__actionTriggered) |
196 modelMenu.__actionTriggered) |
|
197 modelMenu.setTitle(title) |
198 modelMenu.setTitle(title) |
198 |
199 |
199 icon = parent.data(Qt.DecorationRole) |
200 icon = parent.data(Qt.DecorationRole) |
200 if icon == NotImplemented or icon is None: |
201 if icon == NotImplemented or icon is None: |
201 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
202 icon = UI.PixmapCache.getIcon("defaultIcon.png") |
266 |
267 |
267 @param action reference to the action that was triggered (QAction) |
268 @param action reference to the action that was triggered (QAction) |
268 """ |
269 """ |
269 idx = self.index(action) |
270 idx = self.index(action) |
270 if idx.isValid(): |
271 if idx.isValid(): |
271 self.emit(SIGNAL("activated(const QModelIndex&)"), idx) |
272 self.activated[QModelIndex].emit(idx) |
272 |
273 |
273 def index(self, action): |
274 def index(self, action): |
274 """ |
275 """ |
275 Public method to get the index of an action. |
276 Public method to get the index of an action. |
276 |
277 |