[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Wed Nov 14 20:15:43 CET 2007


SVN commit 736759 by fenton:

Update SessionManager to also load relations.
Include cleanup of sessionmodel.h.


 M  +72 -16    sessionmodel.cpp  
 M  +7 -2      sessionmodel.h  
 M  +0 -1      viewmanager.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.cpp #736758:736759
@@ -14,6 +14,7 @@
 #include <assert.h>
 #include <objectstore.h>
 #include <dataobject.h>
+#include <relation.h>
 
 namespace Kst {
 
@@ -32,9 +33,24 @@
 }
 
 
+const ObjectList<Object> SessionModel::generateObjectList() const {
+  ObjectList<Object> ol;
+  ObjectList<Relation> rol = _store->getObjects<Relation>();
+  ObjectList<DataObject> dol = _store->getObjects<DataObject>();
+
+  foreach(Relation* relation, rol) {
+    ol.append(relation);
+  }
+
+  foreach(DataObject* dataObject, dol) {
+    ol.append(dataObject);
+  }
+  return ol;
+}
+
 int SessionModel::rowCount(const QModelIndex& parent) const {
   Q_ASSERT(_store);
-  DataObjectList dol = _store->getObjects<DataObject>();
+  ObjectList<Object> dol = generateObjectList();
 
   int rc = 0;
   if (!parent.isValid()) {
@@ -46,8 +62,7 @@
     return rc;
   }
 
-  DataObject *pdo = dol.at(parent.row());
-  Q_ASSERT(pdo);
+  DataObject *pdo = kst_cast<DataObject>(dol.at(parent.row()));
   if (pdo) {
     pdo->readLock();
     rc = pdo->outputVectors().count();
@@ -71,7 +86,7 @@
       return qVariantFromValue(v.data());
     } else {
       Q_ASSERT(_store);
-      DataObjectPtr p = _store->getObjects<DataObject>().at(index.row());
+      DataObjectPtr p = kst_cast<DataObject>(generateObjectList().at(index.row()));
       return qVariantFromValue(p.data());
     }
   }
@@ -82,18 +97,26 @@
 
   if (index.internalPointer()) { //parent().isValid()) {
     Q_ASSERT(!index.parent().parent().isValid());
-    return vectorData(index, role);
+    DataObject *parent = static_cast<DataObject*>(index.internalPointer());
+    return vectorData(parent, index);
   }
 
-  return dataObjectData(index, role);
+  Q_ASSERT(_store);
+  ObjectList<Object> dol = generateObjectList();
+  const int row = index.row(), col = index.column();
+  if (DataObjectPtr p = kst_cast<DataObject>(dol.at(row))) {
+    return dataObjectData(p, index);
+  } else if (RelationPtr p = kst_cast<Relation>(dol.at(row))) {
+    return relationData(p, index);
+  } else {
+    return QVariant();
+  }
 }
 
 
-QVariant SessionModel::vectorData(const QModelIndex& index, int role) const {
-  Q_UNUSED(role)
+QVariant SessionModel::vectorData(DataObjectPtr parent, const QModelIndex& index) const {
   QVariant rc;
 
-  DataObject *parent = static_cast<DataObject*>(index.internalPointer());
   if (!parent) {
     return rc;
   }
@@ -136,12 +159,9 @@
 }
 
 
-QVariant SessionModel::dataObjectData(const QModelIndex& index, int role) const {
-  Q_UNUSED(role)
+QVariant SessionModel::dataObjectData(DataObjectPtr p, const QModelIndex& index) const {
   QVariant rc;
   const int row = index.row(), col = index.column();
-  Q_ASSERT(_store);
-  DataObjectPtr p = _store->getObjects<DataObject>().at(row);
   if (!p) {
     return rc;
   }
@@ -175,13 +195,49 @@
 }
 
 
+QVariant SessionModel::relationData(RelationPtr p, const QModelIndex& index) const {
+  QVariant rc;
+  const int row = index.row(), col = index.column();
+  if (!p) {
+    return rc;
+  }
+  switch (col) {
+    case 0:
+      p->readLock();
+      rc.setValue(p->tag().displayString());
+      p->unlock();
+      break;
+    case 1:
+      p->readLock();
+      rc = p->typeString();
+      p->unlock();
+      break;
+    case 2:
+      break;
+    case 3:
+      p->readLock();
+      rc = p->sampleCount();
+      p->unlock();
+      break;
+    case 4:
+      p->readLock();
+      rc = p->propertyString();
+      p->unlock();
+      break;
+    default:
+      break;
+  }
+  return rc;
+}
+
+
 QModelIndex SessionModel::index(int row, int col, const QModelIndex& parent) const {
   if (row < 0 || col < 0 || col > 4) {
     return QModelIndex();
   }
 
   Q_ASSERT(_store);
-  DataObjectList dol = _store->getObjects<DataObject>();
+  ObjectList<Object> dol = generateObjectList();
 
   if (!parent.isValid()) {
     const int cnt = dol.count();
@@ -194,7 +250,7 @@
   const int cnt = dol.count();
   DataObject *p = 0;
   if (row >= 0 && row < cnt) {
-    p = dol.at(row);
+    p = kst_cast<DataObject>(dol.at(row));
   }
   if (!p) {
     return QModelIndex();
@@ -218,7 +274,7 @@
   }
 
   Q_ASSERT(_store);
-  const int cnt = _store->getObjects<DataObject>().indexOf(dop);
+  const int cnt = generateObjectList().indexOf(dop);
   if (cnt < 0) {
     return QModelIndex();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.h #736758:736759
@@ -14,6 +14,9 @@
 
 
 #include <QAbstractItemModel>
+#include "dataobject.h"
+#include "object.h"
+#include "relation.h"
 
 namespace Kst {
 
@@ -33,8 +36,10 @@
   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
 
 private:
-  QVariant vectorData(const QModelIndex& index, int role) const;
-  QVariant dataObjectData(const QModelIndex& index, int role) const;
+  QVariant vectorData(DataObjectPtr parent, const QModelIndex& index) const;
+  QVariant dataObjectData(DataObjectPtr dataObject, const QModelIndex& index) const;
+  QVariant relationData(RelationPtr relation, const QModelIndex& index) const;
+  const ObjectList<Object> generateObjectList() const;
 
   ObjectStore *_store;
 };
--- branches/work/kst/portto4/kst/src/libkstapp/viewmanager.cpp #736758:736759
@@ -13,7 +13,6 @@
 
 #include "application.h"
 #include "mainwindow.h"
-#include "sessionmodel.h"
 #include "tabwidget.h"
 #include "view.h"
 


More information about the Kst mailing list