[Kst] branches/work/kst/portto4/kst/src/libkstapp
Peter Kümmel
syntheticpp at gmx.net
Tue Aug 31 20:04:41 CEST 2010
SVN commit 1170369 by kuemmel:
Start vector index at 0 in GUI
CCBUG: 249544
M +26 -34 vectormodel.cpp
M +3 -4 vectormodel.h
M +3 -0 viewvectordialog.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.cpp #1170368:1170369
@@ -18,7 +18,7 @@
namespace Kst {
VectorModel::VectorModel(Vector *v)
-: QAbstractItemModel(), _v(v) {
+: QAbstractTableModel (), _vector(v) {
assert(v);
}
@@ -27,32 +27,32 @@
}
-int VectorModel::columnCount(const QModelIndex& parent) const {
- Q_UNUSED(parent)
- return 1;
+int VectorModel::columnCount(const QModelIndex&) const {
+ return 2;
}
-int VectorModel::rowCount(const QModelIndex& parent) const {
- Q_UNUSED(parent)
- return _v ? _v->length() : 0;
+int VectorModel::rowCount(const QModelIndex&) const {
+ return _vector ? _vector->length() : 0;
}
QVariant VectorModel::data(const QModelIndex& index, int role) const {
- Q_UNUSED(role)
- QVariant rc;
- if (index.isValid() && _v) {
+ if (index.isValid() && _vector) {
switch (role) {
case Qt::DisplayRole:
- rc = QVariant(_v->value(index.row()));
+ if (index.column() == 0) {
+ return QVariant(index.row());
+ } else if (index.column() == 1) {
+ return QVariant(_vector->value(index.row()));
+ }
break;
case Qt::FontRole:
{
- if (_v->editable()) {
+ if (_vector->editable()) {
QFont f;
f.setBold(true);
- rc = f;
+ return QVariant(f);
}
}
break;
@@ -60,43 +60,35 @@
break;
}
}
- return rc;
+ return QVariant();
}
-QModelIndex VectorModel::index(int row, int col, const QModelIndex& parent) const {
- Q_UNUSED(parent)
- Q_UNUSED(col)
- if (_v && row < _v->length()) {
- return createIndex(row, 1);
- }
+QModelIndex VectorModel::parent(const QModelIndex&) const {
return QModelIndex();
}
-QModelIndex VectorModel::parent(const QModelIndex& index) const {
- Q_UNUSED(index)
- return QModelIndex();
-}
-
-
QVariant VectorModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (!_v || role != Qt::DisplayRole || orientation == Qt::Vertical || section != 0) {
+ if (!_vector || role != Qt::DisplayRole || orientation == Qt::Vertical || section > 1) {
return QAbstractItemModel::headerData(section, orientation, role);
}
- QVariant var;
- var.setValue(_v->Name());
- return var;
+ if (section == 0) {
+ return QVariant("Index");
+ } else if(section == 1) {
+ return QVariant(_vector->Name());
}
+ return QVariant();
+}
Qt::ItemFlags VectorModel::flags(const QModelIndex& index) const {
Qt::ItemFlags f = QAbstractItemModel::flags(index);
- if (!_v || !index.isValid()) {
+ if (!_vector || !index.isValid()) {
return f;
}
- if (_v->editable() && index.row() >= 0 && index.row() < _v->length()) {
+ if (_vector->editable() && index.row() >= 0 && index.row() < _vector->length()) {
f |= Qt::ItemIsEditable;
}
@@ -109,7 +101,7 @@
return QAbstractItemModel::setData(index, value, role);
}
- if (!_v || !index.isValid() || !_v->editable() || index.row() < 0 || index.row() >= _v->length()) {
+ if (!_vector || !index.isValid() || !_vector->editable() || index.row() < 0 || index.row() >= _vector->length()) {
return false;
}
@@ -120,7 +112,7 @@
}
qDebug() << "UGLY!! Add setData API to KstVector!";
- double *d = const_cast<double*>(_v->value());
+ double *d = const_cast<double*>(_vector->value());
d[index.row()] = v;
return true;
}
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.h #1170368:1170369
@@ -12,13 +12,13 @@
#ifndef VECTORMODEL_H
#define VECTORMODEL_H
-#include <QAbstractItemModel>
+#include <QAbstractTableModel >
#include <QPointer>
#include <vector.h>
namespace Kst {
-class VectorModel : public QAbstractItemModel
+class VectorModel : public QAbstractTableModel
{
public:
VectorModel(Vector *v);
@@ -27,14 +27,13 @@
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;
Qt::ItemFlags flags(const QModelIndex& index) const;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
private:
- QPointer<Vector> _v;
+ QPointer<Vector> _vector;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/viewvectordialog.cpp #1170368:1170369
@@ -26,7 +26,10 @@
Q_ASSERT(_doc && _doc->objectStore());
setupUi(this);
+ // TODO ResizeToContents is too expensive
+ //_vectors->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
_vectors->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+ _vectors->verticalHeader()->hide();
connect(_vectorSelector, SIGNAL(selectionChanged(const QString&)), this, SLOT(vectorSelected()));
_vectorSelector->setObjectStore(doc->objectStore());
More information about the Kst
mailing list