Skip to content

Commit

Permalink
Move template text to qgis.user.expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jan 22, 2015
1 parent df939c3 commit 56069c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 15 additions & 0 deletions python/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ def load_user_expressions(path):

expressions.load = load_user_expressions
expressions.load(expressionspath)
expressions.template = """\"\"\"
Template function file. Define new functions using @qgsfunction.
When using args="auto" you may define a new variable for each value for the function.
feature and parent must always be the last args.
To pass a any number of args into a function use args=-1 the first
variable will then be a list of values.
\"\"\"
from qgis.core import *
from qgis.gui import *
@qgsfunction(args="auto", group='Custom')
def func(value1, feature, parent):
pass
"""

8 changes: 3 additions & 5 deletions src/gui/qgsexpressionbuilderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,9 @@ void QgsExpressionBuilderWidget::updateFunctionFileList( QString path )

void QgsExpressionBuilderWidget::newFunctionFile( QString fileName )
{
txtPython->setText( "from qgis.core import *\n"
"from qgis.gui import *\n\n"
"@qgsfunction(args=-1, group='Custom')\n"
"def func(values, feature, parent):\n"
" return str(values)" );
QString templatetxt;
QgsPythonRunner::eval("qgis.user.expressions.template", templatetxt);
txtPython->setText( templatetxt );
int index = cmbFileNames->findText( fileName );
if ( index == -1 )
cmbFileNames->setEditText( fileName );
Expand Down

0 comments on commit 56069c9

Please sign in to comment.