From f1e4c4592b2c2f5632e9ad172076a46e044d402b Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 15 Jun 2016 14:57:37 +1000 Subject: [PATCH] Fallback to generated layout for Select by Value if using a custom UI form Custom UI forms are not supported with the attribute form search mode, but this way users with custom UI forms can still use the feature --- python/gui/qgsattributeeditorcontext.sip | 14 ++++++++++++++ src/app/qgisapp.cpp | 6 ++++-- src/app/qgsselectbyformdialog.cpp | 1 + src/gui/qgsattributeeditorcontext.h | 18 ++++++++++++++++++ src/gui/qgsattributeform.cpp | 3 ++- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/python/gui/qgsattributeeditorcontext.sip b/python/gui/qgsattributeeditorcontext.sip index 7722fecd382..0f61bcd17b3 100644 --- a/python/gui/qgsattributeeditorcontext.sip +++ b/python/gui/qgsattributeeditorcontext.sip @@ -54,5 +54,19 @@ class QgsAttributeEditorContext */ void setFormMode( FormMode mode ); + /** Returns true if the attribute editor should permit use of custom UI forms. + * @see setAllowCustomUi() + * @note added in QGIS 2.16 + */ + bool allowCustomUi() const; + + /** Sets whether the attribute editor should permit use of custom UI forms. + * @param allow set to true to allow custom UI forms, or false to disable them and use default generated + * QGIS forms + * @see allowCustomUi() + * @note added in QGIS 2.16 + */ + void setAllowCustomUi( bool allow ); + const QgsAttributeEditorContext* parentContext() const; }; diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 62a6603dbb0..c58653855ea 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -6929,10 +6929,12 @@ void QgisApp::modifyAttributesOfSelectedFeatures() //dummy feature QgsFeature f; - QgsAttributeDialog* dialog = new QgsAttributeDialog( vl, &f, false, this ); + QgsAttributeEditorContext context; + context.setAllowCustomUi( false ); + + QgsAttributeDialog* dialog = new QgsAttributeDialog( vl, &f, false, this, true, context ); dialog->setMode( QgsAttributeForm::MultiEditMode ); dialog->exec(); - } void QgisApp::mergeSelectedFeatures() diff --git a/src/app/qgsselectbyformdialog.cpp b/src/app/qgsselectbyformdialog.cpp index ea3afe980ff..fc57edc5c02 100644 --- a/src/app/qgsselectbyformdialog.cpp +++ b/src/app/qgsselectbyformdialog.cpp @@ -23,6 +23,7 @@ QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer* layer, const QgsAt { QgsAttributeEditorContext dlgContext = context; dlgContext.setFormMode( QgsAttributeEditorContext::StandaloneDialog ); + dlgContext.setAllowCustomUi( false ); mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this ); mForm->setMode( QgsAttributeForm::SearchMode ); diff --git a/src/gui/qgsattributeeditorcontext.h b/src/gui/qgsattributeeditorcontext.h index 87e21ae339c..a9444e0099d 100644 --- a/src/gui/qgsattributeeditorcontext.h +++ b/src/gui/qgsattributeeditorcontext.h @@ -56,6 +56,7 @@ class GUI_EXPORT QgsAttributeEditorContext , mVectorLayerTools( nullptr ) , mRelationMode( Undefined ) , mFormMode( Embed ) + , mAllowCustomUi( true ) {} QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, FormMode formMode ) @@ -65,6 +66,7 @@ class GUI_EXPORT QgsAttributeEditorContext , mDistanceArea( parentContext.mDistanceArea ) , mRelationMode( Undefined ) , mFormMode( formMode ) + , mAllowCustomUi( true ) { Q_ASSERT( parentContext.vectorLayerTools() ); } @@ -77,6 +79,7 @@ class GUI_EXPORT QgsAttributeEditorContext , mRelation( relation ) , mRelationMode( relationMode ) , mFormMode( widgetMode ) + , mAllowCustomUi( true ) { Q_ASSERT( parentContext.vectorLayerTools() ); } @@ -111,6 +114,20 @@ class GUI_EXPORT QgsAttributeEditorContext */ inline void setFormMode( FormMode mode ) { mFormMode = mode; } + /** Returns true if the attribute editor should permit use of custom UI forms. + * @see setAllowCustomUi() + * @note added in QGIS 2.16 + */ + bool allowCustomUi() const { return mAllowCustomUi; } + + /** Sets whether the attribute editor should permit use of custom UI forms. + * @param allow set to true to allow custom UI forms, or false to disable them and use default generated + * QGIS forms + * @see allowCustomUi() + * @note added in QGIS 2.16 + */ + void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; } + inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; } private: @@ -121,6 +138,7 @@ class GUI_EXPORT QgsAttributeEditorContext QgsRelation mRelation; RelationMode mRelationMode; FormMode mFormMode; + bool mAllowCustomUi; }; #endif // QGSATTRIBUTEEDITORCONTEXT_H diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index cbd6c197aca..8c1eb3840e2 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -1064,7 +1064,8 @@ void QgsAttributeForm::init() setContentsMargins( 0, 0, 0, 0 ); // Try to load Ui-File for layout - if ( mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout && !mLayer->editFormConfig()->uiForm().isEmpty() ) + if ( mContext.allowCustomUi() && mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout && + !mLayer->editFormConfig()->uiForm().isEmpty() ) { QFile file( mLayer->editFormConfig()->uiForm() );