Skip to content

Commit f1e4c45

Browse files
committed
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
1 parent ebf1df5 commit f1e4c45

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

python/gui/qgsattributeeditorcontext.sip

+14
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,19 @@ class QgsAttributeEditorContext
5454
*/
5555
void setFormMode( FormMode mode );
5656

57+
/** Returns true if the attribute editor should permit use of custom UI forms.
58+
* @see setAllowCustomUi()
59+
* @note added in QGIS 2.16
60+
*/
61+
bool allowCustomUi() const;
62+
63+
/** Sets whether the attribute editor should permit use of custom UI forms.
64+
* @param allow set to true to allow custom UI forms, or false to disable them and use default generated
65+
* QGIS forms
66+
* @see allowCustomUi()
67+
* @note added in QGIS 2.16
68+
*/
69+
void setAllowCustomUi( bool allow );
70+
5771
const QgsAttributeEditorContext* parentContext() const;
5872
};

src/app/qgisapp.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -6929,10 +6929,12 @@ void QgisApp::modifyAttributesOfSelectedFeatures()
69296929

69306930
//dummy feature
69316931
QgsFeature f;
6932-
QgsAttributeDialog* dialog = new QgsAttributeDialog( vl, &f, false, this );
6932+
QgsAttributeEditorContext context;
6933+
context.setAllowCustomUi( false );
6934+
6935+
QgsAttributeDialog* dialog = new QgsAttributeDialog( vl, &f, false, this, true, context );
69336936
dialog->setMode( QgsAttributeForm::MultiEditMode );
69346937
dialog->exec();
6935-
69366938
}
69376939

69386940
void QgisApp::mergeSelectedFeatures()

src/app/qgsselectbyformdialog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer* layer, const QgsAt
2323
{
2424
QgsAttributeEditorContext dlgContext = context;
2525
dlgContext.setFormMode( QgsAttributeEditorContext::StandaloneDialog );
26+
dlgContext.setAllowCustomUi( false );
2627

2728
mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this );
2829
mForm->setMode( QgsAttributeForm::SearchMode );

src/gui/qgsattributeeditorcontext.h

+18
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class GUI_EXPORT QgsAttributeEditorContext
5656
, mVectorLayerTools( nullptr )
5757
, mRelationMode( Undefined )
5858
, mFormMode( Embed )
59+
, mAllowCustomUi( true )
5960
{}
6061

6162
QgsAttributeEditorContext( const QgsAttributeEditorContext& parentContext, FormMode formMode )
@@ -65,6 +66,7 @@ class GUI_EXPORT QgsAttributeEditorContext
6566
, mDistanceArea( parentContext.mDistanceArea )
6667
, mRelationMode( Undefined )
6768
, mFormMode( formMode )
69+
, mAllowCustomUi( true )
6870
{
6971
Q_ASSERT( parentContext.vectorLayerTools() );
7072
}
@@ -77,6 +79,7 @@ class GUI_EXPORT QgsAttributeEditorContext
7779
, mRelation( relation )
7880
, mRelationMode( relationMode )
7981
, mFormMode( widgetMode )
82+
, mAllowCustomUi( true )
8083
{
8184
Q_ASSERT( parentContext.vectorLayerTools() );
8285
}
@@ -111,6 +114,20 @@ class GUI_EXPORT QgsAttributeEditorContext
111114
*/
112115
inline void setFormMode( FormMode mode ) { mFormMode = mode; }
113116

117+
/** Returns true if the attribute editor should permit use of custom UI forms.
118+
* @see setAllowCustomUi()
119+
* @note added in QGIS 2.16
120+
*/
121+
bool allowCustomUi() const { return mAllowCustomUi; }
122+
123+
/** Sets whether the attribute editor should permit use of custom UI forms.
124+
* @param allow set to true to allow custom UI forms, or false to disable them and use default generated
125+
* QGIS forms
126+
* @see allowCustomUi()
127+
* @note added in QGIS 2.16
128+
*/
129+
void setAllowCustomUi( bool allow ) { mAllowCustomUi = allow; }
130+
114131
inline const QgsAttributeEditorContext* parentContext() const { return mParentContext; }
115132

116133
private:
@@ -121,6 +138,7 @@ class GUI_EXPORT QgsAttributeEditorContext
121138
QgsRelation mRelation;
122139
RelationMode mRelationMode;
123140
FormMode mFormMode;
141+
bool mAllowCustomUi;
124142
};
125143

126144
#endif // QGSATTRIBUTEEDITORCONTEXT_H

src/gui/qgsattributeform.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,8 @@ void QgsAttributeForm::init()
10641064
setContentsMargins( 0, 0, 0, 0 );
10651065

10661066
// Try to load Ui-File for layout
1067-
if ( mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout && !mLayer->editFormConfig()->uiForm().isEmpty() )
1067+
if ( mContext.allowCustomUi() && mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout &&
1068+
!mLayer->editFormConfig()->uiForm().isEmpty() )
10681069
{
10691070
QFile file( mLayer->editFormConfig()->uiForm() );
10701071

0 commit comments

Comments
 (0)