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

Mike Fenton mike at staikos.net
Mon Nov 19 19:13:27 CET 2007


SVN commit 738793 by fenton:

Update session model to display DataVectors, GeneratedVectors, DataMatrix, GeneratedMatrix and outputVectors and output Matrices for DataObjects.


 M  +17 -10    datamanager.cpp  
 M  +106 -18   sessionmodel.cpp  
 M  +3 -1      sessionmodel.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.cpp #738792:738793
@@ -23,6 +23,7 @@
 #include "curve.h"
 #include "equation.h"
 #include "vector.h"
+#include "matrix.h"
 #include "histogram.h"
 #include "psd.h"
 #include "eventmonitorentry.h"
@@ -128,18 +129,22 @@
   QList<QAction *> actions;
   if (_session->indexAt(position).isValid()) {
     SessionModel *model = static_cast<SessionModel*>(_session->model());
-    _currentObject = model->generateObjectList().at(_session->indexAt(position).row());
-    if (_currentObject) {
-      QAction *action = new QAction(_currentObject->tag().displayString(), this);
-      actions.append(action);
+    if (!model->parent(_session->indexAt(position)).isValid()) {
+      _currentObject = model->generateObjectList().at(_session->indexAt(position).row());
+      if (_currentObject) {
+        QAction *action = new QAction(_currentObject->tag().displayString(), this);
+        actions.append(action);
 
-      action = new DataButtonAction(tr("Edit"));
-      connect(action, SIGNAL(triggered()), this, SLOT(showEditDialog()));
-      actions.append(action);
+        action = new DataButtonAction(tr("Edit"));
+        connect(action, SIGNAL(triggered()), this, SLOT(showEditDialog()));
+        actions.append(action);
 
-      action = new DataButtonAction(tr("Delete"));
-      connect(action, SIGNAL(triggered()), this, SLOT(deleteObject()));
-      actions.append(action);
+        action = new DataButtonAction(tr("Delete"));
+        connect(action, SIGNAL(triggered()), this, SLOT(deleteObject()));
+        actions.append(action);
+      }
+    } else {
+      // TODO what options do output vectors get?
     }
   }
   if (actions.count() > 0)
@@ -165,6 +170,8 @@
       DialogLauncher::self()->showCSDDialog(csd);
     } else if (VectorPtr vector = kst_cast<Vector>(_currentObject)) {
       DialogLauncher::self()->showVectorDialog(vector);
+    } else if (MatrixPtr matrix = kst_cast<Matrix>(_currentObject)) {
+      DialogLauncher::self()->showMatrixDialog(matrix);
     }
   }
 }
--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.cpp #738792:738793
@@ -15,6 +15,10 @@
 #include <objectstore.h>
 #include <dataobject.h>
 #include <relation.h>
