Skip to content

Commit

Permalink
Allow editing when _any_ of the editing capabilities is supported by …
Browse files Browse the repository at this point in the history
…data provider

(instead of checking only AddFeatures)


git-svn-id: http://svn.osgeo.org/qgis/trunk@9708 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 25, 2008
1 parent 025b594 commit 538827c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
3 changes: 3 additions & 0 deletions python/core/qgsvectordataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class QgsVectorDataProvider : QgsDataProvider
SequentialSelectGeometryAtId = 2048
};

/** bitmask of all provider's editing capabilities */
static const int EditingCapabilities;

/**
* Constructor of the vector provider
* @param uri uniform resource locator (URI) for a dataset
Expand Down
3 changes: 1 addition & 2 deletions src/app/legend/qgslegendlayerfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ void QgsLegendLayerFile::addToPopupMenu( QMenu& theMenu, QAction* toggleEditingA

// editing
int cap = vlayer->dataProvider()->capabilities();
if (( cap & QgsVectorDataProvider::AddFeatures )
|| ( cap & QgsVectorDataProvider::DeleteFeatures ) )
if ( cap & QgsVectorDataProvider::EditingCapabilities )
{
if ( toggleEditingAction )
{
Expand Down
33 changes: 20 additions & 13 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3865,7 +3865,7 @@ void QgisApp::toggleEditing( QgsMapLayer *layer )
if ( !vlayer->isEditable() )
{
vlayer->startEditing();
if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures ) )
if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
{
QMessageBox::information( 0, tr( "Start editing failed" ), tr( "Provider cannot be opened for editing" ) );
}
Expand Down Expand Up @@ -4840,15 +4840,22 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
if ( dprovider )
{
//start editing/stop editing
if ( dprovider->capabilities() & QgsVectorDataProvider::AddFeatures )
if ( dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities )
{
mActionToggleEditing->setEnabled( true );
mActionToggleEditing->setChecked( vlayer->isEditable() );
mActionPasteFeatures->setEnabled( vlayer->isEditable() && !clipboard()->empty() );
}
else
{
mActionToggleEditing->setEnabled( false );
}

if ( dprovider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
mActionPasteFeatures->setEnabled( vlayer->isEditable() && !clipboard()->empty() );
}
else
{
mActionPasteFeatures->setEnabled( false );
}

Expand All @@ -4863,19 +4870,26 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionDeleteSelected->setEnabled( false );
mActionCutFeatures->setEnabled( false );
}


// moving enabled if geometry changes are supported
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries )
{
mActionMoveFeature->setEnabled( true );
}
else
{
mActionMoveFeature->setEnabled( false );
}

if ( vlayer->geometryType() == QGis::Point )
{
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::AddFeatures )
{
mActionCapturePoint->setEnabled( true );
mActionMoveFeature->setEnabled( true );
}
else
{
mActionCapturePoint->setEnabled( false );
mActionMoveFeature->setEnabled( false );
}
mActionCaptureLine->setEnabled( false );
mActionCapturePolygon->setEnabled( false );
Expand All @@ -4892,7 +4906,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
mActionMoveVertex->setEnabled( true );
}
mActionMoveFeature->setEnabled( true );
}
return;
}
Expand All @@ -4902,13 +4915,11 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
{
mActionCaptureLine->setEnabled( true );
mActionSplitFeatures->setEnabled( true );
mActionMoveFeature->setEnabled( true );
}
else
{
mActionCaptureLine->setEnabled( false );
mActionSplitFeatures->setEnabled( false );
mActionMoveFeature->setEnabled( false );
}
mActionCapturePoint->setEnabled( false );
mActionCapturePolygon->setEnabled( false );
Expand All @@ -4923,15 +4934,13 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionAddRing->setEnabled( true );
mActionAddIsland->setEnabled( true );
mActionSplitFeatures->setEnabled( true );
mActionMoveFeature->setEnabled( true );
}
else
{
mActionCapturePolygon->setEnabled( false );
mActionAddRing->setEnabled( false );
mActionAddIsland->setEnabled( false );
mActionSplitFeatures->setEnabled( false );
mActionMoveFeature->setEnabled( false );
}
mActionCapturePoint->setEnabled( false );
mActionCaptureLine->setEnabled( false );
Expand All @@ -4943,7 +4952,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionAddVertex->setEnabled( true );
mActionMoveVertex->setEnabled( true );
mActionDeleteVertex->setEnabled( true );
mActionMoveFeature->setEnabled( true );
if ( vlayer->geometryType() == QGis::Polygon )
{
mActionAddRing->setEnabled( true );
Expand All @@ -4957,7 +4965,6 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionAddVertex->setEnabled( false );
mActionMoveVertex->setEnabled( false );
mActionDeleteVertex->setEnabled( false );
mActionMoveFeature->setEnabled( false );
}
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectordataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
RandomSelectGeometryAtId = 1 << 10,
SequentialSelectGeometryAtId = 1 << 11
};

/** bitmask of all provider's editing capabilities */
const static int EditingCapabilities = AddFeatures | DeleteFeatures |
ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;

/**
* Constructor of the vector provider
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,8 @@ bool QgsVectorLayer::startEditing()
return false;
}

if ( !( mDataProvider->capabilities() & QgsVectorDataProvider::AddFeatures ) )
// allow editing if provider supports any of the capabilities
if ( !( mDataProvider->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
{
return false;
}
Expand Down

0 comments on commit 538827c

Please sign in to comment.