Ok, I've changed a bit my model:
Here is how I init it
def __init__(self, qtgDoc, parent=None):
super(QtgModel, self).__init__(parent)
#======= Attributes Declaration =========
[...] # <- We do not care this
self.modelLoger = modelLoger(self) # <- the "listener" of the model
#========================================
#We test our listener :)
self.emit(QtCore.SIGNAL("layoutChanged()"))
class Model(QtCore.QAbstractItemModel):
def __init__(self, qtgDoc, parent=None):
super(QtgModel, self).__init__(parent)
#======= Attributes Declaration =========
[...] # <- We do not care this
self.modelLoger = modelLoger(self) # <- the "listener" of the model
#========================================
#We test our listener :)
self.emit(QtCore.SIGNAL("layoutChanged()"))
To copy to clipboard, switch view to plain text mode
Here is the code of our listener
class modelLoger(object):
def __init__(self, model):
connect = QtCore.
QObject.
connect #We create a shortcut to the function (easiest :P)
connect(model,
QtCore.SIGNAL('layoutChanged()'),
self.layoutChanged)
connect(model,
QtCore.SIGNAL('modelReset()'),
self.modelReset)
connect(model,
QtCore.SIGNAL('rowsInserted(const QModelIndex &, int , int)'),
self.rowsInserted)
def layoutChanged(self):
print time.strftime("%H:%M:%S"), "layout Changed"
def modelReset(self):
print time.strftime("%H:%M:%S"), "modelReset"
def rowsInserted(self):
print time.strftime("%H:%M:%S"), "rowsInserted"
class modelLoger(object):
def __init__(self, model):
connect = QtCore.QObject.connect #We create a shortcut to the function (easiest :P)
connect(model,
QtCore.SIGNAL('layoutChanged()'),
self.layoutChanged)
connect(model,
QtCore.SIGNAL('modelReset()'),
self.modelReset)
connect(model,
QtCore.SIGNAL('rowsInserted(const QModelIndex &, int , int)'),
self.rowsInserted)
def layoutChanged(self):
print time.strftime("%H:%M:%S"), "layout Changed"
def modelReset(self):
print time.strftime("%H:%M:%S"), "modelReset"
def rowsInserted(self):
print time.strftime("%H:%M:%S"), "rowsInserted"
To copy to clipboard, switch view to plain text mode
Here is the output I have (I only launch the application, make a new 'S' under 'A' and quit) :
14:19:35 layout Changed # <- the test in the __init__ of the model
14:19:39 rowsInserted # <- we create the new 's'
#<- we quit :)
14:19:35 layout Changed # <- the test in the __init__ of the model
14:19:39 rowsInserted # <- we create the new 's'
#<- we quit :)
To copy to clipboard, switch view to plain text mode
Thanks for your time
Bookmarks