+#include <datavector.h>
+#include <generatedvector.h>
+#include <datamatrix.h>
+#include <generatedmatrix.h>
 
 namespace Kst {
 
@@ -35,9 +39,29 @@
 
 const ObjectList<Object> SessionModel::generateObjectList() const {
   ObjectList<Object> ol;
+  ObjectList<DataVector> dvol = _store->getObjects<DataVector>();
+  ObjectList<GeneratedVector> gvol = _store->getObjects<GeneratedVector>();
+  ObjectList<DataMatrix> dmol = _store->getObjects<DataMatrix>();
+  ObjectList<GeneratedMatrix> gmol = _store->getObjects<GeneratedMatrix>();
   ObjectList<Relation> rol = _store->getObjects<Relation>();
   ObjectList<DataObject> dol = _store->getObjects<DataObject>();
 
+  foreach(DataVector* vector, dvol) {
+    ol.append(vector);
+  }
+
+  foreach(GeneratedVector* vector, gvol) {
+    ol.append(vector);
+  }
+
+  foreach(DataMatrix* matrix, dmol) {
+    ol.append(matrix);
+  }
+
+  foreach(GeneratedMatrix* matrix, gmol) {
+    ol.append(matrix);
+  }
+
   foreach(Relation* relation, rol) {
     ol.append(relation);
   }
@@ -66,6 +90,7 @@
   if (pdo) {
     pdo->readLock();
     rc = pdo->outputVectors().count();
+    rc += pdo->outputMatrices().count();
     pdo->unlock();
   }
   return rc;
@@ -82,8 +107,14 @@
       Q_ASSERT(!index.parent().parent().isValid());
       QVariant p = data(index.parent(), role);
       DataObjectPtr parent = qVariantValue<DataObject*>(p);
-      VectorPtr v = parent->outputVectors().values()[index.row()];
-      return qVariantFromValue(v.data());
+      const int vectorCount = parent->outputVectors().count();
+      if (index.row() < vectorCount) {
+        if (VectorPtr v = parent->outputVectors().values()[index.row()]) {
+          return qVariantFromValue(v.data());
+        }
+      } else if (MatrixPtr m = parent->outputMatrices().values()[index.row() - vectorCount]) {
+        return qVariantFromValue(m.data());
+      }
     } else {
       Q_ASSERT(_store);
       DataObjectPtr p = kst_cast<DataObject>(generateObjectList().at(index.row()));
@@ -98,36 +129,54 @@
   if (index.internalPointer()) { //parent().isValid()) {
     Q_ASSERT(!index.parent().parent().isValid());
     DataObject *parent = static_cast<DataObject*>(index.internalPointer());
-    return vectorData(parent, index);
+    return dataObjectOutputData(parent, index);
   }
 
   Q_ASSERT(_store);
-  ObjectList<Object> dol = generateObjectList();
-  const int row = index.row(), col = index.column();
-  if (DataObjectPtr p = kst_cast<DataObject>(dol.at(row))) {
+  ObjectList<Object> objectList = generateObjectList();
+  const int row = index.row();
+  if (DataObjectPtr p = kst_cast<DataObject>(objectList.at(row))) {
     return dataObjectData(p, index);
-  } else if (RelationPtr p = kst_cast<Relation>(dol.at(row))) {
+  } else if (RelationPtr p = kst_cast<Relation>(objectList.at(row))) {
     return relationData(p, index);
+  } else if (VectorPtr p = kst_cast<Vector>(objectList.at(row))) {
+    return vectorData(p, index);
+  } else if (MatrixPtr p = kst_cast<Matrix>(objectList.at(row))) {
+    return matrixData(p, index);  
   } else {
     return QVariant();
   }
 }
 
 
-QVariant SessionModel::vectorData(DataObjectPtr parent, const QModelIndex& index) const {
+QVariant SessionModel::dataObjectOutputData(DataObjectPtr parent, const QModelIndex& index) const {
   QVariant rc;
 
   if (!parent) {
     return rc;
   }
 
-  const int row = index.row(), col = index.column();
-  VectorPtr v = parent->outputVectors().values()[row];
+  const int row = index.row();
+  const int vectorCount = parent->outputVectors().count();
+  if (parent->outputVectors().count() > row) {
+    if (VectorPtr v = parent->outputVectors().values()[row]) {
+      return vectorData(v, index);
+    }
+  } else if (MatrixPtr m = parent->outputMatrices().values()[row - vectorCount]) {
+    return matrixData(m, index);
+  }
+  return rc;
+}
+
+
+QVariant SessionModel::vectorData(VectorPtr v, const QModelIndex& index) const {
+  QVariant rc;
+
   if (!v) {
     return rc;
   }
 
-  switch (col) {
+  switch (index.column()) {
     case 0:
       {
       v->readLock();
@@ -159,13 +208,52 @@
 }
 
 
+QVariant SessionModel::matrixData(MatrixPtr matrix, const QModelIndex& index) const {
+  QVariant rc;
+
+  if (!matrix) {
+    return rc;
+  }
+
+  switch (index.column()) {
+    case 0:
+      {
+      matrix->readLock();
+      rc.setValue(matrix->tag().displayString());
+      matrix->unlock();
+      break;
+      }
+    case 1:
+      matrix->readLock();
+      rc = matrix->typeString();
+      matrix->unlock();
+      break;
+    case 2:
+      break;
+    case 3:
+      matrix->readLock();
+      rc = tr("[%1x%2]").arg(matrix->xNumSteps()).arg(matrix->yNumSteps());
+      matrix->unlock();
+      break;
+    case 4:
+      matrix->readLock();
+      rc = tr("[%1..%2]").arg(matrix->minValue()).arg(matrix->maxValue());
+      matrix->unlock();
+      break;
+    default:
+      break;
+  }
+  return rc;
+}
+
+
 QVariant SessionModel::dataObjectData(DataObjectPtr p, const QModelIndex& index) const {
   QVariant rc;
-  const int row = index.row(), col = index.column();
   if (!p) {
     return rc;
   }
-  switch (col) {
+
+  switch (index.column()) {
     case 0:
       p->readLock();
       rc.setValue(p->tag().displayString());
@@ -197,11 +285,11 @@
 
 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) {
+
+  switch (index.column()) {
     case 0:
       p->readLock();
       rc.setValue(p->tag().displayString());
@@ -249,15 +337,15 @@
 
   const int cnt = dol.count();
   DataObject *p = 0;
-  if (row >= 0 && row < cnt) {
-    p = kst_cast<DataObject>(dol.at(row));
+  if (parent.row() >= 0 && parent.row() < cnt) { 
+    p = kst_cast<DataObject>(dol.at(parent.row()));
   }
   if (!p) {
     return QModelIndex();
   }
 
   p->readLock();
-  if (row >= p->outputVectors().count()) {
+  if (row >= (p->outputVectors().count() + p->outputMatrices().count())) {
     p->unlock();
     return QModelIndex();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/sessionmodel.h #738792:738793
@@ -37,7 +37,9 @@
   const ObjectList<Object> generateObjectList() const;
 
 private:
-  QVariant vectorData(DataObjectPtr parent, const QModelIndex& index) const;
+  QVariant dataObjectOutputData(DataObjectPtr parent, const QModelIndex& index) const;
+  QVariant vectorData(VectorPtr parent, const QModelIndex& index) const;
+  QVariant matrixData(MatrixPtr parent, const QModelIndex& index) const;
   QVariant dataObjectData(DataObjectPtr dataObject, const QModelIndex& index) const;
   QVariant relationData(RelationPtr relation, const QModelIndex& index) const;
 


More information about the Kst mailing list