Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Layer properties dialogs: add style manager actions under Style button
This allows for more convenient configuration of layer styles and switching
between them compared to the context menu in the layer tree.

This code has been funded by Tuscany Region (Italy) - SITA (CIG: 6002233F59)
and commissioned to Gis3W s.a.s.
  • Loading branch information
wonder-sk committed Jan 19, 2015
1 parent 368fe68 commit 295f466
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 14 deletions.
64 changes: 50 additions & 14 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -29,6 +29,8 @@
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerstylemanager.h"
#include "qgsmaprenderer.h"
#include "qgsmaptoolemitpoint.h"
#include "qgsmaptopixel.h"
Expand Down Expand Up @@ -90,8 +92,11 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
m->addAction( tr( "Save As Default" ), this, SLOT( on_pbnSaveDefaultStyle_clicked() ) );
m->addAction( tr( "Restore Default" ), this, SLOT( on_pbnLoadDefaultStyle_clicked() ) );
b->setMenu( m );
connect( m, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowStyleMenu() ) );
buttonBox->addButton( b, QDialogButtonBox::ResetRole );

connect( lyr->styleManager(), SIGNAL( currentStyleChanged( QString ) ), this, SLOT( syncToLayer() ) );

connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );

Expand Down Expand Up @@ -1306,6 +1311,49 @@ void QgsRasterLayerProperties::transparencyCellTextEdited( const QString & text
}
}

void QgsRasterLayerProperties::aboutToShowStyleMenu()
{
// this should be unified with QgsVectorLayerProperties::aboutToShowStyleMenu()

QMenu* m = qobject_cast<QMenu*>( sender() );
if ( !m )
return;

// first get rid of previously added style manager actions (they are dynamic)
bool gotFirstSeparator = false;
QList<QAction*> actions = m->actions();
for ( int i = 0; i < actions.count(); ++i )
{
if ( actions[i]->isSeparator() )
{
if ( gotFirstSeparator )
{
// remove all actions after second separator (including it)
while ( actions.count() != i )
delete actions.takeAt( i );
break;
}
else
gotFirstSeparator = true;
}
}

// re-add style manager actions!
m->addSeparator();
QgsMapLayerStyleGuiUtils::instance()->addStyleManagerActions( m, mRasterLayer );
}

void QgsRasterLayerProperties::syncToLayer()
{
QgsRasterRenderer* renderer = mRasterLayer->renderer();
if ( renderer )
{
setRendererWidget( renderer->type() );
}
sync();
mRasterLayer->triggerRepaint();
}

void QgsRasterLayerProperties::setTransparencyToEdited( int row )
{
if ( row >= mTransparencyToEdited.size() )
Expand Down Expand Up @@ -1592,13 +1640,7 @@ void QgsRasterLayerProperties::on_pbnLoadDefaultStyle_clicked()
//reset if the default style was loaded ok only
if ( defaultLoadedFlag )
{
QgsRasterRenderer* renderer = mRasterLayer->renderer();
if ( renderer )
{
setRendererWidget( renderer->type() );
}
sync();
mRasterLayer->triggerRepaint();
syncToLayer();
}
else
{
Expand Down Expand Up @@ -1653,13 +1695,7 @@ void QgsRasterLayerProperties::on_pbnLoadStyle_clicked()
if ( defaultLoadedFlag )
{
settings.setValue( "style/lastStyleDir", QFileInfo( fileName ).absolutePath() );
QgsRasterRenderer* renderer = mRasterLayer->renderer();
if ( renderer )
{
setRendererWidget( renderer->type() );
}
sync();
mRasterLayer->triggerRepaint();
syncToLayer();
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -113,6 +113,11 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
/** Transparency cell changed */
void transparencyCellTextEdited( const QString & text );

void aboutToShowStyleMenu();

/** make GUI reflect the layer's state */
void syncToLayer();

signals:
/** emitted when changes to layer were saved to update legend */
void refreshLegend( QString layerID, bool expandItem );
Expand Down
37 changes: 37 additions & 0 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -36,6 +36,8 @@
#include "qgsgenericprojectionselector.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaplayerstyleguiutils.h"
#include "qgsmaplayerstylemanager.h"
#include "qgspluginmetadata.h"
#include "qgspluginregistry.h"
#include "qgsproject.h"
Expand Down Expand Up @@ -88,8 +90,11 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
m->addAction( tr( "Save As Default" ), this, SLOT( on_pbnSaveDefaultStyle_clicked() ) );
m->addAction( tr( "Restore Default" ), this, SLOT( on_pbnLoadDefaultStyle_clicked() ) );
b->setMenu( m );
connect( m, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowStyleMenu() ) );
buttonBox->addButton( b, QDialogButtonBox::ResetRole );

connect( lyr->styleManager(), SIGNAL( currentStyleChanged( QString ) ), this, SLOT( syncToLayer() ) );

connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) );
connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) );
connect( this, SIGNAL( rejected() ), this, SLOT( onCancel() ) );
Expand Down Expand Up @@ -941,6 +946,38 @@ void QgsVectorLayerProperties::loadStyleMenuTriggered( QAction *action )

}

void QgsVectorLayerProperties::aboutToShowStyleMenu()
{
// this should be unified with QgsRasterLayerProperties::aboutToShowStyleMenu()

QMenu* m = qobject_cast<QMenu*>( sender() );
if ( !m )
return;

// first get rid of previously added style manager actions (they are dynamic)
bool gotFirstSeparator = false;
QList<QAction*> actions = m->actions();
for ( int i = 0; i < actions.count(); ++i )
{
if ( actions[i]->isSeparator() )
{
if ( gotFirstSeparator )
{
// remove all actions after second separator (including it)
while ( actions.count() != i )
delete actions.takeAt( i );
break;
}
else
gotFirstSeparator = true;
}
}

// re-add style manager actions!
m->addSeparator();
QgsMapLayerStyleGuiUtils::instance()->addStyleManagerActions( m, layer );
}

void QgsVectorLayerProperties::showListOfStylesFromDatabase()
{
QString errorMsg;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -137,6 +137,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
/** called when is possible to choice if load the style from filesystem or from db */
void loadStyleMenuTriggered( QAction * );

void aboutToShowStyleMenu();

protected:

Expand Down

0 comments on commit 295f466

Please sign in to comment.