Skip to content

Commit 0cd93a2

Browse files
committedJul 22, 2012
Add CASE and CASE ELSE to expression builder groups
- Use readAll() for function help to preserve html
1 parent d5f16c7 commit 0cd93a2

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed
 
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<h3>CASE statement</h3>
2+
A conditional statement that can be used to evaluate exissions and
3+
return a result.
4+
5+
<h4>Syntax</h4>
6+
<pre>
7+
CASE
8+
WHEN <i>expression</i> THEN <i>result</i>
9+
[ ...n ]
10+
ELSE <i>result</i>
11+
END
12+
</pre>
13+
[ ] marks optional statements
14+
15+
16+
<h4>Arguments</h4>
17+
<!-- List args for functions here-->
18+
<i> WHEN expression</i> - The expression to evaluate. <br>
19+
<i> THEN result</i> - If <i>expression</i> evaluates True then <i>result</i> is returned. <br>
20+
<i> ELSE result</i> - If <i>expression</i> evaluates False then <i>result</i> is returned. <br>
21+
22+
23+
24+
<h4>Example</h4>
25+
<!-- Show example of function.-->
26+
<pre>
27+
CASE
28+
WHEN <i>"column" IS NULL</i> THEN <i>'None'</i>
29+
ELSE <i>"column"</i>
30+
END
31+
</pre>
32+

‎resources/function_help/CASE-en_US

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h3>CASE statement</h3>
2+
A conditional statement that can be used to evaluate exissions and
3+
return a result.
4+
5+
<h4>Syntax</h4>
6+
<pre>
7+
CASE
8+
WHEN <i>expression</i> THEN <i>result</i>
9+
[ ...n ]
10+
[ ELSE <i>result</i> ]
11+
END
12+
</pre>
13+
[ ] marks optional statements
14+
15+
16+
<h4>Arguments</h4>
17+
<!-- List args for functions here-->
18+
<i> WHEN expression</i> - The expression to evaluate. <br>
19+
<i> THEN result</i> - If <i>expression</i> evaluates True then <i>result</i> is returned. <br>
20+
<i> ELSE result</i> - If <i>expression</i> evaluates False then <i>result</i> is returned. <br>
21+
22+
23+
24+
<h4>Example</h4>
25+
<!-- Show example of function.-->
26+
<pre>
27+
CASE
28+
WHEN <i>"column" IS NULL</i> THEN <i>'None'</i>
29+
END
30+
</pre>
31+

‎src/gui/qgsexpressionbuilderwidget.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ QgsExpressionBuilderWidget::QgsExpressionBuilderWidget( QWidget *parent )
7979
registerItem( tr( "Operators" ), "AND", " AND " );
8080
registerItem( tr( "Operators" ), "NOT", " NOT " );
8181

82+
QString casestring = "CASE WHEN condition THEN result END";
83+
QString caseelsestring = "CASE WHEN condition THEN result ELSE result END";
84+
registerItem( tr( "Conditionals" ), "CASE", casestring );
85+
registerItem( tr( "Conditionals" ), "CASE ELSE", caseelsestring );
8286

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

383-
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
387+
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* expressionItem )
384388
{
385-
if ( functionName == NULL )
389+
if ( expressionItem == NULL )
386390
return "";
387391

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

413-
QString name = functionName->text();
417+
QString name = expressionItem->text();
414418

415-
if ( functionName->getItemType() == QgsExpressionItem::Field )
419+
if ( expressionItem->getItemType() == QgsExpressionItem::Field )
416420
name = "Field";
417421

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

436440
// try en_US next
437-
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
441+
fullHelpPath = helpFilesPath + name + "-en_US";
438442
file.setFileName( fullHelpPath );
439443
}
440444
}
@@ -449,11 +453,7 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
449453
{
450454
QTextStream in( &file );
451455
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
452-
while ( !in.atEnd() )
453-
{
454-
QString line = in.readLine();
455-
helpContents += line;
456-
}
456+
helpContents = in.readAll();
457457
}
458458

459459
file.close();

0 commit comments

Comments
 (0)
Please sign in to comment.