@@ -115,6 +115,12 @@ QgsFieldsProperties::QgsFieldsProperties( QgsVectorLayer *layer, QWidget* parent
115
115
mRelationsList ->setHorizontalHeaderItem ( RelFieldCol, new QTableWidgetItem ( tr ( " Field" ) ) );
116
116
mRelationsList ->verticalHeader ()->hide ();
117
117
118
+ // Init function stuff
119
+ mInitCodeSourceComboBox ->addItem ( tr ( " " ) );
120
+ mInitCodeSourceComboBox ->addItem ( tr ( " Load from external file" ) );
121
+ mInitCodeSourceComboBox ->addItem ( tr ( " Provide code in this dialog" ) );
122
+ mInitCodeSourceComboBox ->addItem ( tr ( " Load from the environment" ) );
123
+
118
124
loadRelations ();
119
125
120
126
updateButtons ();
@@ -183,11 +189,15 @@ QTreeWidgetItem *QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
183
189
return newWidget;
184
190
}
185
191
186
- void QgsFieldsProperties::setEditFormInit ( const QString &editForm, const QString &editFormInit, const QString &editFormInitCode, const bool editFormInitUseCode )
192
+ void QgsFieldsProperties::setEditFormInit ( const QString &editForm,
193
+ const QString &initFunction,
194
+ const QString &initCode,
195
+ const QString &initFilePath,
196
+ const QgsEditFormConfig::PythonInitCodeSource &codeSource )
187
197
{
188
198
189
199
// Python init function and code
190
- QString code ( editFormInitCode );
200
+ QString code ( initCode );
191
201
if ( code.isEmpty ( ) )
192
202
{
193
203
code.append ( tr ( " # -*- coding: utf-8 -*-\n\"\"\"\n "
@@ -206,12 +216,11 @@ void QgsFieldsProperties::setEditFormInit( const QString &editForm, const QStrin
206
216
" \t control = dialog.findChild(QWidget, \" MyLineEdit\" )\n " ) );
207
217
208
218
}
209
- leEditForm->setText ( editForm );
210
- leEditFormInitCode->setText ( code );
211
- leEditFormInit->setText ( editFormInit );
212
- leEditFormInitUseCode->setChecked ( editFormInitUseCode );
213
- // Show or hide as needed
214
- mPythonInitCodeGroupBox ->setVisible ( editFormInitUseCode );
219
+ mEditFormLineEdit ->setText ( editForm );
220
+ mInitFilePathLineEdit ->setText ( initFilePath );
221
+ mInitCodeEditorPython ->setText ( code );
222
+ mInitFunctionLineEdit ->setText ( initFunction );
223
+ mInitCodeSourceComboBox ->setCurrentIndex ( codeSource );
215
224
}
216
225
217
226
@@ -453,9 +462,13 @@ void QgsFieldsProperties::on_mMoveUpItem_clicked()
453
462
}
454
463
}
455
464
456
- void QgsFieldsProperties::on_leEditFormInitUseCode_toggled ( bool checked )
465
+ void QgsFieldsProperties::on_mInitCodeSourceComboBox_currentIndexChanged ( int codeSource )
457
466
{
458
- mPythonInitCodeGroupBox ->setVisible ( checked );
467
+ // Show or hide ui elements as needed
468
+ mInitFunctionContainer ->setVisible ( codeSource != QgsEditFormConfig::PythonInitCodeSource::CodeSourceNone );
469
+ mPythonInitCodeGroupBox ->setVisible ( codeSource == QgsEditFormConfig::PythonInitCodeSource::CodeSourceDialog );
470
+ mInitFilePathLineEdit ->setVisible ( codeSource == QgsEditFormConfig::PythonInitCodeSource::CodeSourceFile );
471
+ mInitFilePathLabel ->setVisible ( codeSource == QgsEditFormConfig::PythonInitCodeSource::CodeSourceFile );
459
472
}
460
473
461
474
void QgsFieldsProperties::attributeTypeDialog ()
@@ -805,6 +818,22 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
805
818
return widgetDef;
806
819
}
807
820
821
+
822
+ void QgsFieldsProperties::on_pbtnSelectInitFilePath_clicked ()
823
+ {
824
+ QSettings myQSettings;
825
+ QString lastUsedDir = myQSettings.value ( " style/lastUIDir" , " ." ).toString ();
826
+ QString pyfilename = QFileDialog::getOpenFileName ( this , tr ( " Select Python file" ), lastUsedDir, tr ( " Python file" ) + " (*.py)" );
827
+
828
+ if ( pyfilename.isNull () )
829
+ return ;
830
+
831
+ QFileInfo fi ( pyfilename );
832
+ myQSettings.setValue ( " style/lastUIDir" , fi.path () );
833
+ mInitFilePathLineEdit ->setText ( pyfilename );
834
+ }
835
+
836
+
808
837
void QgsFieldsProperties::on_pbnSelectEditForm_clicked ()
809
838
{
810
839
QSettings myQSettings;
@@ -816,7 +845,7 @@ void QgsFieldsProperties::on_pbnSelectEditForm_clicked()
816
845
817
846
QFileInfo fi ( uifilename );
818
847
myQSettings.setValue ( " style/lastUIDir" , fi.path () );
819
- leEditForm ->setText ( uifilename );
848
+ mEditFormLineEdit ->setText ( uifilename );
820
849
}
821
850
822
851
void QgsFieldsProperties::on_mEditorLayoutComboBox_currentIndexChanged ( int index )
@@ -875,10 +904,14 @@ void QgsFieldsProperties::apply()
875
904
876
905
mLayer ->editFormConfig ()->setLayout (( QgsEditFormConfig::EditorLayout ) mEditorLayoutComboBox ->currentIndex () );
877
906
if ( mEditorLayoutComboBox ->currentIndex () == QgsEditFormConfig::UiFileLayout )
878
- mLayer ->editFormConfig ()->setUiForm ( leEditForm->text () );
879
- mLayer ->editFormConfig ()->setInitFunction ( leEditFormInit->text () );
880
- mLayer ->editFormConfig ()->setUseInitCode ( leEditFormInitUseCode->isChecked () );
881
- mLayer ->editFormConfig ()->setInitCode ( leEditFormInitCode->text () );
907
+ mLayer ->editFormConfig ()->setUiForm ( mEditFormLineEdit ->text () );
908
+
909
+ // Init function configuration
910
+ mLayer ->editFormConfig ()->setInitFunction ( mInitFunctionLineEdit ->text ( ) );
911
+ mLayer ->editFormConfig ()->setInitCode ( mInitCodeEditorPython ->text ( ) );
912
+ mLayer ->editFormConfig ()->setInitFilePath ( mInitFilePathLineEdit ->text ( ) );
913
+ mLayer ->editFormConfig ()->setInitCodeSource (( QgsEditFormConfig::PythonInitCodeSource )mInitCodeSourceComboBox ->currentIndex () );
914
+
882
915
mLayer ->editFormConfig ()->setSuppress (( QgsEditFormConfig::FeatureFormSuppress )mFormSuppressCmbBx ->currentIndex () );
883
916
884
917
mLayer ->setExcludeAttributesWMS ( excludeAttributesWMS );
0 commit comments