31 #include <QItemDelegate> 35 void QgsSizeScaleWidget::setFromSymbol()
43 if ( dynamic_cast< const QgsMarkerSymbolV2*>( mSymbol ) )
47 else if ( dynamic_cast< const QgsLineSymbolV2*>( mSymbol ) )
49 ddSize =
dynamic_cast< const QgsLineSymbolV2*
>( mSymbol )->dataDefinedWidth();
55 for (
int i = 0; i < scaleMethodComboBox->count(); i++ )
57 if ( scaleMethodComboBox->itemData( i ).toInt() == int( expr.type() ) )
64 whileBlocking( mExpressionWidget )->setField( expr.baseExpression() );
65 whileBlocking( minValueSpinBox )->setValue( expr.minValue() );
66 whileBlocking( maxValueSpinBox )->setValue( expr.maxValue() );
69 whileBlocking( nullSizeSpinBox )->setValue( expr.nullSize() );
70 whileBlocking( exponentSpinBox )->setValue( expr.exponent() );
94 if ( widget->
layer() )
110 , mMapCanvas( nullptr )
124 mLayerTreeLayer =
nullptr;
127 treeView->setModel( &mPreviewList );
128 treeView->setItemDelegate(
new ItemDelegate( &mPreviewList ) );
129 treeView->setHeaderHidden(
true );
130 treeView->expandAll();
132 QAction* computeFromLayer =
new QAction(
tr(
"Compute from layer" ),
this );
133 connect( computeFromLayer, SIGNAL( triggered() ),
this, SLOT( computeFromLayerTriggered() ) );
137 computeValuesButton->setMenu( menu );
138 connect( computeValuesButton, SIGNAL( clicked() ), computeValuesButton, SLOT( showMenu() ) );
143 mExpressionWidget->setLayer( mLayer );
146 if ( dynamic_cast<const QgsMarkerSymbolV2*>( mSymbol ) )
152 else if ( dynamic_cast<const QgsLineSymbolV2*>( mSymbol ) )
163 minSizeSpinBox->setShowClearButton(
false );
164 maxSizeSpinBox->setShowClearButton(
false );
165 minValueSpinBox->setShowClearButton(
false );
166 maxValueSpinBox->setShowClearButton(
false );
167 nullSizeSpinBox->setShowClearButton(
false );
172 connect( minSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
173 connect( maxSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
174 connect( minValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
175 connect( maxValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
176 connect( nullSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
177 connect( exponentSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
179 connect( mExpressionWidget, SIGNAL( fieldChanged(
QString ) ),
this, SLOT( computeFromLayerTriggered() ) );
180 connect( scaleMethodComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( updatePreview() ) );
197 mExpressionWidget->asExpression(),
198 minValueSpinBox->value(),
199 maxValueSpinBox->value(),
200 minSizeSpinBox->value(),
201 maxSizeSpinBox->value(),
202 nullSizeSpinBox->value(),
203 exponentSpinBox->value() );
206 void QgsSizeScaleWidget::updatePreview()
208 if ( !mSymbol || !mLayer )
214 exponentSpinBox->show();
216 exponentSpinBox->hide();
220 treeView->setIconSize(
QSize( 512, 512 ) );
221 mPreviewList.
clear();
223 for (
int i = 0; i < breaks.
length(); i++ )
226 if ( dynamic_cast<const QgsMarkerSymbolV2*>( mSymbol ) )
231 symbol->setSize( expr->size( breaks[i] ) );
234 else if ( dynamic_cast<const QgsLineSymbolV2*>( mSymbol ) )
238 symbol->setWidth( expr->size( breaks[i] ) );
243 const QSize sz( node->minimumIconSize() );
244 node->setIconSize( sz );
246 widthMax = qMax( sz.width(), widthMax );
252 for (
int i = 0; i < breaks.
length(); i++ )
257 enlarged.
fill( Qt::transparent );
265 void QgsSizeScaleWidget::computeFromLayerTriggered()
270 QgsExpression expression( mExpressionWidget->currentField() );
278 if ( ! expression.prepare( &context ) )
287 .setSubsetOfAttributes( lst, mLayer->
fields() ) );
290 double min = DBL_MAX;
291 double max = -DBL_MAX;
293 while ( fit.nextFeature( f ) )
296 context.setFeature( f );
297 const double value = expression.evaluate( &context ).toDouble( &ok );
300 max = qMax( max, value );
301 min = qMin( min, value );
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.
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 QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the widget.
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
QgsFields fields() const
Returns the list of fields of this layer.
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...
QString expressionString() const
Returns the expression string of this QgsDataDefined.
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.
This class tracks map layers that are currently loaded and provides various methods to retrieve match...
QStandardItem * item(int row, int column) const
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
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.