Skip to content

Commit

Permalink
Add python bindings for composer command classes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14827 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 2, 2010
1 parent 16f326f commit 2ed7c94
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions python/core/qgsaddremoveitemcommand.sip
Original file line number Diff line number Diff line change
@@ -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 );
};
85 changes: 85 additions & 0 deletions python/core/qgscomposeritemcommand.sip
Original file line number Diff line number Diff line change
@@ -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;
};
14 changes: 14 additions & 0 deletions python/core/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class QgsComposition: QGraphicsScene
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 );

Expand Down Expand Up @@ -125,4 +128,15 @@ class QgsComposition: QGraphicsScene

/**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();
};
6 changes: 6 additions & 0 deletions python/gui/qgscomposerview.sip
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class QgsComposerView: QGraphicsView
/**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* );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgscomposerview.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
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* );
Expand All @@ -115,9 +118,6 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView

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)*/
Expand Down

0 comments on commit 2ed7c94

Please sign in to comment.