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

George Staikos staikos at kde.org
Mon May 28 18:32:24 CEST 2007


SVN commit 669146 by staikos:

more refactoring


 M  +1 -1      CMakeLists.txt  
 M  +3 -1      TODO  
 M  +2 -2      kstmainwindow.cpp  
 D             kstplotcommands.cpp  
 D             kstplotcommands.h  
 M  +11 -2     labelitem.cpp  
 M  +10 -0     labelitem.h  
 M  +9 -0      lineitem.cpp  
 M  +9 -0      lineitem.h  
 A             viewcommand.cpp   kstplotcommands.cpp#669142 [License: GPL (v2+)]
 A             viewcommand.h   kstplotcommands.h#669142 [License: GPL (v2+)]
 M  +63 -2     viewitem.cpp  
 M  +54 -0     viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/CMakeLists.txt #669145:669146
@@ -7,7 +7,7 @@
    viewitem.cpp
    lineitem.cpp
    labelitem.cpp
-   kstplotcommands.cpp
+   viewcommand.cpp
    )
 
 kde4_automoc(${kstapp_LIB_SRCS})
--- branches/work/kst/portto4/kst/src/libkstapp/TODO #669145:669146
@@ -6,4 +6,6 @@
 - Undo/Redo for item select/focus/move and other ItemChange's
 - Make Undo/Redo of move command work for selections too
 - Movement of lines alone doesn't work
-- Box the objects so they can't be dragged out of the visible size of scene?
\ No newline at end of file
+- Box the objects so they can't be dragged out of the visible size of scene
+- Properly namespace
+- Separate files per class
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.cpp #669145:669146
@@ -12,9 +12,9 @@
 #include "kstmainwindow.h"
 #include "kstapplication.h"
 #include "kstplotview.h"
+#include "labelitem.h"
+#include "lineitem.h"
 
-#include "kstplotcommands.h"
-
 #include <QtGui>
 
 using namespace Kst;
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #669145:669146
@@ -11,8 +11,6 @@
 
 #include "labelitem.h"
 
-#include "kstplotcommands.h"
-
 #include <QDebug>
 #include <QInputDialog>
 #include <QGraphicsItem>
@@ -83,8 +81,19 @@
   }
 }
 
+void CreateLabelCommand::createItem() {
+  _item = new LabelItem(_view);
+  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
+
+  //If the item is interrupted while creating itself it will destroy itself
+  //need to delete this too in response...
+  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+
 }
 
+
+}
+
 #include "labelitem.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.h #669145:669146
@@ -33,6 +33,16 @@
   void creationPolygonChanged(KstPlotView::CreationEvent event);
 };
 
+
+class KST_EXPORT CreateLabelCommand : public CreateCommand
+{
+public:
+  CreateLabelCommand() : CreateCommand(QObject::tr("Create Label")) {}
+  CreateLabelCommand(KstPlotView *view): CreateCommand(view, QObject::tr("Create Label")) {}
+  virtual ~CreateLabelCommand() {}
+  virtual void createItem();
+};
+
 }
 
 #endif
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #669145:669146
@@ -67,8 +67,17 @@
   }
 }
 
+void CreateLineCommand::createItem() {
+  _item = new LineItem(_view);
+  connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
+
+  //If the item is interrupted while creating itself it will destroy itself
+  //need to delete this too in response...
+  connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
 }
 
+}
+
 #include "lineitem.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.h #669145:669146
@@ -30,6 +30,15 @@
   void creationPolygonChanged(KstPlotView::CreationEvent event);
 };
 
+class KST_EXPORT CreateLineCommand : public CreateCommand
+{
+public:
+  CreateLineCommand() : CreateCommand(QObject::tr("Create Line")) {}
+  CreateLineCommand(KstPlotView *view) : CreateCommand(view, QObject::tr("Create Line")) {}
+  virtual ~CreateLineCommand() {}
+  virtual void createItem();
+};
+
 }
 
 #endif
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #669145:669146
@@ -10,9 +10,8 @@
  ***************************************************************************/
 
 #include "viewitem.h"
