31 #include <QItemDelegate>
43 return mModel->
item( index.
row() )->icon().actualSize(
QSize( 512, 512 ) );
51 void QgsSizeScaleWidget::setFromSymbol()
62 for (
int i = 0; i < scaleMethodComboBox->count(); i++ )
64 if ( scaleMethodComboBox->itemData( i ).toInt() == int( expr.type() ) )
66 scaleMethodComboBox->setCurrentIndex( i );
71 mExpressionWidget->setField( expr.baseExpression() );
73 minValueSpinBox->setValue( expr.minValue() );
74 maxValueSpinBox->setValue( expr.maxValue() );
75 minSizeSpinBox->setValue( expr.minSize() );
76 maxSizeSpinBox->setValue( expr.maxSize() );
77 nullSizeSpinBox->setValue( expr.nullSize() );
101 if ( widget->
layer() )
129 treeView->setModel( &mPreviewList );
130 treeView->setItemDelegate(
new ItemDelegate( &mPreviewList ) );
131 treeView->setHeaderHidden(
true );
132 treeView->expandAll();
134 QAction* computeFromLayer =
new QAction(
tr(
"Compute from layer" ),
this );
135 connect( computeFromLayer, SIGNAL( triggered() ),
this, SLOT( computeFromLayerTriggered() ) );
139 computeValuesButton->setMenu( menu );
140 connect( computeValuesButton, SIGNAL( clicked() ), computeValuesButton, SLOT( showMenu() ) );
145 mExpressionWidget->setLayer( mLayer );
152 minSizeSpinBox->setShowClearButton(
false );
153 maxSizeSpinBox->setShowClearButton(
false );
154 minValueSpinBox->setShowClearButton(
false );
155 maxValueSpinBox->setShowClearButton(
false );
156 nullSizeSpinBox->setShowClearButton(
false );
161 connect( minSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
162 connect( maxSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
163 connect( minValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
164 connect( maxValueSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
165 connect( nullSizeSpinBox, SIGNAL( valueChanged(
double ) ),
this, SLOT( updatePreview() ) );
167 connect( mExpressionWidget, SIGNAL( fieldChanged(
QString ) ),
this, SLOT( computeFromLayerTriggered() ) );
168 connect( scaleMethodComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( updatePreview() ) );
185 mExpressionWidget->currentField(),
186 minValueSpinBox->value(),
187 maxValueSpinBox->value(),
188 minSizeSpinBox->value(),
189 maxSizeSpinBox->value(),
190 nullSizeSpinBox->value() );
193 void QgsSizeScaleWidget::updatePreview()
195 if ( !mSymbol || !mLayer )
201 treeView->setIconSize(
QSize( 512, 512 ) );
202 mPreviewList.
clear();
204 for (
int i = 0; i < breaks.
length(); i++ )
209 symbol->setSize( expr->size( breaks[i] ) );
211 const QSize sz( node.minimumIconSize() );
212 node.setIconSize( sz );
214 widthMax = qMax( sz.width(), widthMax );
220 for (
int i = 0; i < breaks.
length(); i++ )
223 QPixmap enlarged( widthMax, img.height() );
225 enlarged.
fill( Qt::transparent );
227 p.drawPixmap(
QPoint(( widthMax - img.width() ) / 2, 0 ), img );
233 void QgsSizeScaleWidget::computeFromLayerTriggered()
238 QgsExpression expression( mExpressionWidget->currentField() );
246 if ( ! expression.prepare( &context ) )
255 .setSubsetOfAttributes( lst, mLayer->
fields() ) );
258 double min = DBL_MAX;
259 double max = -DBL_MAX;
261 while ( fit.nextFeature( f ) )
264 context.setFeature( f );
265 const double value = expression.evaluate( &context ).toDouble( &ok );
268 max = qMax( max, value );
269 min = qMin( min, value );
272 minValueSpinBox->setValue( min );
273 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.
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.
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 ...
QgsDataDefined dataDefinedSize() const
Returns data defined size for whole symbol (including all symbol layers).
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)
QPixmap pixmap(const QSize &size, Mode mode, State state) const
ItemDelegate(QStandardItemModel *model)
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.
QString number(int n, int base)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
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)...
virtual QgsSymbolV2 * clone() const override
QSize actualSize(const QSize &size, Mode mode, State state) const
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &index) const override
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...
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.
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.
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.