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

Peter Kümmel syntheticpp at gmx.net
Wed Jan 19 12:37:01 CET 2011


SVN commit 1215710 by kuemmel:

remove some duplicated code

 M  +11 -40    scalarmodel.cpp  
 M  +2 -0      scalarmodel.h  


--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.cpp #1215709:1215710
@@ -93,16 +93,8 @@
 
 
 void ScalarModel::addScalar(ScalarPtr scalar, ScalarTreeItem* parent) {
-  ScalarTreeItem* parentItem;
-  if (parent) {
-    parentItem = parent;
-  } else {
-    parentItem = _rootItem;
+  addScalarTreeItem(QList<QVariant>() << scalar->Name() << scalar->value(), parent);
   }
-  QList<QVariant> data;
-  data << scalar->Name() << scalar->value();
-  new ScalarTreeItem(data, parentItem);
-}
 
 
 void ScalarModel::addScalars(const QHash<QString, Kst::ScalarPtr> scalarMap, ScalarTreeItem* parent) {
@@ -118,44 +110,31 @@
 }
 
 
-void ScalarModel::addVector(VectorPtr vector, ScalarTreeItem* parent) {
+ScalarTreeItem* ScalarModel::addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent) {
   ScalarTreeItem* parentItem;
   if (parent) {
     parentItem = parent;
   } else {
     parentItem = _rootItem;
   }
-  QList<QVariant> data;
-  data << vector->Name();
-  ScalarTreeItem* item = new ScalarTreeItem(data, parentItem);
+  return new ScalarTreeItem(data, parentItem);
+}
+
+
+void ScalarModel::addVector(VectorPtr vector, ScalarTreeItem* parent) {
+  ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << vector->Name(), parent);
   addScalars(vector->scalars(), item);
 }
 
 
 void ScalarModel::addMatrix(MatrixPtr matrix, ScalarTreeItem* parent) {
-  ScalarTreeItem* parentItem;
-  if (parent) {
-    parentItem = parent;
-  } else {
-    parentItem = _rootItem;
-  }
-  QList<QVariant> data;
-  data << matrix->Name();
-  ScalarTreeItem* item = new ScalarTreeItem(data, parentItem);
+  ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << matrix->Name(), parent);
   addScalars(matrix->scalars(), item);
 }
 
 
 void ScalarModel::addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent) {
-  ScalarTreeItem* parentItem;
-  if (parent) {
-    parentItem = parent;
-  } else {
-    parentItem = _rootItem;
-  }
-  QList<QVariant> data;
-  data << dataObject->Name();
-  ScalarTreeItem* item = new ScalarTreeItem(data, parentItem);
+  ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataObject->Name(), parent);
 
   QMap<QString, ObjectPtr> objectMap;
   foreach(Scalar* scalar, dataObject->outputScalars()) {
@@ -183,15 +162,7 @@
 
 
 void ScalarModel::addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent) {
-  ScalarTreeItem* parentItem;
-  if (parent) {
-    parentItem = parent;
-  } else {
-    parentItem = _rootItem;
-  }
-  QList<QVariant> data;
-  data << dataSource->shortName();
-  ScalarTreeItem* item = new ScalarTreeItem(data, parentItem);
+  ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataSource->Name(), parent);
 
   QStringList scalars = dataSource->scalar().list();
   scalars.sort();
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.h #1215709:1215710
@@ -70,6 +70,8 @@
   ObjectStore *_store;
   ScalarTreeItem *_rootItem;
 
+  ScalarTreeItem* addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent);
+
 };
 
 }


More information about the Kst mailing list