Skip to content

Commit 76c12ba

Browse files
committedOct 24, 2016
Split QgsLabelingGui off into QgsTextFormatWidget
New widget allows for setting just the formatting properties of text
1 parent 169b367 commit 76c12ba

14 files changed

+2471
-1896
lines changed
 

‎python/gui/gui.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@
156156
%Include qgsslider.sip
157157
%Include qgssourceselectdialog.sip
158158
%Include qgssublayersdialog.sip
159+
%Include qgssubstitutionlistwidget.sip
159160
%Include qgssvgannotationitem.sip
160161
%Include qgstablewidgetbase.sip
161162
%Include qgstabwidget.sip
162163
%Include qgstablewidgetitem.sip
163164
%Include qgstextannotationitem.sip
165+
%Include qgstextformatwidget.sip
164166
%Include qgstextpreview.sip
165167
%Include qgstrackedvectorlayertools.sip
166168
%Include qgstreewidgetitem.sip
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/** \class QgsSubstitutionListWidget
2+
* \ingroup gui
3+
* A widget which allows users to specify a list of substitutions to apply to a string, with
4+
* options for exporting and importing substitution lists.
5+
* \note added in QGIS 3.0
6+
* \see QgsSubstitutionListDialog
7+
*/
8+
9+
class QgsSubstitutionListWidget : public QgsPanelWidget
10+
{
11+
%TypeHeaderCode
12+
#include <qgssubstitutionlistwidget.h>
13+
%End
14+
15+
public:
16+
17+
/** Constructor for QgsSubstitutionListWidget.
18+
* @param parent parent widget
19+
*/
20+
QgsSubstitutionListWidget( QWidget* parent /TransferThis/ = nullptr );
21+
22+
/** Sets the list of substitutions to show in the widget.
23+
* @param substitutions substitution list
24+
* @see substitutions()
25+
*/
26+
void setSubstitutions( const QgsStringReplacementCollection& substitutions );
27+
28+
/** Returns the list of substitutions currently defined by the widget.
29+
* @see setSubstitutions()
30+
*/
31+
QgsStringReplacementCollection substitutions() const;
32+
33+
signals:
34+
35+
//! Emitted when the substitution definitions change.
36+
void substitutionsChanged( const QgsStringReplacementCollection& substitutions );
37+
38+
};
39+
40+
41+
42+
/** \class QgsSubstitutionListDialog
43+
* \ingroup gui
44+
* A dialog which allows users to specify a list of substitutions to apply to a string, with
45+
* options for exporting and importing substitution lists.
46+
* \see QgsSubstitutionListWidget
47+
*/
48+
49+
class QgsSubstitutionListDialog : public QDialog
50+
{
51+
%TypeHeaderCode
52+
#include <qgssubstitutionlistwidget.h>
53+
%End
54+
55+
public:
56+
57+
/** Constructor for QgsSubstitutionListDialog.
58+
* @param parent parent widget
59+
*/
60+
QgsSubstitutionListDialog( QWidget* parent /TransferThis/ = nullptr );
61+
62+
/** Sets the list of substitutions to show in the dialog.
63+
* @param substitutions substitution list
64+
* @see substitutions()
65+
*/
66+
void setSubstitutions( const QgsStringReplacementCollection& substitutions );
67+
68+
/** Returns the list of substitutions currently defined by the dialog.
69+
* @see setSubstitutions()
70+
*/
71+
QgsStringReplacementCollection substitutions() const;
72+
73+
};

