Skip to content
Permalink
Browse files

Make readOnly mode of vector layers configurable

  • Loading branch information
m-kuhn committed Mar 29, 2016
1 parent 1c59eff commit 93e73ac66f626635d06928725512bd1ea877d463
@@ -215,6 +215,9 @@ class QgsMapLayer : QObject
/** Returns the current blending mode for a layer */
QPainter::CompositionMode blendMode() const;

/** Returns if this layer is read only. */
bool readOnly() const;

/** Synchronises with changes in the datasource
*/
virtual void reload();
@@ -7247,7 +7247,7 @@ bool QgisApp::toggleEditing( QgsMapLayer *layer, bool allowCancel )
if ( vlayer->isModified() || ( tg && tg->layers().contains( vlayer ) && tg->modified() ) )
isModified = true;

if ( !vlayer->isEditable() && !vlayer->isReadOnly() )
if ( !vlayer->isEditable() && !vlayer->readOnly() )
{
if ( !( vlayer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
{
@@ -10011,7 +10011,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

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

mActionToggleEditing->setEnabled( canSupportEditing && !vlayer->isReadOnly() );
mActionToggleEditing->setEnabled( canSupportEditing && !vlayer->readOnly() );
mActionToggleEditing->setChecked( canSupportEditing && isEditable );
mActionSaveLayerEdits->setEnabled( canSupportEditing && isEditable && vlayer->isModified() );
mUndoWidget->dockContents()->setEnabled( canSupportEditing && isEditable );
@@ -193,7 +193,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mToggleEditingButton->blockSignals( true );
mToggleEditingButton->setCheckable( true );
mToggleEditingButton->setChecked( mLayer->isEditable() );
mToggleEditingButton->setEnabled(( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->isReadOnly() );
mToggleEditingButton->setEnabled(( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() );
mToggleEditingButton->blockSignals( false );

mSaveEditsButton->setEnabled( mToggleEditingButton->isEnabled() && mLayer->isEditable() );
@@ -672,7 +672,7 @@ void QgsFieldsProperties::updateButtons()
{
int cap = mLayer->dataProvider()->capabilities();

mToggleEditingButton->setEnabled(( cap & QgsVectorDataProvider::ChangeAttributeValues ) && !mLayer->isReadOnly() );
mToggleEditingButton->setEnabled(( cap & QgsVectorDataProvider::ChangeAttributeValues ) && !mLayer->readOnly() );

if ( mLayer->isEditable() )
{
@@ -56,7 +56,7 @@ bool QgsGuiVectorLayerTools::startEditing( QgsVectorLayer* layer ) const

bool res = true;

if ( !layer->isEditable() && !layer->isReadOnly() )
if ( !layer->isEditable() && !layer->readOnly() )
{
if ( !( layer->dataProvider()->capabilities() & QgsVectorDataProvider::EditingCapabilities ) )
{
@@ -245,11 +245,12 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mLayerSrsId = mProjectSrsId;
}

twIdentifyLayers->setColumnCount( 3 );
twIdentifyLayers->setColumnCount( 4 );
twIdentifyLayers->horizontalHeader()->setVisible( true );
twIdentifyLayers->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Layer" ) ) );
twIdentifyLayers->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Type" ) ) );
twIdentifyLayers->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Identifiable" ) ) );
twIdentifyLayers->setHorizontalHeaderItem( 3, new QTableWidgetItem( tr( "Read Only" ) ) );
twIdentifyLayers->setRowCount( mapLayers.size() );
twIdentifyLayers->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );

@@ -289,9 +290,16 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
twIdentifyLayers->setItem( i, 1, twi );

QCheckBox *cb = new QCheckBox();
cb->setChecked( !noIdentifyLayerIdList.contains( currentLayer->id() ) );
twIdentifyLayers->setCellWidget( i, 2, cb );
QCheckBox *cbIdentify = new QCheckBox();
cbIdentify->setChecked( !noIdentifyLayerIdList.contains( currentLayer->id() ) );
twIdentifyLayers->setCellWidget( i, 2, cbIdentify );

twi = new QTableWidgetItem( type );
twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
QCheckBox *cbReadOnly = new QCheckBox();
cbReadOnly->setChecked( currentLayer->readOnly() );
cbReadOnly->setEnabled( currentLayer->type() == QgsMapLayer::VectorLayer );
twIdentifyLayers->setCellWidget( i, 3, cbReadOnly );
}

grpOWSServiceCapabilities->setChecked( QgsProject::instance()->readBoolEntry( "WMSServiceCapabilities", "/", false ) );
@@ -880,12 +888,17 @@ void QgsProjectProperties::apply()
QStringList noIdentifyLayerList;
for ( int i = 0; i < twIdentifyLayers->rowCount(); i++ )
{
QCheckBox *cb = qobject_cast<QCheckBox *>( twIdentifyLayers->cellWidget( i, 2 ) );
if ( cb && !cb->isChecked() )
QString id = twIdentifyLayers->item( i, 0 )->data( Qt::UserRole ).toString();

QCheckBox *cbIdentify = qobject_cast<QCheckBox *>( twIdentifyLayers->cellWidget( i, 2 ) );
if ( cbIdentify && !cbIdentify->isChecked() )
{
QString id = twIdentifyLayers->item( i, 0 )->data( Qt::UserRole ).toString();
noIdentifyLayerList << id;
}
QCheckBox *cbReadOnly = qobject_cast<QCheckBox *>( twIdentifyLayers->cellWidget( i, 3 ) );
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( id ) );
if ( vl )
vl->setReadOnly( cbReadOnly->checkState() == Qt::Checked );
}

QgsProject::instance()->setNonIdentifiableLayers( noIdentifyLayerList );
@@ -231,6 +231,9 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Returns the current blending mode for a layer */
QPainter::CompositionMode blendMode() const;

/** Returns if this layer is read only. */
bool readOnly() const { return isReadOnly(); }

/** Synchronises with changes in the datasource
*/
virtual void reload() {}
@@ -735,6 +738,12 @@ class CORE_EXPORT QgsMapLayer : public QObject
QgsError mError;

private:
/**
* This method returns true by default but can be overwritten to specify
* that a certain layer is writable.
*/
virtual bool isReadOnly() const { return true; }

/** Layer's spatial reference system.
private to make sure setCrs must be used and layerCrsChanged() is emitted */
QgsCoordinateReferenceSystem* mCRS;
@@ -379,7 +379,7 @@ struct CORE_EXPORT QgsVectorJoinInfo
*
* Provider to display vector data in a GRASS GIS layer.
*
* TODO QGIS3: Remove virtual from non-inherited methods (like isModified, isReadOnly)
* TODO QGIS3: Remove virtual from non-inherited methods (like isModified)
*/


@@ -1090,8 +1090,14 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

virtual bool isSpatial() const override;

/** Returns true if the provider is in read-only mode */
virtual bool isReadOnly() const;
/**
* Returns true if the provider is in read-only mode
*
* @deprecated Use readOnly() instead. Will be made private with QGIS 3
*
* TODO QGIS3: make private
*/
Q_DECL_DEPRECATED virtual bool isReadOnly() const override;

/** Returns true if the provider has been modified since the last commit */
virtual bool isModified() const;
@@ -146,7 +146,7 @@ void QgsRelationEditorWidget::setRelationFeature( const QgsRelation& relation, c
QgsVectorLayer* lyr = relation.referencingLayer();

bool canChangeAttributes = lyr->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !lyr->isReadOnly() )
if ( canChangeAttributes && !lyr->readOnly() )
{
mToggleEditingButton->setEnabled( true );
updateButtons();
@@ -205,7 +205,7 @@ void QgsRelationEditorWidget::setRelations( const QgsRelation& relation, const Q
QgsVectorLayer* lyr = relation.referencingLayer();

bool canChangeAttributes = lyr->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
if ( canChangeAttributes && !lyr->isReadOnly() )
if ( canChangeAttributes && !lyr->readOnly() )
{
mToggleEditingButton->setEnabled( true );
updateButtons();
@@ -218,7 +218,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="mProjOpts_01">
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -248,7 +248,7 @@
<x>0</x>
<y>0</y>
<width>683</width>
<height>779</height>
<height>776</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
@@ -749,8 +749,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>326</width>
<height>46</height>
<width>683</width>
<height>776</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@@ -808,8 +808,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>133</width>
<height>100</height>
<width>683</width>
<height>776</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
@@ -851,6 +851,11 @@
<string>Identifiable</string>
</property>
</column>
<column>
<property name="text">
<string>Read Only</string>
</property>
</column>
</widget>
</item>
</layout>
@@ -889,8 +894,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>582</height>
<width>381</width>
<height>607</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
@@ -1314,8 +1319,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>663</width>
<height>2249</height>
<width>642</width>
<height>2374</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -2380,7 +2385,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>168</width>
<width>166</width>
<height>46</height>
</rect>
</property>

0 comments on commit 93e73ac

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