[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Fri Dec 14 17:15:43 CET 2007
SVN commit 748487 by fenton:
Update ScalarModel to display Scalars of Vectors/Matrices including output Vectors/Matrices of DataObjects.
Create generic ViewPrimitiveDialog with QTreeView for Scalars/Strings.
M +6 -11 libkstapp.pro
M +10 -15 mainwindow.cpp
D scalareditordialog.cpp
D scalareditordialog.h
D scalareditordialog.ui
M +200 -64 scalarmodel.cpp
M +17 -6 scalarmodel.h
D scalartablemodel.cpp
D scalartablemodel.h
D stringeditordialog.cpp
D stringeditordialog.h
D stringeditordialog.ui
A viewprimitivedialog.cpp [License: GPL (v2+)]
A viewprimitivedialog.h [License: GPL (v2+)]
A viewprimitivedialog.ui
--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #748486:748487
@@ -81,15 +81,12 @@
powerspectrumdialog.cpp \
qgetoptions.cpp \
scalardialog.cpp \
- scalareditordialog.cpp \
scalarmodel.cpp \
- scalartablemodel.cpp \
scene.cpp \
selectionrect.cpp \
sessionmodel.cpp \
stringmodel.cpp \
stringtablemodel.cpp \
- stringeditordialog.cpp \
stroketab.cpp \
svgitem.cpp \
tabwidget.cpp \
@@ -102,7 +99,8 @@
viewgridlayout.cpp \
viewitem.cpp \
viewitemdialog.cpp \
- viewmanager.cpp
+ viewmanager.cpp \
+ viewprimitivedialog.cpp
HEADERS += \
application.h \
@@ -167,15 +165,12 @@
powerspectrumdialog.h \
qgetoptions.h \
scalardialog.h \
- scalareditordialog.h \
scalarmodel.h \
- scalartablemodel.h \
scene.h \
selectionrect.h \
sessionmodel.h \
stringmodel.h \
stringtablemodel.h \
- stringeditordialog.h \
svgitem.h \
stroketab.h \
tabwidget.h \
@@ -189,7 +184,8 @@
viewitemdialog.h \
viewitem.h \
viewitemzorder.h \
- viewmanager.h
+ viewmanager.h \
+ viewprimitivedialog.h
FORMS += \
aboutdialog.ui \
@@ -222,13 +218,12 @@
matrixeditordialog.ui \
matrixtab.ui \
powerspectrumtab.ui \
- scalareditordialog.ui \
scalartab.ui \
- stringeditordialog.ui \
stroketab.ui \
vectoreditordialog.ui \
vectortab.ui \
- viewmanager.ui
+ viewmanager.ui \
+ viewprimitivedialog.ui
RESOURCES += \
$$TOPLEVELDIR/src/images/images.qrc
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #748486:748487
@@ -30,9 +30,8 @@
#include "tabwidget.h"
#include "ui_aboutdialog.h"
#include "vectoreditordialog.h"
-#include "scalareditordialog.h"
#include "matrixeditordialog.h"
-#include "stringeditordialog.h"
+#include "viewprimitivedialog.h"
#include "view.h"
#include "viewmanager.h"
@@ -508,20 +507,20 @@
_viewManagerAct->setIcon(QPixmap(":kst_viewmanager.png"));
connect(_viewManagerAct, SIGNAL(triggered()), this, SLOT(showViewManager()));
- _vectorEditorAct = new QAction(tr("&Edit Vectors..."), this);
+ _vectorEditorAct = new QAction(tr("&View Vectors..."), this);
_vectorEditorAct->setStatusTip(tr("Show all vectors in a spreadsheet"));
connect(_vectorEditorAct, SIGNAL(triggered()), this, SLOT(showVectorEditor()));
- _scalarEditorAct = new QAction(tr("Edit &Scalars..."), this);
+ _scalarEditorAct = new QAction(tr("View &Scalars..."), this);
_scalarEditorAct->setStatusTip(tr("Show all scalars in a spreadsheet"));
connect(_scalarEditorAct, SIGNAL(triggered()), this, SLOT(showScalarEditor()));
- _stringEditorAct = new QAction(tr("Edit S&trings..."), this);
+ _stringEditorAct = new QAction(tr("View S&trings..."), this);
_stringEditorAct->setStatusTip(tr("Show all strings in a spreadsheet"));
connect(_stringEditorAct, SIGNAL(triggered()), this, SLOT(showStringEditor()));
- _matrixEditorAct = new QAction(tr("Edit &Matrix..."), this);
- _matrixEditorAct->setStatusTip(tr("Show all matrix in a spreadsheet"));
+ _matrixEditorAct = new QAction(tr("View &Matrix..."), this);
+ _matrixEditorAct->setStatusTip(tr("Show all matrices in a spreadsheet"));
connect(_matrixEditorAct, SIGNAL(triggered()), this, SLOT(showMatrixEditor()));
_exportGraphicsAct = new QAction(tr("&Export..."), this);
@@ -715,18 +714,14 @@
void MainWindow::showScalarEditor() {
- if (!_scalarEditor) {
- _scalarEditor = new ScalarEditorDialog(this, _doc);
- }
- _scalarEditor->show();
+ ViewPrimitiveDialog scalarDialog(this, _doc, ViewPrimitiveDialog::Scalar);
+ scalarDialog.exec();
}
void MainWindow::showStringEditor() {
- if (!_stringEditor) {
- _stringEditor = new StringEditorDialog(this);
- }
- _stringEditor->show();
+ ViewPrimitiveDialog stringDialog(this, _doc, ViewPrimitiveDialog::String);
+ stringDialog.exec();
}
void MainWindow::showMatrixEditor() {
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.cpp #748486:748487
@@ -12,14 +12,18 @@
#include "scalarmodel.h"
#include <assert.h>
+#include <objectstore.h>
+#include <dataobject.h>
+#include <datavector.h>
+#include <generatedvector.h>
+#include <datamatrix.h>
+#include <generatedmatrix.h>
-#include <QFont>
-
namespace Kst {
-ScalarModel::ScalarModel(Scalar *scalar)
-: QAbstractItemModel(), _scalar(scalar) {
- assert(scalar);
+ScalarModel::ScalarModel(ObjectStore *store)
+: QAbstractItemModel(), _store(store) {
+ generateObjectList();
}
@@ -29,105 +33,237 @@
int ScalarModel::columnCount(const QModelIndex& parent) const {
Q_UNUSED(parent)
- return 1;
+ return 2;
}
+void ScalarModel::generateObjectList() {
+ 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<DataObject> dol = _store->getObjects<DataObject>();
+ ObjectList<Scalar> sol = _store->getObjects<Scalar>();
+
+ foreach(DataVector* vector, dvol) {
+ _objectList.append(vector);
+ }
+
+ foreach(GeneratedVector* vector, gvol) {
+ _objectList.append(vector);
+ }
+
+ foreach(DataMatrix* matrix, dmol) {
+ _objectList.append(matrix);
+ }
+
+ foreach(GeneratedMatrix* matrix, gmol) {
+ _objectList.append(matrix);
+ }
+
+ foreach(DataObject* dataObject, dol) {
+ foreach(VectorPtr vector, dataObject->outputVectors()) {
+ _objectList.append(vector);
+ }
+ foreach(MatrixPtr matrix, dataObject->outputMatrices()) {
+ _objectList.append(matrix);
+ }
+ }
+
+ foreach(Scalar* scalar, sol) {
+ if (scalar->orphan()) {
+ _objectList.append(scalar);
+ }
+ }
+}
+
int ScalarModel::rowCount(const QModelIndex& parent) const {
- Q_UNUSED(parent)
- return 1;
+ int rc = 0;
+ if (!parent.isValid()) {
+ rc = _objectList.count();
+ } else if (!parent.parent().isValid()) {
+ if (VectorPtr vector = kst_cast<Vector>(_objectList.at(parent.row()))) {
+ vector->readLock();
+ rc = vector->scalars().count();
+ vector->unlock();
+ } else if (MatrixPtr matrix = kst_cast<Matrix>(_objectList.at(parent.row()))) {
+ matrix->readLock();
+ rc = matrix->scalars().count();
+ matrix->unlock();
+ }
+ }
+ return rc;
}
QVariant ScalarModel::data(const QModelIndex& index, int role) const {
- Q_UNUSED(role)
- Q_UNUSED(index)
+ if (!index.isValid()) {
+ return QVariant();
+ }
+
+ if (role != Qt::DisplayRole) {
+ return QVariant();
+ }
+
+ if (index.internalPointer()) {
+ Object* object = static_cast<Object*>(index.internalPointer());
+ if (!object) {
+ return QVariant();
+ }
+
+ if (VectorPtr parent = kst_cast<Vector>(object)) {
+ return vectorOutputData(parent, index);
+ } else if (MatrixPtr parent = kst_cast<Matrix>(object)) {
+ return matrixOutputData(parent, index);
+ }
+ }
+
+ const int row = index.row();
+ if (row < _objectList.count()) {
+ if (ScalarPtr p = kst_cast<Scalar>(_objectList.at(row))) {
+ return scalarData(p, index);
+ } else if (ObjectPtr p = kst_cast<Object>(_objectList.at(row))) {
+ return objectData(p, index);
+ }
+ }
+
+ return QVariant();
+}
+
+
+QVariant ScalarModel::vectorOutputData(VectorPtr parent, const QModelIndex& index) const {
QVariant rc;
- if (index.isValid() && _scalar) {
- switch (role) {
- case Qt::DisplayRole:
- if (index.column() == 0) {
- rc = QVariant(_scalar->tag().displayString());
- } else {
- rc = QVariant(_scalar->value());
- }
- break;
- case Qt::FontRole:
- {
- if (_scalar->editable()) {
- QFont f;
- f.setBold(true);
- rc = f;
- }
- }
- break;
- default:
- break;
+
+ if (parent) {
+ if (parent->scalars().count() > index.row()) {
+ if (ScalarPtr scalar = parent->scalars().values()[index.row()]) {
+ return scalarData(scalar, index);
+ }
}
}
+
return rc;
}
-QModelIndex ScalarModel::index(int row, int col, const QModelIndex& parent) const {
- Q_UNUSED(parent)
- Q_UNUSED(col)
- if (_scalar) {
- return createIndex(row, 1);
+QVariant ScalarModel::matrixOutputData(MatrixPtr parent, const QModelIndex& index) const {
+ QVariant rc;
+
+ if (parent) {
+ if (parent->scalars().count() > index.row()) {
+ if (ScalarPtr scalar = parent->scalars().values()[index.row()]) {
+ return scalarData(scalar, index);
+ }
+ }
}
- return QModelIndex();
+
+ return rc;
}
-QModelIndex ScalarModel::parent(const QModelIndex& index) const {
- Q_UNUSED(index)
- return QModelIndex();
+QVariant ScalarModel::objectData(ObjectPtr object, const QModelIndex& index) const {
+ QVariant rc;
+
+ if (object) {
+ if (index.column() == Name) {
+ object->readLock();
+ rc.setValue(object->tag().displayString());
+ object->unlock();
+ }
+ }
+
+ return rc;
}
-QVariant ScalarModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (!_scalar || role != Qt::DisplayRole || section != 0) {
- return QAbstractItemModel::headerData(section, orientation, role);
+QVariant ScalarModel::scalarData(ScalarPtr scalar, const QModelIndex& index) const {
+ QVariant rc;
+
+ if (scalar) {
+ if (index.column() == Name) {
+ scalar->readLock();
+ rc.setValue(scalar->tag().name());
+ scalar->unlock();
+ } else if (index.column() == Value) {
+ scalar->readLock();
+ rc = QVariant(scalar->value());
+ scalar->unlock();
+ }
}
- return _scalar->tag().displayString();
+
+ return rc;
}
-Qt::ItemFlags ScalarModel::flags(const QModelIndex& index) const {
- Qt::ItemFlags f = QAbstractItemModel::flags(index);
- if (!_scalar || !index.isValid()) {
- return f;
+QModelIndex ScalarModel::index(int row, int col, const QModelIndex& parent) const {
+ if (row < 0 || col < 0 || col > 1) {
+ return QModelIndex();
}
- if (_scalar->editable() && index.row() >= 0) {
- f |= Qt::ItemIsEditable;
+ const int count = _objectList.count();
+ ObjectPtr object = 0;
+ if (!parent.isValid()) {
+ if (row < count) {
+ return createIndex(row, col);
+ }
+ } else if (!parent.parent().isValid()) {
+ if (parent.row() >= 0 && parent.row() < count) {
+ if (VectorPtr vector = kst_cast<Vector>(_objectList.at(parent.row()))) {
+ vector->readLock();
+ if (row < vector->scalars().count()) {
+ object = vector;
+ }
+ vector->unlock();
+ } else if (MatrixPtr matrix = kst_cast<Matrix>(_objectList.at(parent.row()))) {
+ matrix->readLock();
+ if (row < matrix->scalars().count()) {
+ object = matrix;
+ }
+ matrix->unlock();
+ }
+ }
}
- return f;
+ if (object) {
+ return createIndex(row, col, object);
+ } else {
+ return QModelIndex();
+ }
}
-bool ScalarModel::setData(const QModelIndex& index, const QVariant& value, int role) {
- if (role != Qt::EditRole) {
- return QAbstractItemModel::setData(index, value, role);
- }
+QModelIndex ScalarModel::parent(const QModelIndex& index) const {
+ Q_ASSERT(_store);
+ int row = -1;
- if (!_scalar || !index.isValid() || !_scalar->editable() || index.row() < 0) {
- return false;
+ if (Vector *vector = static_cast<Vector*>(index.internalPointer())) {
+ row = _objectList.indexOf(vector);
+ } else if (Matrix *matrix = static_cast<Matrix*>(index.internalPointer())) {
+ row = _objectList.indexOf(matrix);
}
- bool ok = false;
- double scalarValue = value.toDouble(&ok);
- if (!ok) {
- return false;
+ if (row < 0) {
+ return QModelIndex();
}
-
- qDebug() << "UGLY!! Add setData API to Scalar!";
- _scalar->setValue(scalarValue);
- return true;
+ return createIndex(row, index.column());
}
+QVariant ScalarModel::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/scalarmodel.h #748486:748487
@@ -13,15 +13,20 @@
#define SCALARMODEL_H
#include <QAbstractItemModel>
-#include <QPointer>
-#include <scalar.h>
+#include "dataobject.h"
+#include "object.h"
namespace Kst {
+class ObjectStore;
+
class ScalarModel : public QAbstractItemModel
{
+
+ enum ColumnID { Name, Value };
+
public:
- ScalarModel(Scalar *scalar);
+ ScalarModel(ObjectStore *store);
~ScalarModel();
int columnCount(const QModelIndex& parent = QModelIndex()) const;
@@ -30,11 +35,17 @@
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;
- Qt::ItemFlags flags(const QModelIndex& index) const;
- bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
+ void generateObjectList();
private:
- QPointer<Scalar> _scalar;
+ QVariant dataObjectOutputData(DataObjectPtr parent, const QModelIndex& index) const;
+ QVariant vectorOutputData(VectorPtr parent, const QModelIndex& index) const;
+ QVariant matrixOutputData(MatrixPtr parent, const QModelIndex& index) const;
+ QVariant objectData(ObjectPtr parent, const QModelIndex& index) const;
+ QVariant scalarData(ScalarPtr parent, const QModelIndex& index) const;
+
+ ObjectStore *_store;
+ ObjectList<Object> _objectList;
};
}
More information about the Kst
mailing list