QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgstextformatwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextformatwidget.h
3 ---------------------
4 begin : June 2009
5 copyright : (C) 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
17#ifndef QGSTEXTFORMATWIDGET_H
18#define QGSTEXTFORMATWIDGET_H
19
20#include "ui_qgstextformatwidgetbase.h"
21
22#include "qgis_gui.h"
23#include "qgis_sip.h"
24#include "qgsguiutils.h"
25#include "qgsstringutils.h"
27#include "qgstextformat.h"
28
29#include <QFontDatabase>
30
31class QgsMapCanvas;
33
34
50
51class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionContextGenerator, protected Ui::QgsTextFormatWidgetBase
52{
53 Q_OBJECT
54 Q_PROPERTY( QgsTextFormat format READ format )
55
56 public:
64 QgsTextFormatWidget( const QgsTextFormat &format = QgsTextFormat(), QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsMapLayer *layer = nullptr );
65
66 ~QgsTextFormatWidget() override;
67
74 QgsTextFormat format( bool includeDataDefinedProperties = true ) const;
75
80 void setFormat( const QgsTextFormat &format );
81
87 virtual void setContext( const QgsSymbolWidgetContext &context );
88
95
104
105 public slots:
106
111 void setDockMode( bool enabled );
112
113 signals:
114
117
123
124 protected:
126 enum Mode
127 {
128 Text = 0,
130 };
131
139 QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent SIP_TRANSFERTHIS, Mode mode, QgsMapLayer *layer = nullptr );
140
145 void updateWidgetForFormat( const QgsTextFormat &format );
146
151 void setPreviewBackground( const QColor &color );
152
158 Q_DECL_DEPRECATED void enableDataDefinedAlignment( bool enable ) SIP_DEPRECATED { Q_UNUSED( enable ) }
159
161
168 Qgis::GeometryType labelGeometryType() const;
169
175 void setPropertyOverrideButtonsVisible( bool visible );
176
180 QList<QgsTextFormat::Tab> mTabPositions;
181
183 QButtonGroup *mQuadrantBtnGrp = nullptr;
185 QButtonGroup *mDirectSymbBtnGrp = nullptr;
187 QButtonGroup *mUpsidedownBtnGrp = nullptr;
190
193
196
199
201 QgsMapLayer *mLayer = nullptr;
202
203 QList<QgsSymbolLayerReference> mMaskedSymbolLayers;
204
207
209 QListWidgetItem *mTextItem = nullptr;
211 QListWidgetItem *mFormattingItem = nullptr;
213 QListWidgetItem *mBufferItem = nullptr;
215 QListWidgetItem *mMaskItem = nullptr;
217 QListWidgetItem *mBackgroundItem = nullptr;
219 QListWidgetItem *mShadowItem = nullptr;
221 QListWidgetItem *mCalloutItem = nullptr;
223 QListWidgetItem *mPlacementItem = nullptr;
225 QListWidgetItem *mRenderingItem = nullptr;
226
227 protected slots:
228
231
234
239 virtual void setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type, const QString &stylePath );
240
244 virtual void saveFormat();
245
250 void updatePreview();
251
252#ifndef SIP_RUN
253
261#endif
262
263 private:
264 Mode mWidgetMode = Text;
265
266 QgsCharacterSelectorDialog *mCharDlg = nullptr;
267 std::unique_ptr<QgsPaintEffect> mBufferEffect;
268 std::unique_ptr<QgsPaintEffect> mMaskEffect;
269 std::unique_ptr<QgsPaintEffect> mBackgroundEffect;
270 QColor mPreviewBackgroundColor;
271
272 QFontDatabase mFontDB;
273
274 // background reference font
275 QFont mRefFont;
276 bool mDockMode = false;
277
278 bool mLoadSvgParams = false;
279 QgsExpressionContext mPreviewExpressionContext;
280
281 QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
282
283 void initWidget();
284 void setWidgetMode( Mode mode );
285 void blockFontChangeSignals( bool blk );
286 void populateFontCapitalsComboBox();
287 void populateFontStyleComboBox();
288 void updateFont( const QFont &font );
289 void connectValueChanged( const QList<QWidget *> &widgets );
290
291 void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
292
293 private slots:
294 void optionsStackedWidget_CurrentChanged( int indx );
295 void showBackgroundRadius( bool show );
296 void mShapeSVGPathLineEdit_textChanged( const QString &text );
297 void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
298 void previewScaleChanged( double scale );
299 void mFontSizeSpinBox_valueChanged( double d );
300 void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
301 void mFontStyleComboBox_currentIndexChanged( const QString &text );
302 void mFontUnderlineBtn_toggled( bool ckd );
303 void mFontStrikethroughBtn_toggled( bool ckd );
304 void kerningToggled( bool checked );
305 void mFontWordSpacingSpinBox_valueChanged( double spacing );
306 void mFontLetterSpacingSpinBox_valueChanged( double spacing );
307 void mFontSizeUnitWidget_changed();
308 void mFontMinPixelSpinBox_valueChanged( int px );
309 void mFontMaxPixelSpinBox_valueChanged( int px );
310 void mBufferUnitWidget_changed();
311 void mMaskBufferUnitWidget_changed();
312 void mCoordXDDBtn_changed();
313 void mCoordXDDBtn_activated( bool isActive );
314 void mCoordYDDBtn_changed();
315 void mCoordYDDBtn_activated( bool isActive );
316 void mCoordPointDDBtn_changed();
317 void mCoordPointDDBtn_activated( bool isActive );
318 void mShapeTypeCmbBx_currentIndexChanged( int index );
319 void mShapeRotationCmbBx_currentIndexChanged( int index );
320 void mShapeSVGParamsBtn_clicked();
321 void mShapeSVGSelectorBtn_clicked();
322 void mPreviewTextEdit_textChanged( const QString &text );
323 void mPreviewTextBtn_clicked();
324 void mPreviewBackgroundBtn_colorChanged( const QColor &color );
325 void mDirectSymbLeftToolBtn_clicked();
326 void mDirectSymbRightToolBtn_clicked();
327 void chkLineOrientationDependent_toggled( bool active );
328 void mToolButtonConfigureSubstitutes_clicked();
329 void configureTabStops();
330 void collapseSample( bool collapse );
331 void changeTextColor( const QColor &color );
332 void changeBufferColor( const QColor &color );
333 void scrollPreview();
334 void updateSvgWidgets( const QString &svgPath );
335 void updateAvailableShadowPositions();
336 void updateProperty();
337 void createAuxiliaryField();
338 void updateShapeFrameStatus();
339 void updateBufferFrameStatus();
340 void updateShadowFrameStatus();
341 void updateCalloutFrameStatus();
342 void updateDataDefinedAlignment();
343 void overlapModeChanged();
344};
345
346
357
358class GUI_EXPORT QgsTextFormatDialog : public QDialog
359{
360 Q_OBJECT
361
362 public:
371 QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsMapLayer *layer = nullptr );
372
376 QgsTextFormat format() const;
377
382 void setContext( const QgsSymbolWidgetContext &context );
383
388 QDialogButtonBox *buttonBox() const;
389
390 private:
391 QgsTextFormatWidget *mFormatWidget = nullptr;
392 QDialogButtonBox *mButtonBox = nullptr;
393
394 private slots:
395 void showHelp();
396};
397
408
410{
411 Q_OBJECT
412
413 public:
421 QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsMapLayer *layer = nullptr );
422
426 QgsTextFormat format() const;
427
433 void setFormat( const QgsTextFormat &format );
434
439 void setContext( const QgsSymbolWidgetContext &context );
440
441 void setDockMode( bool dockMode ) override;
442
443 private:
444 QgsTextFormatWidget *mFormatWidget = nullptr;
445 bool mBlockSignals = false;
446};
447
448#endif //QGSTEXTFORMATWIDGET_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
@ Unknown
Unknown types.
Definition qgis.h:362
A dialog for selecting a single character from a single font.
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:80
Property
Data definable properties.
QgsPanelWidgetWrapper(QWidget *widget, QWidget *parent=nullptr)
Wrapper widget for existing widgets which can't have the inheritance tree changed,...
bool dockMode() const
Returns the dock mode state.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A button for controlling property overrides which may apply to a widget.
A collection of string replacements (specified using QgsStringReplacement objects).
StyleEntity
Enum for Entities involved in a style.
Definition qgsstyle.h:204
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
QgsTextFormat format() const
Returns the current formatting settings defined by the widget.
QDialogButtonBox * buttonBox() const
Returns a reference to the dialog's button box.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
QgsTextFormatDialog(const QgsTextFormat &format, QgsMapCanvas *mapCanvas=nullptr, QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QgsMapLayer *layer=nullptr)
Constructor for QgsTextFormatDialog.
void setFormat(const QgsTextFormat &format)
Sets the format to show in the widget.
QgsTextFormatPanelWidget(const QgsTextFormat &format, QgsMapCanvas *mapCanvas=nullptr, QWidget *parent=nullptr, QgsMapLayer *layer=nullptr)
Constructor for QgsTextFormatPanelWidget.
void setDockMode(bool dockMode) override
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
QgsTextFormat format() const
Returns the current formatting settings defined by the widget.
void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
A widget for customizing text formatting settings.
void updatePlacementWidgets()
Updates label placement options to reflect current state of widget.
QListWidgetItem * mMaskItem
Mask widget item.
QButtonGroup * mUpsidedownBtnGrp
Upside down labels button group.
int mMinPixelLimit
Pixel size font limit.
QListWidgetItem * mBackgroundItem
Background widget item.
void setDockMode(bool enabled)
Sets whether the widget should be shown in a compact dock mode.
QgsMapCanvas * mMapCanvas
Associated map canvas.
QgsSymbolWidgetContext context() const
Returns the context in which the widget is shown, e.g., the associated map canvas and expression cont...
QgsTextFormatWidget(const QgsTextFormat &format=QgsTextFormat(), QgsMapCanvas *mapCanvas=nullptr, QWidget *parent=nullptr, QgsMapLayer *layer=nullptr)
Constructor for QgsTextFormatWidget.
QListWidgetItem * mFormattingItem
Formatting widget item.
void deactivateField(QgsPalLayerSettings::Property key)
Deactivate a field from data defined properties and update the corresponding button.
void setFormat(const QgsTextFormat &format)
Sets the current formatting settings.
QListWidgetItem * mTextItem
Text widget item.
Qgis::GeometryType mGeomType
Geometry type for layer, if known.
QButtonGroup * mDirectSymbBtnGrp
Symbol direction button group.
QList< QgsSymbolLayerReference > mMaskedSymbolLayers
void widgetChanged()
Emitted when the text format defined by the widget changes.
Q_DECL_DEPRECATED void enableDataDefinedAlignment(bool enable)
Update the enabled state of the data defined alignment buttons.
QButtonGroup * mQuadrantBtnGrp
Quadrant button group.
QListWidgetItem * mShadowItem
Shadow widget item.
QList< QgsTextFormat::Tab > mTabPositions
Tab positions.
QgsSymbolWidgetContext mContext
Context in which widget is shown.
QListWidgetItem * mBufferItem
Buffer widget item.
void updateLinePlacementOptions()
Updates line placement options to reflect current state of widget.
QListWidgetItem * mCalloutItem
Callout widget item.
void populateDataDefinedButtons()
Sets up connections required for data defined buttons, or updates the existing definition of these bu...
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
QListWidgetItem * mRenderingItem
Rendering widget item.
void updatePreview()
Updates the text preview.
QListWidgetItem * mPlacementItem
Placement widget item.
void auxiliaryFieldCreated()
Emitted when an auxiliary field is created in the widget.
virtual void setFormatFromStyle(const QString &name, QgsStyle::StyleEntity type, const QString &stylePath)
Sets the current text settings from a style entry.
QgsMapLayer * mLayer
Associated vector layer.
QgsStringReplacementCollection mSubstitutions
Text substitution list.
@ Text
Default mode, show text formatting settings only.
@ Labeling
Show labeling settings in addition to text formatting settings.
virtual void saveFormat()
Saves the current text settings to a style entry.
QgsPropertyCollection mDataDefinedProperties
Data defined properties as defined in the widget.
Container for all settings relating to text rendering.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53