mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Add CASE and CASE ELSE to expression builder groups
- Use readAll() for function help to preserve html
This commit is contained in:
parent
d5f16c7cf5
commit
0cd93a2378
32
resources/function_help/CASE ELSE-en_US
Normal file
32
resources/function_help/CASE ELSE-en_US
Normal file
@ -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
resources/function_help/CASE-en_US
Normal file
31
resources/function_help/CASE-en_US
Normal file
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user