Skip to content

Commit

Permalink
Made a toggle editing button instead of the (deactivated) start and s…
Browse files Browse the repository at this point in the history
…top 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@6965 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 26, 2007
1 parent a74f531 commit be40dae
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 100 deletions.
Binary file removed images/themes/default/mActionStopEditing.png
Binary file not shown.
6 changes: 3 additions & 3 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const int AUTOSCROLL_MARGIN = 16;
set mItemBeingMoved pointer to 0 to prevent SuSE 9.0 crash
*/
QgsLegend::QgsLegend(QWidget * parent, const char *name)
: QTreeWidget(parent), mMousePressedFlag(false), mItemBeingMoved(0), mShowLegendLayerFiles(false), mMapCanvas(0), mMinimumIconSize(20, 20)
: QTreeWidget(parent), mMousePressedFlag(false), mItemBeingMoved(0), mShowLegendLayerFiles(false), mToggleEditingAction(0), mMapCanvas(0), mMinimumIconSize(20, 20)
{
connect( this, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
this, SLOT(handleItemChange(QTreeWidgetItem*, int)));
Expand Down Expand Up @@ -390,11 +390,11 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit

if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)
{
(static_cast<QgsLegendLayerFile*>(li))->addToPopupMenu(theMenu);
(static_cast<QgsLegendLayerFile*>(li))->addToPopupMenu(theMenu, mToggleEditingAction);
}
else if(li->type() == QgsLegendItem::LEGEND_LAYER)
{
(static_cast<QgsLegendLayer*>(li))->addToPopupMenu(theMenu);
(static_cast<QgsLegendLayer*>(li))->addToPopupMenu(theMenu, mToggleEditingAction);

if (li->parent())
{
Expand Down
6 changes: 6 additions & 0 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ class QgsLegend : public QTreeWidget
the given QgsLegendLayerFile */
void setName(QgsLegendLayerFile* w, QString layerName);

/**Sets the toggle editing action. Usually called from QgisApp*/
void setToggleEditingAction(QAction* editingAction){mToggleEditingAction = editingAction;}

class QgsLegendPixmaps;
/**Returns structure with legend pixmaps*/
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
Expand Down Expand Up @@ -358,6 +361,9 @@ this item may be moved back to the original position with resetToInitialPosition
decide if the mapcanvas really has to be refreshed*/
std::deque<QString> mLayersPriorToMove;

/**Action for the legendlayer right click menu*/
QAction* mToggleEditingAction;

/*!
* A fuction sed to determin how far down in the list an item is (starting with one for the first Item.
*If the item is not in the legend, -1 is returned
Expand Down
17 changes: 5 additions & 12 deletions src/app/legend/qgslegendlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ QPixmap QgsLegendLayer::getOriginalPixmap() const
}


void QgsLegendLayer::addToPopupMenu(QMenu& theMenu)
void QgsLegendLayer::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
{
QString iconsPath = QgsApplication::themePath();
std::list<QgsLegendLayerFile*> files = legendLayerFiles();
Expand Down Expand Up @@ -498,8 +498,10 @@ void QgsLegendLayer::addToPopupMenu(QMenu& theMenu)
}

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

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

Expand Down Expand Up @@ -588,15 +590,6 @@ void QgsLegendLayer::table()
}
}

void QgsLegendLayer::toggleEditing()
{
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
if (maplayers.size() == 1)
{
maplayers.front()->toggleEditing();
}
}

void QgsLegendLayer::saveAsShapefile()
{
std::list<QgsLegendLayerFile*> maplayers = legendLayerFiles();
Expand Down
4 changes: 1 addition & 3 deletions src/app/legend/qgslegendlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class QgsLegendLayer : public QgsLegendItem
void updateIcon();

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

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

void toggleEditing();

void saveAsShapefile();
void saveSelectionAsShapefile();

Expand Down
71 changes: 41 additions & 30 deletions src/app/legend/qgslegendlayerfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,37 +381,49 @@ void QgsLegendLayerFile::toggleEditing()
{
vlayer->startEditing();
if(!(vlayer->getDataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures))
{
QMessageBox::information(0,tr("Start editing failed"),
tr("Provider cannot be opened for editing"));
}
{
QMessageBox::information(0,tr("Start editing failed"),
tr("Provider cannot be opened for editing"));
}
else
{
vlayer->triggerRepaint();
}
}
else
{
// commit or roll back?
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
tr("Do you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard);

if(commit==QMessageBox::Save)
{
if(!vlayer->commitChanges())
if(vlayer->isModified())
{
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));

// Leave the in-memory editing state alone,
// to give the user a chance to enter different values
// and try the commit again later

// commit or roll back?
QMessageBox::StandardButton commit = QMessageBox::information(0,tr("Stop editing"),
tr("Do you want to save the changes?"),
QMessageBox::Save | QMessageBox::Discard);

if(commit==QMessageBox::Save)
{
if(!vlayer->commitChanges())
{
QMessageBox::information(0,tr("Error"),tr("Could not commit changes"));

// Leave the in-memory editing state alone,
// to give the user a chance to enter different values
// and try the commit again later
}
}
else if(commit==QMessageBox::Discard)
{
if(!vlayer->rollBack())
{
QMessageBox::information(0,tr("Error"),
tr("Problems during roll back"));
}
}
}
}
else if(commit==QMessageBox::Discard)
{
if(!vlayer->rollBack())
else //layer not modified
{
QMessageBox::information(0,tr("Error"),
tr("Problems during roll back"));
vlayer->rollBack();
}
}
vlayer->triggerRepaint();

}
Expand All @@ -430,7 +442,7 @@ void QgsLegendLayerFile::layerNameChanged()
}


void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu)
void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu, QAction* toggleEditingAction)
{
QgsMapLayer* lyr = layer();
QString iconsPath = QgsApplication::themePath();
Expand Down Expand Up @@ -464,11 +476,10 @@ void QgsLegendLayerFile::addToPopupMenu(QMenu& theMenu)
if ((cap & QgsVectorDataProvider::AddFeatures)
||(cap & QgsVectorDataProvider::DeleteFeatures))
{
QAction* toggleEditingAction = theMenu.addAction(tr("Allow Editing"), this, SLOT(toggleEditing()));
toggleEditingAction->setCheckable(true);
toggleEditingAction->blockSignals(true);
toggleEditingAction->setChecked(vlayer->isEditable());
toggleEditingAction->blockSignals(false);
if(toggleEditingAction)
{
theMenu.addAction(toggleEditingAction);
}
}

// save as shapefile
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgslegendlayerfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class QgsLegendLayerFile : public QgsLegendItem
bool isInOverview();

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

public slots:

Expand Down
65 changes: 21 additions & 44 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,12 @@ void QgisApp::createActions()
// Digitising Toolbar Items
//

mActionStartEditing = new QAction(QIcon(myIconPath+"/mActionStartEditing.png"),
tr("Start editing the current layer"), this);
mActionStartEditing->setStatusTip(tr("Start editing the current layer"));
connect(mActionStartEditing, SIGNAL(triggered()), this, SLOT(startEditing()));
//
mActionStopEditing = new QAction(QIcon(myIconPath+"/mActionStopEditing.png"),
tr("Stop editing the current layer"), this);
mActionStopEditing->setStatusTip(tr("Stop editing the current layer"));
connect(mActionStopEditing, SIGNAL(triggered()), this, SLOT(stopEditing()));
mActionToggleEditing = new QAction(QIcon(myIconPath+"/mActionToggleEditing.png"),
tr("Toggle editing"), this);
mActionToggleEditing->setStatusTip(tr("Toggles the editing state of the current layer"));
mActionToggleEditing->setCheckable(true);
connect(mActionToggleEditing, SIGNAL(triggered()), this, SLOT(toggleEditing()));

//
mActionCapturePoint= new QAction(QIcon(myIconPath+"/mActionCapturePoint.png"), tr("Capture Point"), this);
mActionCapturePoint->setShortcut(tr(".","Capture Points"));
Expand Down Expand Up @@ -972,8 +969,7 @@ void QgisApp::createToolBars()
mDigitizeToolBar = addToolBar(tr("Digitizing"));
mDigitizeToolBar->setIconSize(QSize(24,24));
mDigitizeToolBar->setObjectName("Digitizing");
mDigitizeToolBar->addAction(mActionStartEditing);
mDigitizeToolBar->addAction(mActionStopEditing);
mDigitizeToolBar->addAction(mActionToggleEditing);
mDigitizeToolBar->addAction(mActionCapturePoint);
mDigitizeToolBar->addAction(mActionCaptureLine);
mDigitizeToolBar->addAction(mActionCapturePolygon);
Expand Down Expand Up @@ -1277,6 +1273,10 @@ void QgisApp::createLegend()
mMapLegend = new QgsLegend(NULL, "theMapLegend");
mMapLegend->setObjectName("theMapLegend");
mMapLegend->setMapCanvas(mMapCanvas);

//add the toggle editing action also to legend such that right click menu and button show the same state
mMapLegend->setToggleEditingAction(mActionToggleEditing);

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."));
QVBoxLayout *myLegendLayout = new QVBoxLayout;
myLegendLayout->addWidget(mMapLegend);
Expand Down Expand Up @@ -3541,38 +3541,17 @@ void QgisApp::refreshMapCanvas()
mMapCanvas->refresh();
}

void QgisApp::startEditing()
{
QgsMapLayer* theLayer = mMapLegend->currentLayer();
if(!theLayer)
{
return;
}
//only vectorlayers can be edited
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer);
if(!theVectorLayer)
{
return;
}
// TODO: make it work [MD]
//theVectorLayer->startEditing();
}

void QgisApp::stopEditing()
void QgisApp::toggleEditing()
{
QgsMapLayer* theLayer = mMapLegend->currentLayer();
if(!theLayer)
QgsLegendLayerFile* currentLayerFile = mMapLegend->currentLayerFile();
if(currentLayerFile)
{
return;
currentLayerFile->toggleEditing();
}
//only vectorlayers can be edited
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer);
if(!theVectorLayer)
else
{
return;
mActionToggleEditing->setChecked(false);
}
// TODO: make it work [MD]
//theVectorLayer->stopEditing();
}

void QgisApp::showMouseCoordinate(QgsPoint & p)
Expand Down Expand Up @@ -4765,14 +4744,13 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
//start editing/stop editing
if(dprovider->capabilities() & QgsVectorDataProvider::AddFeatures)
{
mActionStartEditing->setEnabled(true);
mActionStopEditing->setEnabled(true);
mActionToggleEditing->setEnabled(true);
mActionToggleEditing->setChecked(vlayer->isEditable());
mActionEditPaste->setEnabled(true);
}
else
{
mActionStartEditing->setEnabled(false);
mActionStopEditing->setEnabled(false);
mActionToggleEditing->setEnabled(false);
mActionEditPaste->setEnabled(false);
}

Expand Down Expand Up @@ -4868,8 +4846,7 @@ void QgisApp::activateDeactivateLayerRelatedActions(QgsMapLayer* layer)
{
mActionSelect->setEnabled(false);
mActionOpenTable->setEnabled(false);
mActionStartEditing->setEnabled(false);
mActionStopEditing->setEnabled(false);
mActionToggleEditing->setEnabled(false);
mActionCapturePoint->setEnabled(false);
mActionCaptureLine->setEnabled(false);
mActionCapturePolygon->setEnabled(false);
Expand Down
10 changes: 3 additions & 7 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,8 @@ public slots:
void refreshMapCanvas();
//! returns pointer to map legend
QgsLegend *legend() { return mMapLegend; }
//! enables the editing mode of the current layer
void startEditing();
//! disables the editing mode of the current layer
void stopEditing();

//! starts/stops editing mode of the current layer
void toggleEditing();

/** Activates or deactivates actions depending on the current maplayer type.
Is called from the legend when the current legend item has changed*/
Expand Down Expand Up @@ -479,8 +476,7 @@ public slots:
QAction *mActionQgisHomePage;
QAction *mActionHelpAbout;
QAction *mArawAction;
QAction *mActionStartEditing;
QAction *mActionStopEditing;
QAction *mActionToggleEditing;
QAction *mActionCapturePoint;
QAction *mActionCaptureLine;
QAction *mActionCapturePolygon;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,7 @@ int QgsVectorLayer::addIsland(const QList<QgsPoint>& ring)
if(errorCode == 0)
{
mChangedGeometries.insert(selectedFeatureId, *cachedIt);
setModified(true, true);
}
return errorCode;
}
Expand Down

0 comments on commit be40dae

Please sign in to comment.