+#include "kstapplication.h"
 
-#include "kstplotcommands.h"
-
 #include <QDebug>
 #include <QGraphicsItem>
 #include <QGraphicsScene>
@@ -47,8 +46,70 @@
 }
 #endif
 
+
+ViewItemCommand::ViewItemCommand(const QString &text, bool addToStack, QUndoCommand *parent)
+    : QUndoCommand(text, parent), _item(kstApp->mainWindow()->currentPlotView()->currentPlotItem()) {
+  if (addToStack)
+    _item->parentView()->undoStack()->push(this);
 }
 
+
+ViewItemCommand::ViewItemCommand(ViewItem *item, const QString &text, bool addToStack, QUndoCommand *parent)
+    : QUndoCommand(text, parent), _item(item) {
+  if (addToStack)
+    _item->parentView()->undoStack()->push(this);
+}
+
+
+ViewItemCommand::~ViewItemCommand() {
+}
+
+
+CreateCommand::CreateCommand(const QString &text, QUndoCommand *parent)
+    : ViewCommand(text, false, parent) {
+}
+
+
+CreateCommand::CreateCommand(KstPlotView *view, const QString &text, QUndoCommand *parent)
+    : ViewCommand(view, text, false, parent) {
+}
+
+
+CreateCommand::~CreateCommand() {
+}
+
+
+void CreateCommand::undo() {
+  if (_item)
+    _item->graphicsItem()->hide();
+}
+
+
+void CreateCommand::redo() {
+  if (!_item)
+    createItem();
+
+  _item->graphicsItem()->show();
+}
+
+
+void CreateCommand::creationComplete() {
+  _view->undoStack()->push(this);
+}
+
+
+void MoveCommand::undo() {
+  _item->graphicsItem()->setPos(_originalPos);
+}
+
+
+void MoveCommand::redo() {
+  _item->graphicsItem()->setPos(_newPos);
+}
+
+
+}
+
 #include "viewitem.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #669145:669146
@@ -14,6 +14,7 @@
 
 #include <QObject>
 #include "kst_export.h"
+#include "viewcommand.h"
 #include "kstplotview.h" //forward declare, but enums??
 
 // #define DEBUG_GEOMETRY 1
@@ -45,6 +46,59 @@
 #endif
 };
 
+class KST_EXPORT ViewItemCommand : public QUndoCommand
+{
+public:
+  ViewItemCommand(const QString &text, bool addToStack = true, QUndoCommand *parent = 0);
+  ViewItemCommand(ViewItem *item, const QString &text, bool addToStack = true, QUndoCommand *parent = 0);
+  virtual ~ViewItemCommand();
+
+protected:
+  QPointer<ViewItem> _item;
+};
+
+// TODO: inherit from ViewItemCommand?
+class KST_EXPORT CreateCommand : public QObject, public ViewCommand
+{
+  Q_OBJECT
+public:
+  CreateCommand(const QString &text, QUndoCommand *parent = 0);
+  CreateCommand(KstPlotView *view, const QString &text, QUndoCommand *parent = 0);
+  virtual ~CreateCommand();
+
+  virtual void undo();
+  virtual void redo();
+  virtual void createItem() = 0;
+
+public Q_SLOTS:
+  void creationComplete();
+
+protected:
+  QPointer<ViewItem> _item;
+};
+
+class KST_EXPORT MoveCommand : public ViewItemCommand
+{
+public:
+  MoveCommand(QPointF originalPos, QPointF newPos)
+      : ViewItemCommand(QObject::tr("Move Object")),
+        _originalPos(originalPos),
+        _newPos(newPos) {}
+  MoveCommand(ViewItem *item, QPointF originalPos, QPointF newPos)
+      : ViewItemCommand(item, QObject::tr("Move Object")),
+        _originalPos(originalPos),
+        _newPos(newPos) {}
+
+  virtual ~MoveCommand() {}
+
+  virtual void undo();
+  virtual void redo();
+
+private:
+  QPointF _originalPos;
+  QPointF _newPos;
+};
+
 }
 
 #endif


More information about the Kst mailing list