‎python/gui/qgstextformatwidget.sip

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/** \class QgsTextFormatWidget
2+
* \ingroup gui
3+
* A widget for customising text formatting settings.
4+
*
5+
* QgsTextFormatWidget provides a widget for controlling the appearance of text rendered
6+
* using QgsTextRenderer. The preview includes all settings contained within
7+
* a QgsTextFormat, including shadow, background and buffer.
8+
*
9+
* Additionally, the widget can handle labeling settings due to the large overlap between
10+
* the text renderer settings and the labeling settings. This mode is possible by
11+
* subclassing QgsTextFormatWidget and calling the protected constructor with a mode
12+
* of Labeling.
13+
*
14+
* @note Added in QGIS 3.0
15+
*/
16+
17+
class QgsTextFormatWidget : public QgsPanelWidget
18+
{
19+
%TypeHeaderCode
20+
#include <qgstextformatwidget.h>
21+
%End
22+
23+
public:
24+
25+
/** Constructor for QgsTextFormatWidget.
26+
* @param format initial formatting settings to show in widget
27+
* @param mapCanvas associated map canvas
28+
* @param parent parent widget
29+
*/
30+
QgsTextFormatWidget( const QgsTextFormat& format = QgsTextFormat(), QgsMapCanvas* mapCanvas = nullptr, QWidget* parent /TransferThis/ = nullptr );
31+
32+
~QgsTextFormatWidget();
33+
34+
/** Returns the current formatting settings defined by the widget.
35+
*/
36+
QgsTextFormat format() const;
37+
38+
public slots:
39+
40+
/** Sets whether the widget should be shown in a compact dock mode.
41+
* @param enabled set to true to show in dock mode.
42+
*/
43+
void setDockMode( bool enabled );
44+
45+
signals:
46+
47+
//! Emitted when the text format defined by the widget changes
48+
void widgetChanged();
49+
50+
protected:
51+
52+
//! Widget mode
53+
enum Mode
54+
{
55+
Text, //!< Default mode, show text formatting settings only
56+
Labeling, //!< Show labeling settings in addition to text formatting settings
57+
};
58+
59+
/** Constructor for QgsTextFormatWidget.
60+
* @param mapCanvas associated map canvas
61+
* @param parent parent widget
62+
* @param mode widget mode
63+
*/
64+
QgsTextFormatWidget( QgsMapCanvas* mapCanvas, QWidget* parent /TransferThis/, Mode mode );
65+
66+
/** Updates the widget's state to reflect the settings in a QgsTextFormat.
67+
* @param format source format
68+
*/
69+
void updateWidgetForFormat( const QgsTextFormat& format );
70+
71+
/** Sets the background color for the text preview widget.
72+
* @param color background color
73+
*/
74+
void setPreviewBackground( const QColor& color );
75+
76+
/** Controls whether data defined alignment buttons are enabled.
77+
* @param enable set to true to enable alignment controls
78+
*/
79+
void enableDataDefinedAlignment( bool enable );
80+
81+
protected slots:
82+
83+
//! Updates line placement options to reflect current state of widget
84+
void updateLinePlacementOptions();
85+
86+
//! Updates label placement options to reflect current state of widget
87+
void updatePlacementWidgets();
88+
};

