Skip to content

Commit 08d4d3b

Browse files
committed
Add apply button to label properties dialog
1 parent bdcfa01 commit 08d4d3b

5 files changed

+64
-15
lines changed

src/app/qgslabelpropertydialog.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <QColorDialog>
2727
#include <QFontDatabase>
2828
#include <QSettings>
29+
#include <QDialogButtonBox>
2930

3031

3132
QgsLabelPropertyDialog::QgsLabelPropertyDialog( const QString& layerId, int featureId, const QFont& labelFont, const QString& labelText, QWidget * parent, Qt::WindowFlags f ):
@@ -47,6 +48,14 @@ QgsLabelPropertyDialog::~QgsLabelPropertyDialog()
4748
settings.setValue( QString( "/Windows/ChangeLabelProps/geometry" ), saveGeometry() );
4849
}
4950

51+
void QgsLabelPropertyDialog::on_buttonBox_clicked( QAbstractButton *button )
52+
{
53+
if ( buttonBox->buttonRole( button ) == QDialogButtonBox::ApplyRole )
54+
{
55+
emit applied();
56+
}
57+
}
58+
5059
void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const QString& labelText )
5160
{
5261
//get feature attributes

src/app/qgslabelpropertydialog.h

+8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ class APP_EXPORT QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPro
3535
/**Returns properties changed by the user*/
3636
const QgsAttributeMap& changedProperties() const { return mChangedProperties; }
3737

38+
signals:
39+
40+
/** Emitted when dialog settings are applied
41+
* @note added in QGIS 2.9
42+
*/
43+
void applied();
44+
3845
private slots:
46+
void on_buttonBox_clicked( QAbstractButton * button );
3947
void on_mShowLabelChkbx_toggled( bool chkd );
4048
void on_mAlwaysShowChkbx_toggled( bool chkd );
4149
void on_mMinScaleSpinBox_valueChanged( int i );

src/app/qgsmaptoolchangelabelproperties.cpp

+34-14
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,44 @@ void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
6262
}
6363

6464
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCurrentLabelPos.labelFont, labeltext, 0 );
65+
66+
connect( &d, SIGNAL( applied() ), this, SLOT( dialogPropertiesApplied() ) );
6567
if ( d.exec() == QDialog::Accepted )
6668
{
67-
const QgsAttributeMap& changes = d.changedProperties();
68-
if ( changes.size() > 0 )
69-
{
70-
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
71-
72-
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
73-
for ( ; changeIt != changes.constEnd(); ++changeIt )
74-
{
75-
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
76-
}
77-
78-
vlayer->endEditCommand();
79-
mCanvas->refresh();
80-
}
69+
applyChanges( d.changedProperties() );
8170
}
71+
8272
deleteRubberBands();
8373
}
8474
}
8575

76+
void QgsMapToolChangeLabelProperties::applyChanges( const QgsAttributeMap& changes )
77+
{
78+
QgsVectorLayer* vlayer = currentLayer();
79+
if ( !vlayer )
80+
return;
81+
82+
if ( changes.size() > 0 )
83+
{
84+
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
85+
86+
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
87+
for ( ; changeIt != changes.constEnd(); ++changeIt )
88+
{
89+
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
90+
}
91+
92+
vlayer->endEditCommand();
93+
mCanvas->refresh();
94+
}
95+
}
96+
97+
void QgsMapToolChangeLabelProperties::dialogPropertiesApplied()
98+
{
99+
QgsLabelPropertyDialog* dlg = qobject_cast<QgsLabelPropertyDialog*>( sender() );
100+
if ( !dlg )
101+
return;
102+
103+
applyChanges( dlg->changedProperties() );
104+
}
105+

src/app/qgsmaptoolchangelabelproperties.h

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ class APP_EXPORT QgsMapToolChangeLabelProperties: public QgsMapToolLabel
3131
virtual void canvasPressEvent( QMouseEvent * e ) override;
3232
virtual void canvasReleaseEvent( QMouseEvent * e ) override;
3333

34+
protected:
35+
36+
/** Applies the label property changes
37+
* @param changes attribute map of changes
38+
* @note added in QGIS 2.9
39+
*/
40+
void applyChanges( const QgsAttributeMap& changes );
41+
42+
private slots:
43+
44+
void dialogPropertiesApplied();
45+
3446
};
3547

3648
#endif // QGSMAPTOOLCHANGELABEL_H

src/ui/qgslabelpropertydialogbase.ui

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@
616616
<enum>Qt::Horizontal</enum>
617617
</property>
618618
<property name="standardButtons">
619-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
619+
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
620620
</property>
621621
</widget>
622622
</item>

0 commit comments

Comments
 (0)