Skip to content
Permalink
Browse files

Add CASE and CASE ELSE to expression builder groups

 - Use readAll() for function help to preserve html
  • Loading branch information
NathanW2 committed Jul 22, 2012
1 parent d5f16c7 commit 0cd93a23780a31a347eb7881b3eaa987e5cfa0e2
Showing with 73 additions and 10 deletions.
  1. +32 −0 resources/function_help/CASE ELSE-en_US
  2. +31 −0 resources/function_help/CASE-en_US
  3. +10 −10 src/gui/qgsexpressionbuilderwidget.cpp
@@ -0,0 +1,32 @@
<h3>CASE statement</h3>
A conditional statement that can be used to evaluate exissions and
return a result.

<h4>Syntax</h4>
<pre>
CASE
WHEN <i>expression</i> THEN <i>result</i>
[ ...n ]
ELSE <i>result</i>
END
</pre>
[ ] marks optional statements


<h4>Arguments</h4>
<!-- List args for functions here-->
<i> WHEN expression</i> - The expression to evaluate. <br>
<i> THEN result</i> - If <i>expression</i> evaluates True then <i>result</i> is returned. <br>
<i> ELSE result</i> - If <i>expression</i> evaluates False then <i>result</i> is returned. <br>



<h4>Example</h4>
<!-- Show example of function.-->
<pre>
CASE
WHEN <i>"column" IS NULL</i> THEN <i>'None'</i>
ELSE <i>"column"</i>
END
</pre>

@@ -0,0 +1,31 @@
<h3>CASE statement</h3>
A conditional statement that can be used to evaluate exissions and
return a result.

<h4>Syntax</h4>
<pre>
CASE
WHEN <i>expression</i> THEN <i>result</i>
[ ...n ]
[ ELSE <i>result</i> ]
END
</pre>
[ ] marks optional statements


<h4>Arguments</h4>
<!-- List args for functions here-->
<i> WHEN expression</i> - The expression to evaluate. <br>
<i> THEN result</i> - If <i>expression</i> evaluates True then <i>result</i> is returned. <br>
<i> ELSE result</i> - If <i>expression</i> evaluates False then <i>result</i> is returned. <br>



<h4>Example</h4>
<!-- Show example of function.-->
<pre>
CASE
WHEN <i>"column" IS NULL</i> THEN <i>'None'</i>
END
</pre>

@@ -79,6 +79,10 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
registerItem( tr( "Operators" ), "AND", " AND " );
registerItem( tr( "Operators" ), "NOT", " NOT " );

QString casestring = "CASE WHEN condition THEN result END";
QString caseelsestring = "CASE WHEN condition THEN result ELSE result END";
registerItem( tr( "Conditionals" ), "CASE", casestring );
registerItem( tr( "Conditionals" ), "CASE ELSE", caseelsestring );

// Load the functions from the QgsExpression class
int count = QgsExpression::functionCount();
@@ -380,9 +384,9 @@ void QgsExpressionBuilderWidget::setExpressionState( bool state )
mExpressionValid = state;
}

QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* expressionItem )
{
if ( functionName == NULL )
if ( expressionItem == NULL )
return "";

// set up the path to the help file
@@ -410,9 +414,9 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
lang = "en_US";
}

QString name = functionName->text();
QString name = expressionItem->text();

if ( functionName->getItemType() == QgsExpressionItem::Field )
if ( expressionItem->getItemType() == QgsExpressionItem::Field )
name = "Field";

QString fullHelpPath = helpFilesPath + name + "-" + lang;
@@ -434,7 +438,7 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
missingError += tr( "It was neither available in your language (%1) nor English." ).arg( lang );

// try en_US next
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
fullHelpPath = helpFilesPath + name + "-en_US";
file.setFileName( fullHelpPath );
}
}
@@ -449,11 +453,7 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
{
QTextStream in( &file );
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
while ( !in.atEnd() )
{
QString line = in.readLine();
helpContents += line;
}
helpContents = in.readAll();
}

file.close();

0 comments on commit 0cd93a2

Please sign in to comment.
You can’t perform that action at this time.