Skip to content

Commit 2fe5d1d

Browse files
author
mhugent
committed
Initial implementation of composer undo / redo
git-svn-id: http://svn.osgeo.org/qgis/trunk@14786 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f404e0f commit 2fe5d1d

40 files changed

+963
-100
lines changed

python/gui/qgscomposerview.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class QgsComposerView: QGraphicsView
8080

8181

8282
public slots:
83-
/**For QgsComposerItemGroup to send its signals to QgsComposer (or other classes that keep track of input widgets)*/
84-
void sendItemRemovedSignal( QgsComposerItem* item );
83+
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
84+
void sendItemAddedSignal( QgsComposerItem* item );
8585

8686
signals:
8787
/**Is emitted when selected item changed. If 0, no item is selected*/

src/app/composer/qgscomposer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@
6565
#include <QSvgGenerator>
6666
#include <QToolBar>
6767
#include <QToolButton>
68-
//#include <QUndoView>
68+
#include <QUndoView>
6969

7070

7171

7272

7373

74-
QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title )
74+
QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title ), mUndoView( 0 )
7575
{
7676
setupUi( this );
7777
setWindowTitle( mTitle );
@@ -217,8 +217,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(),
217217
mCompositionNameComboBox->insertItem( 0, tr( "Map 1" ) );
218218

219219
//undo widget
220-
/*QUndoView* undoWidget = new QUndoView( mComposition->undoStack(), this );
221-
mOptionsTabWidget->addTab( undoWidget, tr( "Command history" ) );*/
220+
mUndoView = new QUndoView( mComposition->undoStack(), this );
221+
mOptionsTabWidget->addTab( mUndoView, tr( "Command history" ) );
222222

223223
// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
224224
mSizeGrip = new QSizeGrip( this );
@@ -1330,6 +1330,11 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
13301330
mComposition->sortZList();
13311331
mView->setComposition( mComposition );
13321332

1333+
if ( mUndoView )
1334+
{
1335+
mUndoView->setStack( mComposition->undoStack() );
1336+
}
1337+
13331338
setSelectionTool();
13341339
}
13351340

@@ -1446,7 +1451,7 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
14461451
return;
14471452
}
14481453

1449-
delete( it.key() );
1454+
//the item itself is not deleted here (usually, this is done in the destructor of QgsAddRemoveItemCommand)
14501455
delete( it.value() );
14511456
mItemWidgetMap.remove( it.key() );
14521457
}

src/app/composer/qgscomposer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class QMoveEvent;
4242
class QResizeEvent;
4343
class QFile;
4444
class QSizeGrip;
45+
class QUndoView;
4546

4647
/** \ingroup MapComposer
4748
* \brief A gui for composing a printable map.
@@ -229,7 +230,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
229230
/**Adds a composer table to the item/widget map and creates a configuration widget*/
230231
void addComposerTable( QgsComposerAttributeTable* table );
231232

232-
/**Removes item from the item/widget map and deletes the configuration widget*/
233+
/**Removes item from the item/widget map and deletes the configuration widget. Does not delete the item itself*/
233234
void deleteItem( QgsComposerItem* item );
234235

235236
/**Shows the configuration widget for a composer item*/
@@ -306,6 +307,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
306307

307308
//! Page & Printer Setup
308309
QPrinter mPrinter;
310+
311+
QUndoView* mUndoView;
309312
};
310313

311314
#endif

src/app/composer/qgscomposerarrowwidget.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ QgsComposerArrowWidget::QgsComposerArrowWidget( QgsComposerArrow* arrow ): QWidg
3939
toolBox->addItem( itemPropertiesWidget, tr( "General options" ) );
4040

4141
setGuiElementValues();
42+
43+
if ( arrow )
44+
{
45+
connect( arrow, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
46+
}
4247
}
4348

4449
QgsComposerArrowWidget::~QgsComposerArrowWidget()
@@ -53,8 +58,10 @@ void QgsComposerArrowWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
5358
return;
5459
}
5560

61+
mArrow->beginCommand( tr( "Arrow outline width" ), QgsComposerMergeCommand::ArrowOutlineWidth );
5662
mArrow->setOutlineWidth( d );
5763
mArrow->update();
64+
mArrow->endCommand();
5865
}
5966

6067
void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
@@ -64,8 +71,10 @@ void QgsComposerArrowWidget::on_mArrowHeadWidthSpinBox_valueChanged( double d )
6471
return;
6572
}
6673

