QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 #include "qgis_sip.h"
22 #include "qgstextformat.h"
23 #include "qgsstringutils.h"
24 #include "qgsguiutils.h"
25 #include "qgssymbolwidgetcontext.h"
26 #include <QFontDatabase>
27 #include "qgis_gui.h"
28 
29 class QgsMapCanvas;
31 
32 
50 class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionContextGenerator, protected Ui::QgsTextFormatWidgetBase
51 {
52  Q_OBJECT
53  Q_PROPERTY( QgsTextFormat format READ format )
54 
55  public:
56 
64  QgsTextFormatWidget( const QgsTextFormat &format = QgsTextFormat(), QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr,
65  QgsVectorLayer *layer = nullptr );
66 
67  ~QgsTextFormatWidget() override;
68 
75  QgsTextFormat format( bool includeDataDefinedProperties = true ) const;
76 
81  void setFormat( const QgsTextFormat &format );
82 
88  virtual void setContext( const QgsSymbolWidgetContext &context );
89 
95  QgsSymbolWidgetContext context() const;
96 
105  void deactivateField( QgsPalLayerSettings::Property key );
106 
107  public slots:
108 
113  void setDockMode( bool enabled );
114 
115  signals:
116 
119 
125 
126  protected:
127 
129  enum Mode
130  {
131  Text = 0,
133  };
134 
142  QgsTextFormatWidget( QgsMapCanvas *mapCanvas, QWidget *parent SIP_TRANSFERTHIS, Mode mode, QgsVectorLayer *layer = nullptr );
143 
148  void updateWidgetForFormat( const QgsTextFormat &format );
149 
154  void setPreviewBackground( const QColor &color );
155 
160  void enableDataDefinedAlignment( bool enable );
161 
163 
170  QgsWkbTypes::GeometryType labelGeometryType() const;
171 
175  QButtonGroup *mQuadrantBtnGrp = nullptr;
177  QButtonGroup *mDirectSymbBtnGrp = nullptr;
179  QButtonGroup *mUpsidedownBtnGrp = nullptr;
181  int mMinPixelLimit = 0;
182 
184  QgsMapCanvas *mMapCanvas = nullptr;
185 
188 
191 
193  QgsVectorLayer *mLayer = nullptr;
194 
195  QList<QgsSymbolLayerReference> mMaskedSymbolLayers;
196 
199 
200  protected slots:
201 
203  void updateLinePlacementOptions();
204 
206  void updatePlacementWidgets();
207 
212  virtual void setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type );
213 
217  virtual void saveFormat();
218 
223  void updatePreview();
224 
225 #ifndef SIP_RUN
226 
233  void populateDataDefinedButtons();
234 #endif
235 
236  private:
237  Mode mWidgetMode = Text;
238 
239  QgsCharacterSelectorDialog *mCharDlg = nullptr;
240  std::unique_ptr< QgsPaintEffect > mBufferEffect;
241  std::unique_ptr< QgsPaintEffect > mMaskEffect;
242  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
243  QColor mPreviewBackgroundColor;
244 
245  QFontDatabase mFontDB;
246 
247  // background reference font
248  QFont mRefFont;
249  bool mDockMode = false;
250 
251  bool mLoadSvgParams = false;
252  QgsExpressionContext mPreviewExpressionContext;
253 
254  QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
255 
256  void initWidget();
257  void setWidgetMode( Mode mode );
258  void toggleDDButtons( bool visible );
259  void blockFontChangeSignals( bool blk );
260  void populateFontCapitalsComboBox();
261  void populateFontStyleComboBox();
262  void updateFont( const QFont &font );
263  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
264 
265  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
266 
267  private slots:
268  void optionsStackedWidget_CurrentChanged( int indx );
269  void showBackgroundRadius( bool show );
270  void mShapeSVGPathLineEdit_textChanged( const QString &text );
271  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
272  void previewScaleChanged( double scale );
273  void mFontSizeSpinBox_valueChanged( double d );
274  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
275  void mFontStyleComboBox_currentIndexChanged( const QString &text );
276  void mFontUnderlineBtn_toggled( bool ckd );
277  void mFontStrikethroughBtn_toggled( bool ckd );
278  void kerningToggled( bool checked );
279  void mFontWordSpacingSpinBox_valueChanged( double spacing );
280  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
281  void mFontSizeUnitWidget_changed();
282  void mFontMinPixelSpinBox_valueChanged( int px );
283  void mFontMaxPixelSpinBox_valueChanged( int px );
284  void mBufferUnitWidget_changed();
285  void mMaskBufferUnitWidget_changed();
286  void mCoordXDDBtn_changed( );
287  void mCoordYDDBtn_changed( );
288  void mShapeTypeCmbBx_currentIndexChanged( int index );
289  void mShapeRotationCmbBx_currentIndexChanged( int index );
290  void mShapeSVGParamsBtn_clicked();
291  void mShapeSVGSelectorBtn_clicked();
292  void mPreviewTextEdit_textChanged( const QString &text );
293  void mPreviewTextBtn_clicked();
294  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
295  void mDirectSymbLeftToolBtn_clicked();
296  void mDirectSymbRightToolBtn_clicked();
297  void chkLineOrientationDependent_toggled( bool active );
298  void mToolButtonConfigureSubstitutes_clicked();
299  void collapseSample( bool collapse );
300  void changeTextColor( const QColor &color );
301  void changeBufferColor( const QColor &color );
302  void scrollPreview();
303  void updateSvgWidgets( const QString &svgPath );
304  void updateAvailableShadowPositions();
305  void updateProperty();
306  void createAuxiliaryField();
307  void updateShapeFrameStatus();
308  void updateBufferFrameStatus();
309  void updateShadowFrameStatus();
310  void updateCalloutFrameStatus();
311 };
312 
313 
326 class GUI_EXPORT QgsTextFormatDialog : public QDialog
327 {
328  Q_OBJECT
329 
330  public:
331 
340  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsVectorLayer *layer = nullptr );
341 
345  QgsTextFormat format() const;
346 
351  void setContext( const QgsSymbolWidgetContext &context );
352 
357  QDialogButtonBox *buttonBox() const;
358 
359  private:
360 
361  QgsTextFormatWidget *mFormatWidget = nullptr;
362  QDialogButtonBox *mButtonBox = nullptr;
363 
364  private slots:
365  void showHelp();
366 
367 };
368 
382 {
383  Q_OBJECT
384 
385  public:
386 
394  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *layer = nullptr );
395 
399  QgsTextFormat format() const;
400 
406  void setFormat( const QgsTextFormat &format );
407 
412  void setContext( const QgsSymbolWidgetContext &context );
413 
414  void setDockMode( bool dockMode ) override;
415 
416  private:
417 
418  QgsTextFormatWidget *mFormatWidget = nullptr;
419  bool mBlockSignals = false;
420 };
421 
422 #endif //QGSTEXTFORMATWIDGET_H
423 
424 
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.
Definition: qgsmapcanvas.h:89
Property
Data definable properties.
Wrapper widget for existing widgets which can't have the inheritance tree changed,...
A grouped map of multiple QgsProperty objects, each referenced by a 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:179
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
A simple dialog for customizing text formatting settings.
A panel widget for customizing text formatting settings.
A widget for customizing text formatting settings.
QList< QgsSymbolLayerReference > mMaskedSymbolLayers
void widgetChanged()
Emitted when the text format defined by the widget changes.
QgsSymbolWidgetContext mContext
Context in which widget is shown.
void auxiliaryFieldCreated()
Emitted when an auxiliary field is created in the widget.
QgsStringReplacementCollection mSubstitutions
Text substitution list.
@ Labeling
Show labeling settings in addition to text formatting settings.
QgsPropertyCollection mDataDefinedProperties
Data defined properties as defined in the widget.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53