Skip to content

Commit

Permalink
Added error messages with QMessageBox
Browse files Browse the repository at this point in the history
Errors on:
* init function not found
* init function with wrong parameters count
  • Loading branch information
elpaso committed Dec 5, 2015
1 parent 5d144d4 commit bc489c9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -37,6 +37,7 @@
#include <QScrollArea>
#include <QTabWidget>
#include <QUiLoader>
#include <QMessageBox>

int QgsAttributeForm::sFormCounter = 0;

Expand Down Expand Up @@ -576,7 +577,8 @@ void QgsAttributeForm::initPython()
{
cleanPython();

// Init Python
// Init Python, if init function is not empty and the combo indicates
// the source for the function code
if ( !mLayer->editFormConfig()->initFunction().isEmpty()
&& mLayer->editFormConfig()->initCodeSource() != QgsEditFormConfig::PythonInitCodeSource::CodeSourceNone )
{
Expand Down Expand Up @@ -621,7 +623,7 @@ void QgsAttributeForm::initPython()
case( QgsEditFormConfig::PythonInitCodeSource::CodeSourceEnvironment ):
case( QgsEditFormConfig::PythonInitCodeSource::CodeSourceNone ):
default:
// Nothing to do
// Nothing to do: the function code should be already in the environment
break;
}

Expand Down Expand Up @@ -655,6 +657,10 @@ void QgsAttributeForm::initPython()
}
else
{
// If we get here, it means that the function doesn't accept three arguments
QMessageBox msgBox;
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 ) );
msgBox.exec();
#if 0
QString expr = QString( "%1(%2)" )
.arg( mLayer->editFormInit() )
Expand All @@ -667,7 +673,10 @@ void QgsAttributeForm::initPython()
}
else
{
QgsLogger::warning( QString( "There was an error evaluating the python init function!" ) );
// If we get here, it means that inspect couldn't find the function
QMessageBox msgBox;
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 ) );
msgBox.exec();
}
}
}
Expand Down

0 comments on commit bc489c9

Please sign in to comment.