Skip to content

Commit 6b14503

Browse files
author
brushtyler
committed
applied patch to make a vector layer read-only, to fix #3157
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14451 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 8fc06d7 commit 6b14503

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

python/core/qgsvectorlayer.sip

+9
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ public:
313313
/** Returns true if the provider is in editing mode */
314314
virtual bool isEditable() const;
315315

316+
/** Returns true if the provider is in read-only mode
317+
@note added in version 1.6 */
318+
virtual bool isReadOnly() const;
319+
316320
/** Returns true if the provider has been modified since the last commit */
317321
virtual bool isModified() const;
318322

@@ -353,6 +357,11 @@ public:
353357

354358
/** returns feature count after commit */
355359
int pendingFeatureCount();
360+
361+
/** Make layer read-only (editing disabled) or not
362+
@return false if the layer is in editing yet
363+
@note added in version 1.6 */
364+
bool setReadOnly( bool readonly = true );
356365

357366
/** Sets whether some features are modified or not */
358367
void setModified(bool modified = TRUE, bool onlyGeometryWasModified = FALSE);

src/app/qgisapp.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,7 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
47244724

47254725
bool res = true;
47264726

4727-
if( !vlayer->isEditable() )
4727+
if( !vlayer->isEditable() && !vlayer->isReadOnly() )
47284728
{
47294729
vlayer->startEditing();
47304730
if( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
@@ -5927,7 +5927,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
59275927
//start editing/stop editing
59285928
if( dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities )
59295929
{
5930-
mActionToggleEditing->setEnabled( true );
5930+
mActionToggleEditing->setEnabled( !vlayer->isReadOnly() );
59315931
mActionToggleEditing->setChecked( vlayer->isEditable() );
59325932
mActionSaveEdits->setEnabled( vlayer->isEditable() );
59335933
}

src/core/qgsvectorlayer.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
100100
mDataProvider( NULL ),
101101
mProviderKey( providerKey ),
102102
mEditable( false ),
103+
mReadOnly( false ),
103104
mModified( false ),
104105
mMaxUpdatedIndex( -1 ),
105106
mActiveCommand( NULL ),
@@ -2483,6 +2484,11 @@ bool QgsVectorLayer::startEditing()
24832484
return false;
24842485
}
24852486

2487+
if ( mReadOnly )
2488+
{
2489+
return false;
2490+
}
2491+
24862492
if ( mEditable )
24872493
{
24882494
// editing already underway
@@ -4204,6 +4210,21 @@ bool QgsVectorLayer::isEditable() const
42044210
return ( mEditable && mDataProvider );
42054211
}
42064212

4213+
bool QgsVectorLayer::isReadOnly() const
4214+
{
4215+
return mReadOnly;
4216+
}
4217+
4218+
bool QgsVectorLayer::setReadOnly( bool readonly )
4219+
{
4220+
// exit if the layer is in editing mode
4221+
if ( readonly && mEditable )
4222+
return false;
4223+
4224+
mReadOnly = readonly;
4225+
return true;
4226+
}
4227+
42074228
bool QgsVectorLayer::isModified() const
42084229
{
42094230
return mModified;

src/core/qgsvectorlayer.h

+11
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
358358
/** Returns true if the provider is in editing mode */
359359
virtual bool isEditable() const;
360360

361+
/** Returns true if the provider is in read-only mode */
362+
virtual bool isReadOnly() const;
363+
361364
/** Returns true if the provider has been modified since the last commit */
362365
virtual bool isModified() const;
363366

@@ -402,6 +405,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
402405
/** returns feature count after commit */
403406
int pendingFeatureCount();
404407

408+
/** Make layer read-only (editing disabled) or not
409+
* @return false if the layer is in editing yet
410+
*/
411+
bool setReadOnly( bool readonly = true );
412+
405413
/** Sets whether some features are modified or not */
406414
void setModified( bool modified = true, bool onlyGeometryWasModified = false );
407415

@@ -708,6 +716,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
708716
/** Flag indicating whether the layer is in editing mode or not */
709717
bool mEditable;
710718

719+
/** Flag indicating whether the layer is in read-only mode (editing disabled) or not */
720+
bool mReadOnly;
721+
711722
/** Flag indicating whether the layer has been modified since the last commit */
712723
bool mModified;
713724

0 commit comments

Comments
 (0)