Skip to content

Commit 9e763f2

Browse files
author
mhugent
committed
Made a toggle editing button instead of the (deactivated) start and stop buttons. The QAction for the toggle button is also used in the legend (right click menu) to have a consistent button/menu state
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6965 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8b8e47e commit 9e763f2

11 files changed

+82
-100
lines changed
-1.05 KB
Binary file not shown.

src/app/legend/qgslegend.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const int AUTOSCROLL_MARGIN = 16;
5959
set mItemBeingMoved pointer to 0 to prevent SuSE 9.0 crash
6060
*/
6161
QgsLegend::QgsLegend(QWidget * parent, const char *name)
62-
: QTreeWidget(parent), mMousePressedFlag(false), mItemBeingMoved(0), mShowLegendLayerFiles(false), mMapCanvas(0), mMinimumIconSize(20, 20)
62+
: QTreeWidget(parent), mMousePressedFlag(false), mItemBeingMoved(0), mShowLegendLayerFiles(false), mToggleEditingAction(0), mMapCanvas(0), mMinimumIconSize(20, 20)
6363
{
6464
connect( this, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
6565
this, SLOT(handleItemChange(QTreeWidgetItem*, int)));
@@ -390,11 +390,11 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
390390

391391
if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)
392392
{
393-
(static_cast<QgsLegendLayerFile*>(li))->addToPopupMenu(theMenu);
393+
(static_cast<QgsLegendLayerFile*>(li))->addToPopupMenu(theMenu, mToggleEditingAction);
394394
}
395395
else if(li->type() == QgsLegendItem::LEGEND_LAYER)
396396
{
397-
(static_cast<QgsLegendLayer*>(li))->addToPopupMenu(theMenu);
397+
(static_cast<QgsLegendLayer*>(li))->addToPopupMenu(theMenu, mToggleEditingAction);
398398

399399
if (li->parent())
400400
{

src/app/legend/qgslegend.h

+6
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class QgsLegend : public QTreeWidget
163163
the given QgsLegendLayerFile */
164164
void setName(QgsLegendLayerFile* w, QString layerName);
165165

166+
/**Sets the toggle editing action. Usually called from QgisApp*/
167+
void setToggleEditingAction(QAction* editingAction){mToggleEditingAction = editingAction;}
168+
166169
class QgsLegendPixmaps;
167170
/**Returns structure with legend pixmaps*/
168171
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
@@ -358,6 +361,9 @@ this item may be moved back to the original position with resetToInitialPosition
358361
decide if the mapcanvas really has to be refreshed*/
359362
std::deque<QString> mLayersPriorToMove;
360363

364+
/**Action for the legendlayer right click menu*/
365+
QAction* mToggleEditingAction;
366+
361367
/*!
362368
* A fuction sed to determin how far down in the list an item is (starting with one for the first Item.
363369
*If the item is not in the legend, -1 is returned

src/app/legend/qgslegendlayer.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
459459
}
460460

461461

462-
void QgsLegendLayer::addToPopupMenu(QMenu& theMenu)
462+
void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
463463
{
464464
QString iconsPath = QgsApplication::themePath();
465465
std::list<QgsLegendLayerFile*> files = legendLayerFiles();
@@ -498,8 +498,10 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu)
498498
}
499499

500500
// allow editing
501-
QAction* toggleEditingAction = theMenu.addAction(tr("&Allow editing"), this, SLOT(toggleEditing()));
502-
toggleEditingAction->setCheckable(true);
501+
if(toggleEditingAction)
502+
{
503+
theMenu.addAction(toggleEditingAction);
504+
}
503505

504506
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(firstLayer);
505507

@@ -588,15 +590,6 @@ void QgsLegendLayer::table()
588590
}
589591
}
590592

591-
void QgsLegendLayer::toggleEditing()
592-
{
593-
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
594-
if (maplayers.size() == 1)
595-
{
596-
maplayers.front()->toggleEditing();
597-
}
598-
}
599-
600593
void QgsLegendLayer::saveAsShapefile()
601594
{
602595
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();

src/app/legend/qgslegendlayer.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class QgsLegendLayer : public QgsLegendItem
7575
void updateIcon();
7676

7777
/** called to add appropriate menu items to legend's popup menu */
78-
void addToPopupMenu(QMenu& theMenu);
78+
void addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction);
7979

8080
/**Determines whether there are layers in overview*/
8181
bool isInOverview();
@@ -88,8 +88,6 @@ class QgsLegendLayer : public QgsLegendItem
8888
/**Show layer attribute table*/
8989
void table();
9090

91-
void toggleEditing();
92-
9391
void saveAsShapefile();
9492
void saveSelectionAsShapefile();
9593

src/app/legend/qgslegendlayerfile.cpp

+41-30
Original file line numberDiff line numberDiff line change
@@ -381,37 +381,49 @@ void QgsLegendLayerFile::toggleEditing()
381381
{
382382
vlayer->startEditing();
383383
if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures))
384-
{
385-
QMessageBox::information(0,tr("Start editing failed"),
386-
tr("Provider cannot be opened for editing"));
387-
}
384+
{
385+
QMessageBox::information(0,tr("Start editing failed"),
386+
tr("Provider cannot be opened for editing"));
387+
}
388+
else
389+
{
390+
vlayer->triggerRepaint();
391+
}
388392
}
389393
else
390394
{
391-
// commit or roll back?
392-
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
393-
tr("Do you want to save the changes?"),
394-
QMessageBox::Save | QMessageBox::Discard);
395-
396-
if(commit==QMessageBox::Save)
397-
{
398-
if(!vlayer->commitChanges())
395+
if(vlayer->isModified())
399396
{
400-
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));
401-
402-
// Leave the in-memory editing state alone,
403-
// to give the user a chance to enter different values
404-
// and try the commit again later
397+
398+
// commit or roll back?
399+
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
400+
tr("Do you want to save the changes?"),
401+
QMessageBox::Save | QMessageBox::Discard);
402+
403+
if(commit==QMessageBox::Save)
404+
{
405+
if(!vlayer->commitChanges())
406+
{
407+
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));
408+
409+
// Leave the in-memory editing state alone,
410+
// to give the user a chance to enter different values
411+
// and try the commit again later
412+
}
413+
}
414+
else if(commit==QMessageBox::Discard)
415+
{
416+
if(!vlayer->rollBack())
417+
{
418+
QMessageBox::information(0,tr("Error"),
419+
tr("Problems during roll back"));
420+
}
421+
}
405422
}
406-
}
407-
else if(commit==QMessageBox::Discard)
408-
{
409-
if(!vlayer->rollBack())
423+
else //layer not modified
410424
{
411-
QMessageBox::information(0,tr("Error"),
412-
tr("Problems during roll back"));
425+
vlayer->rollBack();
413426
}
414-
}
415427
vlayer->triggerRepaint();
416428

