Skip to content

Commit 4cd1e38

Browse files
committed
fieldEditable -> readOnly
1 parent d70a47e commit 4cd1e38

15 files changed

+37
-39
lines changed

python/core/qgseditformconfig.sip

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ class QgsEditFormConfig : QObject
190190
QgsEditorWidgetConfig widgetConfig( const QString& fieldName ) const;
191191

192192
/**
193-
* If this returns false, the widget at the given index will always be read-only.
193+
* If this returns true, the field is manually set to read only.
194194
*/
195-
bool fieldEditable( int idx );
195+
bool readOnly( int idx );
196196

197197
/**
198198
* If set to false, the widget at the given index will be read-only, regardless of the
199199
* layer's editable state and data provider capacities.
200200
* If it is set to true, the widget's editable state will be synchronized with the layer's
201201
* edit state.
202202
*/
203-
void setFieldEditable( int idx, bool editable );
203+
void setReadOnly(int idx, bool readOnly );
204204

205205
/**
206206
* If this returns true, the widget at the given index will receive its label on the previous line

python/core/qgsvectorlayer.sip

+1-1
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ class QgsVectorLayer : QgsMapLayer
10061006
/** Make layer read-only (editing disabled) or not
10071007
* @return false if the layer is in editing yet
10081008
*/
1009-
bool setReadOnly( bool readonly = true );
1009+
bool setFieldEditable( bool editable = true );
10101010

10111011
/**
10121012
* Make layer editable.

src/app/qgsfieldsproperties.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ void QgsFieldsProperties::apply()
848848
int idx = mFieldsList->item( i, attrIdCol )->text().toInt();
849849
FieldConfig cfg = configForRow( i );
850850

851-
mLayer->editFormConfig()->setFieldEditable( i, cfg.mEditable );
851+
mLayer->editFormConfig()->setReadOnly( i, !cfg.mEditable );
852852
mLayer->editFormConfig()->setLabelOnTop( i, cfg.mLabelOnTop );
853853

854854
mLayer->editFormConfig()->setWidgetType( idx, cfg.mEditorWidgetV2Type );
@@ -900,7 +900,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig()
900900
QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
901901
: mButton( 0 )
902902
{
903-
mEditable = layer->editFormConfig()->fieldEditable( idx );
903+
mEditable = !layer->editFormConfig()->readOnly( idx );
904904
mEditableEnabled = layer->fields().fieldOrigin( idx ) != QgsFields::OriginJoin
905905
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;
906906
mLabelOnTop = layer->editFormConfig()->labelOnTop( idx );

src/core/qgseditformconfig.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
QgsEditFormConfig::QgsEditFormConfig( QObject* parent )
55
: QObject( parent )
66
, mEditorLayout( GeneratedLayout )
7-
, mUseInitCode( false )
87
, mFeatureFormSuppress( SuppressDefault )
8+
, mUseInitCode( false )
99
{
1010
connect( QgsProject::instance()->relationManager(), SIGNAL( relationsLoaded() ), this, SLOT( onRelationsLoaded() ) );
1111
}
@@ -72,17 +72,17 @@ void QgsEditFormConfig::setUiForm( const QString& ui )
7272
mEditForm = ui;
7373
}
7474

75-
bool QgsEditFormConfig::fieldEditable( int idx )
75+
bool QgsEditFormConfig::readOnly( int idx )
7676
{
7777
if ( idx >= 0 && idx < mFields.count() )
7878
{
7979
if ( mFields.fieldOrigin( idx ) == QgsFields::OriginJoin
8080
|| mFields.fieldOrigin( idx ) == QgsFields::OriginExpression )
81-
return false;
82-
return mFieldEditables.value( mFields.at( idx ).name(), true );
81+
return true;
82+
return !mFieldEditables.value( mFields.at( idx ).name(), true );
8383
}
8484
else
85-
return true;
85+
return false;
8686
}
8787

8888
bool QgsEditFormConfig::labelOnTop( int idx )
@@ -93,10 +93,10 @@ bool QgsEditFormConfig::labelOnTop( int idx )
9393
return false;
9494
}
9595

96-
void QgsEditFormConfig::setFieldEditable( int idx, bool editable )
96+
void QgsEditFormConfig::setReadOnly( int idx, bool readOnly )
9797
{
9898
if ( idx >= 0 && idx < mFields.count() )
99-
mFieldEditables[ mFields.at( idx ).name()] = editable;
99+
mFieldEditables[ mFields.at( idx ).name()] = !readOnly;
100100
}
101101

102102
void QgsEditFormConfig::setLabelOnTop( int idx, bool onTop )

src/core/qgseditformconfig.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,15 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
441441
QgsEditorWidgetConfig widgetConfig( const QString& fieldName ) const;
442442

443443
/**
444-
* If this returns false, the widget at the given index will always be read-only.
444+
* This returns true if the field is manually set to read only or if the field
445+
* does not support editing like joins or vitual fields.
445446
*/
446-
bool fieldEditable( int idx );
447+
bool readOnly( int idx );
447448

