Skip to content

Commit 034e57c

Browse files
author
mhugent
committedDec 2, 2010
Add python bindings for composer command classes
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14827 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

6 files changed

+135
-3
lines changed

6 files changed

+135
-3
lines changed
 

‎python/core/core.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
// TODO: more files to wrap
1212

1313
%Include qgis.sip
14+
%Include qgsaddremoveitemcommand.sip
1415
%Include qgsapplication.sip
1516
%Include qgscomposerattributetable.sip
1617
%Include qgscomposeritem.sip
18+
%Include qgscomposeritemcommand.sip
1719
%Include qgscomposerlabel.sip
1820
%Include qgscomposerlegend.sip
1921
%Include qgscomposermap.sip
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/** \ingroup MapComposer
2+
A composer command class for adding / removing composer items. If mState == Removed, the command owns the item*/
3+
class QgsAddRemoveItemCommand: QObject, QUndoCommand
4+
{
5+
%TypeHeaderCode
6+
#include "qgsaddremoveitemcommand.h"
7+
%End
8+
public:
9+
10+
enum State
11+
{
12+
Added = 0,
13+
Removed
14+
};
15+
16+
QgsAddRemoveItemCommand( State s, QgsComposerItem* item, QgsComposition* c, const QString& text, QUndoCommand* parent = 0 );
17+
~QgsAddRemoveItemCommand();
18+
19+
void redo();
20+
void undo();
21+
22+
signals:
23+
void itemAdded( QgsComposerItem* item );
24+
void itemRemoved( QgsComposerItem* item );
25+
};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**\ingroup MapComposer
2+
Undo command to undo/redo all composer item related changes*/
3+
class QgsComposerItemCommand: QUndoCommand
4+
{
5+
%TypeHeaderCode
6+
#include "qgscomposeritemcommand.h"
7+
%End
8+
public:
9+
QgsComposerItemCommand( QgsComposerItem* item, const QString& text, QUndoCommand* parent = 0 );
10+
virtual ~QgsComposerItemCommand();
11+
12+
/**Reverses the command*/
13+
void undo();
14+
/**Replays the command*/
15+
void redo();
16+
17+
/**Saves current item state as previous state*/
18+
void savePreviousState();
19+
/**Saves current item state as after state*/
20+
void saveAfterState();
21+
22+
QDomDocument previousState() const;
23+
QDomDocument afterState() const;
24+
25+
/**Returns true if previous state and after state are valid and different*/
26+
bool containsChange() const;
27+
};
28+
29+
/**\ingroup MapComposer
30+
A composer command that merges together with other commands having the same context (=id). Keeps the oldest previous state and uses the
31+
newest after state. The purpose is to avoid too many micro changes in the history*/
32+
class QgsComposerMergeCommand: QgsComposerItemCommand
33+
{
34+
%TypeHeaderCode
35+
#include "qgscomposeritemcommand.h"
36+
%End
37+
public:
38+
enum Context
39+
{
40+
Unknown = 0,
41+
//composer label
42+
ComposerLabelSetText,
43+
//composer map
44+
ComposerMapRotation,
45+
ComposerMapAnnotationDistance,
46+
//composer legend
47+
ComposerLegendText,
48+
LegendSymbolWidth,
49+
LegendSymbolHeight,
50+
LegendLayerSpace,
51+
LegendSymbolSpace,
52+
LegendIconSymbolSpace,
53+
LegendBoxSpace,
54+
//composer picture
55+
ComposerPictureRotation,
56+
// composer scalebar
57+
ScaleBarLineWidth,
58+
ScaleBarHeight,
59+
ScaleBarSegmentSize,
60+
ScaleBarSegmentsLeft,
61+
ScaleBarNSegments,
62+
ScaleBarUnitText,
63+
ScaleBarMapUnitsSegment,
64+
ScaleBarLabelBarSize,
65+
ScaleBarBoxContentSpace,
66+
// composer table
67+
TableMaximumFeatures,
68+
TableMargin,
69+
TableGridStrokeWidth,
70+
//composer shape
71+
ShapeRotation,
72+
ShapeOutlineWidth,
73+
//composer arrow
74+
ArrowOutlineWidth,
75+
ArrowHeadWidth,
76+
//item
77+
ItemOutlineWidth
78+
};
79+
80+
QgsComposerMergeCommand( Context c, QgsComposerItem* item, const QString& text );
81+
~QgsComposerMergeCommand();
82+
83+
bool mergeWith( const QUndoCommand * command );
84+
int id() const;
85+
};

‎python/core/qgscomposition.sip

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class QgsComposition: QGraphicsScene
5757
void setGridStyle( GridStyle s );
5858
GridStyle gridStyle() const;
5959

60+
/**Returns pointer to undo/redo command storage*/
61+
QUndoStack* undoStack();
62+
6063
/**Returns the topmose composer item. Ignores mPaperItem*/
6164
QgsComposerItem* composerItemAt( const QPointF & position );
6265

@@ -125,4 +128,15 @@ class QgsComposition: QGraphicsScene
125128

126129
/**Snaps a scene coordinate point to grid*/
127130
QPointF snapPointToGrid( const QPointF& scenePoint ) const;
131+
132+
/**Allocates new item command and saves initial state in it
133+
@param item target item
134+
@param commandText descriptive command text
135+
@param c context for merge commands (unknown for non-mergeable commands)*/
136+
void beginCommand( QgsComposerItem* item, const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
137+
138+
/**Saves end state of item and pushes command to the undo history*/
139+
void endCommand();
140+
/**Deletes current command*/
141+
void cancelCommand();
128142
};

‎python/gui/qgscomposerview.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ class QgsComposerView: QGraphicsView
6868
/**Returns the composer main window*/
6969
QMainWindow* composerWindow();
7070

71+
void setPaintingEnabled( bool enabled );
72+
bool paintingEnabled() const;
73+
74+
/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
75+
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
76+
7177
protected:
7278
void mousePressEvent( QMouseEvent* );
7379
void mouseReleaseEvent( QMouseEvent* );

‎src/gui/qgscomposerview.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
102102
void setPaintingEnabled( bool enabled ) { mPaintingEnabled = enabled; }
103103
bool paintingEnabled() const { return mPaintingEnabled; }
104104

105+
/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
106+
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
107+
105108
protected:
106109
void mousePressEvent( QMouseEvent* );
107110
void mouseReleaseEvent( QMouseEvent* );
@@ -115,9 +118,6 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
115118

116119
void paintEvent( QPaintEvent* event );
117120

118-
/**Convenience function to create a QgsAddRemoveItemCommand, connect its signals and push it to the undo stack*/
119-
void pushAddRemoveCommand( QgsComposerItem* item, const QString& text, QgsAddRemoveItemCommand::State state = QgsAddRemoveItemCommand::Added );
120-
121121

122122
private:
123123
/**Status of shift key (used for multiple selection)*/

0 commit comments

Comments
 (0)
Please sign in to comment.