Skip to content
Permalink
Browse files

Added `bool supportsEditing` property to QgsVectorLayer

  • Loading branch information
suricactus authored and nyalldawson committed Dec 21, 2020
1 parent f503cb5 commit a05971d5d3ce9a6a6cccc393c6c5f6f3b4160f7f
Showing with 43 additions and 2 deletions.
  1. +16 −0 python/core/auto_generated/qgsvectorlayer.sip.in
  2. +2 −2 src/app/qgisapp.cpp
  3. +10 −0 src/core/qgsvectorlayer.cpp
  4. +15 −0 src/core/qgsvectorlayer.h
@@ -1789,6 +1789,15 @@ If you need only the count of committed features call this method on this layer'
Makes layer read-only (editing disabled) or not

:return: ``False`` if the layer is in editing yet
%End

bool supportsEditing();
%Docstring
Returns whether the layer supports editing or not

:return: ``False`` if the layer is read only or the data provider has no editing capabilities

.. versionadded:: 3.18
%End

bool changeGeometry( QgsFeatureId fid, QgsGeometry &geometry, bool skipDefaultValue = false );
@@ -2921,6 +2930,13 @@ Emitted when the read only state of this layer is changed.
Only applies to manually set readonly state, not to the edit mode.

.. versionadded:: 3.0
%End

void supportsEditingChanged();
%Docstring
Emitted when the read only state or the data provider of this layer is changed.

.. versionadded:: 3.18
%End

void symbolFeatureCountMapChanged();
bool canChangeAttributes = dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;
bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities;
bool canChangeGeometry = isSpatial && dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;
bool canSupportEditing = vlayer->supportsEditing();

mActionLayerSubsetString->setEnabled( !isEditable && dprovider->supportsSubsetString() );

mActionToggleEditing->setEnabled( canSupportEditing && !vlayer->readOnly() );
mActionToggleEditing->setEnabled( canSupportEditing );
mActionToggleEditing->setChecked( canSupportEditing && isEditable );
mActionSaveLayerEdits->setEnabled( canSupportEditing && isEditable && vlayer->isModified() );
mUndoDock->widget()->setEnabled( canSupportEditing && isEditable );
@@ -201,6 +201,8 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
connect( QgsProject::instance()->relationManager(), &QgsRelationManager::relationsLoaded, this, &QgsVectorLayer::onRelationsLoaded );

connect( this, &QgsVectorLayer::subsetStringChanged, this, &QgsMapLayer::configChanged );
connect( this, &QgsVectorLayer::dataSourceChanged, this, &QgsVectorLayer::supportsEditingChanged );
connect( this, &QgsVectorLayer::readOnlyChanged, this, &QgsVectorLayer::supportsEditingChanged );

// Default simplify drawing settings
QgsSettings settings;
@@ -3667,6 +3669,14 @@ bool QgsVectorLayer::setReadOnly( bool readonly )
return true;
}

bool QgsVectorLayer::supportsEditing()
{
if ( ! mDataProvider )
return false;

return mDataProvider->capabilities() & QgsVectorDataProvider::EditingCapabilities && ! mReadOnly;
}

bool QgsVectorLayer::isModified() const
{
emit beforeModifiedCheck();
@@ -392,6 +392,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
Q_PROPERTY( bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged )
Q_PROPERTY( bool supportsEditing READ supportsEditing NOTIFY supportsEditingChanged )

public:

@@ -1691,6 +1692,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
bool setReadOnly( bool readonly = true );

/**
* Returns whether the layer supports editing or not
* \return FALSE if the layer is read only or the data provider has no editing capabilities
* \since QGIS 3.18
*/
bool supportsEditing();

/**
* Changes a feature's \a geometry within the layer's edit buffer
* (but does not immediately commit the changes). The \a fid argument
@@ -2718,6 +2726,13 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
void readOnlyChanged();

/**
* Emitted when the read only state or the data provider of this layer is changed.
*
* \since QGIS 3.18
*/
void supportsEditingChanged();

/**
* Emitted when the feature count for symbols on this layer has been recalculated.
*

0 comments on commit a05971d

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