mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -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" ), "AND", " AND " );
|
||||||
registerItem( tr( "Operators" ), "NOT", " NOT " );
|
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
|
// Load the functions from the QgsExpression class
|
||||||
int count = QgsExpression::functionCount();
|
int count = QgsExpression::functionCount();
|
||||||
@ -380,9 +384,9 @@ void QgsExpressionBuilderWidget::setExpressionState( bool state )
|
|||||||
mExpressionValid = state;
|
mExpressionValid = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functionName )
|
QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* expressionItem )
|
||||||
{
|
{
|
||||||
if ( functionName == NULL )
|
if ( expressionItem == NULL )
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
// set up the path to the help file
|
// set up the path to the help file
|
||||||
@ -410,9 +414,9 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
|
|||||||
lang = "en_US";
|
lang = "en_US";
|
||||||
}
|
}
|
||||||
|
|
||||||
QString name = functionName->text();
|
QString name = expressionItem->text();
|
||||||
|
|
||||||
if ( functionName->getItemType() == QgsExpressionItem::Field )
|
if ( expressionItem->getItemType() == QgsExpressionItem::Field )
|
||||||
name = "Field";
|
name = "Field";
|
||||||
|
|
||||||
QString fullHelpPath = helpFilesPath + name + "-" + lang;
|
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 );
|
missingError += tr( "It was neither available in your language (%1) nor English." ).arg( lang );
|
||||||
|
|
||||||
// try en_US next
|
// try en_US next
|
||||||
fullHelpPath = helpFilesPath + functionName->text() + "-en_US";
|
fullHelpPath = helpFilesPath + name + "-en_US";
|
||||||
file.setFileName( fullHelpPath );
|
file.setFileName( fullHelpPath );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -449,11 +453,7 @@ QString QgsExpressionBuilderWidget::loadFunctionHelp( QgsExpressionItem* functio
|
|||||||
{
|
{
|
||||||
QTextStream in( &file );
|
QTextStream in( &file );
|
||||||
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
|
in.setCodec( "UTF-8" ); // Help files must be in Utf-8
|
||||||
while ( !in.atEnd() )
|
helpContents = in.readAll();
|
||||||
{
|
|
||||||
QString line = in.readLine();
|
|
||||||
helpContents += line;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user