[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/office/flake
From: Jan Hambrecht <jaham () gmx ! net>
Date: 2006-05-25 14:53:27
Message-ID: 1148568807.937186.7505.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 544623 by jaham:
* implemented the KoShapeCreateCommand for undo/redo on shape creation
* added a KoShapeControllerInterface to be implemented by the applications document classes
* added a basic FlakeDocument which:
- holds a list of all shapes
- holds a list of all views
- implements the KoShapeControllerInterface
M +33 -0 lib/KoCommand.cpp
M +15 -0 lib/KoCommand.h
A lib/KoShapeControllerInterface.h [License: LGPL (v2+)]
M +49 -3 testapp/mainwindow.cpp
M +29 -1 testapp/mainwindow.h
--- trunk/playground/office/flake/lib/KoCommand.cpp #544622:544623
@@ -2,6 +2,7 @@
#include "KoShape.h"
#include "KoShapeGroup.h"
#include "KoShapeContainer.h"
+#include "KoShapeControllerInterface.h"
#include <QString>
@@ -155,3 +156,35 @@
QString KoUngroupShapesCommand::name () const {
return "Ungroup shapes";
}
+
+KoShapeCreateCommand::KoShapeCreateCommand( KoShapeControllerInterface *controller, KoShape *shape )
+: m_controller( controller )
+, m_shape( shape )
+, m_deleteShape( true )
+{
+}
+
+KoShapeCreateCommand::~KoShapeCreateCommand() {
+ if( m_shape && m_deleteShape )
+ delete m_shape;
+}
+
+void KoShapeCreateCommand::execute () {
+ if( ! m_shape || ! m_controller )
+ return;
+
+ m_controller->addShape( m_shape );
+ m_deleteShape = false;
+}
+
+void KoShapeCreateCommand::unexecute () {
+ if( ! m_shape || ! m_controller )
+ return;
+
+ m_controller->removeShape( m_shape );
+ m_deleteShape = true;
+}
+
+QString KoShapeCreateCommand::name () const {
+ return "Create shape";
+}
--- trunk/playground/office/flake/lib/KoCommand.h #544622:544623
@@ -30,6 +30,7 @@
class KoShape;
class KoShapeGroup;
class KoShapeContainer;
+class KoShapeControllerInterface;
class QString;
/// The undo / redo command for shape moving.
@@ -129,4 +130,18 @@
QString name () const;
};
+/// The undo / redo command for creating shapes
+class KoShapeCreateCommand : public KCommand {
+public:
+ KoShapeCreateCommand( KoShapeControllerInterface *controller, KoShape *shape );
+ virtual ~KoShapeCreateCommand();
+ void execute ();
+ void unexecute ();
+ virtual QString name () const;
+protected:
+ KoShapeControllerInterface *m_controller;
+ KoShape *m_shape;
+ bool m_deleteShape;
+};
+
#endif
--- trunk/playground/office/flake/testapp/mainwindow.cpp #544622:544623
@@ -46,7 +46,7 @@
#include "math.h"
-FlakeCanvas::FlakeCanvas(KSillyCommandHistory *commandHistory, QList<KoShape *> &objects)
+FlakeCanvas::FlakeCanvas(KSillyCommandHistory *commandHistory, const QList<KoShape *> &objects)
: QWidget()
, m_objects(objects)
, m_tool( "Default", 0, "Default", this )
@@ -355,14 +355,60 @@
update(clipRect);
}
+FlakeDocument::FlakeDocument() {
+}
+
+FlakeDocument::~FlakeDocument() {
+ while (!m_objects.isEmpty())
+ delete m_objects.takeFirst();
+}
+
+void FlakeDocument::addShape( KoShape* shape ) {
+ if( shape )
+ m_objects.append( shape );
+}
+
+void FlakeDocument::removeShape( KoShape* shape ) {
+ m_objects.removeAll(shape);
+ // remove the shape from all the attached views
+ foreach( KoCanvasBase* view, m_views ) {
+ if( view ) {
+ view->shapeManager()->remove( shape );
+ view->updateCanvas( shape->boundingBox() );
+ }
+ }
+}
+
+void FlakeDocument::addView( KoCanvasBase* view ) {
+ if( view )
+ m_views.append( view );
+}
+
+void FlakeDocument::removeView( KoCanvasBase* view ) {
+ m_views.removeAll( view );
+}
+
// ########## MainWindow ########
MainWindow::MainWindow()
{
m_commandHistory = new KSillyCommandHistory();
+ m_document = new FlakeDocument();
+
QList<KoShape *> testObjects = FlakeCanvas::createObjects();
- m_canvas = new FlakeCanvas(m_commandHistory, testObjects);
+ foreach (KoShape *shape, testObjects ) {
+ KCommand* cmd = new KoShapeCreateCommand( m_document, shape );
+ m_commandHistory->addCommand( cmd, true );
+ }
+
+ m_canvas = new FlakeCanvas(m_commandHistory, m_document->objects());
QSplitter *splitter = new QSplitter(Qt::Vertical);
- splitter->addWidget(new FlakeCanvas(m_commandHistory, testObjects));
+ FlakeCanvas* fc = new FlakeCanvas(m_commandHistory, m_document->objects());
+
+ // attach the views to the document
+ m_document->addView( m_canvas );
+ m_document->addView( fc );
+
+ splitter->addWidget( fc );
splitter->addWidget(m_canvas);
QList<int> sizes;
sizes << 0 << 100;
--- trunk/playground/office/flake/testapp/mainwindow.h #544622:544623
@@ -31,6 +31,7 @@
#include <KoViewConverter.h>
#include <KoCanvasBase.h>
#include <kcommand.h>
+#include <KoShapeControllerInterface.h>
class QAction;
class QListWidget;
@@ -47,7 +48,7 @@
Q_OBJECT
public:
- FlakeCanvas(KSillyCommandHistory *commandHistory, QList<KoShape*> &objects);
+ FlakeCanvas(KSillyCommandHistory *commandHistory, const QList<KoShape*> &objects);
virtual ~FlakeCanvas() {};
static QList<KoShape *> createObjects();
@@ -125,7 +126,33 @@
bool m_snapToGrid;
};
+/// a very basic document holding all the applications objects
+class FlakeDocument : public QObject, public KoShapeControllerInterface
+{
+ Q_OBJECT
+public:
+ FlakeDocument();
+ virtual ~FlakeDocument();
+ /// returns the list of objects
+ const QList<KoShape *> & objects() const { return m_objects; }
+
+ // inherited from KoShapeControllerInterface
+ virtual void addShape( KoShape* shape );
+ virtual void removeShape( KoShape* shape );
+
+ /// add a new view
+ void addView( KoCanvasBase* view );
+ /// remove a connected view
+ void removeView( KoCanvasBase* view );
+
+private:
+ /// the list of the documents objects
+ QList<KoShape *> m_objects;
+ /// the list of the connected views
+ QList<KoCanvasBase*> m_views;
+};
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -153,6 +180,7 @@
FlakeCanvas * m_canvas;
KSillyCommandHistory *m_commandHistory;
+ FlakeDocument* m_document;
QToolBar * m_fileToolBar;
QAction * m_aboutAct;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic