Skip to content
Permalink
Browse files
Made a toggle editing button instead of the (deactivated) start and s…
…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 be40dae94363d5d149c005d3707cbf0749f94b0b
Binary file not shown.
@@ -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)));
@@ -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())
{
@@ -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; }
@@ -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
@@ -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();
@@ -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);

@@ -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();
@@ -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();
@@ -88,8 +88,6 @@ class QgsLegendLayer : public QgsLegendItem
/**Show layer attribute table*/
void table();

void toggleEditing();

void saveAsShapefile();
void saveSelectionAsShapefile();

@@ -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();

}
@@ -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();
@@ -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
@@ -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:

@@ -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"));
@@ -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);
@@ -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);
@@ -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)
@@ -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);
}

@@ -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);
@@ -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*/
@@ -479,8 +476,7 @@ public slots:
QAction *mActionQgisHomePage;
QAction *mActionHelpAbout;
QAction *mArawAction;
QAction *mActionStartEditing;
QAction *mActionStopEditing;
QAction *mActionToggleEditing;
QAction *mActionCapturePoint;
QAction *mActionCaptureLine;
QAction *mActionCapturePolygon;
@@ -1526,6 +1526,7 @@ int QgsVectorLayer::addIsland(const QList<QgsPoint>& ring)
if(errorCode == 0)
{
mChangedGeometries.insert(selectedFeatureId, *cachedIt);
setModified(true, true);
}
return errorCode;
}

0 comments on commit be40dae

Please sign in to comment.