132
132
#include " qgsrenderer.h"
133
133
#include " qgsserversourceselect.h"
134
134
#include " qgsshortcutsmanager.h"
135
+ #include " qgsundowidget.h"
135
136
#include " qgsvectordataprovider.h"
136
137
#include " qgsvectorlayer.h"
137
138
#include " ogr/qgsopenvectorlayerdialog.h"
@@ -363,6 +364,11 @@ QgisApp::QgisApp( QSplashScreen *splash, QWidget * parent, Qt::WFlags fl )
363
364
mInternalClipboard = new QgsClipboard; // create clipboard
364
365
mQgisInterface = new QgisAppInterface ( this ); // create the interfce
365
366
367
+ // create undo widget
368
+ mUndoWidget = new QgsUndoWidget ( NULL , mMapCanvas );
369
+ addDockWidget (Qt::LeftDockWidgetArea, mUndoWidget );
370
+ mUndoWidget ->hide ();
371
+
366
372
// set application's icon
367
373
setWindowIcon ( QPixmap ( qgis_xpm ) );
368
374
@@ -583,11 +589,6 @@ void QgisApp::createActions()
583
589
// Edit Menu Items
584
590
585
591
#if 0
586
- mActionUndo = new QAction( tr( "&Undo" ), this );
587
- shortcuts->registerAction( mActionUndo, tr( "Ctrl+Z" ) );
588
- mActionUndo->setStatusTip( tr( "Undo the last operation" ) );
589
- connect( mActionUndo, SIGNAL( triggered ), this, SLOT( undo() ) );
590
-
591
592
mActionCut = new QAction( tr( "Cu&t" ), this );
592
593
shortcuts->registerAction( mActionCut, tr( "Ctrl+X" ) );
593
594
mActionCut->setStatusTip( tr( "Cut the current selection's contents to the clipboard" ) );
@@ -604,6 +605,18 @@ void QgisApp::createActions()
604
605
connect( mActionPaste, SIGNAL( triggered ), this, SLOT( paste() ) );
605
606
#endif
606
607
608
+ mActionUndo = new QAction ( getThemeIcon ( " mActionUndo.png" ), tr ( " &Undo" ), this );
609
+ shortcuts->registerAction ( mActionUndo , tr ( " Ctrl+Z" ) );
610
+ mActionUndo ->setStatusTip ( tr ( " Undo the last operation" ) );
611
+ mActionUndo ->setEnabled ( false );
612
+ // action connected to mUndoWidget::undo slot in setupConnections()
613
+
614
+ mActionRedo = new QAction ( getThemeIcon ( " mActionRedo.png" ), tr ( " &Redo" ), this );
615
+ shortcuts->registerAction ( mActionRedo , tr ( " Ctrl+Shift+Z" ) );
616
+ mActionRedo ->setStatusTip ( tr ( " Redo the last operation" ) );
617
+ mActionRedo ->setEnabled ( false );
618
+ // action connected to mUndoWidget::redo slot in setupConnections()
619
+
607
620
mActionCutFeatures = new QAction ( getThemeIcon ( " mActionEditCut.png" ), tr ( " Cut Features" ), this );
608
621
shortcuts->registerAction ( mActionCutFeatures , tr ( " Ctrl+X" ) );
609
622
mActionCutFeatures ->setStatusTip ( tr ( " Cut selected features" ) );
@@ -1132,11 +1145,14 @@ void QgisApp::createMenus()
1132
1145
mEditMenu = menuBar ()->addMenu ( tr ( " &Edit" ) );
1133
1146
1134
1147
#if 0
1135
- mEditMenu->addAction( mActionUndo );
1136
1148
mEditMenu->addAction( mActionCut );
1137
1149
mEditMenu->addAction( mActionCopy );
1138
1150
mEditMenu->addAction( mActionPaste );
1139
1151
#endif
1152
+ mEditMenu ->addAction ( mActionUndo );
1153
+ mEditMenu ->addAction ( mActionRedo );
1154
+ mActionEditSeparator0 = mEditMenu ->addSeparator ();
1155
+
1140
1156
mEditMenu ->addAction ( mActionCutFeatures );
1141
1157
mEditMenu ->addAction ( mActionCopyFeatures );
1142
1158
mEditMenu ->addAction ( mActionPasteFeatures );
@@ -1360,6 +1376,8 @@ void QgisApp::createToolBars()
1360
1376
mAdvancedDigitizeToolBar = addToolBar ( tr ( " Advanced Digitizing" ) );
1361
1377
mAdvancedDigitizeToolBar ->setIconSize ( myIconSize );
1362
1378
mAdvancedDigitizeToolBar ->setObjectName ( " Advanced Digitizing" );
1379
+ mAdvancedDigitizeToolBar ->addAction ( mActionUndo );
1380
+ mAdvancedDigitizeToolBar ->addAction ( mActionRedo );
1363
1381
mAdvancedDigitizeToolBar ->addAction ( mActionSimplifyFeature );
1364
1382
mAdvancedDigitizeToolBar ->addAction ( mActionAddRing );
1365
1383
mAdvancedDigitizeToolBar ->addAction ( mActionAddIsland );
@@ -1638,6 +1656,8 @@ void QgisApp::setupConnections()
1638
1656
mMapLegend , SLOT ( addLayer ( QgsMapLayer * ) ) );
1639
1657
connect ( mMapLegend , SIGNAL ( currentLayerChanged ( QgsMapLayer* ) ),
1640
1658
this , SLOT ( activateDeactivateLayerRelatedActions ( QgsMapLayer* ) ) );
1659
+ connect ( mMapLegend , SIGNAL ( currentLayerChanged ( QgsMapLayer* ) ),
1660
+ mUndoWidget , SLOT ( layerChanged ( QgsMapLayer* ) ) );
1641
1661
1642
1662
1643
1663
// signal when mouse moved over window (coords display in status bar)
@@ -1664,7 +1684,12 @@ void QgisApp::setupConnections()
1664
1684
1665
1685
connect ( QgsProject::instance (), SIGNAL ( layerLoaded ( int , int ) ), this , SLOT ( showProgress ( int , int ) ) );
1666
1686
1687
+ // setup undo/redo actions
1688
+ connect ( mActionUndo , SIGNAL ( triggered () ), mUndoWidget , SLOT ( undo () ) );
1689
+ connect ( mActionRedo , SIGNAL ( triggered () ), mUndoWidget , SLOT ( redo () ) );
1690
+ connect ( mUndoWidget , SIGNAL ( undoStackChanged () ), this , SLOT (updateUndoActions ()) );
1667
1691
}
1692
+
1668
1693
void QgisApp::createCanvas ()
1669
1694
{
1670
1695
// "theMapCanvas" used to find this canonical instance later
@@ -4083,13 +4108,14 @@ void QgisApp::deleteSelected()
4083
4108
return ;
4084
4109
}
4085
4110
4086
-
4111
+ vlayer-> beginEditCommand ( tr ( " Features deleted " ) );
4087
4112
if ( !vlayer->deleteSelectedFeatures () )
4088
4113
{
4089
4114
QMessageBox::information ( this , tr ( " Problem deleting features" ),
4090
4115
tr ( " A problem occured during deletion of features" ) );
4091
4116
}
4092
4117
4118
+ vlayer->endEditCommand ();
4093
4119
// notify the project we've made a change
4094
4120
QgsProject::instance ()->dirty ( true );
4095
4121
}
@@ -4228,6 +4254,8 @@ void QgisApp::mergeSelectedFeatures()
4228
4254
}
4229
4255
}
4230
4256
4257
+ vl->beginEditCommand ( tr (" Merged features" ) );
4258
+
4231
4259
// create new feature
4232
4260
QgsFeature newFeature;
4233
4261
newFeature.setGeometry (unionGeom);
@@ -4241,6 +4269,8 @@ void QgisApp::mergeSelectedFeatures()
4241
4269
4242
4270
vl->addFeature (newFeature, false );
4243
4271
4272
+ vl->endEditCommand ();;
4273
+
4244
4274
if (mapCanvas ())
4245
4275
{
4246
4276
mapCanvas ()->refresh ();
@@ -4361,7 +4391,9 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection )
4361
4391
{
4362
4392
QgsFeatureList features = selectionVectorLayer->selectedFeatures ();
4363
4393
clipboard ()->replaceWithCopyOf ( selectionVectorLayer->dataProvider ()->fields (), features );
4394
+ selectionVectorLayer->beginEditCommand ( tr (" Features cut" ) );
4364
4395
selectionVectorLayer->deleteSelectedFeatures ();
4396
+ selectionVectorLayer->endEditCommand ();
4365
4397
}
4366
4398
}
4367
4399
}
@@ -4410,7 +4442,9 @@ void QgisApp::editPaste( QgsMapLayer * destinationLayer )
4410
4442
4411
4443
if ( pasteVectorLayer != 0 )
4412
4444
{
4445
+ pasteVectorLayer->beginEditCommand ( tr (" Features pasted" ) );
4413
4446
pasteVectorLayer->addFeatures ( clipboard ()->copyOf () );
4447
+ pasteVectorLayer->endEditCommand ();
4414
4448
mMapCanvas ->refresh ();
4415
4449
}
4416
4450
}
@@ -5420,6 +5454,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
5420
5454
mActionLayerProperties ->setEnabled ( false );
5421
5455
mActionAddToOverview ->setEnabled ( false );
5422
5456
mActionCopyFeatures ->setEnabled ( false );
5457
+ mActionUndo ->setEnabled ( false );
5458
+ mActionRedo ->setEnabled ( false );
5423
5459
return ;
5424
5460
}
5425
5461
@@ -6139,3 +6175,20 @@ QPixmap QgisApp::getThemePixmap( const QString theName )
6139
6175
return QPixmap ( myDefaultPath );
6140
6176
}
6141
6177
}
6178
+
6179
+ void QgisApp::updateUndoActions ()
6180
+ {
6181
+ bool canUndo = false , canRedo = false ;
6182
+ QgsMapLayer* layer = this ->activeLayer ();
6183
+ if (layer)
6184
+ {
6185
+ QgsVectorLayer* vlayer = dynamic_cast <QgsVectorLayer*>( layer );
6186
+ if ( vlayer && vlayer->isEditable () )
6187
+ {
6188
+ canUndo = vlayer->undoStack ()->canUndo ();
6189
+ canRedo = vlayer->undoStack ()->canRedo ();
6190
+ }
6191
+ }
6192
+ mActionUndo ->setEnabled ( canUndo );
6193
+ mActionRedo ->setEnabled ( canRedo );
6194
+ }
0 commit comments