Skip to content

Commit

Permalink
Add CASE and CASE ELSE to expression builder groups
Browse files Browse the repository at this point in the history
 - Use readAll() for function help to preserve html
  • Loading branch information
NathanW2 committed Jul 22, 2012
1 parent d5f16c7 commit 0cd93a2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
32 changes: 32 additions & 0 deletions resources/function_help/CASE ELSE-en_US
@@ -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>

31 changes: 31 additions & 0 deletions resources/function_help/CASE-en_US
@@ -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>

20 changes: 10 additions & 10 deletions src/gui/qgsexpressionbuilderwidget.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
}
}
Expand All @@ -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();
Expand Down

0 comments on commit 0cd93a2

Please sign in to comment.