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

George Staikos staikos at kde.org
Mon May 28 21:05:47 CEST 2007


SVN commit 669201 by staikos:

 add a vector table model as a table of vector models


 M  +1 -0      CMakeLists.txt  
 M  +11 -2     mainwindow.cpp  
 M  +11 -3     vectormodel.cpp  
 M  +1 -0      vectormodel.h  
 A             vectortablemodel.cpp   [License: GPL (v2+)]
 A             vectortablemodel.h   [License: GPL (v2+)]


--- branches/work/kst/portto4/kst/src/libkstapp/CMakeLists.txt #669200:669201
@@ -9,6 +9,7 @@
    lineitem.cpp
    mainwindow.cpp
    vectormodel.cpp
+   vectortablemodel.cpp
    viewcommand.cpp
    view.cpp
    viewitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #669200:669201
@@ -23,7 +23,7 @@
 
 // Temporaries
 #include <QTableView>
-#include "vectormodel.h"
+#include "vectortablemodel.h"
 
 namespace Kst {
 
@@ -134,13 +134,22 @@
   QTableView *view = new QTableView;
   KstVectorPtr v = new KstVector;
   v->resize(999999);
+  KstVectorPtr v2 = new KstVector;
+  v2->resize(999999);
   double *d = const_cast<double *>(v->value()); // yay :)
+  double *d2 = const_cast<double *>(v2->value()); // yay :)
   d[0] = 1;
+  d2[0] = 1;
   for (int i = 1; i < v->length(); ++i) {
     d[i] = d[i-1] + 0.002;
+    d2[i] = d2[i-1] + 0.003;
   }
   VectorModel *m = new VectorModel(v);
-  view->setModel(m);
+  VectorModel *m2 = new VectorModel(v2);
+  VectorTableModel *tm = new VectorTableModel;
+  tm->vectors().append(m);
+  tm->vectors().append(m2);
+  view->setModel(tm);
   view->resize(300, 500);
   view->show();
 }
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.cpp #669200:669201
@@ -39,8 +39,9 @@
 
 QVariant VectorModel::data(const QModelIndex& index, int role) const {
   Q_UNUSED(role)
-  if (!index.isValid() || role != Qt::DisplayRole)
+  if (!index.isValid() || role != Qt::DisplayRole) {
     return QVariant();
+  }
   return QVariant(_v->value(index.row()));
 }
 
@@ -55,12 +56,19 @@
 }
 
 
-QModelIndex VectorModel::parent(const QModelIndex& index) const
-{
+QModelIndex VectorModel::parent(const QModelIndex& index) const {
   Q_UNUSED(index)
   return QModelIndex();
 }
 
+
+QVariant VectorModel::headerData(int section, Qt::Orientation orientation, int role) const {
+  if (role != Qt::DisplayRole || orientation == Qt::Vertical || section != 0) {
+    return QAbstractItemModel::headerData(section, orientation, role);
+  }
+  return _v->tagName();
 }
 
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.h #669200:669201
@@ -28,6 +28,7 @@
   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;
 
 private:
   KstVectorPtr _v;


More information about the Kst mailing list