E5Gui/E5ModelToolBar.py

changeset 482
4650a72c307a
parent 55
b5c84934de9c
child 635
ab9f99806cf8
diff -r ad71812ba395 -r 4650a72c307a E5Gui/E5ModelToolBar.py
--- a/E5Gui/E5ModelToolBar.py	Tue Aug 10 13:15:03 2010 +0200
+++ b/E5Gui/E5ModelToolBar.py	Tue Aug 10 14:17:54 2010 +0200
@@ -15,7 +15,11 @@
 class E5ModelToolBar(QToolBar):
     """
     Class implementing a tool bar populated from a QAbstractItemModel.
+    
+    @signal activated(QModelIndex) emitted when an action has been triggered
     """
+    activated = pyqtSignal(QModelIndex)
+    
     def __init__(self, title = None, parent = None):
         """
         Constructor
@@ -50,34 +54,18 @@
         @param model reference to the model (QAbstractItemModel)
         """
         if self.__model is not None:
-            self.disconnect(self.__model, 
-                            SIGNAL("modelReset()"), 
-                            self._build)
-            self.disconnect(self.__model, 
-                            SIGNAL("rowsInserted(const QModelIndex&, int, int)"), 
-                            self._build)
-            self.disconnect(self.__model, 
-                            SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), 
-                            self._build)
-            self.disconnect(self.__model, 
-                            SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"),
-                            self._build)
+            self.__model.modelReset[()].disconnect(self._build)
+            self.__model.rowsInserted[QModelIndex, int, int].disconnect(self._build)
+            self.__model.rowsRemoved[QModelIndex, int, int].disconnect(self._build)
+            self.__model.dataChanged[QModelIndex, QModelIndex].disconnect(self._build)
         
         self.__model = model
         
         if self.__model is not None:
-            self.connect(self.__model, 
-                         SIGNAL("modelReset()"), 
-                         self._build)
-            self.connect(self.__model, 
-                         SIGNAL("rowsInserted(const QModelIndex&, int, int)"), 
-                         self._build)
-            self.connect(self.__model, 
-                         SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), 
-                         self._build)
-            self.connect(self.__model, 
-                         SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), 
-                         self._build)
+            self.__model.modelReset[()].connect(self._build)
+            self.__model.rowsInserted[QModelIndex, int, int].connect(self._build)
+            self.__model.rowsRemoved[QModelIndex, int, int].connect(self._build)
+            self.__model.dataChanged[QModelIndex, QModelIndex].connect(self._build)
     
     def model(self):
         """
@@ -176,7 +164,7 @@
             act = obj.defaultAction()
             idx = self.index(act)
             if idx.isValid():
-                self.emit(SIGNAL("activated(const QModelIndex&)"), idx)
+                self.activated[QModelIndex].emit(idx)
         elif evt.type() == QEvent.MouseButtonPress:
             if evt.buttons() & Qt.LeftButton:
                 self.__dragStartPosition = self.mapFromGlobal(evt.globalPos())
@@ -286,4 +274,4 @@
         Public method to reset the saved internal state.
         """
         self._mouseButton = Qt.NoButton
-        self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier)
\ No newline at end of file
+        self._keyboardModifiers = Qt.KeyboardModifiers(Qt.NoModifier)

eric ide

mercurial