QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
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 
194 
195  protected slots:
196 
198  void updateLinePlacementOptions();
199 
201  void updatePlacementWidgets();
202 
207  virtual void setFormatFromStyle( const QString &name, QgsStyle::StyleEntity type );
208 
212  virtual void saveFormat();
213 
218  void updatePreview();
219 
220 #ifndef SIP_RUN
221 
228  void populateDataDefinedButtons();
229 #endif
230 
231  private:
232  Mode mWidgetMode = Text;
233 
234  QgsCharacterSelectorDialog *mCharDlg = nullptr;
235  std::unique_ptr< QgsPaintEffect > mBufferEffect;
236  std::unique_ptr< QgsPaintEffect > mMaskEffect;
237  std::unique_ptr< QgsPaintEffect > mBackgroundEffect;
238  QColor mPreviewBackgroundColor;
239 
240  QFontDatabase mFontDB;
241 
242  // background reference font
243  QFont mRefFont;
244  bool mDockMode = false;
245 
246  bool mLoadSvgParams = false;
247  QgsExpressionContext mPreviewExpressionContext;
248 
249  QMap<QgsPalLayerSettings::Property, QgsPropertyOverrideButton *> mButtons;
250 
251  void initWidget();
252  void setWidgetMode( Mode mode );
253  void toggleDDButtons( bool visible );
254  void blockFontChangeSignals( bool blk );
255  void populateFontCapitalsComboBox();
256  void populateFontStyleComboBox();
257  void updateFont( const QFont &font );
258  void connectValueChanged( const QList<QWidget *> &widgets, const char *slot );
259 
260  void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsPalLayerSettings::Property key );
261 
262  private slots:
263  void optionsStackedWidget_CurrentChanged( int indx );
264  void showBackgroundRadius( bool show );
265  void showBackgroundPenStyle( bool show );
266  void mShapeSVGPathLineEdit_textChanged( const QString &text );
267  void onSubstitutionsChanged( const QgsStringReplacementCollection &substitutions );
268  void previewScaleChanged( double scale );
269  void mFontSizeSpinBox_valueChanged( double d );
270  void mFontCapitalsComboBox_currentIndexChanged( int index );
271  void mFontFamilyCmbBx_currentFontChanged( const QFont &f );
272  void mFontStyleComboBox_currentIndexChanged( const QString &text );
273  void mFontUnderlineBtn_toggled( bool ckd );
274  void mFontStrikethroughBtn_toggled( bool ckd );
275  void kerningToggled( bool checked );
276  void mFontWordSpacingSpinBox_valueChanged( double spacing );
277  void mFontLetterSpacingSpinBox_valueChanged( double spacing );
278  void mFontSizeUnitWidget_changed();
279  void mFontMinPixelSpinBox_valueChanged( int px );
280  void mFontMaxPixelSpinBox_valueChanged( int px );
281  void mBufferUnitWidget_changed();
282  void mMaskBufferUnitWidget_changed();
283  void mCoordXDDBtn_changed( );
284  void mCoordYDDBtn_changed( );
285  void mShapeTypeCmbBx_currentIndexChanged( int index );
286  void mShapeRotationCmbBx_currentIndexChanged( int index );
287  void mShapeSVGParamsBtn_clicked();
288  void mShapeSVGSelectorBtn_clicked();
289  void mPreviewTextEdit_textChanged( const QString &text );
290  void mPreviewTextBtn_clicked();
291  void mPreviewBackgroundBtn_colorChanged( const QColor &color );
292  void mDirectSymbLeftToolBtn_clicked();
293  void mDirectSymbRightToolBtn_clicked();
294  void chkLineOrientationDependent_toggled( bool active );
295  void mToolButtonConfigureSubstitutes_clicked();
296  void collapseSample( bool collapse );
297  void changeTextColor( const QColor &color );
298  void changeBufferColor( const QColor &color );
299  void scrollPreview();
300  void updateSvgWidgets( const QString &svgPath );
301  void updateAvailableShadowPositions();
302  void updateProperty();
303  void createAuxiliaryField();
304  void updateShapeFrameStatus();
305  void updateBufferFrameStatus();
306  void updateShadowFrameStatus();
307  void updateCalloutFrameStatus();
308 };
309 
310 
323 class GUI_EXPORT QgsTextFormatDialog : public QDialog
324 {
325  Q_OBJECT
326 
327  public:
328 
337  QgsTextFormatDialog( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsVectorLayer *layer = nullptr );
338 
342  QgsTextFormat format() const;
343 
348  void setContext( const QgsSymbolWidgetContext &context );
349 
354  QDialogButtonBox *buttonBox() const;
355 
356  private:
357 
358  QgsTextFormatWidget *mFormatWidget = nullptr;
359  QDialogButtonBox *mButtonBox = nullptr;
360 
361  private slots:
362  void showHelp();
363 
364 };
365 
379 {
380  Q_OBJECT
381 
382  public:
383 
391  QgsTextFormatPanelWidget( const QgsTextFormat &format, QgsMapCanvas *mapCanvas = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr, QgsVectorLayer *layer = nullptr );
392 
396  QgsTextFormat format() const;
397 
402  void setContext( const QgsSymbolWidgetContext &context );
403 
404  void setDockMode( bool dockMode ) override;
405 
406  private:
407 
408  QgsTextFormatWidget *mFormatWidget = nullptr;
409 };
410 
411 #endif //QGSTEXTFORMATWIDGET_H
412 
413 
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
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
qgsstringutils.h
QgsSymbolWidgetContext
Definition: qgssymbolwidgetcontext.h:35
QgsMapCanvas
Definition: qgsmapcanvas.h:83
QgsTextFormatDialog
Definition: qgstextformatwidget.h:323
qgssymbolwidgetcontext.h
QgsPropertyOverrideButton
Definition: qgspropertyoverridebutton.h:50
QgsTextFormatWidget::mContext
QgsSymbolWidgetContext mContext
Context in which widget is shown.
Definition: qgstextformatwidget.h:185
QgsTextFormat
Definition: qgstextformat.h:38
qgis_sip.h
QgsTextFormatWidget::mMaskedSymbolLayers
QgsSymbolLayerReferenceList mMaskedSymbolLayers
Definition: qgstextformatwidget.h:193
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
Definition: qgstextformatwidget.h:50
QgsStringReplacementCollection
A collection of string replacements (specified using QgsStringReplacement objects).
Definition: qgsstringutils.h:115
QgsTextFormatPanelWidget
Definition: qgstextformatwidget.h:378
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:165
QgsCharacterSelectorDialog
Definition: qgscharacterselectordialog.h:34
QgsSymbolLayerReferenceList
QList< QgsSymbolLayerReference > QgsSymbolLayerReferenceList
Definition: qgssymbollayerreference.h:160
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsPalLayerSettings::Property
Property
Data definable properties.
Definition: qgspallabeling.h:337
qgstextformat.h
QgsPanelWidgetWrapper
Wrapper widget for existing widgets which can't have the inheritance tree changed,...
Definition: qgspanelwidget.h:200
qgsguiutils.h
QgsExpressionContextGenerator
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:188
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