417429
}
@@ -430,7 +442,7 @@ void QgsLegendLayerFile::layerNameChanged()
430442
}
431443

432444

433-
void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu)
445+
void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
434446
{
435447
QgsMapLayer* lyr = layer();
436448
QString iconsPath = QgsApplication::themePath();
@@ -464,11 +476,10 @@ void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu)
464476
if ((cap & QgsVectorDataProvider::AddFeatures)
465477
||(cap & QgsVectorDataProvider::DeleteFeatures))
466478
{
467-
QAction* toggleEditingAction = theMenu.addAction(tr("Allow Editing"), this, SLOT(toggleEditing()));
468-
toggleEditingAction->setCheckable(true);
469-
toggleEditingAction->blockSignals(true);
470-
toggleEditingAction->setChecked(vlayer->isEditable());
471-
toggleEditingAction->blockSignals(false);
479+
if(toggleEditingAction)
480+
{
481+
theMenu.addAction(toggleEditingAction);
482+
}
472483
}
473484

474485
// save as shapefile

src/app/legend/qgslegendlayerfile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class QgsLegendLayerFile : public QgsLegendItem
6464
bool isInOverview();
6565

6666
/** called to add appropriate menu items to legend's popup menu */
67-
void addToPopupMenu(QMenu& theMenu);
67+
void addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction);
6868

6969
public slots:
7070

src/app/qgisapp.cpp

