Skip to content
Permalink
Browse files

applied patch to make a vector layer read-only, to fix #3157

git-svn-id: http://svn.osgeo.org/qgis/trunk@14451 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler
brushtyler committed Oct 29, 2010
1 parent 6253fb7 commit 519f120602dff9935307eaef8785c6aad90c13c3
Showing with 43 additions and 2 deletions.
  1. +9 −0 python/core/qgsvectorlayer.sip
  2. +2 −2 src/app/qgisapp.cpp
  3. +21 −0 src/core/qgsvectorlayer.cpp
  4. +11 −0 src/core/qgsvectorlayer.h
@@ -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;

@@ -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);
@@ -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 ) )
@@ -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() );
}
@@ -100,6 +100,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
mDataProvider( NULL ),
mProviderKey( providerKey ),
mEditable( false ),
mReadOnly( false ),
mModified( false ),
mMaxUpdatedIndex( -1 ),
mActiveCommand( NULL ),
@@ -2483,6 +2484,11 @@ bool QgsVectorLayer::startEditing()
return false;
}

if ( mReadOnly )
{
return false;
}

if ( mEditable )
{
// editing already underway
@@ -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;
@@ -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;

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

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

0 comments on commit 519f120

Please sign in to comment.
You can’t perform that action at this time.