@@ -702,15 +702,12 @@ void QgisApp::createActions()
702
702
// Digitising Toolbar Items
703
703
//
704
704
705
- mActionStartEditing = new QAction (QIcon (myIconPath+" /mActionStartEditing.png" ),
706
- tr (" Start editing the current layer" ), this );
707
- mActionStartEditing ->setStatusTip (tr (" Start editing the current layer" ));
708
- connect (mActionStartEditing , SIGNAL (triggered ()), this , SLOT (startEditing ()));
709
- //
710
- mActionStopEditing = new QAction (QIcon (myIconPath+" /mActionStopEditing.png" ),
711
- tr (" Stop editing the current layer" ), this );
712
- mActionStopEditing ->setStatusTip (tr (" Stop editing the current layer" ));
713
- connect (mActionStopEditing , SIGNAL (triggered ()), this , SLOT (stopEditing ()));
705
+ mActionToggleEditing = new QAction (QIcon (myIconPath+" /mActionToggleEditing.png" ),
706
+ tr (" Toggle editing" ), this );
707
+ mActionToggleEditing ->setStatusTip (tr (" Toggles the editing state of the current layer" ));
708
+ mActionToggleEditing ->setCheckable (true );
709
+ connect (mActionToggleEditing , SIGNAL (triggered ()), this , SLOT (toggleEditing ()));
710
+
714
711
//
715
712
mActionCapturePoint = new QAction (QIcon (myIconPath+" /mActionCapturePoint.png" ), tr (" Capture Point" ), this );
716
713
mActionCapturePoint ->setShortcut (tr (" ." ," Capture Points" ));
@@ -972,8 +969,7 @@ void QgisApp::createToolBars()
972
969
mDigitizeToolBar = addToolBar (tr (" Digitizing" ));
973
970
mDigitizeToolBar ->setIconSize (QSize (24 ,24 ));
974
971
mDigitizeToolBar ->setObjectName (" Digitizing" );
975
- mDigitizeToolBar ->addAction (mActionStartEditing );
976
- mDigitizeToolBar ->addAction (mActionStopEditing );
972
+ mDigitizeToolBar ->addAction (mActionToggleEditing );
977
973
mDigitizeToolBar ->addAction (mActionCapturePoint );
978
974
mDigitizeToolBar ->addAction (mActionCaptureLine );
979
975
mDigitizeToolBar ->addAction (mActionCapturePolygon );
@@ -1277,6 +1273,10 @@ void QgisApp::createLegend()
1277
1273
mMapLegend = new QgsLegend (NULL , " theMapLegend" );
1278
1274
mMapLegend ->setObjectName (" theMapLegend" );
1279
1275
mMapLegend ->setMapCanvas (mMapCanvas );
1276
+
1277
+ // add the toggle editing action also to legend such that right click menu and button show the same state
1278
+ mMapLegend ->setToggleEditingAction (mActionToggleEditing );
1279
+
1280
1280
QWhatsThis::add (mMapLegend , tr (" Map legend that displays all the layers currently on the map canvas. Click on the check box to turn a layer on or off. Double click on a layer in the legend to customize its appearance and set other properties." ));
1281
1281
QVBoxLayout *myLegendLayout = new QVBoxLayout;
1282
1282
myLegendLayout->addWidget (mMapLegend );
@@ -3541,38 +3541,17 @@ void QgisApp::refreshMapCanvas()
3541
3541
mMapCanvas ->refresh ();
3542
3542
}
3543
3543
3544
- void QgisApp::startEditing ()
3545
- {
3546
- QgsMapLayer* theLayer = mMapLegend ->currentLayer ();
3547
- if (!theLayer)
3548
- {
3549
- return ;
3550
- }
3551
- // only vectorlayers can be edited
3552
- QgsVectorLayer* theVectorLayer = dynamic_cast <QgsVectorLayer*>(theLayer);
3553
- if (!theVectorLayer)
3554
- {
3555
- return ;
3556
- }
3557
- // TODO: make it work [MD]
3558
- // theVectorLayer->startEditing();
3559
- }
3560
-
3561
- void QgisApp::stopEditing ()
3544
+ void QgisApp::toggleEditing ()
3562
3545
{
3563
- QgsMapLayer* theLayer = mMapLegend ->currentLayer ();
3564
- if (!theLayer )
3546
+ QgsLegendLayerFile* currentLayerFile = mMapLegend ->currentLayerFile ();
3547
+ if (currentLayerFile )
3565
3548
{
3566
- return ;
3549
+ currentLayerFile-> toggleEditing () ;
3567
3550
}
3568
- // only vectorlayers can be edited
3569
- QgsVectorLayer* theVectorLayer = dynamic_cast <QgsVectorLayer*>(theLayer);
3570
- if (!theVectorLayer)
3551
+ else
3571
3552
{
3572
- return ;
3553
+ mActionToggleEditing -> setChecked ( false ) ;
3573
3554
}
3574
- // TODO: make it work [MD]
3575
- // theVectorLayer->stopEditing();
3576
3555
}
3577
3556
3578
3557
void QgisApp::showMouseCoordinate (QgsPoint & p)
@@ -4765,14 +4744,13 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
4765
4744
// start editing/stop editing
4766
4745
if (dprovider->capabilities () & QgsVectorDataProvider::AddFeatures)
4767
4746
{
4768
- mActionStartEditing ->setEnabled (true );
4769
- mActionStopEditing -> setEnabled ( true );
4747
+ mActionToggleEditing ->setEnabled (true );
4748
+ mActionToggleEditing -> setChecked (vlayer-> isEditable () );
4770
4749
mActionEditPaste ->setEnabled (true );
4771
4750
}
4772
4751
else
4773
4752
{
4774
- mActionStartEditing ->setEnabled (false );
4775
- mActionStopEditing ->setEnabled (false );
4753
+ mActionToggleEditing ->setEnabled (false );
4776
4754
mActionEditPaste ->setEnabled (false );
4777
4755
}
4778
4756
@@ -4868,8 +4846,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
4868
4846
{
4869
4847
mActionSelect ->setEnabled (false );
4870
4848
mActionOpenTable ->setEnabled (false );
4871
- mActionStartEditing ->setEnabled (false );
4872
- mActionStopEditing ->setEnabled (false );
4849
+ mActionToggleEditing ->setEnabled (false );
4873
4850
mActionCapturePoint ->setEnabled (false );
4874
4851
mActionCaptureLine ->setEnabled (false );
4875
4852
mActionCapturePolygon ->setEnabled (false );
0 commit comments