Index: src/app/qgisapp.cpp =================================================================== --- src/app/qgisapp.cpp (revision 14443) +++ src/app/qgisapp.cpp (working copy) @@ -4722,7 +4722,7 @@ bool res = true; - if( !vlayer->isEditable() ) + if( !vlayer->isEditable() && !vlayer->isReadOnly() ) { vlayer->startEditing(); if( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) ) @@ -5922,7 +5922,7 @@ //start editing/stop editing if( dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities ) { - mActionToggleEditing->setEnabled( true ); + mActionToggleEditing->setEnabled( !vlayer->isReadOnly() ); mActionToggleEditing->setChecked( vlayer->isEditable() ); mActionSaveEdits->setEnabled( vlayer->isEditable() ); } Index: src/core/qgsvectorlayer.cpp =================================================================== --- src/core/qgsvectorlayer.cpp (revision 14443) +++ src/core/qgsvectorlayer.cpp (working copy) @@ -100,6 +100,7 @@ mDataProvider( NULL ), mProviderKey( providerKey ), mEditable( false ), + mReadOnly( false ), mModified( false ), mMaxUpdatedIndex( -1 ), mActiveCommand( NULL ), @@ -2483,6 +2484,11 @@ return false; } + if ( mReadOnly ) + { + return false; + } + if ( mEditable ) { // editing already underway @@ -4204,6 +4210,21 @@ return ( mEditable && mDataProvider ); } +bool QgsVectorLayer::isReadOnly() const +{ + return mReadOnly; +} + +bool QgsVectorLayer::setReadOnly( bool readonly ) +{ + // exit if the layer is in editing mode + if ( readonly && mEditable ) + return false; + + mReadOnly = readonly; + return true; +} + bool QgsVectorLayer::isModified() const { return mModified; Index: src/core/qgsvectorlayer.h =================================================================== --- src/core/qgsvectorlayer.h (revision 14443) +++ src/core/qgsvectorlayer.h (working copy) @@ -358,6 +358,9 @@ /** Returns true if the provider is in editing mode */ virtual bool isEditable() const; + /** Returns true if the provider is in read-only mode */ + virtual bool isReadOnly() const; + /** Returns true if the provider has been modified since the last commit */ virtual bool isModified() const; @@ -402,6 +405,11 @@ /** returns feature count after commit */ int pendingFeatureCount(); + /** Make layer read-only (editing disabled) or not + * @return false if the layer is in editing yet + */ + bool setReadOnly( bool readonly = true ); + /** Sets whether some features are modified or not */ void setModified( bool modified = true, bool onlyGeometryWasModified = false ); @@ -708,6 +716,9 @@ /** Flag indicating whether the layer is in editing mode or not */ bool mEditable; + /** Flag indicating whether the layer is in read-only mode (editing disabled) or not */ + bool mReadOnly; + /** Flag indicating whether the layer has been modified since the last commit */ bool mModified; Index: python/core/qgsvectorlayer.sip =================================================================== --- python/core/qgsvectorlayer.sip (revision 14443) +++ python/core/qgsvectorlayer.sip (working copy) @@ -313,6 +313,9 @@ /** Returns true if the provider is in editing mode */ virtual bool isEditable() const; + /** Returns true if the provider is in read-only mode */ + virtual bool isReadOnly() const; + /** Returns true if the provider has been modified since the last commit */ virtual bool isModified() const; @@ -353,6 +356,11 @@ /** returns feature count after commit */ int pendingFeatureCount(); + + /** Make layer read-only (editing disabled) or not + * @return false if the layer is in editing yet + */ + bool setReadOnly( bool readonly = true ); /** Sets whether some features are modified or not */ void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);