[Kst] branches/work/kst/portto4/kst/src/libkstapp
Peter Kümmel
syntheticpp at gmx.net
Wed Jan 19 14:43:54 CET 2011
SVN commit 1215738 by kuemmel:
last changes to ScalarModel, now we are prepared for StringModel
M +9 -38 scalarmodel.cpp
M +50 -8 scalarmodel.h
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.cpp #1215737:1215738
@@ -73,26 +73,25 @@
}
-ScalarModel::ScalarModel(ObjectStore *store)
+PrimitiveModel::PrimitiveModel(ObjectStore *store)
: QAbstractItemModel(), _store(store) {
QList<QVariant> rootData;
rootData << "Scalars";
_rootItem = new ScalarTreeItem(rootData);
- createTree();
}
-ScalarModel::~ScalarModel() {
+PrimitiveModel::~PrimitiveModel() {
}
-int ScalarModel::columnCount(const QModelIndex& parent) const {
+int PrimitiveModel::columnCount(const QModelIndex& parent) const {
Q_UNUSED(parent)
return 2;
}
-ScalarTreeItem* ScalarModel::addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent) {
+ScalarTreeItem* PrimitiveModel::addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent) {
ScalarTreeItem* parentItem;
if (parent) {
parentItem = parent;
@@ -103,18 +102,6 @@
}
-void ScalarModel::addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent) {
- ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataObject->Name(), parent);
-
- ObjectList<Primitive> primitives = dataObject->outputPrimitives();
- foreach(PrimitivePtr prim, primitives) {
- if (!kst_cast<String>(prim)) {
- addPrimitivesScalars<Scalar>(prim.data(), item);
- }
- }
-}
-
-
void ScalarModel::addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent) {
ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataSource->Name(), parent);
@@ -131,26 +118,10 @@
}
-void ScalarModel::createTree() {
- QList<ObjectPtr> objects = _store->objectList();
- foreach(const ObjectPtr& obj, objects) {
- if (kst_cast<Primitive>(obj)) {
- if (kst_cast<Scalar>(obj) && !kst_cast<Scalar>(obj)->orphan()) {
- continue;
- }
- addPrimitivesScalars<Scalar>(kst_cast<Primitive>(obj));
- } else if (kst_cast<DataSource>(obj) && !kst_cast<DataSource>(obj)->scalar().list().isEmpty()) {
- addDataSource(kst_cast<DataSource>(obj));
- } else if (kst_cast<DataObject>(obj)) {
- addDataObject(kst_cast<DataObject>(obj));
- }
- }
-}
-
-int ScalarModel::rowCount(const QModelIndex& parent) const {
+int PrimitiveModel::rowCount(const QModelIndex& parent) const {
ScalarTreeItem *parentItem;
if (parent.column() > 0)
return 0;
@@ -164,7 +135,7 @@
}
-QVariant ScalarModel::data(const QModelIndex& index, int role) const {
+QVariant PrimitiveModel::data(const QModelIndex& index, int role) const {
if (!index.isValid()) {
return QVariant();
}
@@ -179,7 +150,7 @@
}
-QModelIndex ScalarModel::index(int row, int col, const QModelIndex& parent) const {
+QModelIndex PrimitiveModel::index(int row, int col, const QModelIndex& parent) const {
if (row < 0 || col < 0 || col > 1) {
return QModelIndex();
}
@@ -202,7 +173,7 @@
}
-QModelIndex ScalarModel::parent(const QModelIndex& index) const {
+QModelIndex PrimitiveModel::parent(const QModelIndex& index) const {
Q_ASSERT(_store);
if (!index.isValid())
@@ -218,7 +189,7 @@
}
-QVariant ScalarModel::headerData(int section, Qt::Orientation orientation, int role) const {
+QVariant PrimitiveModel::headerData(int section, Qt::Orientation orientation, int role) const {
if (role != Qt::DisplayRole) {
return QAbstractItemModel::headerData(section, orientation, role);
}
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.h #1215737:1215738
@@ -43,14 +43,14 @@
ScalarTreeItem *parentItem;
};
-class ScalarModel : public QAbstractItemModel
+class PrimitiveModel : public QAbstractItemModel
{
enum ColumnID { Name, Value };
public:
- ScalarModel(ObjectStore *store);
- ~ScalarModel();
+ PrimitiveModel(ObjectStore *store);
+ ~PrimitiveModel();
int columnCount(const QModelIndex& parent = QModelIndex()) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
@@ -59,8 +59,24 @@
QModelIndex parent(const QModelIndex& index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
- void createTree();
+ template<class T>
+ void createTree() {
+ QList<ObjectPtr> objects = _store->objectList();
+ foreach(const ObjectPtr& obj, objects) {
+ if (kst_cast<Primitive>(obj)) {
+ if (kst_cast<T>(obj) && !kst_cast<T>(obj)->orphan()) {
+ continue;
+ }
+ addPrimitivesScalars<T>(kst_cast<Primitive>(obj));
+ } else if (kst_cast<DataSource>(obj) && !kst_cast<DataSource>(obj)->scalar().list().isEmpty()) {
+ addDataSource(kst_cast<DataSource>(obj));
+ } else if (kst_cast<DataObject>(obj)) {
+ addDataObject<T>(kst_cast<DataObject>(obj));
+ }
+ }
+ }
+
template<class T>
void addScalar(T* scalar, ScalarTreeItem* parent = 0) {
addScalarTreeItem(QList<QVariant>() << scalar->Name() << scalar->value(), parent);
@@ -70,7 +86,7 @@
void addScalars(const PrimitiveMap& scalarMap, ScalarTreeItem* parent) {
foreach(const PrimitivePtr& scalar, scalarMap) {
if(kst_cast<T>(scalar)) {
- addScalar<Scalar>(kst_cast<T>(scalar), parent);
+ addScalar<T>(kst_cast<T>(scalar), parent);
}
}
}
@@ -81,18 +97,44 @@
addScalars<T>(prim->metas(), item);
}
- void addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent = 0);
- void addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent = 0);
+ template<class T>
+ void addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent = 0) {
+ ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataObject->Name(), parent);
+ ObjectList<Primitive> primitives = dataObject->outputPrimitives();
+ foreach(PrimitivePtr prim, primitives) {
+ if (!kst_cast<String>(prim)) {
+ addPrimitivesScalars<T>(prim.data(), item);
+ }
+ }
+ }
+ virtual void addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent = 0) = 0;
+
+protected:
+ ScalarTreeItem* addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent);
+
private:
ObjectStore *_store;
ScalarTreeItem *_rootItem;
+};
- ScalarTreeItem* addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent);
+class ScalarModel : public PrimitiveModel
+{
+ enum ColumnID { Name, Value };
+
+public:
+ ScalarModel(ObjectStore *store) : PrimitiveModel(store) {
+ createTree<Scalar>();
+ }
+
+ void addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent = 0);
};
+
+
+
}
#endif
More information about the Kst
mailing list