[QGIS Commit] r14827 - in trunk/qgis: python/core python/gui src/gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Dec 2 04:55:43 EST 2010


Author: mhugent
Date: 2010-12-02 01:55:42 -0800 (Thu, 02 Dec 2010)
New Revision: 14827

Added:
   trunk/qgis/python/core/qgsaddremoveitemcommand.sip
   trunk/qgis/python/core/qgscomposeritemcommand.sip
Modified:
   trunk/qgis/python/core/core.sip
   trunk/qgis/python/core/qgscomposition.sip
   trunk/qgis/python/gui/qgscomposerview.sip
   trunk/qgis/src/gui/qgscomposerview.h
Log:
Add python bindings for composer command classes

Modified: trunk/qgis/python/core/core.sip
===================================================================
--- trunk/qgis/python/core/core.sip	2010-12-02 08:44:48 UTC (rev 14826)
+++ trunk/qgis/python/core/core.sip	2010-12-02 09:55:42 UTC (rev 14827)
@@ -11,9 +11,11 @@
 // TODO: more files to wrap
 
 %Include qgis.sip
+%Include qgsaddremoveitemcommand.sip
 %Include qgsapplication.sip
 %Include qgscomposerattributetable.sip
 %Include qgscomposeritem.sip
+%Include qgscomposeritemcommand.sip
 %Include qgscomposerlabel.sip
 %Include qgscomposerlegend.sip
 %Include qgscomposermap.sip

Added: trunk/qgis/python/core/qgsaddremoveitemcommand.sip
===================================================================
--- trunk/qgis/python/core/qgsaddremoveitemcommand.sip	                        (rev 0)
+++ trunk/qgis/python/core/qgsaddremoveitemcommand.sip	2010-12-02 09:55:42 UTC (rev 14827)
@@ -0,0 +1,25 @@
+/** \ingroup MapComposer
+A composer command class for adding / removing composer items. If mState == Removed, the command owns the item*/
+class QgsAddRemoveItemCommand: QObject, QUndoCommand
+{
+%TypeHeaderCode
+  #include "qgsaddremoveitemcommand.h"
+%End
+  public:
+
+    enum State
+    {
+      Added = 0,
+      Removed
+    };
+
+    QgsAddRemoveItemCommand( State s, QgsComposerItem* item, QgsComposition* c, const QString& text, QUndoCommand* parent = 0 );
+    ~QgsAddRemoveItemCommand();
+
+    void redo();
+    void undo();
+
+  signals:
+    void itemAdded( QgsComposerItem* item );
+    void itemRemoved( QgsComposerItem* item );
+};

Added: trunk/qgis/python/core/qgscomposeritemcommand.sip
===================================================================
--- trunk/qgis/python/core/qgscomposeritemcommand.sip	                        (rev 0)
+++ trunk/qgis/python/core/qgscomposeritemcommand.sip	2010-12-02 09:55:42 UTC (rev 14827)
@@ -0,0 +1,85 @@
+/**\ingroup MapComposer
+Undo command to undo/redo all composer item related changes*/
+class QgsComposerItemCommand: QUndoCommand
+{
+%TypeHeaderCode
+  #include "qgscomposeritemcommand.h"
+%End
+  public:
+    QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent = 0 );
+    virtual ~QgsComposerItemCommand();
+
+    /**Reverses the command*/
+    void undo();
+    /**Replays the command*/
+    void redo();
+
+    /**Saves current item state as previous state*/
+    void savePreviousState();
+    /**Saves current item state as after state*/
+    void saveAfterState();
+
+    QDomDocument previousState() const;
+    QDomDocument afterState() const;
+
+    /**Returns true if previous state and after state are valid and different*/
+    bool containsChange() const;
+};
+
+/**\ingroup MapComposer
+A composer command that merges together with other commands having the same context (=id). Keeps the oldest previous state and uses the
+  newest after state. The purpose is to avoid too many micro changes in the history*/
+class QgsComposerMergeCommand: QgsComposerItemCommand
+{
+%TypeHeaderCode
+  #include "qgscomposeritemcommand.h"
+%End
+  public:
+    enum Context
+    {
+      Unknown = 0,
+      //composer label
+      ComposerLabelSetText,
+      //composer map
+      ComposerMapRotation,
+      ComposerMapAnnotationDistance,
+      //composer legend
+      ComposerLegendText,
+      LegendSymbolWidth,
+      LegendSymbolHeight,
+      LegendLayerSpace,
+      LegendSymbolSpace,
+      LegendIconSymbolSpace,
+      LegendBoxSpace,
+      //composer picture
+      ComposerPictureRotation,
+      // composer scalebar
+      ScaleBarLineWidth,
+      ScaleBarHeight,
+      ScaleBarSegmentSize,
+      ScaleBarSegmentsLeft,
+      ScaleBarNSegments,
+      ScaleBarUnitText,
+      ScaleBarMapUnitsSegment,
+      ScaleBarLabelBarSize,
+      ScaleBarBoxContentSpace,
+      // composer table
+      TableMaximumFeatures,
+      TableMargin,
+      TableGridStrokeWidth,
+      //composer shape
+      ShapeRotation,
+      ShapeOutlineWidth,
+      //composer arrow
+      ArrowOutlineWidth,
+      ArrowHeadWidth,
+      //item
+      ItemOutlineWidth
+    };
+
+    QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
+    ~QgsComposerMergeCommand();
+
+    bool mergeWith( const QUndoCommand * command );
+    int id() const;
+ };

