Skip to content

Commit bc489c9

Browse files
committed
Added error messages with QMessageBox
Errors on: * init function not found * init function with wrong parameters count
1 parent 5d144d4 commit bc489c9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/gui/qgsattributeform.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <QScrollArea>
3838
#include <QTabWidget>
3939
#include <QUiLoader>
40+
#include <QMessageBox>
4041

4142
int QgsAttributeForm::sFormCounter = 0;
4243

@@ -576,7 +577,8 @@ void QgsAttributeForm::initPython()
576577
{
577578
cleanPython();
578579

579-
// Init Python
580+
// Init Python, if init function is not empty and the combo indicates
581+
// the source for the function code
580582
if ( !mLayer->editFormConfig()->initFunction().isEmpty()
581583
&& mLayer->editFormConfig()->initCodeSource() != QgsEditFormConfig::PythonInitCodeSource::CodeSourceNone )
582584
{
@@ -621,7 +623,7 @@ void QgsAttributeForm::initPython()
621623
case( QgsEditFormConfig::PythonInitCodeSource::CodeSourceEnvironment ):
622624
case( QgsEditFormConfig::PythonInitCodeSource::CodeSourceNone ):
623625
default:
624-
// Nothing to do
626+
// Nothing to do: the function code should be already in the environment
625627
break;
626628
}
627629

@@ -655,6 +657,10 @@ void QgsAttributeForm::initPython()
655657
}
656658
else
657659
{
660+
// If we get here, it means that the function doesn't accept three arguments
661+
QMessageBox msgBox;
662+
msgBox.setText( tr( "The python init function (<code>%1</code>) does not accept three arguments as expected!<br>Please check the function name in the <b>Fields</b> tab of the layer properties." ).arg( initFunction ) );
663+
msgBox.exec();
658664
#if 0
659665
QString expr = QString( "%1(%2)" )
660666
.arg( mLayer->editFormInit() )
@@ -667,7 +673,10 @@ void QgsAttributeForm::initPython()
667673
}
668674
else
669675
{
670-
QgsLogger::warning( QString( "There was an error evaluating the python init function!" ) );
676+
// If we get here, it means that inspect couldn't find the function
677+
QMessageBox msgBox;
678+
msgBox.setText( tr( "The python init function (<code>%1</code>) could not be found!<br>Please check the function name in the <b>Fields</b> tab of the layer properties." ).arg( initFunction ) );
679+
msgBox.exec();
671680
}
672681
}
673682
}

0 commit comments

Comments
 (0)