Skip to content
Permalink
Browse files

Add apply button to label properties dialog

  • Loading branch information
nyalldawson committed Mar 29, 2015
1 parent bdcfa01 commit 08d4d3bad54040ec049865b717a1d44c6f079d98
@@ -26,6 +26,7 @@
#include <QColorDialog>
#include <QFontDatabase>
#include <QSettings>
#include <QDialogButtonBox>


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

void QgsLabelPropertyDialog::on_buttonBox_clicked( QAbstractButton *button )
{
if ( buttonBox->buttonRole( button ) == QDialogButtonBox::ApplyRole )
{
emit applied();
}
}

void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const QString& labelText )
{
//get feature attributes
@@ -35,7 +35,15 @@ class APP_EXPORT QgsLabelPropertyDialog: public QDialog, private Ui::QgsLabelPro
/**Returns properties changed by the user*/
const QgsAttributeMap& changedProperties() const { return mChangedProperties; }

signals:

/** Emitted when dialog settings are applied
* @note added in QGIS 2.9
*/
void applied();

private slots:
void on_buttonBox_clicked( QAbstractButton * button );
void on_mShowLabelChkbx_toggled( bool chkd );
void on_mAlwaysShowChkbx_toggled( bool chkd );
void on_mMinScaleSpinBox_valueChanged( int i );
@@ -62,24 +62,44 @@ void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
}

QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCurrentLabelPos.labelFont, labeltext, 0 );

connect( &d, SIGNAL( applied() ), this, SLOT( dialogPropertiesApplied() ) );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );

QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
}

vlayer->endEditCommand();
mCanvas->refresh();
}
applyChanges( d.changedProperties() );
}

deleteRubberBands();
}
}

void QgsMapToolChangeLabelProperties::applyChanges( const QgsAttributeMap& changes )
{
QgsVectorLayer* vlayer = currentLayer();
if ( !vlayer )
return;

if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );

QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
}

vlayer->endEditCommand();
mCanvas->refresh();
}
}

void QgsMapToolChangeLabelProperties::dialogPropertiesApplied()
{
QgsLabelPropertyDialog* dlg = qobject_cast<QgsLabelPropertyDialog*>( sender() );
if ( !dlg )
return;

applyChanges( dlg->changedProperties() );
}

@@ -31,6 +31,18 @@ class APP_EXPORT QgsMapToolChangeLabelProperties: public QgsMapToolLabel
virtual void canvasPressEvent( QMouseEvent * e ) override;
virtual void canvasReleaseEvent( QMouseEvent * e ) override;

protected:

/** Applies the label property changes
* @param changes attribute map of changes
* @note added in QGIS 2.9
*/
void applyChanges( const QgsAttributeMap& changes );

private slots:

void dialogPropertiesApplied();

};

#endif // QGSMAPTOOLCHANGELABEL_H
@@ -616,7 +616,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>

0 comments on commit 08d4d3b

Please sign in to comment.
You can’t perform that action at this time.