mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Expose renderer variables to users
This commit is contained in:
parent
1725182909
commit
962a4e975f
@ -457,6 +457,10 @@ class QgsExpressionContext
|
||||
static const QString EXPR_GEOMETRY_PART_COUNT;
|
||||
//! Inbuilt variable name for geometry part number variable
|
||||
static const QString EXPR_GEOMETRY_PART_NUM;
|
||||
//! Inbuilt variable name for cluster size variable
|
||||
static const QString EXPR_CLUSTER_SIZE;
|
||||
//! Inbuilt variable name for cluster color variable
|
||||
static const QString EXPR_CLUSTER_COLOR;
|
||||
};
|
||||
|
||||
/** \ingroup core
|
||||
|
@ -15,6 +15,13 @@ class QgsLayerPropertiesWidget : QgsPanelWidget
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the layer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -33,6 +40,7 @@ class QgsLayerPropertiesWidget : QgsPanelWidget
|
||||
* be kept alive for the lifetime of the properties widget.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context );
|
||||
|
||||
|
@ -29,6 +29,12 @@ class QgsRendererWidget : QgsPanelWidget
|
||||
*/
|
||||
const QgsMapCanvas* mapCanvas() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the renderer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Returns the vector layer associated with the widget.
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
@ -118,6 +124,12 @@ class QgsDataDefinedValueDialog : QDialog
|
||||
*/
|
||||
const QgsVectorLayer* vectorLayer() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available for the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
public slots:
|
||||
void dataDefinedChanged();
|
||||
|
||||
|
@ -19,6 +19,13 @@ class QgsSymbolLayerWidget : QWidget
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the layer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -47,6 +54,7 @@ class QgsSymbolLayerWidget : QWidget
|
||||
* be kept alive for the lifetime of the layer widget.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context );
|
||||
|
||||
|
@ -16,6 +16,7 @@ class QgsSymbolSelectorWidget : QgsPanelWidget
|
||||
* @param context expression context pointer. Ownership is transferred to the dialog.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context /Transfer/ );
|
||||
|
||||
@ -27,6 +28,13 @@ class QgsSymbolSelectorWidget : QgsPanelWidget
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available for the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -106,6 +114,7 @@ class QgsSymbolSelectorDialog : QDialog
|
||||
* @param context expression context pointer. Ownership is transferred to the dialog.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context /Transfer/ );
|
||||
|
||||
@ -117,6 +126,13 @@ class QgsSymbolSelectorDialog : QDialog
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
|
@ -14,6 +14,12 @@ class QgsSymbolsListWidget : QWidget
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
|
@ -5094,6 +5094,10 @@ void QgsExpression::initVariableHelp()
|
||||
|
||||
gVariableHelpTexts.insert( "symbol_color", QCoreApplication::translate( "symbol_color", "Color of symbol used to render the feature." ) );
|
||||
gVariableHelpTexts.insert( "symbol_angle", QCoreApplication::translate( "symbol_angle", "Angle of symbol used to render the feature (valid for marker symbols only)." ) );
|
||||
|
||||
//cluster variables
|
||||
gVariableHelpTexts.insert( "cluster_color", QCoreApplication::translate( "cluster_color", "Color of symbols within a cluster, or NULL if symbols have mixed colors." ) );
|
||||
gVariableHelpTexts.insert( "cluster_size", QCoreApplication::translate( "cluster_size", "Number of symbols contained within a cluster." ) );
|
||||
}
|
||||
|
||||
QString QgsExpression::variableHelpText( const QString &variableName, bool showValue, const QVariant &value )
|
||||
|
@ -40,6 +40,8 @@ const QString QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT( "geometry_part_cou
|
||||
const QString QgsExpressionContext::EXPR_GEOMETRY_PART_NUM( "geometry_part_num" );
|
||||
const QString QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT( "geometry_point_count" );
|
||||
const QString QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM( "geometry_point_num" );
|
||||
const QString QgsExpressionContext::EXPR_CLUSTER_SIZE( "cluster_size" );
|
||||
const QString QgsExpressionContext::EXPR_CLUSTER_COLOR( "cluster_color" );
|
||||
|
||||
//
|
||||
// QgsExpressionContextScope
|
||||
|
@ -503,6 +503,10 @@ class CORE_EXPORT QgsExpressionContext
|
||||
static const QString EXPR_GEOMETRY_POINT_COUNT;
|
||||
//! Inbuilt variable name for point number variable
|
||||
static const QString EXPR_GEOMETRY_POINT_NUM;
|
||||
//! Inbuilt variable name for cluster size variable
|
||||
static const QString EXPR_CLUSTER_SIZE;
|
||||
//! Inbuilt variable name for cluster color variable
|
||||
static const QString EXPR_CLUSTER_COLOR;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -438,15 +438,15 @@ QgsExpressionContextScope* QgsPointDistanceRenderer::createGroupScope( const Clu
|
||||
|
||||
if ( groupColor.isValid() )
|
||||
{
|
||||
clusterScope->setVariable( "cluster_color", QgsSymbolLayerUtils::encodeColor( groupColor ) );
|
||||
clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, QgsSymbolLayerUtils::encodeColor( groupColor ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
//mixed colors
|
||||
clusterScope->setVariable( "cluster_color", "" );
|
||||
clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" );
|
||||
}
|
||||
|
||||
clusterScope->setVariable( "cluster_size", group.size() );
|
||||
clusterScope->setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, group.size() );
|
||||
}
|
||||
return clusterScope;
|
||||
}
|
||||
|
@ -528,6 +528,7 @@ void QgsCategorizedSymbolRendererWidget::changeSelectedSymbols()
|
||||
QgsSymbol* newSymbol = mCategorizedSymbol->clone();
|
||||
QgsSymbolSelectorDialog dlg( newSymbol, mStyle, mLayer, this );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
dlg.setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
if ( !dlg.exec() )
|
||||
{
|
||||
delete newSymbol;
|
||||
@ -550,6 +551,7 @@ void QgsCategorizedSymbolRendererWidget::changeCategorizedSymbol()
|
||||
QgsSymbol* newSymbol = mCategorizedSymbol->clone();
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
dlg->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
|
||||
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
@ -594,6 +596,7 @@ void QgsCategorizedSymbolRendererWidget::changeCategorySymbol()
|
||||
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( symbol, mStyle, mLayer, nullptr );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
dlg->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
|
||||
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
openPanel( dlg );
|
||||
|
@ -830,6 +830,7 @@ void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol()
|
||||
QgsSymbol* newSymbol = mGraduatedSymbol->clone();
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
dlg->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
|
||||
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
@ -908,6 +909,7 @@ void QgsGraduatedSymbolRendererWidget::changeRangeSymbol( int rangeIdx )
|
||||
QgsSymbol* newSymbol = mRenderer->ranges()[rangeIdx].symbol()->clone();
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( newSymbol, mStyle, mLayer, nullptr );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
dlg->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateSymbolsFromWidget() ) );
|
||||
connect( dlg, SIGNAL( accepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
|
@ -126,6 +126,7 @@ void QgsInvertedPolygonRendererWidget::on_mRendererComboBox_currentIndexChanged(
|
||||
mEmbeddedRendererWidget.reset( m->createRendererWidget( mLayer, mStyle, const_cast<QgsFeatureRenderer*>( mRenderer->embeddedRenderer() )->clone() ) );
|
||||
connect( mEmbeddedRendererWidget.data(), SIGNAL( widgetChanged() ), this, SIGNAL( widgetChanged() ) );
|
||||
mEmbeddedRendererWidget->setMapCanvas( mMapCanvas );
|
||||
mEmbeddedRendererWidget->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
if ( layout()->count() > 2 )
|
||||
{
|
||||
|
@ -126,6 +126,15 @@ QgsLayerPropertiesWidget::QgsLayerPropertiesWidget( QgsSymbolLayer* layer, const
|
||||
mEffectWidget->setPaintEffect( mLayer->paintEffect() );
|
||||
}
|
||||
|
||||
void QgsLayerPropertiesWidget::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mAdditionalScopes = scopes;
|
||||
|
||||
QgsSymbolLayerWidget* w = dynamic_cast< QgsSymbolLayerWidget* >( stackedWidget->currentWidget() );
|
||||
if ( w )
|
||||
w->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
}
|
||||
|
||||
void QgsLayerPropertiesWidget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
@ -191,6 +200,7 @@ void QgsLayerPropertiesWidget::updateSymbolLayerWidget( QgsSymbolLayer* layer )
|
||||
if ( w )
|
||||
{
|
||||
w->setExpressionContext( mPresetExpressionContext );
|
||||
w->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
if ( mMapCanvas )
|
||||
w->setMapCanvas( mMapCanvas );
|
||||
w->setSymbolLayer( layer );
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define QGSLAYERPROPERTIESWIDGET_H
|
||||
|
||||
#include "ui_widget_layerproperties.h"
|
||||
#include "qgsexpressioncontext.h"
|
||||
|
||||
class QgsSymbol;
|
||||
class QgsSymbolLayer;
|
||||
@ -24,7 +25,6 @@ class QgsSymbolLayerWidget;
|
||||
class QgsVectorLayer;
|
||||
class QgsMapCanvas;
|
||||
class QgsPanelWidget;
|
||||
class QgsExpressionContext;
|
||||
|
||||
class SymbolLayerItem;
|
||||
|
||||
@ -49,6 +49,13 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QgsPanelWidget, private Ui::L
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const { return mPresetExpressionContext; }
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the layer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -74,6 +81,7 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QgsPanelWidget, private Ui::L
|
||||
* be kept alive for the lifetime of the properties widget.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context );
|
||||
|
||||
@ -96,6 +104,7 @@ class GUI_EXPORT QgsLayerPropertiesWidget : public QgsPanelWidget, private Ui::L
|
||||
|
||||
private:
|
||||
QgsExpressionContext* mPresetExpressionContext;
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
|
||||
};
|
||||
|
@ -135,6 +135,12 @@ void QgsPointClusterRendererWidget::on_mRendererSettingsButton_clicked()
|
||||
{
|
||||
QgsRendererWidget* w = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
|
||||
w->setMapCanvas( mMapCanvas );
|
||||
QgsExpressionContextScope scope;
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" );
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 );
|
||||
QList< QgsExpressionContextScope > scopes = mAdditionalScopes;
|
||||
scopes << scope;
|
||||
w->setAdditionalExpressionContextScopes( scopes );
|
||||
connect( w, SIGNAL( widgetChanged() ), this, SLOT( updateRendererFromWidget() ) );
|
||||
w->setDockMode( this->dockMode() );
|
||||
openPanel( w );
|
||||
@ -178,6 +184,12 @@ void QgsPointClusterRendererWidget::on_mCenterSymbolPushButton_clicked()
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( markerSymbol, QgsStyle::defaultStyle(), mLayer, this );
|
||||
dlg->setDockMode( this->dockMode() );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
QgsExpressionContextScope scope;
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" );
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 );
|
||||
QList< QgsExpressionContextScope > scopes = mAdditionalScopes;
|
||||
scopes << scope;
|
||||
dlg->setAdditionalExpressionContextScopes( scopes );
|
||||
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateCenterSymbolFromWidget() ) );
|
||||
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
|
@ -214,6 +214,12 @@ void QgsPointDisplacementRendererWidget::on_mRendererSettingsButton_clicked()
|
||||
{
|
||||
QgsRendererWidget* w = m->createRendererWidget( mLayer, mStyle, mRenderer->embeddedRenderer()->clone() );
|
||||
w->setMapCanvas( mMapCanvas );
|
||||
QgsExpressionContextScope scope;
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" );
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 );
|
||||
QList< QgsExpressionContextScope > scopes = mAdditionalScopes;
|
||||
scopes << scope;
|
||||
w->setAdditionalExpressionContextScopes( scopes );
|
||||
connect( w, SIGNAL( widgetChanged() ), this, SLOT( updateRendererFromWidget() ) );
|
||||
openPanel( w );
|
||||
}
|
||||
@ -351,6 +357,13 @@ void QgsPointDisplacementRendererWidget::on_mCenterSymbolPushButton_clicked()
|
||||
QgsMarkerSymbol* markerSymbol = mRenderer->centerSymbol()->clone();
|
||||
QgsSymbolSelectorWidget* dlg = new QgsSymbolSelectorWidget( markerSymbol, QgsStyle::defaultStyle(), mLayer, this );
|
||||
dlg->setMapCanvas( mMapCanvas );
|
||||
|
||||
QgsExpressionContextScope scope;
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_COLOR, "" );
|
||||
scope.setVariable( QgsExpressionContext::EXPR_CLUSTER_SIZE, 0 );
|
||||
QList< QgsExpressionContextScope > scopes = mAdditionalScopes;
|
||||
scopes << scope;
|
||||
dlg->setAdditionalExpressionContextScopes( scopes );
|
||||
connect( dlg, SIGNAL( widgetChanged() ), this, SLOT( updateCenterSymbolFromWidget() ) );
|
||||
connect( dlg, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( cleanUpSymbolSelector( QgsPanelWidget* ) ) );
|
||||
openPanel( dlg );
|
||||
|
@ -172,6 +172,7 @@ void QgsRendererWidget::changeSymbolWidth()
|
||||
|
||||
QgsDataDefinedWidthDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
dlg.setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -200,6 +201,7 @@ void QgsRendererWidget::changeSymbolSize()
|
||||
|
||||
QgsDataDefinedSizeDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
dlg.setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -228,6 +230,7 @@ void QgsRendererWidget::changeSymbolAngle()
|
||||
|
||||
QgsDataDefinedRotationDialog dlg( symbolList, mLayer );
|
||||
dlg.setMapCanvas( mMapCanvas );
|
||||
dlg.setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
|
||||
if ( QDialog::Accepted == dlg.exec() )
|
||||
{
|
||||
@ -269,6 +272,11 @@ const QgsMapCanvas* QgsRendererWidget::mapCanvas() const
|
||||
return mMapCanvas;
|
||||
}
|
||||
|
||||
void QgsRendererWidget::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mAdditionalScopes = scopes;
|
||||
}
|
||||
|
||||
void QgsRendererWidget::applyChanges()
|
||||
{
|
||||
apply();
|
||||
@ -325,6 +333,12 @@ QgsExpressionContext QgsDataDefinedValueDialog::createExpressionContext() const
|
||||
if ( vectorLayer() )
|
||||
expContext << QgsExpressionContextUtils::layerScope( vectorLayer() );
|
||||
|
||||
// additional scopes
|
||||
Q_FOREACH ( const QgsExpressionContextScope& scope, mAdditionalScopes )
|
||||
{
|
||||
expContext.appendScope( new QgsExpressionContextScope( scope ) );
|
||||
}
|
||||
|
||||
return expContext;
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,12 @@ class GUI_EXPORT QgsRendererWidget : public QgsPanelWidget
|
||||
*/
|
||||
const QgsMapCanvas* mapCanvas() const;
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the renderer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Returns the vector layer associated with the widget.
|
||||
* @note added in QGIS 2.12
|
||||
*/
|
||||
@ -91,6 +97,9 @@ class GUI_EXPORT QgsRendererWidget : public QgsPanelWidget
|
||||
QAction* mPasteAction;
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
|
||||
//! List of additional expression context scopes to add to default expression context
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
|
||||
/** Subclasses may provide the capability of changing multiple symbols at once by implementing the following two methods
|
||||
and by connecting the slot contextMenuViewCategories(const QPoint&)*/
|
||||
virtual QList<QgsSymbol*> selectedSymbols() { return QList<QgsSymbol*>(); }
|
||||
@ -121,6 +130,7 @@ class GUI_EXPORT QgsRendererWidget : public QgsPanelWidget
|
||||
*/
|
||||
virtual void apply();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -170,6 +180,12 @@ class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataD
|
||||
*/
|
||||
const QgsVectorLayer* vectorLayer() const { return mLayer; }
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available for the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes ) { mAdditionalScopes = scopes; }
|
||||
|
||||
public slots:
|
||||
void dataDefinedChanged();
|
||||
|
||||
@ -181,6 +197,9 @@ class GUI_EXPORT QgsDataDefinedValueDialog : public QDialog, public Ui::QgsDataD
|
||||
*/
|
||||
void init( const QString& description ); // needed in children ctor to call virtual
|
||||
|
||||
//! List of additional scopes to add to default expression context
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
|
||||
private:
|
||||
QgsDataDefined symbolDataDefined() const;
|
||||
|
||||
|
@ -261,6 +261,7 @@ void QgsRuleBasedRendererWidget::refineRuleCategoriesGui()
|
||||
w->setPanelTitle( tr( "Add categories to rules" ) );
|
||||
connect( w, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( refineRuleCategoriesAccepted( QgsPanelWidget* ) ) );
|
||||
w->setMapCanvas( mMapCanvas );
|
||||
w->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
openPanel( w );
|
||||
}
|
||||
|
||||
@ -270,6 +271,7 @@ void QgsRuleBasedRendererWidget::refineRuleRangesGui()
|
||||
w->setPanelTitle( tr( "Add ranges to rules" ) );
|
||||
connect( w, SIGNAL( panelAccepted( QgsPanelWidget* ) ), this, SLOT( refineRuleRangesAccepted( QgsPanelWidget* ) ) );
|
||||
w->setMapCanvas( mMapCanvas );
|
||||
w->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
openPanel( w );
|
||||
}
|
||||
|
||||
|
@ -84,15 +84,28 @@ QgsExpressionContext QgsSymbolLayerWidget::createExpressionContext() const
|
||||
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, 1, true ) );
|
||||
expContext.lastScope()->addVariable( QgsExpressionContextScope::StaticVariable( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1, true ) );
|
||||
|
||||
// additional scopes
|
||||
Q_FOREACH ( const QgsExpressionContextScope& scope, mAdditionalScopes )
|
||||
{
|
||||
expContext.appendScope( new QgsExpressionContextScope( scope ) );
|
||||
}
|
||||
|
||||
//TODO - show actual value
|
||||
expContext.setOriginalValueVariable( QVariant() );
|
||||
|
||||
expContext.setHighlightedVariables( QStringList() << QgsExpressionContext::EXPR_ORIGINAL_VALUE << QgsExpressionContext::EXPR_SYMBOL_COLOR
|
||||
<< QgsExpressionContext::EXPR_GEOMETRY_PART_COUNT << QgsExpressionContext::EXPR_GEOMETRY_PART_NUM
|
||||
<< QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT << QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM );
|
||||
<< QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT << QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM
|
||||
<< QgsExpressionContext::EXPR_CLUSTER_COLOR << QgsExpressionContext::EXPR_CLUSTER_SIZE );
|
||||
|
||||
return expContext;
|
||||
}
|
||||
|
||||
void QgsSymbolLayerWidget::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mAdditionalScopes = scopes;
|
||||
}
|
||||
|
||||
void QgsSymbolLayerWidget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
|
@ -53,6 +53,13 @@ class GUI_EXPORT QgsSymbolLayerWidget : public QWidget, protected QgsExpressionC
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const { return mPresetExpressionContext; }
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the layer.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -81,6 +88,7 @@ class GUI_EXPORT QgsSymbolLayerWidget : public QWidget, protected QgsExpressionC
|
||||
* be kept alive for the lifetime of the layer widget.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context ) { mPresetExpressionContext = context; }
|
||||
|
||||
@ -96,6 +104,7 @@ class GUI_EXPORT QgsSymbolLayerWidget : public QWidget, protected QgsExpressionC
|
||||
const QgsVectorLayer* mVectorLayer;
|
||||
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
@ -286,6 +286,11 @@ void QgsSymbolSelectorWidget::setExpressionContext( QgsExpressionContext *contex
|
||||
updatePreview();
|
||||
}
|
||||
|
||||
void QgsSymbolSelectorWidget::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mAdditionalScopes = scopes;
|
||||
}
|
||||
|
||||
void QgsSymbolSelectorWidget::setMapCanvas( QgsMapCanvas *canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
@ -416,6 +421,7 @@ void QgsSymbolSelectorWidget::layerChanged()
|
||||
QgsLayerPropertiesWidget *layerProp = new QgsLayerPropertiesWidget( currentItem->layer(), parent->symbol(), mVectorLayer );
|
||||
layerProp->setDockMode( this->dockMode() );
|
||||
layerProp->setExpressionContext( mPresetExpressionContext.data() );
|
||||
layerProp->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
layerProp->setMapCanvas( mMapCanvas );
|
||||
setWidget( layerProp );
|
||||
connect( layerProp, SIGNAL( changed() ), mDataDefineRestorer.data(), SLOT( restore() ) );
|
||||
@ -433,6 +439,7 @@ void QgsSymbolSelectorWidget::layerChanged()
|
||||
// Now populate symbols of that type using the symbols list widget:
|
||||
QgsSymbolsListWidget *symbolsList = new QgsSymbolsListWidget( currentItem->symbol(), mStyle, mAdvancedMenu, this, mVectorLayer );
|
||||
symbolsList->setExpressionContext( mPresetExpressionContext.data() );
|
||||
symbolsList->setAdditionalExpressionContextScopes( mAdditionalScopes );
|
||||
symbolsList->setMapCanvas( mMapCanvas );
|
||||
|
||||
setWidget( symbolsList );
|
||||
@ -711,6 +718,11 @@ void QgsSymbolSelectorDialog::setExpressionContext( QgsExpressionContext *contex
|
||||
mSelectorWidget->setExpressionContext( context );
|
||||
}
|
||||
|
||||
void QgsSymbolSelectorDialog::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mSelectorWidget->setAdditionalExpressionContextScopes( scopes );
|
||||
}
|
||||
|
||||
QgsExpressionContext *QgsSymbolSelectorDialog::expressionContext() const
|
||||
{
|
||||
return mSelectorWidget->expressionContext();
|
||||
|
@ -104,6 +104,7 @@ class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::Qgs
|
||||
* @param context expression context pointer. Ownership is transferred to the dialog.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context );
|
||||
|
||||
@ -115,6 +116,13 @@ class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::Qgs
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const { return mPresetExpressionContext.data(); }
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available for the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the dialog. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -245,6 +253,7 @@ class GUI_EXPORT QgsSymbolSelectorWidget: public QgsPanelWidget, private Ui::Qgs
|
||||
private:
|
||||
QScopedPointer<DataDefinedRestorer> mDataDefineRestorer;
|
||||
QScopedPointer< QgsExpressionContext > mPresetExpressionContext;
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
|
||||
QgsMapCanvas* mMapCanvas;
|
||||
};
|
||||
@ -269,9 +278,17 @@ class GUI_EXPORT QgsSymbolSelectorDialog : public QDialog
|
||||
* @param context expression context pointer. Ownership is transferred to the dialog.
|
||||
* @note added in QGIS 2.12
|
||||
* @see expressionContext()
|
||||
* @see setAdditionalExpressionContextScopes()
|
||||
*/
|
||||
void setExpressionContext( QgsExpressionContext* context );
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
* @see setExpressionContext()
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Returns the expression context used for the dialog, if set. This expression context is used for
|
||||
* evaluating data defined symbol properties and for populating based expression widgets in
|
||||
* the dialog.
|
||||
|
@ -130,6 +130,11 @@ QgsSymbolsListWidget::~QgsSymbolsListWidget()
|
||||
btnAdvanced->menu()->removeAction( mClipFeaturesAction );
|
||||
}
|
||||
|
||||
void QgsSymbolsListWidget::setAdditionalExpressionContextScopes( const QList<QgsExpressionContextScope>& scopes )
|
||||
{
|
||||
mAdditionalScopes = scopes;
|
||||
}
|
||||
|
||||
void QgsSymbolsListWidget::setMapCanvas( QgsMapCanvas* canvas )
|
||||
{
|
||||
mMapCanvas = canvas;
|
||||
@ -448,6 +453,12 @@ QgsExpressionContext QgsSymbolsListWidget::createExpressionContext() const
|
||||
|
||||
expContext << QgsExpressionContextUtils::layerScope( layer() );
|
||||
|
||||
// additional scopes
|
||||
Q_FOREACH ( const QgsExpressionContextScope& scope, mAdditionalScopes )
|
||||
{
|
||||
expContext.appendScope( new QgsExpressionContextScope( scope ) );
|
||||
}
|
||||
|
||||
return expContext;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,12 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
|
||||
*/
|
||||
QgsExpressionContext* expressionContext() const { return mPresetExpressionContext; }
|
||||
|
||||
/** Sets a list of additional expression context scopes to show as available within the symbol.
|
||||
* @param scopes list of additional scopes which will be added in order to the end of the default expression context
|
||||
* @note added in QGIS 3.0
|
||||
*/
|
||||
void setAdditionalExpressionContextScopes( const QList< QgsExpressionContextScope >& scopes );
|
||||
|
||||
/** Sets the map canvas associated with the widget. This allows the widget to retrieve the current
|
||||
* map scale and other properties from the canvas.
|
||||
* @param canvas map canvas
|
||||
@ -120,6 +126,7 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
|
||||
void populateGroups( const QString& parent = "", const QString& prepend = "" );
|
||||
|
||||
QgsExpressionContext* mPresetExpressionContext;
|
||||
QList< QgsExpressionContextScope > mAdditionalScopes;
|
||||
|
||||
QgsExpressionContext createExpressionContext() const override;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user