448449
/**
449-
* If set to false, the widget at the given index will be read-only, regardless of the
450-
* layer's editable state and data provider capacities.
451-
* If it is set to true, the widget's editable state will be synchronized with the layer's
452-
* edit state.
450+
* If set to false, the widget at the given index will be read-only.
453451
*/
454-
void setFieldEditable( int idx, bool editable );
452+
void setReadOnly( int idx, bool readOnly = true );
455453

456454
/**
457455
* If this returns true, the widget at the given index will receive its label on the previous line

src/core/qgsvectorlayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ bool QgsVectorLayer::isReadOnly() const
27192719
return mReadOnly;
27202720
}
27212721

2722-
bool QgsVectorLayer::setReadOnly( bool readonly )
2722+
bool QgsVectorLayer::setFieldEditable( bool readonly )
27232723
{
27242724
// exit if the layer is in editing mode
27252725
if ( readonly && mEditBuffer )

src/core/qgsvectorlayer.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11261126
/** Make layer read-only (editing disabled) or not
11271127
* @return false if the layer is in editing yet
11281128
*/
1129-
bool setReadOnly( bool readonly = true );
1129+
bool setFieldEditable( bool editable = true );
11301130

11311131
/**
11321132
* Make layer editable.
@@ -1469,9 +1469,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
14691469
/**
14701470
* Is edit widget editable
14711471
*
1472-
* @deprecated Use `editFormConfig()->readOnly()` instead
1472+
* @deprecated Use `editFormConfig()->fieldEditable()` instead
14731473
*/
1474-
Q_DECL_DEPRECATED bool fieldEditable( int idx ) { return mEditFormConfig->readOnly( idx ); }
1474+
Q_DECL_DEPRECATED bool fieldEditable( int idx ) { return !mEditFormConfig->readOnly( idx ); }
14751475

14761476
/**
14771477
* Label widget on top
@@ -1481,9 +1481,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
14811481

14821482
/**
14831483
* Set edit widget editable
1484-
* @deprecated Use `editFormConfig()->setReadOnly()` instead
1484+
* @deprecated Use `editFormConfig()->setFieldEditable()` instead
14851485
*/
1486-
Q_DECL_DEPRECATED void setReadOnly( int idx, bool editable ) { mEditFormConfig->setFieldEditable( idx, editable ); }
1486+
Q_DECL_DEPRECATED void setFieldEditable( int idx, bool editable ) { mEditFormConfig->setReadOnly( idx, !editable ); }
14871487

