Skip to content

Commit

Permalink
Fallback to generated layout for Select by Value if using a custom
Browse files Browse the repository at this point in the history
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 f1e4c45
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
14 changes: 14 additions & 0 deletions python/gui/qgsattributeeditorcontext.sip
Expand Up @@ -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;
};
6 changes: 4 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsselectbyformdialog.cpp
Expand Up @@ -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 );
Expand Down
18 changes: 18 additions & 0 deletions src/gui/qgsattributeeditorcontext.h
Expand Up @@ -56,6 +56,7 @@ class GUI_EXPORT QgsAttributeEditorContext
, mVectorLayerTools( nullptr )
, mRelationMode( Undefined )
, mFormMode( Embed )
, mAllowCustomUi( true )
{}

QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, FormMode formMode )
Expand All @@ -65,6 +66,7 @@ class GUI_EXPORT QgsAttributeEditorContext
, mDistanceArea( parentContext.mDistanceArea )
, mRelationMode( Undefined )
, mFormMode( formMode )
, mAllowCustomUi( true )
{
Q_ASSERT( parentContext.vectorLayerTools() );
}
Expand All @@ -77,6 +79,7 @@ class GUI_EXPORT QgsAttributeEditorContext
, mRelation( relation )
, mRelationMode( relationMode )
, mFormMode( widgetMode )
, mAllowCustomUi( true )
{
Q_ASSERT( parentContext.vectorLayerTools() );
}
Expand Down Expand Up @@ -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:
Expand All @@ -121,6 +138,7 @@ class GUI_EXPORT QgsAttributeEditorContext
QgsRelation mRelation;
RelationMode mRelationMode;
FormMode mFormMode;
bool mAllowCustomUi;
};

#endif // QGSATTRIBUTEEDITORCONTEXT_H
3 changes: 2 additions & 1 deletion src/gui/qgsattributeform.cpp
Expand Up @@ -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() );

Expand Down

0 comments on commit f1e4c45

Please sign in to comment.