6 """ |
6 """ |
7 Module implementing a tool bar populated from a QAbstractItemModel. |
7 Module implementing a tool bar populated from a QAbstractItemModel. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint, QEvent |
10 from PyQt4.QtCore import pyqtSignal, qVersion, Qt, QModelIndex, QPoint, QEvent |
11 from PyQt4.QtGui import QApplication, QDrag, QPixmap, QToolBar, QIcon, QToolButton |
11 from PyQt4.QtGui import QApplication, QDrag, QPixmap, QToolBar, QIcon, \ |
|
12 QToolButton |
12 |
13 |
13 |
14 |
14 class E5ModelToolBar(QToolBar): |
15 class E5ModelToolBar(QToolBar): |
15 """ |
16 """ |
16 Class implementing a tool bar populated from a QAbstractItemModel. |
17 Class implementing a tool bar populated from a QAbstractItemModel. |
52 |
53 |
53 @param model reference to the model (QAbstractItemModel) |
54 @param model reference to the model (QAbstractItemModel) |
54 """ |
55 """ |
55 if self.__model is not None: |
56 if self.__model is not None: |
56 self.__model.modelReset[()].disconnect(self._build) |
57 self.__model.modelReset[()].disconnect(self._build) |
57 self.__model.rowsInserted[QModelIndex, int, int].disconnect(self._build) |
58 self.__model.rowsInserted[QModelIndex, int, int].disconnect( |
58 self.__model.rowsRemoved[QModelIndex, int, int].disconnect(self._build) |
59 self._build) |
59 self.__model.dataChanged[QModelIndex, QModelIndex].disconnect(self._build) |
60 self.__model.rowsRemoved[QModelIndex, int, int].disconnect( |
|
61 self._build) |
|
62 self.__model.dataChanged[QModelIndex, QModelIndex].disconnect( |
|
63 self._build) |
60 |
64 |
61 self.__model = model |
65 self.__model = model |
62 |
66 |
63 if self.__model is not None: |
67 if self.__model is not None: |
64 self.__model.modelReset[()].connect(self._build) |
68 self.__model.modelReset[()].connect(self._build) |
65 self.__model.rowsInserted[QModelIndex, int, int].connect(self._build) |
69 self.__model.rowsInserted[QModelIndex, int, int].connect( |
66 self.__model.rowsRemoved[QModelIndex, int, int].connect(self._build) |
70 self._build) |
67 self.__model.dataChanged[QModelIndex, QModelIndex].connect(self._build) |
71 self.__model.rowsRemoved[QModelIndex, int, int].connect( |
|
72 self._build) |
|
73 self.__model.dataChanged[QModelIndex, QModelIndex].connect( |
|
74 self._build) |
68 |
75 |
69 def model(self): |
76 def model(self): |
70 """ |
77 """ |
71 Public method to get a reference to the model. |
78 Public method to get a reference to the model. |
72 |
79 |
223 |
230 |
224 if not (evt.buttons() & Qt.LeftButton): |
231 if not (evt.buttons() & Qt.LeftButton): |
225 super().mouseMoveEvent(evt) |
232 super().mouseMoveEvent(evt) |
226 return |
233 return |
227 |
234 |
228 manhattanLength = (evt.pos() - self.__dragStartPosition).manhattanLength() |
235 manhattanLength = (evt.pos() - |
|
236 self.__dragStartPosition).manhattanLength() |
229 if manhattanLength <= QApplication.startDragDistance(): |
237 if manhattanLength <= QApplication.startDragDistance(): |
230 super().mouseMoveEvent(evt) |
238 super().mouseMoveEvent(evt) |
231 return |
239 return |
232 |
240 |
233 act = self.actionAt(self.__dragStartPosition) |
241 act = self.actionAt(self.__dragStartPosition) |