13 from .E5ModelMenu import E5ModelMenu |
13 from .E5ModelMenu import E5ModelMenu |
14 |
14 |
15 class E5ModelToolBar(QToolBar): |
15 class E5ModelToolBar(QToolBar): |
16 """ |
16 """ |
17 Class implementing a tool bar populated from a QAbstractItemModel. |
17 Class implementing a tool bar populated from a QAbstractItemModel. |
|
18 |
|
19 @signal activated(QModelIndex) emitted when an action has been triggered |
18 """ |
20 """ |
|
21 activated = pyqtSignal(QModelIndex) |
|
22 |
19 def __init__(self, title = None, parent = None): |
23 def __init__(self, title = None, parent = None): |
20 """ |
24 """ |
21 Constructor |
25 Constructor |
22 |
26 |
23 @param title title for the tool bar (string) |
27 @param title title for the tool bar (string) |
48 Public method to set the model for the tool bar. |
52 Public method to set the model for the tool bar. |
49 |
53 |
50 @param model reference to the model (QAbstractItemModel) |
54 @param model reference to the model (QAbstractItemModel) |
51 """ |
55 """ |
52 if self.__model is not None: |
56 if self.__model is not None: |
53 self.disconnect(self.__model, |
57 self.__model.modelReset[()].disconnect(self._build) |
54 SIGNAL("modelReset()"), |
58 self.__model.rowsInserted[QModelIndex, int, int].disconnect(self._build) |
55 self._build) |
59 self.__model.rowsRemoved[QModelIndex, int, int].disconnect(self._build) |
56 self.disconnect(self.__model, |
60 self.__model.dataChanged[QModelIndex, QModelIndex].disconnect(self._build) |
57 SIGNAL("rowsInserted(const QModelIndex&, int, int)"), |
|
58 self._build) |
|
59 self.disconnect(self.__model, |
|
60 SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), |
|
61 self._build) |
|
62 self.disconnect(self.__model, |
|
63 SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), |
|
64 self._build) |
|
65 |
61 |
66 self.__model = model |
62 self.__model = model |
67 |
63 |
68 if self.__model is not None: |
64 if self.__model is not None: |
69 self.connect(self.__model, |
65 self.__model.modelReset[()].connect(self._build) |
70 SIGNAL("modelReset()"), |
66 self.__model.rowsInserted[QModelIndex, int, int].connect(self._build) |
71 self._build) |
67 self.__model.rowsRemoved[QModelIndex, int, int].connect(self._build) |
72 self.connect(self.__model, |
68 self.__model.dataChanged[QModelIndex, QModelIndex].connect(self._build) |
73 SIGNAL("rowsInserted(const QModelIndex&, int, int)"), |
|
74 self._build) |
|
75 self.connect(self.__model, |
|
76 SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), |
|
77 self._build) |
|
78 self.connect(self.__model, |
|
79 SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), |
|
80 self._build) |
|
81 |
69 |
82 def model(self): |
70 def model(self): |
83 """ |
71 """ |
84 Public method to get a reference to the model. |
72 Public method to get a reference to the model. |
85 |
73 |
174 self._mouseButton = evt.button() |
162 self._mouseButton = evt.button() |
175 self._keyboardModifiers = evt.modifiers() |
163 self._keyboardModifiers = evt.modifiers() |
176 act = obj.defaultAction() |
164 act = obj.defaultAction() |
177 idx = self.index(act) |
165 idx = self.index(act) |
178 if idx.isValid(): |
166 if idx.isValid(): |
179 self.emit(SIGNAL("activated(const QModelIndex&)"), idx) |
167 self.activated[QModelIndex].emit(idx) |
180 elif evt.type() == QEvent.MouseButtonPress: |
168 elif evt.type() == QEvent.MouseButtonPress: |
181 if evt.buttons() & Qt.LeftButton: |
169 if evt.buttons() & Qt.LeftButton: |
182 self.__dragStartPosition = self.mapFromGlobal(evt.globalPos()) |
170 self.__dragStartPosition = self.mapFromGlobal(evt.globalPos()) |
183 |
171 |
184 return False |
172 return False |