QGIS API Documentation 3.43.0-Master (ebb4087afc0)
Loading...
Searching...
No Matches
qgslegendsettings.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslegendsettings.h
3 --------------------------------------
4 Date : July 2014
5 Copyright : (C) 2014 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSLEGENDSETTINGS_H
17#define QGSLEGENDSETTINGS_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include <QColor>
22#include <QSizeF>
23
24class QRectF;
25
26#include "qgslegendstyle.h"
27
29
37class CORE_EXPORT QgsLegendSettings
38{
39 public:
41
48 void updateDataDefinedProperties( QgsRenderContext &context );
49
55 void setTitle( const QString &t ) { mTitle = t; }
56
62 QString title() const { return mTitle; }
63
68 Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
69
74 void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
75
82
88 QgsLegendStyle style( Qgis::LegendComponent s ) const { return mStyleMap.value( s ); }
89
95 void setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
96
103 double boxSpace() const {return mBoxSpace;}
104
111 void setBoxSpace( double s ) {mBoxSpace = s;}
112
121 void setWrapChar( const QString &t ) {mWrapChar = t;}
122
131 QString wrapChar() const {return mWrapChar;}
132
138 double columnSpace() const {return mColumnSpace;}
139
145 void setColumnSpace( double s ) { mColumnSpace = s;}
146
155 int columnCount() const { return mColumnCount; }
156
165 void setColumnCount( int c ) { mColumnCount = c;}
166
172 bool splitLayer() const { return mSplitLayer; }
173
179 void setSplitLayer( bool s ) { mSplitLayer = s;}
180
188 bool equalColumnWidth() const { return mEqualColumnWidth; }
189
197 void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
198
205 Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
206
213 Q_DECL_DEPRECATED void setFontColor( const QColor &c ) SIP_DEPRECATED;
214
221 Q_DECL_DEPRECATED QColor layerFontColor() const SIP_DEPRECATED;
222
230 Q_DECL_DEPRECATED void setLayerFontColor( const QColor &fontColor ) SIP_DEPRECATED;
231
237 QSizeF symbolSize() const {return mSymbolSize;}
238
244 void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
245
252 double maximumSymbolSize() const {return mMaxSymbolSize; }
253
262 void setMaximumSymbolSize( double size ) { mMaxSymbolSize = size;}
263
270 double minimumSymbolSize() const {return mMinSymbolSize; }
271
280 void setMinimumSymbolSize( double size ) { mMinSymbolSize = size;}
281
290 void setSymbolAlignment( Qt::AlignmentFlag alignment ) { mSymbolAlignment = alignment; }
291
300 Qt::AlignmentFlag symbolAlignment() const { return mSymbolAlignment; }
301
308 bool drawRasterStroke() const { return mRasterSymbolStroke; }
309
317 void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
318
326 QColor rasterStrokeColor() const { return mRasterStrokeColor; }
327
336 void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
337
345 double rasterStrokeWidth() const { return mRasterStrokeWidth; }
346
355 void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
356
362 QSizeF wmsLegendSize() const {return mWmsLegendSize;}
363
369 void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
370
378 void setSynchronousLegendRequests( bool b ) {mSynchronousLegendRequests = b;}
379
387 bool synchronousLegendRequests() const {return mSynchronousLegendRequests;}
388
395 Q_DECL_DEPRECATED double lineSpacing() const SIP_DEPRECATED { return mLineSpacing; }
396
403 Q_DECL_DEPRECATED void setLineSpacing( double s );
404
408 Q_DECL_DEPRECATED double mmPerMapUnit() const SIP_DEPRECATED;
409
413 Q_DECL_DEPRECATED void setMmPerMapUnit( double mmPerMapUnit ) SIP_DEPRECATED;
414
418 Q_DECL_DEPRECATED bool useAdvancedEffects() const SIP_DEPRECATED;
419
423 Q_DECL_DEPRECATED void setUseAdvancedEffects( bool use ) SIP_DEPRECATED;
424
431 Q_DECL_DEPRECATED double mapScale() const SIP_DEPRECATED;
432
439 Q_DECL_DEPRECATED void setMapScale( double scale ) SIP_DEPRECATED;
440
446 Q_DECL_DEPRECATED double mapUnitsPerPixel() const SIP_DEPRECATED;
447
453 Q_DECL_DEPRECATED void setMapUnitsPerPixel( double mapUnitsPerPixel ) SIP_DEPRECATED;
454
458 Q_DECL_DEPRECATED int dpi() const SIP_DEPRECATED;
459
463 Q_DECL_DEPRECATED void setDpi( int dpi ) SIP_DEPRECATED;
464
465// utility functions
466
480 QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
481
486 QStringList splitStringForWrapping( const QString &stringToSplt ) const;
487
492 void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
493
504 void drawText( QPainter *p, const QRectF &rect, const QString &text, const QFont &font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
505
507 QFont scaledFontPixelSize( const QFont &font ) const;
508
510 double pixelFontSize( double pointSize ) const;
511
513 double textWidthMillimeters( const QFont &font, const QString &text ) const;
514
516 double fontHeightCharacterMM( const QFont &font, QChar c ) const;
517
519 double fontAscentMillimeters( const QFont &font ) const;
520
522 double fontDescentMillimeters( const QFont &font ) const;
523
528 Qgis::LegendJsonRenderFlags jsonRenderFlags() const;
529
534 void setJsonRenderFlags( const Qgis::LegendJsonRenderFlags &jsonRenderFlags );
535
536 private:
537
538 QString mTitle;
539
541 Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
542
543 QString mWrapChar;
544
546 qreal mBoxSpace = 2;
547
549 QSizeF mSymbolSize;
550
552 double mMaxSymbolSize = 0.0;
553
555 double mMinSymbolSize = 0.0;
556
558 QSizeF mWmsLegendSize;
559
561 bool mSynchronousLegendRequests = false;
562
564 double mLineSpacing = 1;
565
567 double mColumnSpace = 2;
568
570 int mColumnCount = 1;
571
573 bool mSplitLayer = false;
574
576 bool mEqualColumnWidth = false;
577
578 bool mRasterSymbolStroke = true;
579 QColor mRasterStrokeColor;
580 double mRasterStrokeWidth = 0.0;
581
582 QMap<Qgis::LegendComponent, QgsLegendStyle> mStyleMap;
583
585 double mMmPerMapUnit = 1;
586
588 bool mUseAdvancedEffects = true;
589
591 double mMapScale = 1;
592
594 int mDpi = 96;
595
597 Qt::AlignmentFlag mSymbolAlignment = Qt::AlignLeft;
598
600 Qgis::LegendJsonRenderFlags mJsonRenderFlags;
601};
602
603
604
605#endif // QGSLEGENDSETTINGS_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
LegendComponent
Component of legends which can be styled.
Definition qgis.h:4384
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
int columnCount() const
Returns the desired minimum number of columns to show in the legend.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QString wrapChar() const
Returns the string used as a wrapping character.
void setWrapChar(const QString &t)
Sets a string to use as a wrapping character.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
void setColumnSpace(double s)
Sets the margin space between adjacent columns (in millimeters).
QgsLegendStyle & rstyle(Qgis::LegendComponent s)
Returns modifiable reference to the style for a legend component.
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
void setColumnCount(int c)
Sets the desired minimum number of columns to show in the legend.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void setStyle(Qgis::LegendComponent s, const QgsLegendStyle &style)
Sets the style for a legend component.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Q_DECL_DEPRECATED double lineSpacing() const
Returns the line spacing to use between lines of legend text.
void setSplitLayer(bool s)
Sets whether layer components can be split over multiple columns.
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
QgsLegendStyle style(Qgis::LegendComponent s) const
Returns the style for a legend component.
void setEqualColumnWidth(bool s)
Sets whether all columns should have equal widths.
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
void setSynchronousLegendRequests(bool b)
Sets whether to request legend graphics synchronously.
bool synchronousLegendRequests() const
Returns whether to request legend graphics synchronously.
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
void setMaximumSymbolSize(double size)
Set the maximum symbol size for symbol (in millimeters).
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
void setMinimumSymbolSize(double size)
Set the minimum symbol size for symbol (in millimeters).
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Contains detailed styling information relating to how a layout legend should be rendered.
Contains information about the context of a rendering operation.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126