‎src/app/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ SET(QGIS_APP_SRCS
116116
qgsrelationadddlg.cpp
117117
qgsselectbyformdialog.cpp
118118
qgsstatisticalsummarydockwidget.cpp
119-
qgssubstitutionlistwidget.cpp
120119
qgstextannotationdialog.cpp
121120
qgssvgannotationdialog.cpp
122121
qgsundowidget.cpp
@@ -293,7 +292,6 @@ SET (QGIS_APP_MOC_HDRS
293292
qgsselectbyformdialog.h
294293
qgssponsors.h
295294
qgsstatisticalsummarydockwidget.h
296-
qgssubstitutionlistwidget.h
297295
qgssvgannotationdialog.h
298296
qgstextannotationdialog.h
299297
qgstipgui.h

‎src/app/qgslabelinggui.cpp

Lines changed: 23 additions & 1321 deletions
Large diffs are not rendered by default.

‎src/app/qgslabelinggui.h

Lines changed: 6 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,18 @@
1515
* *
1616
***************************************************************************/
1717

18-
#ifndef QgsLabelingGUI_H
19-
#define QgsLabelingGUI_H
18+
#ifndef QGSLABELINGGUI_H
19+
#define QGSLABELINGGUI_H
2020

21-
#include <QDialog>
22-
#include <QFontDatabase>
23-
#include <ui_qgslabelingguibase.h>
24-
#include "qgsstringutils.h"
2521
#include "qgspallabeling.h"
22+
#include "qgstextformatwidget.h"
2623

27-
class QgsVectorLayer;
28-
class QgsMapCanvas;
29-
class QgsCharacterSelectorDialog;
30-
31-
class APP_EXPORT QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase, private QgsExpressionContextGenerator
24+
class APP_EXPORT QgsLabelingGui : public QgsTextFormatWidget, private QgsExpressionContextGenerator
3225
{
3326
Q_OBJECT
3427

3528
public:
3629
QgsLabelingGui( QgsVectorLayer* layer, QgsMapCanvas* mapCanvas, const QgsPalLayerSettings* settings, QWidget* parent );
37-
~QgsLabelingGui();
3830

3931
QgsPalLayerSettings layerSettings();
4032
void writeSettingsToLayer();
@@ -48,111 +40,30 @@ class APP_EXPORT QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
4840

4941
void setLabelMode( LabelMode mode );
5042

51-
signals:
52-
void widgetChanged();
43+
void setLayer( QgsMapLayer* layer );
5344

5445
public slots:
55-
void setLayer( QgsMapLayer* layer );
56-
void setDockMode( bool enabled );
57-
void connectValueChanged( const QList<QWidget *> &widgets, const char* slot );
5846

59-
void init();
60-
void collapseSample( bool collapse );
6147
void apply();
62-
void changeTextColor( const QColor &color );
63-
void changeBufferColor( const QColor &color );
6448

6549
void updateUi();
66-
void updatePreview();
67-
void scrollPreview();
68-
void updatePlacementWidgets();
69-
void updateSvgWidgets( const QString& svgPath );
70-
71-
void on_mFontSizeSpinBox_valueChanged( double d );
72-
void on_mFontCapitalsComboBox_currentIndexChanged( int index );
73-
void on_mFontFamilyCmbBx_currentFontChanged( const QFont& f );
74-
void on_mFontStyleComboBox_currentIndexChanged( const QString & text );
75-
void on_mFontUnderlineBtn_toggled( bool ckd );
76-
void on_mFontStrikethroughBtn_toggled( bool ckd );
77-
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
78-
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
79-
void on_mFontSizeUnitWidget_changed();
80-
void on_mFontMinPixelSpinBox_valueChanged( int px );
81-
void on_mFontMaxPixelSpinBox_valueChanged( int px );
82-
void on_mBufferUnitWidget_changed();
83-
void on_mCoordXDDBtn_dataDefinedActivated( bool active );
84-
void on_mCoordYDDBtn_dataDefinedActivated( bool active );
85-
86-
void on_mShapeTypeCmbBx_currentIndexChanged( int index );
87-
void on_mShapeRotationCmbBx_currentIndexChanged( int index );
88-
void on_mShapeSVGParamsBtn_clicked();
89-
void on_mShapeSVGSelectorBtn_clicked();
90-
91-
void on_mPreviewTextEdit_textChanged( const QString & text );
92-
void on_mPreviewTextBtn_clicked();
93-
void on_mPreviewBackgroundBtn_colorChanged( const QColor &color );
94-
void on_mDirectSymbLeftToolBtn_clicked();
95-
void on_mDirectSymbRightToolBtn_clicked();
96-
void on_mChkNoObstacle_toggled( bool active );
97-
void on_chkLineOrientationDependent_toggled( bool active );
98-
99-
void on_mToolButtonConfigureSubstitutes_clicked();
10050

10151
protected:
10252
void blockInitSignals( bool block );
103-
void blockFontChangeSignals( bool blk );
104-
void setPreviewBackground( const QColor& color );
10553
void syncDefinedCheckboxFrame( QgsDataDefinedButton* ddBtn, QCheckBox* chkBx, QFrame* f );
106-
void populateFontCapitalsComboBox();
107-
void populateFontStyleComboBox();
108-
void populatePlacementMethods();
109-
void populateFieldNames();
11054
void populateDataDefinedButtons( QgsPalLayerSettings& s );
11155
/** Sets data defined property attribute to map */
11256
void setDataDefinedProperty( const QgsDataDefinedButton* ddBtn, QgsPalLayerSettings::DataDefinedProperties p, QgsPalLayerSettings& lyr );
113-
void updateFont( const QFont& font );
11457

11558
private:
11659
QgsVectorLayer* mLayer;
117-
QgsMapCanvas* mMapCanvas;
11860
const QgsPalLayerSettings* mSettings;
11961
LabelMode mMode;
120-
QFontDatabase mFontDB;
121-
QgsCharacterSelectorDialog* mCharDlg;
122-
123-
QButtonGroup* mQuadrantBtnGrp;
124-
QButtonGroup* mDirectSymbBtnGrp;
125-
QButtonGroup* mUpsidedownBtnGrp;
126-
127-
QButtonGroup* mPlacePointBtnGrp;
128-
QButtonGroup* mPlaceLineBtnGrp;
129-
QButtonGroup* mPlacePolygonBtnGrp;
130-
131-
// background reference font
132-
QFont mRefFont;
133-
bool mDockMode;
134-
int mPreviewSize;
135-
136-
int mMinPixelLimit;
137-
138-
bool mLoadSvgParams;
139-
140-
QgsStringReplacementCollection mSubstitutions;
141-
142-
void enableDataDefinedAlignment( bool enable );
14362

14463
QgsExpressionContext createExpressionContext() const override;
14564

146-
private slots:
147-
void optionsStackedWidget_CurrentChanged( int indx );
148-
void showBackgroundRadius( bool show );
149-
void showBackgroundPenStyle( bool show );
150-
void on_mShapeSVGPathLineEdit_textChanged( const QString& text );
151-
void updateLinePlacementOptions();
152-
void onSubstitutionsChanged( const QgsStringReplacementCollection& substitutions );
153-
void previewScaleChanged( double scale );
15465
};
15566

156-
#endif
67+
#endif // QGSLABELINGGUI_H
15768

15869

‎src/gui/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ SET(QGIS_GUI_SRCS
302302
qgsshortcutsmanager.cpp
303303
qgsslider.cpp
304304
qgssublayersdialog.cpp
305+
qgssubstitutionlistwidget.cpp
305306
qgssqlcomposerdialog.cpp
306307
qgssvgannotationitem.cpp
307308
qgstablewidgetbase.cpp
308309
qgstabwidget.cpp
309310
qgstablewidgetitem.cpp
310311
qgstextannotationitem.cpp
312+
qgstextformatwidget.cpp
311313
qgstextpreview.cpp
312314
qgstrackedvectorlayertools.cpp
313315
qgstreewidgetitem.cpp
@@ -460,8 +462,10 @@ SET(QGIS_GUI_MOC_HDRS
460462
qgsslider.h
461463
qgssqlcomposerdialog.h
462464
qgssublayersdialog.h
465+
qgssubstitutionlistwidget.h
463466
qgstablewidgetbase.h
464467
qgstabwidget.h
468+
qgstextformatwidget.h
465469
qgstextpreview.h
466470
qgstreewidgetitem.h
467471
qgsunitselectionwidget.h

‎src/app/qgssubstitutionlistwidget.h renamed to ‎src/gui/qgssubstitutionlistwidget.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
#include "qgsstringutils.h"
2525

2626
/** \class QgsSubstitutionListWidget
27-
* \ingroup app
27+
* \ingroup gui
2828
* A widget which allows users to specify a list of substitutions to apply to a string, with
2929
* options for exporting and importing substitution lists.
3030
* \note added in QGIS 3.0
3131
* \see QgsSubstitutionListDialog
3232
*/
33-
class APP_EXPORT QgsSubstitutionListWidget : public QgsPanelWidget, private Ui::QgsSubstitutionListWidgetBase
33+
class GUI_EXPORT QgsSubstitutionListWidget : public QgsPanelWidget, private Ui::QgsSubstitutionListWidgetBase
3434
{
3535
Q_OBJECT
3636
Q_PROPERTY( QgsStringReplacementCollection substitutions READ substitutions WRITE setSubstitutions NOTIFY substitutionsChanged )
@@ -73,12 +73,13 @@ class APP_EXPORT QgsSubstitutionListWidget : public QgsPanelWidget, private Ui::
7373
};
7474

7575
/** \class QgsSubstitutionListDialog
76-
* \ingroup app
76+
* \ingroup gui
7777
* A dialog which allows users to specify a list of substitutions to apply to a string, with
7878
* options for exporting and importing substitution lists.
79+
* \note added in QGIS 3.0
7980
* \see QgsSubstitutionListWidget
8081
*/
81-
class APP_EXPORT QgsSubstitutionListDialog : public QDialog
82+
class GUI_EXPORT QgsSubstitutionListDialog : public QDialog
8283
{
8384
Q_OBJECT
8485
Q_PROPERTY( QgsStringReplacementCollection substitutions READ substitutions WRITE setSubstitutions )

‎src/gui/qgstextformatwidget.cpp

Lines changed: 1378 additions & 0 deletions
Large diffs are not rendered by default.

‎src/gui/qgstextformatwidget.h

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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 "qgstextrenderer.h"
22+
#include "qgsstringutils.h"
23+
#include <QFontDatabase>
24+
25+
class QgsMapCanvas;
26+
class QgsCharacterSelectorDialog;
27+
28+
29+
/** \class QgsTextFormatWidget
30+
* \ingroup gui
31+
* A widget for customising text formatting settings.
32+
*
33+
* QgsTextFormatWidget provides a widget for controlling the appearance of text rendered
34+
* using QgsTextRenderer. The preview includes all settings contained within
35+
* a QgsTextFormat, including shadow, background and buffer.
36+
*
37+
* Additionally, the widget can handle labeling settings due to the large overlap between
38+
* the text renderer settings and the labeling settings. This mode is possible by
39+
* subclassing QgsTextFormatWidget and calling the protected constructor with a mode
40+
* of Labeling.
41+
*
42+
* @note Added in QGIS 3.0
43+
*/
44+
45+
class GUI_EXPORT QgsTextFormatWidget : public QWidget, protected Ui::QgsTextFormatWidgetBase
46+
{
47+
Q_OBJECT
48+
Q_PROPERTY( QgsTextFormat format READ format )
49+
50+
public:
51+
52+
/** Constructor for QgsTextFormatWidget.
53+
* @param format initial formatting settings to show in widget
54+
* @param mapCanvas associated map canvas
55+
* @param parent parent widget
56+
*/
57+
QgsTextFormatWidget( const QgsTextFormat& format = QgsTextFormat(), QgsMapCanvas* mapCanvas = nullptr, QWidget* parent = nullptr );
58+
59+
~QgsTextFormatWidget();
60+
61+
/** Returns the current formatting settings defined by the widget.
62+
*/
63+
QgsTextFormat format() const;
64+
65+
public slots:
66+
67+
/** Sets whether the widget should be shown in a compact dock mode.
68+
* @param enabled set to true to show in dock mode.
69+
*/
70+
void setDockMode( bool enabled );
71+
72+
signals:
73+
74+
//! Emitted when the text format defined by the widget changes
75+
void widgetChanged();
76+
77+
protected:
78+
79+
//! Widget mode
80+
enum Mode
81+
{
82+
Text = 0, //!< Default mode, show text formatting settings only
83+
Labeling, //!< Show labeling settings in addition to text formatting settings
84+
};
85+
86+
/** Constructor for QgsTextFormatWidget.
87+
* @param mapCanvas associated map canvas
88+
* @param parent parent widget
89+
* @param mode widget mode
90+
*/
91+
QgsTextFormatWidget( QgsMapCanvas* mapCanvas, QWidget* parent, Mode mode );
92+
93+
/** Updates the widget's state to reflect the settings in a QgsTextFormat.
94+
* @param format source format
95+
*/
96+
void updateWidgetForFormat( const QgsTextFormat& format );
97+
98+
/** Sets the background color for the text preview widget.
99+
* @param color background color
100+
*/
101+
void setPreviewBackground( const QColor& color );
102+
103+
/** Controls whether data defined alignment buttons are enabled.
104+
* @param enable set to true to enable alignment controls
105+
*/
106+
void enableDataDefinedAlignment( bool enable );
107+
108+
//! Text substitution list
109+
QgsStringReplacementCollection mSubstitutions;
110+
//! Quadrant button group
111+
QButtonGroup* mQuadrantBtnGrp;
112+
//! Symbol direction button group
113+
QButtonGroup* mDirectSymbBtnGrp;
114+
//! Upside down labels button group
115+
QButtonGroup* mUpsidedownBtnGrp;
116+
//! Point placement button group
117+
QButtonGroup* mPlacePointBtnGrp;
118+
//! Line placement button group
119+
QButtonGroup* mPlaceLineBtnGrp;
120+
//! Polygon placement button group
121+
QButtonGroup* mPlacePolygonBtnGrp;
122+
//! Pixel size font limit
123+
int mMinPixelLimit;
124+
125+
protected slots:
126+
127+
//! Updates line placement options to reflect current state of widget
128+
void updateLinePlacementOptions();
129+
130+
//! Updates label placement options to reflect current state of widget
131+
void updatePlacementWidgets();
132+
133+
private:
134+
Mode mWidgetMode;
135+
QgsMapCanvas* mMapCanvas;
136+
QgsCharacterSelectorDialog* mCharDlg;
137+
138+
QFontDatabase mFontDB;
139+
140+
// background reference font
141+
QFont mRefFont;
142+
bool mDockMode;
143+
144+
bool mLoadSvgParams;
145+
146+
void initWidget();
147+
void setWidgetMode( Mode mode );
148+
void toggleDDButtons( bool visible );
149+
void blockFontChangeSignals( bool blk );
150+
void populateFontCapitalsComboBox();
151+
void populateFontStyleComboBox();
152+
void updateFont( const QFont& font );
153+
void connectValueChanged( const QList<QWidget *> &widgets, const char* slot );
154+
155+
private slots:
156+
void optionsStackedWidget_CurrentChanged( int indx );
157+
void showBackgroundRadius( bool show );
158+
void showBackgroundPenStyle( bool show );
159+
void on_mShapeSVGPathLineEdit_textChanged( const QString& text );
160+
void onSubstitutionsChanged( const QgsStringReplacementCollection& substitutions );
161+
void previewScaleChanged( double scale );
162+
void on_mFontSizeSpinBox_valueChanged( double d );
163+
void on_mFontCapitalsComboBox_currentIndexChanged( int index );
164+
void on_mFontFamilyCmbBx_currentFontChanged( const QFont& f );
165+
void on_mFontStyleComboBox_currentIndexChanged( const QString & text );
166+
void on_mFontUnderlineBtn_toggled( bool ckd );
167+
void on_mFontStrikethroughBtn_toggled( bool ckd );
168+
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
169+
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
170+
void on_mFontSizeUnitWidget_changed();
171+
void on_mFontMinPixelSpinBox_valueChanged( int px );
172+
void on_mFontMaxPixelSpinBox_valueChanged( int px );
173+
void on_mBufferUnitWidget_changed();
174+
void on_mCoordXDDBtn_dataDefinedActivated( bool active );
175+
void on_mCoordYDDBtn_dataDefinedActivated( bool active );
176+
void on_mShapeTypeCmbBx_currentIndexChanged( int index );
177+
void on_mShapeRotationCmbBx_currentIndexChanged( int index );
178+
void on_mShapeSVGParamsBtn_clicked();
179+
void on_mShapeSVGSelectorBtn_clicked();
180+
void on_mPreviewTextEdit_textChanged( const QString & text );
181+
void on_mPreviewTextBtn_clicked();
182+
void on_mPreviewBackgroundBtn_colorChanged( const QColor &color );
183+
void on_mDirectSymbLeftToolBtn_clicked();
184+
void on_mDirectSymbRightToolBtn_clicked();
185+
void on_mChkNoObstacle_toggled( bool active );
186+
void on_chkLineOrientationDependent_toggled( bool active );
187+
void on_mToolButtonConfigureSubstitutes_clicked();
188+
void collapseSample( bool collapse );
189+
void changeTextColor( const QColor &color );
190+
void changeBufferColor( const QColor &color );
191+
void updatePreview();
192+
void scrollPreview();
193+
void updateSvgWidgets( const QString& svgPath );
194+
};
195+
196+
#endif //QGSTEXTFORMATWIDGET_H
197+
198+

‎src/ui/qgslabelingguibase.ui renamed to ‎src/ui/qgstextformatwidgetbase.ui

Lines changed: 504 additions & 474 deletions
Large diffs are not rendered by default.

‎tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ ADD_PYTHON_TEST(PyQgsSyntacticSugar test_syntactic_sugar.py)
104104
ADD_PYTHON_TEST(PyQgsStringUtils test_qgsstringutils.py)
105105
ADD_PYTHON_TEST(PyQgsSymbol test_qgssymbol.py)
106106
ADD_PYTHON_TEST(PyQgsSymbolLayerUtils test_qgssymbollayerutils.py)
107+
ADD_PYTHON_TEST(PyQgsTextFormatWidget test_qgstextformatwidget.py)
107108
ADD_PYTHON_TEST(PyQgsTreeWidgetItem test_qgstreewidgetitem.py)
108109
ADD_PYTHON_TEST(PyQgsUnitTypes test_qgsunittypes.py)
109110
ADD_PYTHON_TEST(PyQgsVectorColorRamp test_qgsvectorcolorramp.py)
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsTextFormatWidget.
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Nyall Dawson'
10+
__date__ = '2016-09'
11+
__copyright__ = 'Copyright 2016, The QGIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import qgis # NOQA
16+
import os
17+
18+
from qgis.core import (QgsTextBufferSettings,
19+
QgsTextBackgroundSettings,
20+
QgsTextShadowSettings,
21+
QgsTextFormat,
22+
QgsUnitTypes,
23+
QgsMapUnitScale)
24+
from qgis.gui import (QgsTextFormatWidget)
25+
from qgis.PyQt.QtGui import (QColor, QPainter, QFont, QImage, QBrush, QPen)
26+
from qgis.PyQt.QtCore import (Qt, QSizeF, QPointF, QRectF, QDir)
27+
from qgis.testing import unittest, start_app
28+
from utilities import getTestFont, svgSymbolsPath
29+
30+
start_app()
31+
32+
33+
class PyQgsTextFormatWidget(unittest.TestCase):
34+
35+
def createBufferSettings(self):
36+
s = QgsTextBufferSettings()
37+
s.setEnabled(True)
38+
s.setSize(5)
39+
s.setSizeUnit(QgsUnitTypes.RenderPixels)
40+
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
41+
s.setColor(QColor(255, 0, 0))
42+
s.setFillBufferInterior(True)
43+
s.setOpacity(0.5)
44+
s.setJoinStyle(Qt.RoundJoin)
45+
s.setBlendMode(QPainter.CompositionMode_Difference)
46+
return s
47+
48+
def checkBufferSettings(self, s):
49+
""" test QgsTextBufferSettings """
50+
self.assertTrue(s.enabled())
51+
self.assertEqual(s.size(), 5)
52+
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPixels)
53+
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
54+
self.assertEqual(s.color(), QColor(255, 0, 0))
55+
self.assertTrue(s.fillBufferInterior())
56+
self.assertEqual(s.opacity(), 0.5)
57+
self.assertEqual(s.joinStyle(), Qt.RoundJoin)
58+
self.assertEqual(s.blendMode(), QPainter.CompositionMode_Difference)
59+
60+
def createBackgroundSettings(self):
61+
s = QgsTextBackgroundSettings()
62+
s.setEnabled(True)
63+
s.setType(QgsTextBackgroundSettings.ShapeEllipse)
64+
s.setSvgFile('svg.svg')
65+
s.setSizeType(QgsTextBackgroundSettings.SizeFixed)
66+
s.setSize(QSizeF(1, 2))
67+
s.setSizeUnit(QgsUnitTypes.RenderPixels)
68+
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
69+
s.setRotationType(QgsTextBackgroundSettings.RotationFixed)
70+
s.setRotation(45)
71+
s.setOffset(QPointF(3, 4))
72+
s.setOffsetUnit(QgsUnitTypes.RenderMapUnits)
73+
s.setOffsetMapUnitScale(QgsMapUnitScale(5, 6))
74+
s.setRadii(QSizeF(11, 12))
75+
s.setRadiiUnit(QgsUnitTypes.RenderPixels)
76+
s.setRadiiMapUnitScale(QgsMapUnitScale(15, 16))
77+
s.setFillColor(QColor(255, 0, 0))
78+
s.setBorderColor(QColor(0, 255, 0))
79+
s.setOpacity(0.5)
80+
s.setJoinStyle(Qt.RoundJoin)
81+
s.setBlendMode(QPainter.CompositionMode_Difference)
82+
s.setBorderWidth(7)
83+
s.setBorderWidthUnit(QgsUnitTypes.RenderMapUnits)
84+
s.setBorderWidthMapUnitScale(QgsMapUnitScale(QgsMapUnitScale(25, 26)))
85+
return s
86+
87+
def checkBackgroundSettings(self, s):
88+
""" test QgsTextBackgroundSettings """
89+
self.assertTrue(s.enabled())
90+
self.assertEqual(s.type(), QgsTextBackgroundSettings.ShapeEllipse)
91+
self.assertEqual(s.svgFile(), 'svg.svg')
92+
self.assertEqual(s.sizeType(), QgsTextBackgroundSettings.SizeFixed)
93+
self.assertEqual(s.size(), QSizeF(1, 2))
94+
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPixels)
95+
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
96+
self.assertEqual(s.rotationType(), QgsTextBackgroundSettings.RotationFixed)
97+
self.assertEqual(s.rotation(), 45)
98+
self.assertEqual(s.offset(), QPointF(3, 4))
99+
self.assertEqual(s.offsetUnit(), QgsUnitTypes.RenderMapUnits)
100+
self.assertEqual(s.offsetMapUnitScale(), QgsMapUnitScale(5, 6))
101+
self.assertEqual(s.radii(), QSizeF(11, 12))
102+
self.assertEqual(s.radiiUnit(), QgsUnitTypes.RenderPixels)
103+
self.assertEqual(s.radiiMapUnitScale(), QgsMapUnitScale(15, 16))
104+
self.assertEqual(s.fillColor(), QColor(255, 0, 0))
105+
self.assertEqual(s.borderColor(), QColor(0, 255, 0))
106+
self.assertEqual(s.opacity(), 0.5)
107+
self.assertEqual(s.joinStyle(), Qt.RoundJoin)
108+
self.assertEqual(s.blendMode(), QPainter.CompositionMode_Difference)
109+
self.assertEqual(s.borderWidth(), 7)
110+
self.assertEqual(s.borderWidthUnit(), QgsUnitTypes.RenderMapUnits)
111+
self.assertEqual(s.borderWidthMapUnitScale(), QgsMapUnitScale(25, 26))
112+
113+
def createShadowSettings(self):
114+
s = QgsTextShadowSettings()
115+
s.setEnabled(True)
116+
s.setShadowPlacement(QgsTextShadowSettings.ShadowBuffer)
117+
s.setOffsetAngle(45)
118+
s.setOffsetDistance(75)
119+
s.setOffsetUnit(QgsUnitTypes.RenderMapUnits)
120+
s.setOffsetMapUnitScale(QgsMapUnitScale(5, 6))
121+
s.setOffsetGlobal(True)
122+
s.setBlurRadius(11)
123+
s.setBlurRadiusUnit(QgsUnitTypes.RenderMapUnits)
124+
s.setBlurRadiusMapUnitScale(QgsMapUnitScale(15, 16))
125+
s.setBlurAlphaOnly(True)
126+
s.setColor(QColor(255, 0, 0))
127+
s.setOpacity(0.5)
128+
s.setScale(123)
129+
s.setBlendMode(QPainter.CompositionMode_Difference)
130+
return s
131+
132+
def checkShadowSettings(self, s):
133+
""" test QgsTextShadowSettings """
134+
self.assertTrue(s.enabled())
135+
self.assertEqual(s.shadowPlacement(), QgsTextShadowSettings.ShadowBuffer)
136+
self.assertEqual(s.offsetAngle(), 45)
137+
self.assertEqual(s.offsetDistance(), 75)
138+
self.assertEqual(s.offsetUnit(), QgsUnitTypes.RenderMapUnits)
139+
self.assertEqual(s.offsetMapUnitScale(), QgsMapUnitScale(5, 6))
140+
self.assertTrue(s.offsetGlobal())
141+
self.assertEqual(s.blurRadius(), 11)
142+
self.assertEqual(s.blurRadiusUnit(), QgsUnitTypes.RenderMapUnits)
143+
self.assertEqual(s.blurRadiusMapUnitScale(), QgsMapUnitScale(15, 16))
144+
self.assertTrue(s.blurAlphaOnly())
145+
self.assertEqual(s.color(), QColor(255, 0, 0))
146+
self.assertEqual(s.opacity(), 0.5)
147+
self.assertEqual(s.scale(), 123)
148+
self.assertEqual(s.blendMode(), QPainter.CompositionMode_Difference)
149+
150+
def createFormatSettings(self):
151+
s = QgsTextFormat()
152+
s.setBuffer(self.createBufferSettings())
153+
s.setBackground(self.createBackgroundSettings())
154+
s.setShadow(self.createShadowSettings())
155+
s.setFont(getTestFont())
156+
s.setNamedStyle('Roman')
157+
s.setSize(5)
158+
s.setSizeUnit(QgsUnitTypes.RenderPoints)
159+
s.setSizeMapUnitScale(QgsMapUnitScale(1, 2))
160+
s.setColor(QColor(255, 0, 0))
161+
s.setOpacity(0.5)
162+
s.setBlendMode(QPainter.CompositionMode_Difference)
163+
s.setLineHeight(5)
164+
return s
165+
166+
def checkTextFormat(self, s):
167+
""" test QgsTextFormat """
168+
self.checkBufferSettings(s.buffer())
169+
self.checkShadowSettings(s.shadow())
170+
self.checkBackgroundSettings(s.background())
171+
self.assertEqual(s.font().family(), 'QGIS Vera Sans')
172+
self.assertEqual(s.namedStyle(), 'Roman')
173+
self.assertEqual(s.size(), 5)
174+
self.assertEqual(s.sizeUnit(), QgsUnitTypes.RenderPoints)
175+
self.assertEqual(s.sizeMapUnitScale(), QgsMapUnitScale(1, 2))
176+
self.assertEqual(s.color(), QColor(255, 0, 0))
177+
self.assertEqual(s.opacity(), 0.5)
178+
self.assertEqual(s.blendMode(), QPainter.CompositionMode_Difference)
179+
self.assertEqual(s.lineHeight(), 5)
180+
181+
def testSettings(self):
182+
# test that widget correctly sets and returns matching settings
183+
s = self.createFormatSettings()
184+
w = QgsTextFormatWidget(s)
185+
self.checkTextFormat(w.format())
186+
187+
188+
if __name__ == '__main__':
189+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.