31 #include <QItemDelegate> 40 SignalBlocker(
QObject *
object )
43 mObject->blockSignals(
true );
47 mObject->blockSignals(
false );
52 SignalBlocker(
const SignalBlocker& rh );
53 SignalBlocker& operator=(
const SignalBlocker& rh );
61 void QgsSizeScaleWidget::setFromSymbol()
69 if ( dynamic_cast< const QgsMarkerSymbolV2*>( mSymbol ) )
73 else if ( dynamic_cast< const QgsLineSymbolV2*>( mSymbol ) )
75 ddSize =
dynamic_cast< const QgsLineSymbolV2*
>( mSymbol )->dataDefinedWidth();
81 for (
int i = 0; i < scaleMethodComboBox->count(); i++ )
83 if ( scaleMethodComboBox->itemData( i ).toInt() == int( expr.type() ) )
85 ( SignalBlocker( scaleMethodComboBox ), scaleMethodComboBox->setCurrentIndex( i ) );
92 ( SignalBlocker( mExpressionWidget ), mExpressionWidget->setField( expr.baseExpression() ) );
93 ( SignalBlocker( minValueSpinBox ), minValueSpinBox->setValue( expr.minValue() ) );
94 ( SignalBlocker( maxValueSpinBox ), maxValueSpinBox->setValue( expr.maxValue() ) );
95 ( SignalBlocker( minSizeSpinBox ), minSizeSpinBox->setValue( expr.minSize() ) );
96 ( SignalBlocker( maxSizeSpinBox ), maxSizeSpinBox->setValue( expr.maxSize() ) );
97 ( SignalBlocker( nullSizeSpinBox ), nullSizeSpinBox->setValue( expr.nullSize() ) );
98 ( SignalBlocker( exponentSpinBox ), exponentSpinBox->setValue( expr.exponent() ) );
122 if ( widget->
layer() )
138 , mMapCanvas( nullptr )
152 mLayerTreeLayer =
nullptr;
155 treeView->setModel( &mPreviewList );
156 treeView->setItemDelegate(
new ItemDelegate( &mPreviewList ) );
157 treeView->setHeaderHidden(
true );
158 treeView->expandAll();
160 QAction* computeFromLayer =
new QAction(
tr(
"Compute from layer" ),
this );
161 connect( computeFromLayer, SIGNAL( triggered() ),
this, SLOT( computeFromLayerTriggered() ) );
165 computeValuesButton->setMenu( menu );
166 connect( computeValuesButton, SIGNAL( clicked() ), computeValuesButton, SLOT( showMenu() ) );
171 mExpressionWidget->setLayer( mLayer );
174 if ( dynamic_cast<const QgsMarkerSymbolV2*>( mSymbol ) )
180 else if ( dynamic_cast<const QgsLineSymbolV2*>( mSymbol ) )
191 minSizeSpinBox->setShowClearButton(
false );
192 maxSizeSpinBox->setShowClearButton(
false );
193 minValueSpinBox->setShowClearButton(
false );
194 maxValueSpinBox->setShowClearButton(
false );
195 nullSizeSpinBox->setShowClearButton(
false );
200 connect( minSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
201 connect( maxSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
202 connect( minValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
203 connect( maxValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
204 connect( nullSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
205 connect( exponentSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
207 connect( mExpressionWidget, SIGNAL( fieldChanged(
QString ) ),
this, SLOT( computeFromLayerTriggered() ) );
208 connect( scaleMethodComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( updatePreview() ) );
225 mExpressionWidget->asExpression(),
226 minValueSpinBox->value(),
227 maxValueSpinBox->value(),
228 minSizeSpinBox->value(),
229 maxSizeSpinBox->value(),
230 nullSizeSpinBox->value(),
231 exponentSpinBox->value() );
234 void QgsSizeScaleWidget::updatePreview()
236 if ( !mSymbol || !mLayer )
242 exponentSpinBox->show();
244 exponentSpinBox->hide();
248 treeView->setIconSize(
QSize( 512, 512 ) );
249 mPreviewList.
clear();
251 for (
int i = 0; i < breaks.
length(); i++ )
254 if ( dynamic_cast<const QgsMarkerSymbolV2*>( mSymbol ) )
259 symbol->setSize( expr->size( breaks[i] ) );
262 else if ( dynamic_cast<const QgsLineSymbolV2*>( mSymbol ) )
266 symbol->setWidth( expr->size( breaks[i] ) );
271 const QSize sz( node->minimumIconSize() );
272 node->setIconSize( sz );
274 widthMax = qMax( sz.width(), widthMax );
280 for (
int i = 0; i < breaks.
length(); i++ )
285 enlarged.
fill( Qt::transparent );
293 void QgsSizeScaleWidget::computeFromLayerTriggered()
298 QgsExpression expression( mExpressionWidget->currentField() );
306 if ( ! expression.prepare( &context ) )
315 .setSubsetOfAttributes( lst, mLayer->
fields() ) );
318 double min = DBL_MAX;
319 double max = -DBL_MAX;
321 while ( fit.nextFeature( f ) )
324 context.setFeature( f );
325 const double value = expression.evaluate( &context ).toDouble( &ok );
328 max = qMax( max, value );
329 min = qMin( min, value );
332 ( SignalBlocker( minValueSpinBox ), minValueSpinBox->setValue( min ) );
333 ( SignalBlocker( maxSizeSpinBox ), maxValueSpinBox->setValue( max ) );
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
Single variable definition for use within a QgsExpressionContextScope.
void setIcon(const QIcon &icon)
A container class for data source field mapping or expression.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
void fill(const QColor &color)
static QgsExpressionContextScope * atlasScope(const QgsAtlasComposition *atlas)
Creates a new scope which contains variables and functions relating to a QgsAtlasComposition.
QgsFields fields() const
Returns the list of fields of this layer.
virtual QgsSymbolV2 * clone() const =0
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
Class storing parameters of a scale expression, which is a subclass of QgsExpression for expressions ...
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QString expressionString() const
Returns the expression string of this QgsDataDefined.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QString tr(const char *sourceText, const char *disambiguation, int n)
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
QPixmap pixmap(const QSize &size, Mode mode, State state) const
The QgsMapSettings class contains configuration for rendering of the map.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
QString number(int n, int base)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QSize actualSize(const QSize &size, Mode mode, State state) const
Single scope for storing variables and functions for use within a QgsExpressionContext.
const QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
QStandardItem * item(int row, int column) const
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object...
QgsExpressionContextScope & expressionContextScope()
Returns a reference to the expression context scope for the map canvas.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node. The node must not have a parent yet. The node will be owned by this group...
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user...
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
static const QString EXPR_GEOMETRY_PART_NUM
Inbuilt variable name for geometry part number variable.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
static const QString EXPR_GEOMETRY_PART_COUNT
Inbuilt variable name for geometry part count variable.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
void appendRow(const QList< QStandardItem * > &items)
Layer tree node points to a map layer.