[Kst] branches/work/kst/portto4/kst/src/libkstapp
Peter Kümmel
syntheticpp at gmx.net
Wed Jan 19 14:47:45 CET 2011
SVN commit 1215739 by kuemmel:
add StringModel which also shows meta data loaded from datasources
M +11 -113 stringmodel.cpp
M +8 -20 stringmodel.h
--- branches/work/kst/portto4/kst/src/libkstapp/stringmodel.cpp #1215738:1215739
@@ -23,125 +23,23 @@
namespace Kst {
-StringModel::StringModel(ObjectStore *store)
-: QAbstractItemModel(), _store(store) {
- generateObjectList();
-}
+void StringModel::addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent) {
+ ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataSource->Name(), parent);
-StringModel::~StringModel() {
+ QStringList scalars = dataSource->string().list();
+ scalars.sort();
+ foreach(QString scalar, scalars) {
+ QList<QVariant> data;
+ QString value;
+ DataString::ReadInfo readInfo(&value);
+ dataSource->string().read(scalar, readInfo);
+ data << scalar << value;
+ new ScalarTreeItem(data, item);
}
-
-
-int StringModel::columnCount(const QModelIndex& parent) const {
- Q_UNUSED(parent)
- return 2;
}
-void StringModel::generateObjectList() {
- ObjectList<DataObject> dol = _store->getObjects<DataObject>();
- ObjectList<String> sol = _store->getObjects<String>();
-
- foreach(DataObject* dataObject, dol) {
- foreach(StringPtr string, dataObject->outputStrings()) {
- _objectList.append(string);
}
- }
- foreach(String* string, sol) {
- if (string->orphan()) {
- _objectList.append(string);
- }
- }
-}
-
-int StringModel::rowCount(const QModelIndex& parent) const {
- int rc = 0;
- if (!parent.isValid()) {
- rc = _objectList.count();
- }
- return rc;
-}
-
-
-QVariant StringModel::data(const QModelIndex& index, int role) const {
- if (!index.isValid()) {
- return QVariant();
- }
-
- if (role != Qt::DisplayRole) {
- return QVariant();
- }
-
- const int row = index.row();
- if (row < _objectList.count()) {
- if (StringPtr p = kst_cast<String>(_objectList.at(row))) {
- return stringData(p, index);
- }
- }
-
- return QVariant();
-}
-
-
-QVariant StringModel::stringData(StringPtr string, const QModelIndex& index) const {
- QVariant rc;
-
- if (string) {
- if (index.column() == Name) {
- string->readLock();
- rc.setValue(string->Name());
- string->unlock();
- } else if (index.column() == Value) {
- string->readLock();
- rc = QVariant(string->value());
- string->unlock();
- }
- }
-
- return rc;
-}
-
-
-QModelIndex StringModel::index(int row, int col, const QModelIndex& parent) const {
- if (row < 0 || col < 0 || col > 1) {
- return QModelIndex();
- }
-
- const int count = _objectList.count();
- ObjectPtr object = 0;
- if (!parent.isValid()) {
- if (row < count) {
- return createIndex(row, col);
- }
- }
-
- return QModelIndex();
-}
-
-
-QModelIndex StringModel::parent(const QModelIndex& index) const {
- Q_UNUSED(index);
- return QModelIndex();
-}
-
-
-QVariant StringModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (role != Qt::DisplayRole) {
- return QAbstractItemModel::headerData(section, orientation, role);
- }
- switch (section) {
- case Name:
- return tr("Name");
- case Value:
- return tr("Value");
- default:
- break;
- }
- return QVariant();
-}
-
-}
-
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/stringmodel.h #1215738:1215739
@@ -13,38 +13,26 @@
#ifndef STRINGMODEL_H
#define STRINGMODEL_H
-#include <QAbstractItemModel>
-#include "dataobject.h"
-#include "object.h"
+#include "scalarmodel.h"
+
namespace Kst {
-class ObjectStore;
-
-class StringModel : public QAbstractItemModel
+class StringModel : public PrimitiveModel
{
enum ColumnID { Name, Value };
public:
- StringModel(ObjectStore *store);
- ~StringModel();
+ StringModel(ObjectStore *store) : PrimitiveModel(store) {
+ createTree<String>();
+ }
- int columnCount(const QModelIndex& parent = QModelIndex()) const;
- int rowCount(const QModelIndex& parent = QModelIndex()) const;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
- QModelIndex index(int row, int col, const QModelIndex& parent = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index) const;
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
- void generateObjectList();
-private:
- QVariant stringData(StringPtr string, const QModelIndex& index) const;
-
- ObjectStore *_store;
- ObjectList<Object> _objectList;
+ void addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent = 0);
};
+
}
#endif
More information about the Kst
mailing list