Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fieldEditable -> readOnly
  • Loading branch information
m-kuhn committed Nov 19, 2015
1 parent d70a47e commit 4cd1e38
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 39 deletions.
6 changes: 3 additions & 3 deletions python/core/qgseditformconfig.sip
Expand Up @@ -190,17 +190,17 @@ class QgsEditFormConfig : QObject
QgsEditorWidgetConfig widgetConfig( const QString& fieldName ) const;

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

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

/**
* If this returns true, the widget at the given index will receive its label on the previous line
Expand Down
2 changes: 1 addition & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -1006,7 +1006,7 @@ class QgsVectorLayer : QgsMapLayer
/** Make layer read-only (editing disabled) or not
* @return false if the layer is in editing yet
*/
bool setReadOnly( bool readonly = true );
bool setFieldEditable( bool editable = true );

/**
* Make layer editable.
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -848,7 +848,7 @@ void QgsFieldsProperties::apply()
int idx = mFieldsList->item( i, attrIdCol )->text().toInt();
FieldConfig cfg = configForRow( i );

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

mLayer->editFormConfig()->setWidgetType( idx, cfg.mEditorWidgetV2Type );
Expand Down Expand Up @@ -900,7 +900,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig()
QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
: mButton( 0 )
{
mEditable = layer->editFormConfig()->fieldEditable( idx );
mEditable = !layer->editFormConfig()->readOnly( idx );
mEditableEnabled = layer->fields().fieldOrigin( idx ) != QgsFields::OriginJoin
&& layer->fields().fieldOrigin( idx ) != QgsFields::OriginExpression;
mLabelOnTop = layer->editFormConfig()->labelOnTop( idx );
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -4,8 +4,8 @@
QgsEditFormConfig::QgsEditFormConfig( QObject* parent )
: QObject( parent )
, mEditorLayout( GeneratedLayout )
, mUseInitCode( false )
, mFeatureFormSuppress( SuppressDefault )
, mUseInitCode( false )
{
connect( QgsProject::instance()->relationManager(), SIGNAL( relationsLoaded() ), this, SLOT( onRelationsLoaded() ) );
}
Expand Down Expand Up @@ -72,17 +72,17 @@ void QgsEditFormConfig::setUiForm( const QString& ui )
mEditForm = ui;
}

bool QgsEditFormConfig::fieldEditable( int idx )
bool QgsEditFormConfig::readOnly( int idx )
{
if ( idx >= 0 && idx < mFields.count() )
{
if ( mFields.fieldOrigin( idx ) == QgsFields::OriginJoin
|| mFields.fieldOrigin( idx ) == QgsFields::OriginExpression )
return false;
return mFieldEditables.value( mFields.at( idx ).name(), true );
return true;
return !mFieldEditables.value( mFields.at( idx ).name(), true );
}
else
return true;
return false;
}

bool QgsEditFormConfig::labelOnTop( int idx )
Expand All @@ -93,10 +93,10 @@ bool QgsEditFormConfig::labelOnTop( int idx )
return false;
}

void QgsEditFormConfig::setFieldEditable( int idx, bool editable )
void QgsEditFormConfig::setReadOnly( int idx, bool readOnly )
{
if ( idx >= 0 && idx < mFields.count() )
mFieldEditables[ mFields.at( idx ).name()] = editable;
mFieldEditables[ mFields.at( idx ).name()] = !readOnly;
}

void QgsEditFormConfig::setLabelOnTop( int idx, bool onTop )
Expand Down
12 changes: 5 additions & 7 deletions src/core/qgseditformconfig.h
Expand Up @@ -441,17 +441,15 @@ class CORE_EXPORT QgsEditFormConfig : public QObject
QgsEditorWidgetConfig widgetConfig( const QString& fieldName ) const;

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

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

/**
* If this returns true, the widget at the given index will receive its label on the previous line
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -2719,7 +2719,7 @@ bool QgsVectorLayer::isReadOnly() const
return mReadOnly;
}

bool QgsVectorLayer::setReadOnly( bool readonly )
bool QgsVectorLayer::setFieldEditable( bool readonly )
{
// exit if the layer is in editing mode
if ( readonly && mEditBuffer )
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsvectorlayer.h
Expand Up @@ -1126,7 +1126,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** Make layer read-only (editing disabled) or not
* @return false if the layer is in editing yet
*/
bool setReadOnly( bool readonly = true );
bool setFieldEditable( bool editable = true );

/**
* Make layer editable.
Expand Down Expand Up @@ -1469,9 +1469,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/**
* Is edit widget editable
*
* @deprecated Use `editFormConfig()->readOnly()` instead
* @deprecated Use `editFormConfig()->fieldEditable()` instead
*/
Q_DECL_DEPRECATED bool fieldEditable( int idx ) { return mEditFormConfig->readOnly( idx ); }
Q_DECL_DEPRECATED bool fieldEditable( int idx ) { return !mEditFormConfig->readOnly( idx ); }

