Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed Jun 15, 2016
1 parent ebf1df5 commit f1e4c4592b2c2f5632e9ad172076a46e044d402b
@@ -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;
};
@@ -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()
@@ -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 );
@@ -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
@@ -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() );

0 comments on commit f1e4c45

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