74+
mArrow->beginCommand( tr( "Arrowhead width" ), QgsComposerMergeCommand::ArrowHeadWidth );
6775
mArrow->setArrowHeadWidth( d );
6876
mArrow->update();
77+
mArrow->endCommand();
6978
}
7079

7180
void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
@@ -82,8 +91,10 @@ void QgsComposerArrowWidget::on_mArrowColorButton_clicked()
8291
#endif
8392
if ( newColor.isValid() )
8493
{
94+
mArrow->beginCommand( tr( "Arrow color changed" ) );
8595
mArrow->setArrowColor( newColor );
8696
mArrow->update();
97+
mArrow->endCommand();
8798
}
8899
}
89100

@@ -143,17 +154,21 @@ void QgsComposerArrowWidget::on_mDefaultMarkerRadioButton_toggled( bool toggled
143154
{
144155
if ( mArrow && toggled )
145156
{
157+
mArrow->beginCommand( tr( "Arrow marker changed" ) );
146158
mArrow->setMarkerMode( QgsComposerArrow::DefaultMarker );
147159
mArrow->update();
160+
mArrow->endCommand();
148161
}
149162
}
150163

151164
void QgsComposerArrowWidget::on_mNoMarkerRadioButton_toggled( bool toggled )
152165
{
153166
if ( mArrow && toggled )
154167
{
168+
mArrow->beginCommand( tr( "Arrow marker changed" ) );
155169
mArrow->setMarkerMode( QgsComposerArrow::NoMarker );
156170
mArrow->update();
171+
mArrow->endCommand();
157172
}
158173
}
159174

@@ -162,15 +177,18 @@ void QgsComposerArrowWidget::on_mSvgMarkerRadioButton_toggled( bool toggled )
162177
enableSvgInputElements( toggled );
163178
if ( mArrow && toggled )
164179
{
180+
mArrow->beginCommand( tr( "Arrow marker changed" ) );
165181
mArrow->setMarkerMode( QgsComposerArrow::SVGMarker );
166182
mArrow->update();
183+
mArrow->endCommand();
167184
}
168185
}
169186

170-
void QgsComposerArrowWidget::on_mStartMarkerLineEdit_textChanged( const QString & text )
187+
void QgsComposerArrowWidget::on_mStartMarkerLineEdit_editingFinished( const QString & text )
171188
{
172189
if ( mArrow )
173190
{
191+
mArrow->beginCommand( tr( "Arrow start marker" ) );
174192
QFileInfo fi( text );
175193
if ( fi.exists() )
176194
{
@@ -181,13 +199,15 @@ void QgsComposerArrowWidget::on_mStartMarkerLineEdit_textChanged( const QString
181199
mArrow->setStartMarker( "" );
182200
}
183201
mArrow->update();
202+
mArrow->endCommand();
184203
}
185204
}
186205

187-
void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString & text )
206+
void QgsComposerArrowWidget::on_mEndMarkerLineEdit_editingFinished( const QString & text )
188207
{
189208
if ( mArrow )
190209
{
210+
mArrow->beginCommand( tr( "Arrow start marker" ) );
191211
QFileInfo fi( text );
192212
if ( fi.exists() )
193213
{
@@ -198,6 +218,7 @@ void QgsComposerArrowWidget::on_mEndMarkerLineEdit_textChanged( const QString &
198218
mArrow->setEndMarker( "" );
199219
}
200220
mArrow->update();
221+
mArrow->endCommand();
201222
}
202223
}
203224

@@ -207,7 +228,9 @@ void QgsComposerArrowWidget::on_mStartMarkerToolButton_clicked()
207228
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "Start marker svg file" ), fi.dir().absolutePath() );
208229
if ( !svgFileName.isNull() )
209230
{
231+
mArrow->beginCommand( tr( "Arrow start marker" ) );
210232
mStartMarkerLineEdit->setText( svgFileName );
233+
mArrow->endCommand();
211234
}
212235
}
213236

@@ -217,6 +240,8 @@ void QgsComposerArrowWidget::on_mEndMarkerToolButton_clicked()
217240
QString svgFileName = QFileDialog::getOpenFileName( 0, tr( "End marker svg file" ), fi.dir().absolutePath() );
218241
if ( !svgFileName.isNull() )
219242
{
243+
mArrow->beginCommand( tr( "Arrow end marker" ) );
220244
mEndMarkerLineEdit ->setText( svgFileName );
245+
mArrow->endCommand();
221246
}
222247
}

src/app/composer/qgscomposerarrowwidget.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget
3333
QgsComposerArrow* mArrow;
3434