Modified: trunk/qgis/python/core/qgscomposition.sip
===================================================================
--- trunk/qgis/python/core/qgscomposition.sip	2010-12-02 08:44:48 UTC (rev 14826)
+++ trunk/qgis/python/core/qgscomposition.sip	2010-12-02 09:55:42 UTC (rev 14827)
@@ -57,6 +57,9 @@
     void setGridStyle( GridStyle s );
     GridStyle gridStyle() const;
 
+    /**Returns pointer to undo/redo command storage*/
+    QUndoStack* undoStack();
+
     /**Returns the topmose composer item. Ignores mPaperItem*/
     QgsComposerItem* composerItemAt( const QPointF & position );
 
@@ -125,4 +128,15 @@
 
     /**Snaps a scene coordinate point to grid*/
     QPointF snapPointToGrid( const QPointF& scenePoint ) const;
+
+    /**Allocates new item command and saves initial state in it
+      @param item target item
+      @param commandText descriptive command text
+      @param c context for merge commands (unknown for non-mergeable commands)*/
+    void beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
+
+    /**Saves end state of item and pushes command to the undo history*/
+    void endCommand();
+    /**Deletes current command*/
+    void cancelCommand();
 };

Modified: trunk/qgis/python/gui/qgscomposerview.sip
===================================================================
--- trunk/qgis/python/gui/qgscomposerview.sip	2010-12-02 08:44:48 UTC (rev 14826)
+++ trunk/qgis/python/gui/qgscomposerview.sip	2010-12-02 09:55:42 UTC (rev 14827)
@@ -68,6 +68,12 @@
     /**Returns the composer main window*/
     QMainWindow* composerWindow();
 
+    void setPaintingEnabled( bool enabled );
+    bool paintingEnabled() const;
+
+    /**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
+    void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
+
   protected:
     void mousePressEvent( QMouseEvent* );
     void mouseReleaseEvent( QMouseEvent* );

Modified: trunk/qgis/src/gui/qgscomposerview.h
===================================================================
--- trunk/qgis/src/gui/qgscomposerview.h	2010-12-02 08:44:48 UTC (rev 14826)
+++ trunk/qgis/src/gui/qgscomposerview.h	2010-12-02 09:55:42 UTC (rev 14827)
@@ -102,6 +102,9 @@
     void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
     bool paintingEnabled() const { return mPaintingEnabled; }
 
+    /**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
+    void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
+
   protected:
     void mousePressEvent( QMouseEvent* );
     void mouseReleaseEvent( QMouseEvent* );
@@ -115,10 +118,7 @@
 
     void paintEvent( QPaintEvent* event );
 
-    /**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
-    void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
 
-
   private:
     /**Status of shift key (used for multiple selection)*/
     bool mShiftKeyPressed;



More information about the QGIS-commit mailing list