/**
* Label widget on top
Expand All @@ -1481,9 +1481,9 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer

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

/**
* Label widget on top
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -75,7 +75,7 @@ QWidget *QgsAttributeTableDelegate::createEditor(

w->setAutoFillBackground( true );

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

return w;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -681,7 +681,7 @@ Qt::ItemFlags QgsAttributeTableModel::flags( const QModelIndex &index ) const
Qt::ItemFlags flags = QAbstractItemModel::flags( index );

if ( layer()->isEditable() &&
layer()->editFormConfig()->fieldEditable( mAttributes[ index.column()] ) &&
!layer()->editFormConfig()->readOnly( mAttributes[ index.column()] ) &&
(( layer()->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
FID_IS_NEW( rowToId( index.row() ) ) ) )
flags |= Qt::ItemIsEditable;
Expand Down
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
Expand Up @@ -245,7 +245,7 @@ void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomEle
cfg = mWidgetFactories[ewv2Type]->readEditorConfig( ewv2CfgElem, vectorLayer, idx );
}

vectorLayer->editFormConfig()->setFieldEditable( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) == "1" );
vectorLayer->editFormConfig()->setReadOnly( idx, ewv2CfgElem.attribute( "fieldEditable", "1" ) != "1" );
vectorLayer->editFormConfig()->setLabelOnTop( idx, ewv2CfgElem.attribute( "labelOnTop", "0" ) == "1" );
vectorLayer->editFormConfig()->setWidgetConfig( idx, cfg );
}
Expand Down Expand Up @@ -301,7 +301,7 @@ void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement&
if ( mWidgetFactories.contains( widgetType ) )
{
QDomElement ewv2CfgElem = doc.createElement( "widgetv2config" );
ewv2CfgElem.setAttribute( "fieldEditable", vectorLayer->editFormConfig()->fieldEditable( idx ) );
ewv2CfgElem.setAttribute( "fieldEditable", !vectorLayer->editFormConfig()->readOnly( idx ) );
ewv2CfgElem.setAttribute( "labelOnTop", vectorLayer->editFormConfig()->labelOnTop( idx ) );

mWidgetFactories[widgetType]->writeConfig( vectorLayer->editFormConfig()->widgetConfig( idx ), ewv2CfgElem, doc, vectorLayer, idx );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -175,7 +175,7 @@ bool QgsAttributeForm::save()
QVariant srcVar = eww->value();
// need to check dstVar.isNull() != srcVar.isNull()
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar
if (( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() && mLayer->editFormConfig()->fieldEditable( eww->fieldIdx() ) )
if (( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() && !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) )
{
dst[eww->fieldIdx()] = srcVar;

Expand Down Expand Up @@ -220,7 +220,7 @@ bool QgsAttributeForm::save()
{
if (( dst.at( i ) == src.at( i ) && dst.at( i ).isNull() == src.at( i ).isNull() ) // If field is not changed...
|| !dst.at( i ).isValid() // or the widget returns invalid (== do not change)
|| !mLayer->editFormConfig()->fieldEditable( i ) ) // or the field cannot be edited ...
|| mLayer->editFormConfig()->readOnly( i ) ) // or the field cannot be edited ...
{
continue;
}
Expand Down Expand Up @@ -367,7 +367,7 @@ void QgsAttributeForm::synchronizeEnabledState()
QgsEditorWidgetWrapper* eww = qobject_cast<QgsEditorWidgetWrapper*>( ww );
if ( eww )
{
fieldEditable = mLayer->editFormConfig()->fieldEditable( eww->fieldIdx() ) &&
fieldEditable = !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) &&
(( mLayer->dataProvider() && layer()->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues ) ||
FID_IS_NEW( mFeature.id() ) );
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ QgsGeometryCheckerResultTab::QgsGeometryCheckerResultTab( QgisInterface* iface,
QgsGeometryCheckerResultTab::~QgsGeometryCheckerResultTab()
{
if ( mFeaturePool->getLayer() )
mFeaturePool->getLayer()->setReadOnly( false );
mFeaturePool->getLayer()->setFieldEditable( false );
delete mChecker;
delete mFeaturePool;
qDeleteAll( mCurrentRubberBands );
Expand Down
Expand Up @@ -286,7 +286,7 @@ void QgsGeometryCheckerSetupTab::runChecks()
emit checkerStarted( checker, featurePool );

/** Add result layer (do this after checkerStarted, otherwise warning about removing of result layer may appear) **/
layer->setReadOnly( true );
layer->setFieldEditable( true );
if ( ui.radioButtonOutputNew->isChecked() )
{
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << layer );
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp
Expand Up @@ -261,7 +261,7 @@ void QgsGeometrySnapperDialog::run()
}
}

layer->setReadOnly( true );
layer->setFieldEditable( true );
if ( ui.radioButtonOutputNew->isChecked() )
{
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer*>() << layer );
Expand Down Expand Up @@ -294,7 +294,7 @@ void QgsGeometrySnapperDialog::run()
ui.progressBar->hide();
ui.widgetInputs->setEnabled( true );

layer->setReadOnly( false );
layer->setFieldEditable( false );

/** Refresh canvas **/
mIface->mapCanvas()->refresh();
Expand Down
4 changes: 2 additions & 2 deletions src/providers/grass/qgsgrassprovider.cpp
Expand Up @@ -1138,8 +1138,8 @@ void QgsGrassProvider::startEditing( QgsVectorLayer *vectorLayer )

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

mEditedCount++;

Expand Down

0 comments on commit 4cd1e38

Please sign in to comment.