[Kst] branches/work/kst/portto4/kst/src/libkstapp
George Staikos
staikos at kde.org
Wed May 30 08:54:45 CEST 2007
SVN commit 669725 by staikos:
add a more generic vector editor/spreadsheet mode dialog
M +2 -0 CMakeLists.txt
M +1 -1 datamanager.ui
M +53 -13 mainwindow.cpp
M +9 -0 mainwindow.h
A vectoreditordialog.cpp [License: GPL (v2+)]
A vectoreditordialog.h [License: GPL (v2+)]
A vectoreditordialog.ui
M +8 -8 vectormodel.cpp
M +3 -2 vectormodel.h
M +2 -2 vectortablemodel.h
--- branches/work/kst/portto4/kst/src/libkstapp/CMakeLists.txt #669724:669725
@@ -15,6 +15,7 @@
plotitem.cpp
sessionmodel.cpp
tabwidget.cpp
+ vectoreditordialog.cpp
vectormodel.cpp
vectortablemodel.cpp
viewcommand.cpp
@@ -24,6 +25,7 @@
kde4_add_ui_files(kstapp_LIB_SRCS
datamanager.ui
+ vectoreditordialog.ui
)
kde4_automoc(${kstapp_LIB_SRCS})
--- branches/work/kst/portto4/kst/src/libkstapp/datamanager.ui #669724:669725
@@ -30,7 +30,7 @@
</widget>
</item>
<item row="0" column="1" >
- <widget class="QListView" name="session" >
+ <widget class="QTreeView" name="session" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>7</hsizetype>
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #669724:669725
@@ -20,20 +20,23 @@
#include "pictureitem.h"
#include "plotitem.h"
#include "tabwidget.h"
+#include "vectoreditordialog.h"
#include "view.h"
#include <QtGui>
// Temporaries
#include "kstavector.h"
+#include "kstdatacollection.h"
#include "kstdataobjectcollection.h"
#include "kstequation.h"
-#include "vectortablemodel.h"
+
namespace Kst {
MainWindow::MainWindow() {
_dataManager = 0;
+ _vectorEditor = 0;
_doc = new Document;
_tabWidget = new TabWidget(this);
_undoGroup = new QUndoGroup(this);
@@ -54,6 +57,8 @@
MainWindow::~MainWindow() {
+ delete _vectorEditor;
+ _vectorEditor = 0;
delete _dataManager;
_dataManager = 0;
delete _doc;
@@ -61,6 +66,36 @@
}
+void MainWindow::cleanup() {
+ KST::dataObjectList.lock().writeLock();
+ KstDataObjectList dol = KST::dataObjectList;
+ KST::dataObjectList.clear();
+ KST::dataObjectList.lock().unlock();
+ dol.clear();
+ KST::dataSourceList.lock().writeLock();
+ KST::dataSourceList.clear();
+ KST::dataSourceList.lock().unlock();
+ KST::matrixList.lock().writeLock();
+ KST::matrixList.clear();
+ KST::matrixList.lock().unlock();
+ KST::scalarList.lock().writeLock();
+ KST::scalarList.clear();
+ KST::scalarList.lock().unlock();
+ KST::stringList.lock().writeLock();
+ KST::stringList.clear();
+ KST::stringList.lock().unlock();
+ KST::vectorList.lock().writeLock();
+ KST::vectorList.clear();
+ KST::vectorList.lock().unlock();
+}
+
+
+void MainWindow::closeEvent(QCloseEvent *e) {
+ cleanup();
+ QMainWindow::closeEvent(e);
+}
+
+
Document *MainWindow::document() const {
return _doc;
}
@@ -129,7 +164,6 @@
void MainWindow::demoModel() {
- QTableView *view = new QTableView;
KstVectorPtr v = new KstVector;
v->resize(999999);
KstVectorPtr v2 = new KstVector;
@@ -143,17 +177,10 @@
d[i] = d[i-1] + 0.002;
d2[i] = d2[i-1] + 0.003;
}
- VectorModel *m = new VectorModel(v);
- VectorModel *m2 = new VectorModel(v2);
- VectorModel *m3 = new VectorModel(v3);
- VectorTableModel *tm = new VectorTableModel;
- tm->vectors().append(m);
- tm->vectors().append(m2);
- tm->vectors().append(m3);
- view->setModel(tm);
- view->resize(300, 500);
- view->show();
KstEquationPtr ep = new KstEquation("My Equation", "x^2", 0, 100, 1000);
+ ep->writeLock();
+ ep->update(0);
+ ep->unlock();
KST::addDataObjectToList(ep.data());
}
@@ -217,10 +244,14 @@
_exitAct->setStatusTip(tr("Exit the application"));
connect(_exitAct, SIGNAL(triggered()), this, SLOT(close()));
- _dataManagerAct = new QAction(tr("Data &Manager"), this);
+ _dataManagerAct = new QAction(tr("Data &Manager..."), this);
_dataManagerAct->setStatusTip(tr("Show Kst's data manager window"));
connect(_dataManagerAct, SIGNAL(triggered()), this, SLOT(showDataManager()));
+ _vectorEditorAct = new QAction(tr("&Vectors..."), this);
+ _vectorEditorAct->setStatusTip(tr("Show all vectors in a spreadsheet"));
+ connect(_vectorEditorAct, SIGNAL(triggered()), this, SLOT(showVectorEditor()));
+
_aboutAct = new QAction(tr("&About"), this);
_aboutAct->setStatusTip(tr("Show Kst's About box"));
connect(_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
@@ -248,6 +279,7 @@
_dataMenu = menuBar()->addMenu(tr("&Data"));
_dataMenu->addAction(_dataManagerAct);
+ _dataMenu->addAction(_vectorEditorAct);
_plotMenu = menuBar()->addMenu(tr("&Plot"));
_plotMenu->addAction(_createLabelAct);
@@ -292,6 +324,14 @@
}
+void MainWindow::showVectorEditor() {
+ if (!_vectorEditor) {
+ _vectorEditor = new VectorEditorDialog(this, _doc);
+ }
+ _vectorEditor->show();
+}
+
+
void MainWindow::readSettings() {
QSettings settings;
QPoint pos = settings.value("pos", QPoint(20, 20)).toPoint();
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #669724:669725
@@ -23,6 +23,7 @@
class DataManager;
class Document;
class TabWidget;
+class VectorEditorDialog;
class View;
class MainWindow : public QMainWindow
@@ -38,6 +39,7 @@
public Q_SLOTS:
void showDataManager();
+ void showVectorEditor();
private Q_SLOTS:
void aboutToQuit();
@@ -53,6 +55,11 @@
void demoModel();
+ void cleanup();
+
+ protected:
+ void closeEvent(QCloseEvent *e);
+
private:
void createActions();
void createMenus();
@@ -68,6 +75,7 @@
QUndoGroup *_undoGroup;
DataManager *_dataManager;
+ VectorEditorDialog *_vectorEditor;
// Do we need these? I don't think so...
QMenu *_fileMenu;
@@ -99,6 +107,7 @@
QAction *_closeTabAct;
QAction *_exitAct;
QAction *_dataManagerAct;
+ QAction *_vectorEditorAct;
QAction *_aboutAct;
QAction *_aboutQtAct;
};
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.cpp #669724:669725
@@ -17,9 +17,9 @@
namespace Kst {
-VectorModel::VectorModel(KstVectorPtr v)
+VectorModel::VectorModel(KstVector *v)
: QAbstractItemModel(), _v(v) {
- assert(v.data());
+ assert(v);
}
@@ -35,14 +35,14 @@
int VectorModel::rowCount(const QModelIndex& parent) const {
Q_UNUSED(parent)
- return _v->length();
+ return _v ? _v->length() : 0;
}
QVariant VectorModel::data(const QModelIndex& index, int role) const {
Q_UNUSED(role)
QVariant rc;
- if (index.isValid()) {
+ if (index.isValid() && _v) {
switch (role) {
case Qt::DisplayRole:
rc = QVariant(_v->value(index.row()));
@@ -67,7 +67,7 @@
QModelIndex VectorModel::index(int row, int col, const QModelIndex& parent) const {
Q_UNUSED(parent)
Q_UNUSED(col)
- if (row < _v->length()) {
+ if (_v && row < _v->length()) {
return createIndex(row, 1);
}
return QModelIndex();
@@ -81,7 +81,7 @@
QVariant VectorModel::headerData(int section, Qt::Orientation orientation, int role) const {
- if (role != Qt::DisplayRole || orientation == Qt::Vertical || section != 0) {
+ if (!_v || role != Qt::DisplayRole || orientation == Qt::Vertical || section != 0) {
return QAbstractItemModel::headerData(section, orientation, role);
}
return _v->tagName();
@@ -90,7 +90,7 @@
Qt::ItemFlags VectorModel::flags(const QModelIndex& index) const {
Qt::ItemFlags f = QAbstractItemModel::flags(index);
- if (!index.isValid()) {
+ if (!_v || !index.isValid()) {
return f;
}
@@ -107,7 +107,7 @@
return QAbstractItemModel::setData(index, value, role);
}
- if (!index.isValid() || !_v->editable() || index.row() < 0 || index.row() >= _v->length()) {
+ if (!_v || !index.isValid() || !_v->editable() || index.row() < 0 || index.row() >= _v->length()) {
return false;
}
--- branches/work/kst/portto4/kst/src/libkstapp/vectormodel.h #669724:669725
@@ -13,6 +13,7 @@
#define VECTORMODEL_H
#include <QAbstractItemModel>
+#include <QPointer>
#include <kstvector.h>
namespace Kst {
@@ -20,7 +21,7 @@
class VectorModel : public QAbstractItemModel
{
public:
- VectorModel(KstVectorPtr v);
+ VectorModel(KstVector *v);
~VectorModel();
int columnCount(const QModelIndex& parent = QModelIndex()) const;
@@ -33,7 +34,7 @@
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
private:
- KstVectorPtr _v;
+ QPointer<KstVector> _v;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/vectortablemodel.h #669724:669725
@@ -28,11 +28,11 @@
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);
QVector<VectorModel*>& vectors() { return _vectors; }
const QVector<VectorModel*>& vectors() const { return _vectors; }
- Qt::ItemFlags flags(const QModelIndex& index) const;
- bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
private:
QVector<VectorModel*> _vectors;
More information about the Kst
mailing list