mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Add method for highlighting variables in the expression builder
This commit is contained in:
parent
334ea504db
commit
85bda6c05f
@ -221,6 +221,21 @@ class QgsExpressionContext
|
||||
*/
|
||||
QVariant variable( const QString& name ) const;
|
||||
|
||||
/** Returns true if the specified variable name is intended to be highlighted to the
|
||||
* user. This is used by the expression builder to more prominently display the
|
||||
* variable.
|
||||
* @param name variable name
|
||||
* @see setHighlightedVariables()
|
||||
*/
|
||||
bool isHighlightedVariable( const QString& name ) const;
|
||||
|
||||
/** Sets the list of variable names within the context intended to be highlighted to the user. This
|
||||
* is used by the expression builder to more prominently display these variables.
|
||||
* @param variableNames variable names to highlight
|
||||
* @see isHighlightedVariable()
|
||||
*/
|
||||
void setHighlightedVariables( const QStringList& variableNames );
|
||||
|
||||
/** Returns the currently active scope from the context for a specified variable name.
|
||||
* As scopes later in the stack override earlier contexts, this will be the last matching
|
||||
* scope which contains a matching variable.
|
||||
|
@ -121,10 +121,12 @@ class QgsExpressionBuilderWidget : QWidget
|
||||
* @param expressionText The text that is inserted into the expression area when the user double clicks on the item.
|
||||
* @param helpText The help text that the user will see when item is selected.
|
||||
* @param type The type of the expression item.
|
||||
* @param highlightedItem set to true to make the item highlighted, which inserts a bold copy of the item at the top level
|
||||
*/
|
||||
void registerItem( QString group, QString label, QString expressionText,
|
||||
QString helpText = "",
|
||||
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode );
|
||||
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode,
|
||||
bool highlightedItem = false );
|
||||
|
||||
bool isExpressionValid();
|
||||
|
||||
|
@ -158,6 +158,7 @@ QgsExpressionContext::QgsExpressionContext( const QgsExpressionContext& other )
|
||||
{
|
||||
mStack << new QgsExpressionContextScope( *scope );
|
||||
}
|
||||
mHighlightedVariables = other.mHighlightedVariables;
|
||||
}
|
||||
|
||||
QgsExpressionContext& QgsExpressionContext::operator=( const QgsExpressionContext & other )
|
||||
@ -168,6 +169,7 @@ QgsExpressionContext& QgsExpressionContext::operator=( const QgsExpressionContex
|
||||
{
|
||||
mStack << new QgsExpressionContextScope( *scope );
|
||||
}
|
||||
mHighlightedVariables = other.mHighlightedVariables;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -193,6 +195,16 @@ QVariant QgsExpressionContext::variable( const QString& name ) const
|
||||
return scope ? scope->variable( name ) : QVariant();
|
||||
}
|
||||
|
||||
bool QgsExpressionContext::isHighlightedVariable( const QString &name ) const
|
||||
{
|
||||
return mHighlightedVariables.contains( name );
|
||||
}
|
||||
|
||||
void QgsExpressionContext::setHighlightedVariables( const QStringList& variableNames )
|
||||
{
|
||||
mHighlightedVariables = variableNames;
|
||||
}
|
||||
|
||||
const QgsExpressionContextScope* QgsExpressionContext::activeScopeForVariable( const QString& name ) const
|
||||
{
|
||||
//iterate through stack backwards, so that higher priority variables take precedence
|
||||
|
@ -252,6 +252,21 @@ class CORE_EXPORT QgsExpressionContext
|
||||
*/
|
||||
QVariant variable( const QString& name ) const;
|
||||
|
||||
/** Returns true if the specified variable name is intended to be highlighted to the
|
||||
* user. This is used by the expression builder to more prominently display the
|
||||
* variable.
|
||||
* @param name variable name
|
||||
* @see setHighlightedVariables()
|
||||
*/
|
||||
bool isHighlightedVariable( const QString& name ) const;
|
||||
|
||||
/** Sets the list of variable names within the context intended to be highlighted to the user. This
|
||||
* is used by the expression builder to more prominently display these variables.
|
||||
* @param variableNames variable names to highlight
|
||||
* @see isHighlightedVariable()
|
||||
*/
|
||||
void setHighlightedVariables( const QStringList& variableNames );
|
||||
|
||||
/** Returns the currently active scope from the context for a specified variable name.
|
||||
* As scopes later in the stack override earlier contexts, this will be the last matching
|
||||
* scope which contains a matching variable.
|
||||
@ -373,6 +388,7 @@ class CORE_EXPORT QgsExpressionContext
|
||||
private:
|
||||
|
||||
QList< QgsExpressionContextScope* > mStack;
|
||||
QStringList mHighlightedVariables;
|
||||
|
||||
};
|
||||
|
||||
|
@ -336,10 +336,11 @@ void QgsExpressionBuilderWidget::registerItem( QString group,
|
||||
QString label,
|
||||
QString expressionText,
|
||||
QString helpText,
|
||||
QgsExpressionItem::ItemType type )
|
||||
QgsExpressionItem::ItemType type, bool highlightedItem )
|
||||
{
|
||||
QgsExpressionItem* item = new QgsExpressionItem( label, expressionText, helpText, type );
|
||||
item->setData( label, Qt::UserRole );
|
||||
|
||||
// Look up the group and insert the new function.
|
||||
if ( mExpressionGroups.contains( group ) )
|
||||
{
|
||||
@ -355,6 +356,18 @@ void QgsExpressionBuilderWidget::registerItem( QString group,
|
||||
mModel->appendRow( newgroupNode );
|
||||
mExpressionGroups.insert( group, newgroupNode );
|
||||
}
|
||||
|
||||
if ( highlightedItem )
|
||||
{
|
||||
//insert a copy as a top level item
|
||||
QgsExpressionItem* topLevelItem = new QgsExpressionItem( label, expressionText, helpText, type );
|
||||
topLevelItem->setData( label, Qt::UserRole );
|
||||
QFont font = topLevelItem->font();
|
||||
font.setBold( true );
|
||||
topLevelItem->setFont( font );
|
||||
mModel->appendRow( topLevelItem );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool QgsExpressionBuilderWidget::isExpressionValid()
|
||||
@ -581,7 +594,10 @@ void QgsExpressionBuilderWidget::loadExpressionContext()
|
||||
QStringList variableNames = mExpressionContext.filteredVariableNames();
|
||||
Q_FOREACH ( QString variable, variableNames )
|
||||
{
|
||||
registerItem( "Variables", variable, " @" + variable + " ", QgsExpression::variableHelpText( variable, true, mExpressionContext.variable( variable ) ) );
|
||||
registerItem( "Variables", variable, " @" + variable + " ",
|
||||
QgsExpression::variableHelpText( variable, true, mExpressionContext.variable( variable ) ),
|
||||
QgsExpressionItem::ExpressionNode,
|
||||
mExpressionContext.isHighlightedVariable( variable ) );
|
||||
}
|
||||
|
||||
// Load the functions from the expression context
|
||||
|
@ -163,10 +163,12 @@ class GUI_EXPORT QgsExpressionBuilderWidget : public QWidget, private Ui::QgsExp
|
||||
* @param expressionText The text that is inserted into the expression area when the user double clicks on the item.
|
||||
* @param helpText The help text that the user will see when item is selected.
|
||||
* @param type The type of the expression item.
|
||||
* @param highlightedItem set to true to make the item highlighted, which inserts a bold copy of the item at the top level
|
||||
*/
|
||||
void registerItem( QString group, QString label, QString expressionText,
|
||||
QString helpText = "",
|
||||
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode );
|
||||
QgsExpressionItem::ItemType type = QgsExpressionItem::ExpressionNode,
|
||||
bool highlightedItem = false );
|
||||
|
||||
bool isExpressionValid();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user