Skip to content

Commit

Permalink
Place 'allow editing' into the legend layer right click menu. Newly a…
Browse files Browse the repository at this point in the history
…dded vector layers are not editable per default any more

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5335 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 21, 2006
1 parent d3a17de commit 97d368b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/gui/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ QgsVectorLayer::QgsVectorLayer(QString vectorLayerPath,
// have no effect on existing layers
QSettings settings;
updateThreshold = settings.readNumEntry("Map/updateThreshold", 1000);
//editing is now enabled by default
if(dataProvider->capabilities()&QgsVectorDataProvider::AddFeatures)
{
startEditing();
}
}
} // QgsVectorLayer ctor

Expand Down
9 changes: 4 additions & 5 deletions src/gui/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ public slots:
void triggerRepaint();
/**Shows the properties dialog*/
virtual void showLayerProperties();
void startEditing();
void stopEditing();


public:

Expand Down Expand Up @@ -471,12 +474,8 @@ public slots:


protected slots:
void toggleEditing();

void startEditing();

void stopEditing();

void toggleEditing();

private: // Private attributes

Expand Down
38 changes: 38 additions & 0 deletions src/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,22 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
{
theMenu.addAction(tr("&Make to toplevel item"), this, SLOT(makeToTopLevelItem()));
}
//add entry 'allow editing'
QAction* toggleEditingAction = theMenu.addAction(tr("&Allow editing"), this, SLOT(legendLayerToggleEditing()));
toggleEditingAction->setCheckable(true);
QgsLegendLayer* theLayer = dynamic_cast<QgsLegendLayer*>(li);
if(theLayer)
{
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(theLayer->firstMapLayer());
if(!theVectorLayer || theLayer->mapLayers().size() !=1)
{
toggleEditingAction->setEnabled(false);
}
if(theVectorLayer)
{
toggleEditingAction->setChecked(theVectorLayer->isEditable());
}
}
}
else if(li->type() == QgsLegendItem::LEGEND_GROUP)
{
Expand Down Expand Up @@ -652,6 +668,28 @@ void QgsLegend::legendLayerShowProperties()
ml->showLayerProperties();
}

void QgsLegend::legendLayerToggleEditing()
{
QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer*>(currentItem());
if(!ll)
{
return;
}
QgsVectorLayer* theVectorLayer = dynamic_cast<QgsVectorLayer*>(ll->firstMapLayer());
if(!theVectorLayer)
{
return;
}
if(theVectorLayer->isEditable())
{
theVectorLayer->stopEditing();
}
else
{
theVectorLayer->startEditing();
}
}

void QgsLegend::expandAll()
{
QTreeWidgetItem* theItem = firstItem();
Expand Down
2 changes: 2 additions & 0 deletions src/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ this item may be moved back to the original position with resetToInitialPosition
void legendLayerRemoveFromOverview();
/**Shows the property dialog of the first legend layer file in a legend layer*/
void legendLayerShowProperties();
/**Toggles the editing mode of the first layer file of a legend layer*/
void legendLayerToggleEditing();
/**Sets all listview items to open*/
void expandAll();
/**Sets all listview items to closed*/
Expand Down

0 comments on commit 97d368b

Please sign in to comment.