Skip to content

Commit

Permalink
applied patch to make a vector layer read-only, to fix #3157
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14451 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Oct 29, 2010
1 parent 6253fb7 commit 519f120
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
9 changes: 9 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -313,6 +313,10 @@ public:
/** Returns true if the provider is in editing mode */
virtual bool isEditable() const;

/** Returns true if the provider is in read-only mode
@note added in version 1.6 */
virtual bool isReadOnly() const;

/** Returns true if the provider has been modified since the last commit */
virtual bool isModified() const;

Expand Down Expand Up @@ -353,6 +357,11 @@ public:

/** returns feature count after commit */
int pendingFeatureCount();

/** Make layer read-only (editing disabled) or not
@return false if the layer is in editing yet
@note added in version 1.6 */
bool setReadOnly( bool readonly = true );

/** Sets whether some features are modified or not */
void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -4724,7 +4724,7 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )

bool res = true;

if( !vlayer->isEditable() )
if( !vlayer->isEditable() && !vlayer->isReadOnly() )
{
vlayer->startEditing();
if( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
Expand Down Expand Up @@ -5927,7 +5927,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
//start editing/stop editing
if( dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities )
{
mActionToggleEditing->setEnabled( true );
mActionToggleEditing->setEnabled( !vlayer->isReadOnly() );
mActionToggleEditing->setChecked( vlayer->isEditable() );
mActionSaveEdits->setEnabled( vlayer->isEditable() );
}
Expand Down
21 changes: 21 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -100,6 +100,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
mDataProvider( NULL ),
mProviderKey( providerKey ),
mEditable( false ),
mReadOnly( false ),
mModified( false ),
mMaxUpdatedIndex( -1 ),
mActiveCommand( NULL ),
Expand Down Expand Up @@ -2483,6 +2484,11 @@ bool QgsVectorLayer::startEditing()
return false;
}

if ( mReadOnly )
{
return false;
}

if ( mEditable )
{
// editing already underway
Expand Down Expand Up @@ -4204,6 +4210,21 @@ bool QgsVectorLayer::isEditable() const
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;
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -358,6 +358,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** 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;

Expand Down Expand Up @@ -402,6 +405,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** 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 );

Expand Down Expand Up @@ -708,6 +716,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** 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;

Expand Down

0 comments on commit 519f120

Please sign in to comment.