+21-44
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,12 @@ void QgisApp::createActions()
702702
// Digitising Toolbar Items
703703
//
704704

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+
714711
//
715712
mActionCapturePoint= new QAction(QIcon(myIconPath+"/mActionCapturePoint.png"), tr("Capture Point"), this);
716713
mActionCapturePoint->setShortcut(tr(".","Capture Points"));
@@ -972,8 +969,7 @@ void QgisApp::createToolBars()
972969
mDigitizeToolBar = addToolBar(tr("Digitizing"));
973970
mDigitizeToolBar->setIconSize(QSize(24,24));
974971
mDigitizeToolBar->setObjectName("Digitizing");
975-
mDigitizeToolBar->addAction(mActionStartEditing);
976-
mDigitizeToolBar->addAction(mActionStopEditing);
972+
mDigitizeToolBar->addAction(mActionToggleEditing);
977973
mDigitizeToolBar->addAction(mActionCapturePoint);
978974
mDigitizeToolBar->addAction(mActionCaptureLine);
979975
mDigitizeToolBar->addAction(mActionCapturePolygon);
@@ -1277,6 +1273,10 @@ void QgisApp::createLegend()
12771273
mMapLegend = new QgsLegend(NULL, "theMapLegend");
12781274
mMapLegend->setObjectName("theMapLegend");
12791275
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+
12801280
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."));
12811281
QVBoxLayout *myLegendLayout = new QVBoxLayout;
12821282
myLegendLayout->addWidget(mMapLegend);
@@ -3541,38 +3541,17 @@ void QgisApp::refreshMapCanvas()
35413541
mMapCanvas->refresh();
35423542
}
35433543

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()
35623545
{
3563-
QgsMapLayer* theLayer = mMapLegend->currentLayer();
3564-
if(!theLayer)
3546+
QgsLegendLayerFile* currentLayerFile = mMapLegend->currentLayerFile();
3547+
if(currentLayerFile)
35653548
{
3566-
return;
3549+
currentLayerFile->toggleEditing();
35673550
}
3568-
//only vectorlayers can be edited
3569-
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer);
3570-
if(!theVectorLayer)
3551+
else
35713552
{
3572-
return;
3553+
mActionToggleEditing->setChecked(false);
35733554
}
3574-
// TODO: make it work [MD]
3575-
//theVectorLayer->stopEditing();
35763555
}
35773556

35783557
void QgisApp::showMouseCoordinate(QgsPoint & p)
@@ -4765,14 +4744,13 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
47654744
//start editing/stop editing
47664745
if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
47674746
{
4768-
mActionStartEditing->setEnabled(true);
4769-
mActionStopEditing->setEnabled(true);
4747+
mActionToggleEditing->setEnabled(true);
4748+
mActionToggleEditing->setChecked(vlayer->isEditable());
47704749
mActionEditPaste->setEnabled(true);
47714750
}
47724751
else
47734752
{
4774-
mActionStartEditing->setEnabled(false);
4775-
mActionStopEditing->setEnabled(false);
4753+
mActionToggleEditing->setEnabled(false);
47764754
mActionEditPaste->setEnabled(false);
47774755
}
47784756

@@ -4868,8 +4846,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
48684846
{
48694847
mActionSelect->setEnabled(false);
48704848
mActionOpenTable->setEnabled(false);
4871-
mActionStartEditing->setEnabled(false);
4872-
mActionStopEditing->setEnabled(false);
4849+
mActionToggleEditing->setEnabled(false);
48734850
mActionCapturePoint->setEnabled(false);
48744851
mActionCaptureLine->setEnabled(false);
48754852
mActionCapturePolygon->setEnabled(false);

src/app/qgisapp.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,8 @@ public slots:
304304
void refreshMapCanvas();
305305
//! returns pointer to map legend
306306
QgsLegend *legend() { return mMapLegend; }
307-
//! enables the editing mode of the current layer
308-
void startEditing();
309-
//! disables the editing mode of the current layer
310-
void stopEditing();
311-
307+
//! starts/stops editing mode of the current layer
308+
void toggleEditing();
312309

313310
/** Activates or deactivates actions depending on the current maplayer type.
314311
Is called from the legend when the current legend item has changed*/
@@ -479,8 +476,7 @@ public slots:
479476
QAction *mActionQgisHomePage;
480477
QAction *mActionHelpAbout;
481478
QAction *mArawAction;
482-
QAction *mActionStartEditing;
483-
QAction *mActionStopEditing;
479+
QAction *mActionToggleEditing;
484480
QAction *mActionCapturePoint;
485481
QAction *mActionCaptureLine;
486482
QAction *mActionCapturePolygon;

src/core/qgsvectorlayer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ int QgsVectorLayer::addIsland(const QList<QgsPoint>& ring)
15261526
if(errorCode == 0)
15271527
{
15281528
mChangedGeometries.insert(selectedFeatureId, *cachedIt);
1529+
setModified(true, true);
15291530
}
15301531
return errorCode;
15311532
}

0 commit comments

Comments
 (0)