QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
118  void widgetChanged();
119 
124  void auxiliaryFieldCreated();
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 
161  Q_DECL_DEPRECATED void enableDataDefinedAlignment( bool enable ) SIP_DEPRECATED { Q_UNUSED( enable ) }
162 
164 
171  QgsWkbTypes::GeometryType labelGeometryType() const;
172 
176  QButtonGroup *mQuadrantBtnGrp = nullptr;
178  QButtonGroup *mDirectSymbBtnGrp = nullptr;
180  QButtonGroup *mUpsidedownBtnGrp = nullptr;
182  int mMinPixelLimit = 0;
183 
185  QgsMapCanvas *mMapCanvas = nullptr;
186 
189 
192 
194  QgsVectorLayer *mLayer = nullptr;
195 
196  QList<QgsSymbolLayerReference> mMaskedSymbolLayers;
197 
200 
201  protected slots:
202 
204  void updateLinePlacementOptions();
205 
207  void updatePlacementWidgets();
208 
213  virtual void setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type, const QString &stylePath );
214 
218  virtual void saveFormat();
219 
224  void updatePreview();
225 
226 #ifndef SIP_RUN
227 
234  void populateDataDefinedButtons();
235 #endif
236 
237  private:
238  Mode mWidgetMode = Text;
239 
240  QgsCharacterSelectorDialog *mCharDlg = nullptr;
241  std::unique_ptr< QgsPaintEffect > mBufferEffect;
242  std::unique_ptr< QgsPaintEffect > mMaskEffect;
243  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
244  QColor mPreviewBackgroundColor;
245 
246  QFontDatabase mFontDB;
247 
248  // background reference font
249  QFont mRefFont;
250  bool mDockMode = false;
251 
252  bool mLoadSvgParams = false;
253  QgsExpressionContext mPreviewExpressionContext;
254 
255  QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
256 
257  void initWidget();
258  void setWidgetMode( Mode mode );
259  void toggleDDButtons( bool visible );
260  void blockFontChangeSignals( bool blk );
261  void populateFontCapitalsComboBox();
262  void populateFontStyleComboBox();
263  void updateFont( const QFont &font );
264  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
265 
266  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
267 
268  private slots:
269  void optionsStackedWidget_CurrentChanged( int indx );
270  void showBackgroundRadius( bool show );
271  void mShapeSVGPathLineEdit_textChanged( const QString &text );
272  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
273  void previewScaleChanged( double scale );
274  void mFontSizeSpinBox_valueChanged( double d );
275  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
276  void mFontStyleComboBox_currentIndexChanged( const QString &text );
277  void mFontUnderlineBtn_toggled( bool ckd );
278  void mFontStrikethroughBtn_toggled( bool ckd );
279  void kerningToggled( bool checked );
280  void mFontWordSpacingSpinBox_valueChanged( double spacing );
281  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
282  void mFontSizeUnitWidget_changed();
283  void mFontMinPixelSpinBox_valueChanged( int px );
284  void mFontMaxPixelSpinBox_valueChanged( int px );
285  void mBufferUnitWidget_changed();
286  void mMaskBufferUnitWidget_changed();
287  void mCoordXDDBtn_changed();
288  void mCoordXDDBtn_activated( bool isActive );
289  void mCoordYDDBtn_changed();
290  void mCoordYDDBtn_activated( bool isActive );
291  void mCoordPointDDBtn_changed();
292  void mCoordPointDDBtn_activated( bool isActive );
293  void mShapeTypeCmbBx_currentIndexChanged( int index );
294  void mShapeRotationCmbBx_currentIndexChanged( int index );
295  void mShapeSVGParamsBtn_clicked();
296  void mShapeSVGSelectorBtn_clicked();
297  void mPreviewTextEdit_textChanged( const QString &text );
298  void mPreviewTextBtn_clicked();
299  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
300  void mDirectSymbLeftToolBtn_clicked();
301  void mDirectSymbRightToolBtn_clicked();
302  void chkLineOrientationDependent_toggled( bool active );
303  void mToolButtonConfigureSubstitutes_clicked();
304  void collapseSample( bool collapse );
305  void changeTextColor( const QColor &color );
306  void changeBufferColor( const QColor &color );
307  void scrollPreview();
308  void updateSvgWidgets( const QString &svgPath );
309  void updateAvailableShadowPositions();
310  void updateProperty();
311  void createAuxiliaryField();
312  void updateShapeFrameStatus();
313  void updateBufferFrameStatus();
314  void updateShadowFrameStatus();
315  void updateCalloutFrameStatus();
316  void updateDataDefinedAlignment();
317  void overlapModeChanged();
318 };
319 
320 
333 class GUI_EXPORT QgsTextFormatDialog : public QDialog
334 {
335  Q_OBJECT
336 
337  public:
338 
347  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsVectorLayer *layer = nullptr );
348 
352  QgsTextFormat format() const;
353 
358  void setContext( const QgsSymbolWidgetContext &context );
359 
364  QDialogButtonBox *buttonBox() const;
365 
366  private:
367 
368  QgsTextFormatWidget *mFormatWidget = nullptr;
369  QDialogButtonBox *mButtonBox = nullptr;
370 
371  private slots:
372  void showHelp();
373 
374 };
375 
389 {
390  Q_OBJECT
391 
392  public:
393 
401  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *layer = nullptr );
402 
406  QgsTextFormat format() const;
407 
413  void setFormat( const QgsTextFormat &format );
414 
419  void setContext( const QgsSymbolWidgetContext &context );
420 
421  void setDockMode( bool dockMode ) override;
422 
423  private:
424 
425  QgsTextFormatWidget *mFormatWidget = nullptr;
426  bool mBlockSignals = false;
427 };
428 
429 #endif //QGSTEXTFORMATWIDGET_H
430 
431 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsPanelWidget::setDockMode
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Definition: qgspanelwidget.cpp:44
QgsTextFormatWidget::mMaskedSymbolLayers
QList< QgsSymbolLayerReference > mMaskedSymbolLayers
Definition: qgstextformatwidget.h:196
qgsstringutils.h
QgsSymbolWidgetContext
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
Definition: qgssymbolwidgetcontext.h:35
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
QgsTextFormatDialog
A simple dialog for customizing text formatting settings.
Definition: qgstextformatwidget.h:333
qgssymbolwidgetcontext.h
QgsPropertyOverrideButton
A button for controlling property overrides which may apply to a widget.
Definition: qgspropertyoverridebutton.h:50
QgsTextFormatWidget::mContext
QgsSymbolWidgetContext mContext
Context in which widget is shown.
Definition: qgstextformatwidget.h:188
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
qgis_sip.h
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsTextFormatWidget
A widget for customizing text formatting settings.
Definition: qgstextformatwidget.h:50
QgsStringReplacementCollection
A collection of string replacements (specified using QgsStringReplacement objects).
Definition: qgsstringutils.h:115
QgsTextFormatPanelWidget
A panel widget for customizing text formatting settings.
Definition: qgstextformatwidget.h:388
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsTextFormatWidget::mSubstitutions
QgsStringReplacementCollection mSubstitutions
Text substitution list.
Definition: qgstextformatwidget.h:174
QgsTextFormatWidget::enableDataDefinedAlignment
Q_DECL_DEPRECATED void enableDataDefinedAlignment(bool enable)
Update the enabled state of the data defined alignment buttons.
Definition: qgstextformatwidget.h:161
QgsCharacterSelectorDialog
A dialog for selecting a single character from a single font.
Definition: qgscharacterselectordialog.h:34
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
QgsPalLayerSettings::Property
Property
Data definable properties.
Definition: qgspallabeling.h:144
qgstextformat.h
QgsPanelWidgetWrapper
Wrapper widget for existing widgets which can't have the inheritance tree changed,...
Definition: qgspanelwidget.h:210
qgsguiutils.h
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsTextFormatWidget::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Data defined properties as defined in the widget.
Definition: qgstextformatwidget.h:191
QgsTextFormatWidget::Labeling
@ Labeling
Show labeling settings in addition to text formatting settings.
Definition: qgstextformatwidget.h:132
QgsTextFormatWidget::Mode
Mode
Widget mode.
Definition: qgstextformatwidget.h:129
QgsStyle::StyleEntity
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:178