Skip to content

Commit 67b2724

Browse files
committedJul 24, 2017
Port decoration buttons to QgsSymbolButton
1 parent 6398b74 commit 67b2724

9 files changed

+90
-189
lines changed
 

‎src/app/qgsannotationwidget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgssymbollayerutils.h"
2323
#include "qgssymbol.h"
2424
#include "qgssymbolselectordialog.h"
25+
#include "qgisapp.h"
2526
#include <QColorDialog>
2627

2728

@@ -66,6 +67,8 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
6667

6768
blockAllSignals( false );
6869
}
70+
mMapMarkerButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
71+
mFrameStyleButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
6972
}
7073

7174
QgsAnnotationWidget::~QgsAnnotationWidget()

‎src/app/qgsdecorationgriddialog.cpp

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidget *parent )
3232
: QDialog( parent )
3333
, mDeco( deco )
34-
, mLineSymbol( nullptr )
35-
, mMarkerSymbol( nullptr )
3634
{
3735
setupUi( this );
3836

@@ -65,6 +63,8 @@ QgsDecorationGridDialog::QgsDecorationGridDialog( QgsDecorationGrid &deco, QWidg
6563

6664
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsDecorationGridDialog::apply );
6765
connect( mAnnotationFontButton, &QgsFontButton::changed, this, &QgsDecorationGridDialog::annotationFontChanged );
66+
67+
mMarkerSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
6868
}
6969

7070
void QgsDecorationGridDialog::updateGuiElements()
@@ -88,22 +88,8 @@ void QgsDecorationGridDialog::updateGuiElements()
8888
// mLineWidthSpinBox->setValue( gridPen.widthF() );
8989
// mLineColorButton->setColor( gridPen.color() );
9090

91-
if ( mLineSymbol )
92-
delete mLineSymbol;
93-
if ( mDeco.lineSymbol() )
94-
{
95-
mLineSymbol = static_cast<QgsLineSymbol *>( mDeco.lineSymbol()->clone() );
96-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() );
97-
mLineSymbolButton->setIcon( icon );
98-
}
99-
if ( mMarkerSymbol )
100-
delete mMarkerSymbol;
101-
if ( mDeco.markerSymbol() )
102-
{
103-
mMarkerSymbol = static_cast<QgsMarkerSymbol *>( mDeco.markerSymbol()->clone() );
104-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() );
105-
mMarkerSymbolButton->setIcon( icon );
106-
}
91+
mLineSymbolButton->setSymbol( mDeco.lineSymbol()->clone() );
92+
mMarkerSymbolButton->setSymbol( mDeco.markerSymbol()->clone() );
10793

10894
whileBlocking( mAnnotationFontButton )->setCurrentFont( mDeco.gridAnnotationFont() );
10995

@@ -157,26 +143,14 @@ void QgsDecorationGridDialog::updateDecoFromGui()
157143
mDeco.setGridAnnotationDirection( QgsDecorationGrid::BoundaryDirection );
158144
}
159145
mDeco.setGridAnnotationPrecision( mCoordinatePrecisionSpinBox->value() );
160-
if ( mLineSymbol )
161-
{
162-
mDeco.setLineSymbol( mLineSymbol );
163-
mLineSymbol = mDeco.lineSymbol()->clone();
164-
}
165-
if ( mMarkerSymbol )
166-
{
167-
mDeco.setMarkerSymbol( mMarkerSymbol );
168-
mMarkerSymbol = mDeco.markerSymbol()->clone();
169-
}
146+
mDeco.setLineSymbol( mLineSymbolButton->clonedSymbol< QgsLineSymbol >() );
147+
mDeco.setMarkerSymbol( mMarkerSymbolButton->clonedSymbol< QgsMarkerSymbol >() );
170148
}
171149

172150
QgsDecorationGridDialog::~QgsDecorationGridDialog()
173151
{
174152
QgsSettings settings;
175153
settings.setValue( QStringLiteral( "/Windows/DecorationGrid/geometry" ), saveGeometry() );
176-
if ( mLineSymbol )
177-
delete mLineSymbol;
178-
if ( mMarkerSymbol )
179-
delete mMarkerSymbol;
180154
}
181155