14881488
/**
14891489
* Label widget on top

src/gui/attributetable/qgsattributetabledelegate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ QWidget *QgsAttributeTableDelegate::createEditor(
7575

7676
w->setAutoFillBackground( true );
7777

78-
eww->setEnabled( vl->editFormConfig()->fieldEditable( fieldIdx ) );
78+
eww->setEnabled( !vl->editFormConfig()->readOnly( fieldIdx ) );
7979

8080
return w;
8181
}

src/gui/attributetable/qgsattributetablemodel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
681681
Qt::ItemFlags flags = QAbstractItemModel::flags( index );
682682

683683
if ( layer()->isEditable() &&
684-
layer()->editFormConfig()->fieldEditable( mAttributes[ index.column()] ) &&
684+
!layer()->editFormConfig()->readOnly( mAttributes[ index.column()] ) &&
685685
(( layer()->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
686686
FID_IS_NEW( rowToId( index.row() ) ) ) )
687687
flags |= Qt::ItemIsEditable;

src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle
245245
cfg = mWidgetFactories[ewv2Type]->readEditorConfig( ewv2CfgElem, vectorLayer, idx );
246246
}
247247

248-
vectorLayer->editFormConfig()->setFieldEditable( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) == "1" );
248+
vectorLayer->editFormConfig()->setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
249249
vectorLayer->editFormConfig()->setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
250250
vectorLayer->editFormConfig()->setWidgetConfig( idx, cfg );
251251
}
@@ -301,7 +301,7 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
301301
if ( mWidgetFactories.contains( widgetType ) )
302302
{
303303
QDomElement ewv2CfgElem = doc.createElement( "widgetv2config" );
304-
ewv2CfgElem.setAttribute( "fieldEditable", vectorLayer->editFormConfig()->fieldEditable( idx ) );
304+
ewv2CfgElem.setAttribute( "fieldEditable", !vectorLayer->editFormConfig()->readOnly( idx ) );
305305
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->editFormConfig()->labelOnTop( idx ) );
306306

307307
mWidgetFactories[widgetType]->writeConfig( vectorLayer->editFormConfig()->widgetConfig( idx ), ewv2CfgElem, doc, vectorLayer, idx );

src/gui/qgsattributeform.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool QgsAttributeForm::save()
175175
QVariant srcVar = eww->value();
176176
// need to check dstVar.isNull() != srcVar.isNull()
177177
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar
178-
if (( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() && mLayer->editFormConfig()->fieldEditable( eww->fieldIdx() ) )
178+
if (( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() && !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) )
179179
{
180180
dst[eww->fieldIdx()] = srcVar;
181181

@@ -220,7 +220,7 @@ bool QgsAttributeForm::save()
220220
{
221221
if (( dst.at( i ) == src.at( i ) && dst.at( i ).isNull() == src.at( i ).isNull() ) // If field is not changed...
222222
|| !dst.at( i ).isValid() // or the widget returns invalid (== do not change)
223-
|| !mLayer->editFormConfig()->fieldEditable( i ) ) // or the field cannot be edited ...
223+
|| mLayer->editFormConfig()->readOnly( i ) ) // or the field cannot be edited ...
224224
{
225225
continue;
226226
}
@@ -367,7 +367,7 @@ void QgsAttributeForm::synchronizeEnabledState()
367367
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
368368
if ( eww )
369369
{
370-
fieldEditable = mLayer->editFormConfig()->fieldEditable( eww->fieldIdx() ) &&
370+
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
371371
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
372372
FID_IS_NEW( mFeature.id() ) );
373373
}

src/plugins/geometry_checker/ui/qgsgeometrycheckerresulttab.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ QgsGeometryCheckerResultTab::QgsGeometryCheckerResultTab( QgisInterface* iface,
7878
QgsGeometryCheckerResultTab::~QgsGeometryCheckerResultTab()
7979
{
8080
if ( mFeaturePool->getLayer() )
81-
mFeaturePool->getLayer()->setReadOnly( false );
81+
mFeaturePool->getLayer()->setFieldEditable( false );
8282
delete mChecker;
8383
delete mFeaturePool;
8484
qDeleteAll( mCurrentRubberBands );

src/plugins/geometry_checker/ui/qgsgeometrycheckersetuptab.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
286286
emit checkerStarted( checker, featurePool );
287287

288288
/** Add result layer (do this after checkerStarted, otherwise warning about removing of result layer may appear) **/
289-
layer->setReadOnly( true );
289+
layer->setFieldEditable( true );
290290
if ( ui.radioButtonOutputNew->isChecked() )
291291
{
292292
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << layer );

src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void QgsGeometrySnapperDialog::run()
261261
}
262262
}
263263

264-
layer->setReadOnly( true );
264+
layer->setFieldEditable( true );
265265
if ( ui.radioButtonOutputNew->isChecked() )
266266
{
267267
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << layer );
@@ -294,7 +294,7 @@ void QgsGeometrySnapperDialog::run()
294294
ui.progressBar->hide();
295295
ui.widgetInputs->setEnabled( true );
296296

297-
layer->setReadOnly( false );
297+
layer->setFieldEditable( false );
298298

299299
/** Refresh canvas **/
300300
mIface->mapCanvas()->refresh();

src/providers/grass/qgsgrassprovider.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1138,8 +1138,8 @@ void QgsGrassProvider::startEditing( QgsVectorLayer *vectorLayer )
11381138

11391139
// TODO: enable cats editing once all consequences are implemented
11401140
// disable cat and topo symbol editing
1141-
vectorLayer->editFormConfig()->setFieldEditable( mLayer->keyColumn(), false );
1142-
vectorLayer->editFormConfig()->setFieldEditable( mLayer->fields().size() - 1, false );
1141+
vectorLayer->editFormConfig()->setReadOnly( mLayer->keyColumn(), true );
1142+
vectorLayer->editFormConfig()->setReadOnly( mLayer->fields().size() - 1, true );
11431143

11441144
mEditedCount++;
11451145

0 commit comments

Comments
 (0)