Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add apply button to label properties dialog
  • Loading branch information
nyalldawson committed Mar 29, 2015
1 parent bdcfa01 commit 08d4d3b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/app/qgslabelpropertydialog.cpp
Expand Up @@ -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 ):
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/app/qgslabelpropertydialog.h
Expand Up @@ -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 );
Expand Down
48 changes: 34 additions & 14 deletions src/app/qgsmaptoolchangelabelproperties.cpp
Expand Up @@ -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() );
}

12 changes: 12 additions & 0 deletions src/app/qgsmaptoolchangelabelproperties.h
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/ui/qgslabelpropertydialogbase.ui
Expand Up @@ -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>
Expand Down

0 comments on commit 08d4d3b

Please sign in to comment.