From 14098567c81a21e08a7a49cb9117148f6a639740 Mon Sep 17 00:00:00 2001 From: Martin Baeuml Date: Mon, 16 May 2011 18:18:44 +0200 Subject: [PATCH] add more data access functions to the model --- annotations/model.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/annotations/model.py b/annotations/model.py index a8f2c29..a1629f3 100644 --- a/annotations/model.py +++ b/annotations/model.py @@ -14,8 +14,12 @@ class ModelItem: self.parent_ = parent self.children_ = [] - def children(self): - return self.children_ + def children(self, index=None): + if index is None: + return self.children_ + else: + # return tuple child, index of the child + return [(child, index.child(row, 0)) for row, child in enumerate(self.children_)] def parent(self): return self.parent_ @@ -52,7 +56,7 @@ class FileModelItem(ModelItem): def data(self, index, role): if role == Qt.DisplayRole and index.column() == 0: return os.path.basename(self.filename()) - return QVariant() + return ModelItem.data(self, index, role) @staticmethod def create(file, parent): @@ -81,6 +85,8 @@ class ImageFileModelItem(FileModelItem): def data(self, index, role): if role == ImageRole: return okapy.loadImage(self.fullpath(index)) + elif role == DataRole: + return self.file_ return FileModelItem.data(self, index, role) class VideoFileModelItem(FileModelItem): @@ -165,7 +171,7 @@ class AnnotationModelItem(ModelItem): for key, value in data.iteritems(): print key, value if not key in self.annotation_: - print "not in annoation: ", key + print "not in annotation: ", key next = len(self.children_) index.model().beginInsertRows(index, next, next) self.children_.append(KeyValueModelItem(key, self)) @@ -195,6 +201,10 @@ class AnnotationModelItem(ModelItem): return QVariant() + def setValue(self, key, value, index): + self.annotation_[key] = value + index.model().dataChanged.emit(index, index.sibling(index.row(), 0)) + def value(self, key): return self.annotation_[key]