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

Adam Treat treat at kde.org
Fri May 25 01:33:00 CEST 2007


SVN commit 668062 by treat:

* Undo and redo for the label command works.


 M  +9 -1      kstmainwindow.cpp  
 M  +1 -0      kstmainwindow.h  
 M  +26 -9     kstplotcommands.cpp  
 M  +6 -0      kstplotcommands.h  


--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.cpp #668061:668062
@@ -20,9 +20,11 @@
 KstMainWindow::KstMainWindow() {
 
   _tabWidget = new QTabWidget(this);
-
   _undoGroup = new QUndoGroup(this);
 
+  connect(_tabWidget, SIGNAL(currentChanged(int)),
+          this, SLOT(currentPlotChanged()));
+
   createPlotView();
 
   setCentralWidget(_tabWidget);
@@ -60,6 +62,7 @@
   connect(plotView, SIGNAL(destroyed(QObject*)),
           this, SLOT(plotViewDestroyed(QObject*)));
   _undoGroup->addStack(plotView->undoStack());
+  _undoGroup->setActiveStack(plotView->undoStack());
 
   QString label = plotView->objectName().isEmpty() ?
                   QString("Plot %1").arg(QString::number(_tabWidget->count())) :
@@ -70,6 +73,11 @@
 }
 
 
+void KstMainWindow::currentPlotChanged() {
+  _undoGroup->setActiveStack(currentPlotView()->undoStack());
+}
+
+
 void KstMainWindow::plotViewDestroyed(QObject *object) {
   KstPlotView *plotView = qobject_cast<KstPlotView*>(object);
   _tabWidget->removeTab(_tabWidget->indexOf(plotView));
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.h #668061:668062
@@ -37,6 +37,7 @@
 private Q_SLOTS:
   void aboutToQuit();
   void about();
+  void currentPlotChanged();
   void plotViewDestroyed(QObject *object);
   void createLabel();
 
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotcommands.cpp #668061:668062
@@ -53,20 +53,13 @@
 
 CreateLabelCommand::CreateLabelCommand()
     : KstPlotViewCommand(QObject::tr("Create Label")) {
-
-  bool ok;
-  QString text = QInputDialog::getText(_view, QObject::tr("label"),
-                                       QObject::tr("label:"), QLineEdit::Normal,
-                                       QString::null, &ok);
-  if (ok && !text.isEmpty()) {
-    _item = new LabelItem(text, _view);
-    _view->scene()->addItem(_item->graphicsItem());
-  }
+  createItem();
 }
 
 
 CreateLabelCommand::CreateLabelCommand(KstPlotView *view)
     : KstPlotViewCommand(view, QObject::tr("Create Label")) {
+  createItem();
 }
 
 
@@ -74,4 +67,28 @@
 }
 
 
+void CreateLabelCommand::undo() {
+  if (_item)
+    _item->graphicsItem()->hide();
+}
+
+
+void CreateLabelCommand::redo() {
+  if (!_item)
+    createItem();
+
+  _item->graphicsItem()->show();
+}
+
+void CreateLabelCommand::createItem() {
+  bool ok;
+  QString text = QInputDialog::getText(_view, QObject::tr("label"),
+                                       QObject::tr("label:"), QLineEdit::Normal,
+                                       QString::null, &ok);
+  if (ok && !text.isEmpty()) {
+    _item = new LabelItem(text, _view);
+    _view->scene()->addItem(_item->graphicsItem());
+  }
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotcommands.h #668061:668062
@@ -49,6 +49,12 @@
   CreateLabelCommand(KstPlotView *view);
   virtual ~CreateLabelCommand();
 
+  virtual void undo();
+  virtual void redo();
+
+private:
+  void createItem();
+
 protected:
   QPointer<KstPlotItem> _item;
 };


More information about the Kst mailing list