182156
void QgsDecorationGridDialog::on_buttonBox_helpRequested()
@@ -210,53 +184,6 @@ void QgsDecorationGridDialog::on_mGridTypeComboBox_currentIndexChanged( int inde
210184
mMarkerSymbolButton->setEnabled( index == QgsDecorationGrid::Marker );
211185
}
212186

213-
214-
void QgsDecorationGridDialog::on_mLineSymbolButton_clicked()
215-
{
216-
if ( ! mLineSymbol )
217-
return;
218-
219-
QgsLineSymbol *lineSymbol = mLineSymbol->clone();
220-
QgsSymbolSelectorDialog dlg( lineSymbol, QgsStyle::defaultStyle(), nullptr, this );
221-
if ( dlg.exec() == QDialog::Rejected )
222-
{
223-
delete lineSymbol;
224-
}
225-
else
226-
{
227-
delete mLineSymbol;
228-
mLineSymbol = lineSymbol;
229-
if ( mLineSymbol )
230-
{
231-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mLineSymbol, mLineSymbolButton->iconSize() );
232-
mLineSymbolButton->setIcon( icon );
233-
}
234-
}
235-
}
236-
237-
void QgsDecorationGridDialog::on_mMarkerSymbolButton_clicked()
238-
{
239-
if ( ! mMarkerSymbol )
240-
return;
241-
242-
QgsMarkerSymbol *markerSymbol = mMarkerSymbol->clone();
243-
QgsSymbolSelectorDialog dlg( markerSymbol, QgsStyle::defaultStyle(), nullptr, this );
244-
if ( dlg.exec() == QDialog::Rejected )
245-
{
246-
delete markerSymbol;
247-
}
248-
else
249-
{
250-
delete mMarkerSymbol;
251-
mMarkerSymbol = markerSymbol;
252-
if ( mMarkerSymbol )
253-
{
254-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mMarkerSymbol, mMarkerSymbolButton->iconSize() );
255-
mMarkerSymbolButton->setIcon( icon );
256-
}
257-
}
258-
}
259-
260187
void QgsDecorationGridDialog::on_mPbtnUpdateFromExtents_clicked()
261188
{
262189
updateInterval( true );

‎src/app/qgsdecorationgriddialog.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class APP_EXPORT QgsDecorationGridDialog : public QDialog, private Ui::QgsDecora
4040
void on_buttonBox_rejected();
4141
void on_buttonBox_helpRequested();
4242
void on_mGridTypeComboBox_currentIndexChanged( int index );
43-
void on_mLineSymbolButton_clicked();
44-
void on_mMarkerSymbolButton_clicked();
4543
void on_mPbtnUpdateFromExtents_clicked();
4644
void on_mPbtnUpdateFromLayer_clicked();
4745

@@ -51,8 +49,6 @@ class APP_EXPORT QgsDecorationGridDialog : public QDialog, private Ui::QgsDecora
5149

5250
private:
5351
QgsDecorationGrid &mDeco;
54-
QgsLineSymbol *mLineSymbol = nullptr;
55-
QgsMarkerSymbol *mMarkerSymbol = nullptr;
5652

5753
void updateGuiElements();
5854
void updateDecoFromGui();

‎src/app/qgsdecorationlayoutextentdialog.cpp

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,22 @@ QgsDecorationLayoutExtentDialog::QgsDecorationLayoutExtentDialog( QgsDecorationL
4444

4545
updateGuiElements();
4646
connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsDecorationLayoutExtentDialog::apply );
47-
connect( mSymbolButton, &QPushButton::clicked, this, &QgsDecorationLayoutExtentDialog::changeSymbol );
47+
48+
mSymbolButton->setMapCanvas( QgisApp::instance()->mapCanvas() );
4849
}
4950

5051
void QgsDecorationLayoutExtentDialog::updateGuiElements()
5152
{
5253
grpEnable->setChecked( mDeco.enabled() );
53-
54-
if ( mDeco.symbol() )
55-
{
56-
mSymbol.reset( static_cast<QgsFillSymbol *>( mDeco.symbol()->clone() ) );
57-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSymbol.get(), mSymbolButton->iconSize() );
58-
mSymbolButton->setIcon( icon );
59-
}
54+
mSymbolButton->setSymbol( mDeco.symbol()->clone() );
6055
mButtonFontStyle->setTextFormat( mDeco.textFormat() );
6156
mCheckBoxLabelExtents->setChecked( mDeco.labelExtents() );
6257
}
6358

