QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
22#include <QColor>
23#include <QSizeF>
24
25class QRectF;
26
27#include "qgslegendstyle.h"
28
30
38class CORE_EXPORT QgsLegendSettings
39{
40 public:
42
50
56 void setTitle( const QString &t ) { mTitle = t; }
57
63 QString title() const { return mTitle; }
64
69 Qt::AlignmentFlag titleAlignment() const { return mTitleAlignment; }
70
75 void setTitleAlignment( Qt::AlignmentFlag alignment ) { mTitleAlignment = alignment; }
76
82 SIP_SKIP QgsLegendStyle &rstyle( Qgis::LegendComponent s ) SIP_SKIP { return mStyleMap[static_cast< int >( s )]; }
83
89 QgsLegendStyle style( Qgis::LegendComponent s ) const { return mStyleMap[ static_cast< int >( s ) ]; }
90
96 void setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style ) { mStyleMap[ static_cast< int >( s ) ] = style; }
97
104 double boxSpace() const {return mBoxSpace;}
105
112 void setBoxSpace( double s ) {mBoxSpace = s;}
113
122 void setWrapChar( const QString &t ) {mWrapChar = t;}
123
132 QString wrapChar() const {return mWrapChar;}
133
139 double columnSpace() const {return mColumnSpace;}
140
146 void setColumnSpace( double s ) { mColumnSpace = s;}
147
156 int columnCount() const { return mColumnCount; }
157
166 void setColumnCount( int c ) { mColumnCount = c;}
167
173 bool splitLayer() const { return mSplitLayer; }
174
180 void setSplitLayer( bool s ) { mSplitLayer = s;}
181
189 bool equalColumnWidth() const { return mEqualColumnWidth; }
190
198 void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;}
199
206 Q_DECL_DEPRECATED QColor fontColor() const SIP_DEPRECATED;
207
214 Q_DECL_DEPRECATED void setFontColor( const QColor &c ) SIP_DEPRECATED;
215
222 Q_DECL_DEPRECATED QColor layerFontColor() const SIP_DEPRECATED;
223
231 Q_DECL_DEPRECATED void setLayerFontColor( const QColor &fontColor ) SIP_DEPRECATED;
232
238 QSizeF symbolSize() const {return mSymbolSize;}
239
245 void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
246
253 double maximumSymbolSize() const {return mMaxSymbolSize; }
254
263 void setMaximumSymbolSize( double size ) { mMaxSymbolSize = size;}
264
271 double minimumSymbolSize() const {return mMinSymbolSize; }
272
281 void setMinimumSymbolSize( double size ) { mMinSymbolSize = size;}
282
291 void setSymbolAlignment( Qt::AlignmentFlag alignment ) { mSymbolAlignment = alignment; }
292
301 Qt::AlignmentFlag symbolAlignment() const { return mSymbolAlignment; }
302
309 bool drawRasterStroke() const { return mRasterSymbolStroke; }
310
318 void setDrawRasterStroke( bool enabled ) { mRasterSymbolStroke = enabled; }
319
327 QColor rasterStrokeColor() const { return mRasterStrokeColor; }
328
337 void setRasterStrokeColor( const QColor &color ) { mRasterStrokeColor = color; }
338
346 double rasterStrokeWidth() const { return mRasterStrokeWidth; }
347
356 void setRasterStrokeWidth( double width ) { mRasterStrokeWidth = width; }
357
363 QSizeF wmsLegendSize() const {return mWmsLegendSize;}
364
370 void setWmsLegendSize( QSizeF s ) {mWmsLegendSize = s;}
371
379 void setSynchronousLegendRequests( bool b ) {mSynchronousLegendRequests = b;}
380
388 bool synchronousLegendRequests() const {return mSynchronousLegendRequests;}
389
396 Q_DECL_DEPRECATED double lineSpacing() const SIP_DEPRECATED { return mLineSpacing; }
397
404 Q_DECL_DEPRECATED void setLineSpacing( double s );
405
409 Q_DECL_DEPRECATED double mmPerMapUnit() const SIP_DEPRECATED;
410
414 Q_DECL_DEPRECATED void setMmPerMapUnit( double mmPerMapUnit ) SIP_DEPRECATED;
415
419 Q_DECL_DEPRECATED bool useAdvancedEffects() const SIP_DEPRECATED;
420
424 Q_DECL_DEPRECATED void setUseAdvancedEffects( bool use ) SIP_DEPRECATED;
425
432 Q_DECL_DEPRECATED double mapScale() const SIP_DEPRECATED;
433
440 Q_DECL_DEPRECATED void setMapScale( double scale ) SIP_DEPRECATED;
441
447 Q_DECL_DEPRECATED double mapUnitsPerPixel() const SIP_DEPRECATED;
448
454 Q_DECL_DEPRECATED void setMapUnitsPerPixel( double mapUnitsPerPixel ) SIP_DEPRECATED;
455
459 Q_DECL_DEPRECATED int dpi() const SIP_DEPRECATED;
460
464 Q_DECL_DEPRECATED void setDpi( int dpi ) SIP_DEPRECATED;
465
466// utility functions
467
472
481 QStringList evaluateItemText( const QString &text, const QgsExpressionContext &context ) const;
482
487 QStringList splitStringForWrapping( const QString &stringToSplt ) const;
488
493 void drawText( QPainter *p, double x, double y, const QString &text, const QFont &font ) const;
494
505 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;
506
508 QFont scaledFontPixelSize( const QFont &font ) const;
509
511 double pixelFontSize( double pointSize ) const;
512
514 double textWidthMillimeters( const QFont &font, const QString &text ) const;
515
517 double fontHeightCharacterMM( const QFont &font, QChar c ) const;
518
520 double fontAscentMillimeters( const QFont &font ) const;
521
523 double fontDescentMillimeters( const QFont &font ) const;
524
529 Qgis::LegendJsonRenderFlags jsonRenderFlags() const;
530
535 void setJsonRenderFlags( const Qgis::LegendJsonRenderFlags &jsonRenderFlags );
536
547 double autoWrapLinesAfter() const { return mAutoWrapLinesAfter; }
548
559 void setAutoWrapLinesAfter( double length ) { mAutoWrapLinesAfter = length; }
560
561 private:
562
563 QString mTitle;
564
566 Qt::AlignmentFlag mTitleAlignment = Qt::AlignLeft;
567
568 QString mWrapChar;
569
570 double mAutoWrapLinesAfter = 0;
571
573 qreal mBoxSpace = 2;
574
576 QSizeF mSymbolSize;
577
579 double mMaxSymbolSize = 0.0;
580
582 double mMinSymbolSize = 0.0;
583
585 QSizeF mWmsLegendSize;
586
588 bool mSynchronousLegendRequests = false;
589
591 double mLineSpacing = 1;
592
594 double mColumnSpace = 2;
595
597 int mColumnCount = 1;
598
600 bool mSplitLayer = false;
601
603 bool mEqualColumnWidth = false;
604
605 bool mRasterSymbolStroke = true;
606 QColor mRasterStrokeColor;
607 double mRasterStrokeWidth = 0.0;
608
609 QVector<QgsLegendStyle> mStyleMap;
610
612 double mMmPerMapUnit = 1;
613
615 bool mUseAdvancedEffects = true;
616
618 double mMapScale = 1;
619
621 int mDpi = 96;
622
624 Qt::AlignmentFlag mSymbolAlignment = Qt::AlignLeft;
625
627 Qgis::LegendJsonRenderFlags mJsonRenderFlags;
628};
629
630
631
632#endif // QGSLEGENDSETTINGS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
LegendComponent
Component of legends which can be styled.
Definition qgis.h:4575
QFlags< LegendJsonRenderFlag > LegendJsonRenderFlags
Definition qgis.h:4599
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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 autoWrapLinesAfter() const
Returns the maximum line length (in millimeters) allowed before lines of text in the legend will be a...
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.
void setAutoWrapLinesAfter(double length)
Sets the maximum line length (in millimeters) allowed before lines of text in the legend will be auto...
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
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).
void updateDataDefinedProperties(QgsRenderContext &context)
Updates any data-defined properties in the settings, using the specified render context.
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:114
#define SIP_SKIP
Definition qgis_sip.h:134