3535
void blockAllSignals( bool block );
36-
void setGuiElementValues();
36+
3737
QButtonGroup* mRadioButtonGroup;
3838

3939
/**Enables / disables the SVG line inputs*/
@@ -46,10 +46,12 @@ class QgsComposerArrowWidget: public QWidget, private Ui::QgsComposerArrowWidget
4646
void on_mDefaultMarkerRadioButton_toggled( bool toggled );
4747
void on_mNoMarkerRadioButton_toggled( bool toggled );
4848
void on_mSvgMarkerRadioButton_toggled( bool toggled );
49-
void on_mStartMarkerLineEdit_textChanged( const QString & text );
50-
void on_mEndMarkerLineEdit_textChanged( const QString & text );
49+
void on_mStartMarkerLineEdit_editingFinished( const QString & text );
50+
void on_mEndMarkerLineEdit_editingFinished( const QString & text );
5151
void on_mStartMarkerToolButton_clicked();
5252
void on_mEndMarkerToolButton_clicked();
53+
54+
void setGuiElementValues();
5355
};
5456

5557
#endif // QGSCOMPOSERARROWWIDGET_H

src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ void QgsComposerItemWidget::on_mFrameColorButton_clicked()
5252
return; //dialog canceled
5353
}
5454

55+
mItem->beginCommand( tr( "Frame color changed" ) );
5556
QPen thePen;
5657
thePen.setColor( newFrameColor );
5758
thePen.setWidthF( mOutlineWidthSpinBox->value() );
5859

5960
mItem->setPen( thePen );
6061
mItem->update();
62+
mItem->endCommand();
6163
}
6264

6365
void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
@@ -73,6 +75,7 @@ void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
7375
return; //dialog canceled
7476
}
7577

78+
mItem->beginCommand( tr( "Background color changed" ) );
7679
newBackgroundColor.setAlpha( mOpacitySlider->value() );
7780
mItem->setBrush( QBrush( QColor( newBackgroundColor ), Qt::SolidPattern ) );
7881
//if the item is a composer map, we need to regenerate the map image
@@ -83,6 +86,7 @@ void QgsComposerItemWidget::on_mBackgroundColorButton_clicked()
8386
cm->cache();
8487
}
8588
mItem->update();
89+
mItem->endCommand();
8690
}
8791

8892
void QgsComposerItemWidget::on_mOpacitySlider_sliderReleased()
@@ -93,11 +97,13 @@ void QgsComposerItemWidget::on_mOpacitySlider_sliderReleased()
9397
}
9498
int value = mOpacitySlider->value();
9599

100+
mItem->beginCommand( tr( "Item opacity changed" ) );
96101
QBrush itemBrush = mItem->brush();
97102
QColor brushColor = itemBrush.color();
98103
brushColor.setAlpha( value );
99104
mItem->setBrush( QBrush( brushColor ) );
100105
mItem->update();
106+
mItem->endCommand();
101107
}
102108

103109
void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
@@ -107,9 +113,11 @@ void QgsComposerItemWidget::on_mOutlineWidthSpinBox_valueChanged( double d )
107113
return;
108114
}
109115

116+
mItem->beginCommand( tr( "Item outline width" ), QgsComposerMergeCommand::ItemOutlineWidth );
110117
QPen itemPen = mItem->pen();
111118
itemPen.setWidthF( d );
112119
mItem->setPen( itemPen );
120+
mItem->endCommand();
113121
}
114122

115123
void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
@@ -119,6 +127,7 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
119127
return;
120128
}
121129

130+
mItem->beginCommand( tr( "Item frame toggled" ) );
122131
if ( state == Qt::Checked )
123132
{
124133
mItem->setFrame( true );
@@ -128,6 +137,7 @@ void QgsComposerItemWidget::on_mFrameCheckBox_stateChanged( int state )
128137
mItem->setFrame( false );
129138
}
130139
mItem->update();
140+
mItem->endCommand();
131141
}
132142

133143
void QgsComposerItemWidget::setValuesForGuiElements()
@@ -165,6 +175,14 @@ void QgsComposerItemWidget::on_mPositionButton_clicked()
165175
return;
166176
}
167177

178+
mItem->beginCommand( tr( "Item position changed" ) );
168179
QgsItemPositionDialog d( mItem, 0 );
169-
d.exec();
180+
if ( d.exec() == QDialog::Accepted )
181+
{
182+
mItem->endCommand();
183+
}
184+
else
185+
{
186+
mItem->cancelCommand();
187+
}
170188
}

0 commit comments

Comments
 (0)