23 |
23 |
24 def __init__(self, title=None, parent=None): |
24 def __init__(self, title=None, parent=None): |
25 """ |
25 """ |
26 Constructor |
26 Constructor |
27 |
27 |
28 @param title title for the tool bar (string) |
28 @param title title for the tool bar |
29 @param parent reference to the parent widget (QWidget) |
29 @type str |
|
30 @param parent reference to the parent widget |
|
31 @type QWidget |
30 """ |
32 """ |
31 if title is not None: |
33 if title is not None: |
32 super().__init__(title, parent) |
34 super().__init__(title, parent) |
33 else: |
35 else: |
34 super().__init__(parent) |
36 super().__init__(parent) |
50 |
52 |
51 def setModel(self, model): |
53 def setModel(self, model): |
52 """ |
54 """ |
53 Public method to set the model for the tool bar. |
55 Public method to set the model for the tool bar. |
54 |
56 |
55 @param model reference to the model (QAbstractItemModel) |
57 @param model reference to the model |
|
58 @type QAbstractItemModel |
56 """ |
59 """ |
57 if self.__model is not None: |
60 if self.__model is not None: |
58 self.__model.modelReset.disconnect(self._build) |
61 self.__model.modelReset.disconnect(self._build) |
59 self.__model.rowsInserted[QModelIndex, int, int].disconnect(self._build) |
62 self.__model.rowsInserted[QModelIndex, int, int].disconnect(self._build) |
60 self.__model.rowsRemoved[QModelIndex, int, int].disconnect(self._build) |
63 self.__model.rowsRemoved[QModelIndex, int, int].disconnect(self._build) |
70 |
73 |
71 def model(self): |
74 def model(self): |
72 """ |
75 """ |
73 Public method to get a reference to the model. |
76 Public method to get a reference to the model. |
74 |
77 |
75 @return reference to the model (QAbstractItemModel) |
78 @return reference to the model |
|
79 @rtype QAbstractItemModel |
76 """ |
80 """ |
77 return self.__model |
81 return self.__model |
78 |
82 |
79 def setRootIndex(self, idx): |
83 def setRootIndex(self, idx): |
80 """ |
84 """ |
81 Public method to set the root index. |
85 Public method to set the root index. |
82 |
86 |
83 @param idx index to be set as the root index (QModelIndex) |
87 @param idx index to be set as the root index |
|
88 @type QModelIndex |
84 """ |
89 """ |
85 self.__root = idx |
90 self.__root = idx |
86 |
91 |
87 def rootIndex(self): |
92 def rootIndex(self): |
88 """ |
93 """ |
89 Public method to get the root index. |
94 Public method to get the root index. |
90 |
95 |
91 @return root index (QModelIndex) |
96 @return root index |
|
97 @rtype QModelIndex |
92 """ |
98 """ |
93 return self.__root |
99 return self.__root |
94 |
100 |
95 def _build(self): |
101 def _build(self): |
96 """ |
102 """ |
145 |
153 |
146 def _createMenu(self): |
154 def _createMenu(self): |
147 """ |
155 """ |
148 Protected method to create the menu for a tool bar action. |
156 Protected method to create the menu for a tool bar action. |
149 |
157 |
150 @return menu for a tool bar action (EricModelMenu) |
158 @return menu for a tool bar action |
|
159 @rtype EricModelMenu |
151 """ |
160 """ |
152 from .EricModelMenu import EricModelMenu |
161 from .EricModelMenu import EricModelMenu |
153 |
162 |
154 return EricModelMenu(self) |
163 return EricModelMenu(self) |
155 |
164 |
156 def eventFilter(self, obj, evt): |
165 def eventFilter(self, obj, evt): |
157 """ |
166 """ |
158 Public method to handle event for other objects. |
167 Public method to handle event for other objects. |
159 |
168 |
160 @param obj reference to the object (QObject) |
169 @param obj reference to the object |
161 @param evt reference to the event (QEvent) |
170 @type QObject |
162 @return flag indicating that the event should be filtered out (boolean) |
171 @param evt reference to the event |
|
172 @type QEvent |
|
173 @return flag indicating that the event should be filtered out |
|
174 @rtype bool |
163 """ |
175 """ |
164 if evt.type() == QEvent.Type.MouseButtonRelease: |
176 if evt.type() == QEvent.Type.MouseButtonRelease: |
165 self._mouseButton = evt.button() |
177 self._mouseButton = evt.button() |
166 self._keyboardModifiers = evt.modifiers() |
178 self._keyboardModifiers = evt.modifiers() |
167 act = obj.defaultAction() |
179 act = obj.defaultAction() |
180 |
192 |
181 def dragEnterEvent(self, evt): |
193 def dragEnterEvent(self, evt): |
182 """ |
194 """ |
183 Protected method to handle drag enter events. |
195 Protected method to handle drag enter events. |
184 |
196 |
185 @param evt reference to the event (QDragEnterEvent) |
197 @param evt reference to the event |
|
198 @type QDragEnterEvent |
186 """ |
199 """ |
187 if self.__model is not None: |
200 if self.__model is not None: |
188 mimeTypes = self.__model.mimeTypes() |
201 mimeTypes = self.__model.mimeTypes() |
189 for mimeType in mimeTypes: |
202 for mimeType in mimeTypes: |
190 if evt.mimeData().hasFormat(mimeType): |
203 if evt.mimeData().hasFormat(mimeType): |
194 |
207 |
195 def dropEvent(self, evt): |
208 def dropEvent(self, evt): |
196 """ |
209 """ |
197 Protected method to handle drop events. |
210 Protected method to handle drop events. |
198 |
211 |
199 @param evt reference to the event (QDropEvent) |
212 @param evt reference to the event |
|
213 @type QDropEvent |
200 @exception RuntimeError raised to indicate an invalid model index |
214 @exception RuntimeError raised to indicate an invalid model index |
201 """ |
215 """ |
202 if self.__model is not None: |
216 if self.__model is not None: |
203 act = self.actionAt(evt.position().toPoint()) |
217 act = self.actionAt(evt.position().toPoint()) |
204 parentIndex = self.__root |
218 parentIndex = self.__root |
224 |
238 |
225 def mouseMoveEvent(self, evt): |
239 def mouseMoveEvent(self, evt): |
226 """ |
240 """ |
227 Protected method to handle mouse move events. |
241 Protected method to handle mouse move events. |
228 |
242 |
229 @param evt reference to the event (QMouseEvent) |
243 @param evt reference to the event |
|
244 @type QMouseEvent |
230 @exception RuntimeError raised to indicate an invalid model index |
245 @exception RuntimeError raised to indicate an invalid model index |
231 """ |
246 """ |
232 if self.__model is None: |
247 if self.__model is None: |
233 super().mouseMoveEvent(evt) |
248 super().mouseMoveEvent(evt) |
234 return |
249 return |
266 |
281 |
267 def hideEvent(self, evt): |
282 def hideEvent(self, evt): |
268 """ |
283 """ |
269 Protected method to handle hide events. |
284 Protected method to handle hide events. |
270 |
285 |
271 @param evt reference to the hide event (QHideEvent) |
286 @param evt reference to the hide event |
|
287 @type QHideEvent |
272 """ |
288 """ |
273 self.clear() |
289 self.clear() |
274 super().hideEvent(evt) |
290 super().hideEvent(evt) |
275 |
291 |
276 def showEvent(self, evt): |
292 def showEvent(self, evt): |
277 """ |
293 """ |
278 Protected method to handle show events. |
294 Protected method to handle show events. |
279 |
295 |
280 @param evt reference to the hide event (QHideEvent) |
296 @param evt reference to the hide event |
|
297 @type QHideEvent |
281 """ |
298 """ |
282 if len(self.actions()) == 0: |
299 if len(self.actions()) == 0: |
283 self._build() |
300 self._build() |
284 super().showEvent(evt) |
301 super().showEvent(evt) |
285 |
302 |