QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 "qgstextrenderer.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 
160  void enableDataDefinedAlignment( bool enable );
161 
163 
167  QButtonGroup *mQuadrantBtnGrp = nullptr;
169  QButtonGroup *mDirectSymbBtnGrp = nullptr;
171  QButtonGroup *mUpsidedownBtnGrp = nullptr;
173  QButtonGroup *mPlacePointBtnGrp = nullptr;
175  QButtonGroup *mPlaceLineBtnGrp = nullptr;
177  QButtonGroup *mPlacePolygonBtnGrp = nullptr;
179  int mMinPixelLimit = 0;
180 
182  QgsMapCanvas *mMapCanvas = nullptr;
183 
186 
189 
191  QgsVectorLayer *mLayer = nullptr;
192  protected slots:
193 
195  void updateLinePlacementOptions();
196 
198  void updatePlacementWidgets();
199 
204  virtual void setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type );
205 
209  virtual void saveFormat();
210 
215  void updatePreview();
216 
217 #ifndef SIP_RUN
218 
225  void populateDataDefinedButtons();
226 #endif
227 
228  private:
229  Mode mWidgetMode = Text;
230 
231  QgsCharacterSelectorDialog *mCharDlg = nullptr;
232  std::unique_ptr< QgsPaintEffect > mBufferEffect;
233  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
234  QColor mPreviewBackgroundColor;
235 
236  QFontDatabase mFontDB;
237 
238  // background reference font
239  QFont mRefFont;
240  bool mDockMode = false;
241 
242  bool mLoadSvgParams = false;
243  QgsExpressionContext mPreviewExpressionContext;
244 
245  QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
246 
247  void initWidget();
248  void setWidgetMode( Mode mode );
249  void toggleDDButtons( bool visible );
250  void blockFontChangeSignals( bool blk );
251  void populateFontCapitalsComboBox();
252  void populateFontStyleComboBox();
253  void updateFont( const QFont &font );
254  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
255 
256  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
257 
258  private slots:
259  void optionsStackedWidget_CurrentChanged( int indx );
260  void showBackgroundRadius( bool show );
261  void showBackgroundPenStyle( bool show );
262  void mShapeSVGPathLineEdit_textChanged( const QString &text );
263  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
264  void previewScaleChanged( double scale );
265  void mFontSizeSpinBox_valueChanged( double d );
266  void mFontCapitalsComboBox_currentIndexChanged( int index );
267  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
268  void mFontStyleComboBox_currentIndexChanged( const QString &text );
269  void mFontUnderlineBtn_toggled( bool ckd );
270  void mFontStrikethroughBtn_toggled( bool ckd );
271  void kerningToggled( bool checked );
272  void mFontWordSpacingSpinBox_valueChanged( double spacing );
273  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
274  void mFontSizeUnitWidget_changed();
275  void mFontMinPixelSpinBox_valueChanged( int px );
276  void mFontMaxPixelSpinBox_valueChanged( int px );
277  void mBufferUnitWidget_changed();
278  void mCoordXDDBtn_activated( bool active );
279  void mCoordYDDBtn_activated( bool active );
280  void mShapeTypeCmbBx_currentIndexChanged( int index );
281  void mShapeRotationCmbBx_currentIndexChanged( int index );
282  void mShapeSVGParamsBtn_clicked();
283  void mShapeSVGSelectorBtn_clicked();
284  void mPreviewTextEdit_textChanged( const QString &text );
285  void mPreviewTextBtn_clicked();
286  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
287  void mDirectSymbLeftToolBtn_clicked();
288  void mDirectSymbRightToolBtn_clicked();
289  void mChkNoObstacle_toggled( bool active );
290  void chkLineOrientationDependent_toggled( bool active );
291  void mToolButtonConfigureSubstitutes_clicked();
292  void collapseSample( bool collapse );
293  void changeTextColor( const QColor &color );
294  void changeBufferColor( const QColor &color );
295  void scrollPreview();
296  void updateSvgWidgets( const QString &svgPath );
297  void updateAvailableShadowPositions();
298  void updateProperty();
299  void createAuxiliaryField();
300  void updateShapeFrameStatus();
301  void updateBufferFrameStatus();
302 };
303 
304 
317 class GUI_EXPORT QgsTextFormatDialog : public QDialog
318 {
319  Q_OBJECT
320 
321  public:
322 
331  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsVectorLayer *layer = nullptr );
332 
336  QgsTextFormat format() const;
337 
342  void setContext( const QgsSymbolWidgetContext &context );
343 
348  QDialogButtonBox *buttonBox() const;
349 
350  private:
351 
352  QgsTextFormatWidget *mFormatWidget = nullptr;
353  QDialogButtonBox *mButtonBox = nullptr;
354 
355  private slots:
356  void showHelp();
357 
358 };
359 
373 {
374  Q_OBJECT
375 
376  public:
377 
385  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *layer = nullptr );
386 
390  QgsTextFormat format() const;
391 
396  void setContext( const QgsSymbolWidgetContext &context );
397 
398  void setDockMode( bool dockMode ) override;
399 
400  private:
401 
402  QgsTextFormatWidget *mFormatWidget = nullptr;
403 };
404 
405 #endif //QGSTEXTFORMATWIDGET_H
406 
407 
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsSymbolWidgetContext mContext
Context in which widget is shown.
A dialog for selecting a single character from a single font.
A widget for customizing text formatting settings.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
Show labeling settings in addition to text formatting settings.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs...
StyleEntity
Enum for Entities involved in a style.
Definition: qgsstyle.h:177
Property
Data definable properties.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
A button for controlling property overrides which may apply to a widget.
QgsPropertyCollection mDataDefinedProperties
Data defined properties as defined in the widget.
Contains settings which reflect the context in which a symbol (or renderer) widget is shown...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsStringReplacementCollection mSubstitutions
Text substitution list.
Abstract interface for generating an expression context.
A collection of string replacements (specified using QgsStringReplacement objects).
A panel widget for customizing text formatting settings.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Container for all settings relating to text rendering.
A simple dialog for customizing text formatting settings.
Represents a vector layer which manages a vector based data sets.
Wrapper widget for existing widgets which can&#39;t have the inheritance tree changed, e.g dialogs.