[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Thu May 24 19:23:23 CEST 2007
SVN commit 667983 by treat:
* Work on command pattern
M +35 -3 kstmainwindow.cpp
M +10 -3 kstmainwindow.h
M +13 -3 kstplotview.cpp
M +5 -0 kstplotview.h
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.cpp #667982:667983
@@ -17,11 +17,12 @@
KstMainWindow::KstMainWindow() {
- _undoStack = new QUndoStack(this);
+ _undoGroup = new QUndoGroup(this);
_tabWidget = new QTabWidget(this);
- _tabWidget->addTab(new KstPlotView, "Plot #1");
- _tabWidget->addTab(new KstPlotView, "Plot #2");
+
+ createPlotView();
+
setCentralWidget(_tabWidget);
createActions();
@@ -37,6 +38,37 @@
}
+QUndoGroup *KstMainWindow::undoGroup() const {
+ return _undoGroup;
+}
+
+
+QTabWidget *KstMainWindow::tabWidget() const {
+ return _tabWidget;
+}
+
+
+KstPlotView *KstMainWindow::createPlotView() {
+ KstPlotView *plotView = new KstPlotView;
+ connect(plotView, SIGNAL(destroyed(QObject*)),
+ this, SLOT(plotViewDestroyed(QObject*)));
+ _undoGroup->addStack(plotView->undoStack());
+
+ QString label = plotView->objectName().isEmpty() ?
+ QString("Plot %1").arg(QString::number(_tabWidget->count())) :
+ plotView->objectName();
+
+ _tabWidget->addTab(plotView, label);
+ return plotView;
+}
+
+
+void KstMainWindow::plotViewDestroyed(QObject *object) {
+ KstPlotView *plotView = qobject_cast<KstPlotView*>(object);
+ _tabWidget->removeTab(_tabWidget->indexOf(plotView));
+}
+
+
void KstMainWindow::aboutToQuit() {
writeSettings();
}
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.h #667982:667983
@@ -17,8 +17,10 @@
class QMenu;
class QAction;
class QTabWidget;
-class QUndoStack;
+class QUndoGroup;
+class KstPlotView;
+
class KstMainWindow : public QMainWindow
{
Q_OBJECT
@@ -26,11 +28,16 @@
KstMainWindow();
virtual ~KstMainWindow();
+ QUndoGroup *undoGroup() const;
+ QTabWidget *tabWidget() const;
+
+ KstPlotView *createPlotView();
+
private Q_SLOTS:
void aboutToQuit();
void about();
+ void plotViewDestroyed(QObject *object);
-
private:
void createActions();
void createMenus();
@@ -41,7 +48,7 @@
void writeSettings();
private:
- QUndoStack *_undoStack;
+ QUndoGroup *_undoGroup;
QTabWidget *_tabWidget;
QMenu *_fileMenu;
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.cpp #667982:667983
@@ -13,19 +13,29 @@
#include "kstmainwindow.h"
#include "kstapplication.h"
+#include <QUndoStack>
#include <QGraphicsScene>
KstPlotView::KstPlotView()
: QGraphicsView(kstApp->mainWindow()) {
- QGraphicsScene *scene = new QGraphicsScene(this);
- scene->addText("Hello, Kst Plot!");
- setScene(scene);
+
+ _undoStack = new QUndoStack(this);
+
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->addText("Hello, Kst Plot!");
+ setScene(scene);
+
}
KstPlotView::~KstPlotView() {
}
+
+QUndoStack *KstPlotView::undoStack() const {
+ return _undoStack;
+}
+
#include "kstplotview.moc"
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.h #667982:667983
@@ -16,6 +16,8 @@
#include "kst_export.h"
+class QUndoStack;
+
class KST_EXPORT KstPlotView : public QGraphicsView
{
Q_OBJECT
@@ -23,7 +25,10 @@
KstPlotView();
virtual ~KstPlotView();
+ QUndoStack *undoStack() const;
+
private:
+ QUndoStack *_undoStack;
};
#endif
More information about the Kst
mailing list