6459
void QgsDecorationLayoutExtentDialog::updateDecoFromGui()
6560
{
6661
mDeco.setEnabled( grpEnable->isChecked() );
67-
68-
if ( mSymbol )
69-
{
70-
mDeco.setSymbol( mSymbol->clone() );
71-
}
62+
mDeco.setSymbol( mSymbolButton->clonedSymbol< QgsFillSymbol >() );
7263
mDeco.setTextFormat( mButtonFontStyle->textFormat() );
7364
mDeco.setLabelExtents( mCheckBoxLabelExtents->isChecked() );
7465
}
@@ -95,25 +86,3 @@ void QgsDecorationLayoutExtentDialog::on_buttonBox_rejected()
9586
{
9687
reject();
9788
}
98-
99-
void QgsDecorationLayoutExtentDialog::changeSymbol()
100-
{
101-
if ( !mSymbol )
102-
return;
103-
104-
QgsFillSymbol *symbol = mSymbol->clone();
105-
QgsSymbolSelectorDialog dlg( symbol, QgsStyle::defaultStyle(), nullptr, this );
106-
if ( dlg.exec() == QDialog::Rejected )
107-
{
108-
delete symbol;
109-
}
110-
else
111-
{
112-
mSymbol.reset( symbol );
113-
if ( mSymbol )
114-
{
115-
QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( mSymbol.get(), mSymbolButton->iconSize() );
116-
mSymbolButton->setIcon( icon );
117-
}
118-
}
119-
}

‎src/app/qgsdecorationlayoutextentdialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ class APP_EXPORT QgsDecorationLayoutExtentDialog : public QDialog, private Ui::Q
3939
void on_buttonBox_accepted();
4040
void on_buttonBox_rejected();
4141

42-
void changeSymbol();
4342

4443
private:
4544
QgsDecorationLayoutExtent &mDeco;
46-
std::unique_ptr< QgsFillSymbol > mSymbol;
4745

4846
void updateGuiElements();
4947
void updateDecoFromGui();

‎src/gui/symbology-ng/qgsnullsymbolrendererwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgis_gui.h"
2121

2222
class QgsNullSymbolRenderer;
23-
class QgsSymbolSelectorDialog;
2423

2524
class QMenu;
2625

‎src/gui/symbology-ng/qgsrendererwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class QgsDataDefinedSizeLegendWidget;
2828
class QgsVectorLayer;
2929
class QgsStyle;
3030
class QgsFeatureRenderer;
31-
class QgsSymbolSelectorDialog;
3231
class QgsMapCanvas;
3332

3433
/** \ingroup gui

‎src/ui/qgsdecorationgriddialog.ui

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -180,57 +180,13 @@
180180
</property>
181181
</widget>
182182
</item>
183-
<item row="5" column="1">
184-
<widget class="QPushButton" name="mLineSymbolButton">
185-
<property name="enabled">
186-
<bool>false</bool>
187-
</property>
188-
<property name="sizePolicy">
189-
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
190-
<horstretch>0</horstretch>
191-
<verstretch>0</verstretch>
192-
</sizepolicy>
193-
</property>
194-
<property name="minimumSize">
195-
<size>
196-
<width>100</width>
197-
<height>0</height>
198-
</size>
199-
</property>
200-
<property name="text">
201-
<string/>
202-
</property>
203-
</widget>
204-
</item>
205183
<item row="6" column="0">
206184
<widget class="QLabel" name="mMarkerSymbolLabel">
207185
<property name="text">
208186
<string>Marker symbol</string>
209187
</property>
210188
</widget>
211189
</item>
212-
<item row="6" column="1">
213-
<widget class="QPushButton" name="mMarkerSymbolButton">
214-
<property name="enabled">
215-
<bool>false</bool>
216-
</property>
217-
<property name="sizePolicy">
218-
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
219-
<horstretch>0</horstretch>
220-
<verstretch>0</verstretch>
221-
</sizepolicy>
222-
</property>
223-
<property name="minimumSize">
224-
<size>
225-
<width>100</width>
226-
<height>0</height>
227-
</size>
228-
</property>
229-
<property name="text">
230-
<string/>
231-
</property>
232-
</widget>
233-
</item>
234190
<item row="7" column="0" colspan="2">
235191
<widget class="Line" name="line_3">
236192
<property name="orientation">
@@ -300,6 +256,50 @@
300256
</property>
301257
</widget>
302258
</item>
259+
<item row="5" column="1">
260+
<widget class="QgsSymbolButton" name="mLineSymbolButton">
261+
<property name="enabled">
262+
<bool>false</bool>
263+
</property>
264+
<property name="sizePolicy">
265+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
266+
<horstretch>0</horstretch>
267+
<verstretch>0</verstretch>
268+
</sizepolicy>
269+
</property>
270+
<property name="minimumSize">
271+
<size>
272+
<width>100</width>
273+
<height>0</height>
274+
</size>
275+
</property>
276+
<property name="text">
277+
<string/>
278+
</property>
279+
</widget>
280+
</item>
281+
<item row="6" column="1">
282+
<widget class="QgsSymbolButton" name="mMarkerSymbolButton">
283+
<property name="enabled">
284+
<bool>false</bool>
285+
</property>
286+
<property name="sizePolicy">
287+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
288+
<horstretch>0</horstretch>
289+
<verstretch>0</verstretch>
290+
</sizepolicy>
291+
</property>
292+
<property name="minimumSize">
293+
<size>
294+
<width>100</width>
295+
<height>0</height>
296+
</size>
297+
</property>
298+
<property name="text">
299+
<string/>
300+
</property>
301+
</widget>
302+
</item>
303303
</layout>
304304
<zorder>mOffsetYEdit</zorder>
305305
<zorder>mOffsetXEdit</zorder>
@@ -334,6 +334,11 @@
334334
</layout>
335335
</widget>
336336
<customwidgets>
337+
<customwidget>
338+
<class>QgsSymbolButton</class>
339+
<extends>QToolButton</extends>
340+
<header>qgssymbolbutton.h</header>
341+
</customwidget>
337342
<customwidget>
338343
<class>QgsFontButton</class>
339344
<extends>QToolButton</extends>

‎src/ui/qgsdecorationlayoutextentdialog.ui

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,6 @@
6262
</property>
6363
</widget>
6464
</item>
65-
<item row="0" column="1">
66-
<widget class="QPushButton" name="mSymbolButton">
67-
<property name="enabled">
68-
<bool>false</bool>
69-
</property>
70-
<property name="sizePolicy">
71-
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
72-
<horstretch>0</horstretch>
73-
<verstretch>0</verstretch>
74-
</sizepolicy>
75-
</property>
76-
<property name="minimumSize">
77-
<size>
78-
<width>100</width>
79-
<height>0</height>
80-
</size>
81-
</property>
82-
<property name="text">
83-
<string/>
84-
</property>
85-
</widget>
86-
</item>
8765
<item row="0" column="2">
8866
<spacer name="horizontalSpacer">
8967
<property name="orientation">
@@ -110,6 +88,28 @@
11088
</property>
11189
</widget>
11290
</item>
91+
<item row="0" column="1">
92+
<widget class="QgsSymbolButton" name="mSymbolButton">
93+
<property name="enabled">
94+
<bool>false</bool>
95+
</property>
96+
<property name="sizePolicy">
97+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
98+
<horstretch>0</horstretch>
99+
<verstretch>0</verstretch>
100+
</sizepolicy>
101+
</property>
102+
<property name="minimumSize">
103+
<size>
104+
<width>100</width>
105+
<height>0</height>
106+
</size>
107+
</property>
108+
<property name="text">
109+
<string/>
110+
</property>
111+
</widget>
112+
</item>
113113
</layout>
114114
</widget>
115115
</item>
@@ -126,6 +126,11 @@
126126
</layout>
127127
</widget>
128128
<customwidgets>
129+
<customwidget>
130+
<class>QgsSymbolButton</class>
131+
<extends>QToolButton</extends>
132+
<header>qgssymbolbutton.h</header>
133+
</customwidget>
129134
<customwidget>
130135
<class>QgsFontButton</class>
131136
<extends>QToolButton</extends>
@@ -142,7 +147,7 @@
142147
<connection>
143148
<sender>grpEnable</sender>
144149
<signal>toggled(bool)</signal>
145-
<receiver>mSymbolButton</receiver>
150+
<receiver>mLineSymbolLabel</receiver>
146151
<slot>setEnabled(bool)</slot>
147152
<hints>
148153
<hint type="sourcelabel">

0 commit comments

Comments
 (0)
Please sign in to comment.