Skip to content
Permalink
Browse files

Swap 'set atlas feature' action from compositions to layouts

Time to start making a permenant switch...
  • Loading branch information
nyalldawson committed Jan 1, 2018
1 parent 39ae0ee commit a730eb7a95b4056c9e9808b772421ee65ec504da
Showing with 70 additions and 33 deletions.
  1. +23 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  2. +5 −0 src/app/layout/qgslayoutdesignerdialog.h
  3. +38 −30 src/app/qgisapp.cpp
  4. +4 −3 src/app/qgisapp.h
@@ -3600,4 +3600,27 @@ QgsMessageBar *QgsLayoutDesignerDialog::messageBar()
return mMessageBar;
}

void QgsLayoutDesignerDialog::setAtlasFeature( QgsMapLayer *layer, const QgsFeature &feat )
{
QgsLayoutAtlas *layoutAtlas = atlas();
if ( !layoutAtlas || !layoutAtlas->enabled() || layoutAtlas->coverageLayer() != layer )
{
//either atlas isn't enabled, or layer doesn't match
return;
}

if ( !mActionAtlasPreview->isChecked() )
{
//update gui controls
whileBlocking( mActionAtlasPreview )->setChecked( true );
atlasPreviewTriggered( true );
}

//set current preview feature id
layoutAtlas->seekTo( feat );

//bring layout window to foreground
activate();
}


@@ -138,6 +138,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
QgsMessageBar *messageBar();

/**
* Sets the specified feature as the current atlas feature
*/
void setAtlasFeature( QgsMapLayer *layer, const QgsFeature &feat );

public slots:

/**
@@ -206,6 +206,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgslayertreeview.h"
#include "qgslayertreeviewdefaultactions.h"
#include "qgslayout.h"
#include "qgslayoutatlas.h"
#include "qgslayoutcustomdrophandler.h"
#include "qgslayoutdesignerdialog.h"
#include "qgslayoutmanager.h"
@@ -7560,81 +7561,88 @@ void QgisApp::deleteLayoutDesigners()
void QgisApp::setupLayoutManagerConnections()
{
QgsLayoutManager *manager = QgsProject::instance()->layoutManager();
connect( manager, &QgsLayoutManager::compositionAdded, this, [ = ]( const QString & name )
connect( manager, &QgsLayoutManager::layoutAdded, this, [ = ]( const QString & name )
{
QgsComposition *c = QgsProject::instance()->layoutManager()->compositionByName( name );
if ( !c )
QgsMasterLayoutInterface *l = QgsProject::instance()->layoutManager()->layoutByName( name );
if ( !l )
return;
QgsPrintLayout *pl = dynamic_cast< QgsPrintLayout *>( l );
if ( !pl )
return;

mAtlasFeatureActions.insert( c, nullptr );
connect( c, &QgsComposition::nameChanged, this, [this, c]( const QString & name )
mAtlasFeatureActions.insert( pl, nullptr );
connect( pl, &QgsPrintLayout::nameChanged, this, [this, pl]( const QString & name )
{
QgsMapLayerAction *action = mAtlasFeatureActions.value( c );
QgsMapLayerAction *action = mAtlasFeatureActions.value( pl );
if ( action )
{
action->setText( QString( tr( "Set as atlas feature for %1" ) ).arg( name ) );
}
} );

connect( &c->atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, this, [this, c]( QgsVectorLayer * coverageLayer )
connect( pl->atlas(), &QgsLayoutAtlas::coverageLayerChanged, this, [this, pl]( QgsVectorLayer * coverageLayer )
{
setupAtlasMapLayerAction( c, static_cast< bool >( coverageLayer ) );
setupAtlasMapLayerAction( pl, static_cast< bool >( coverageLayer ) );
} );

connect( &c->atlasComposition(), &QgsAtlasComposition::toggled, this, [this, c]( bool enabled )
connect( pl->atlas(), &QgsLayoutAtlas::toggled, this, [this, pl]( bool enabled )
{
setupAtlasMapLayerAction( c, enabled );
setupAtlasMapLayerAction( pl, enabled );
} );

setupAtlasMapLayerAction( c, c->atlasComposition().enabled() && c->atlasComposition().coverageLayer() );
setupAtlasMapLayerAction( pl, pl->atlas()->enabled() && pl->atlas()->coverageLayer() );
} );

connect( manager, &QgsLayoutManager::compositionAboutToBeRemoved, this, [ = ]( const QString & name )
connect( manager, &QgsLayoutManager::layoutAboutToBeRemoved, this, [ = ]( const QString & name )
{
QgsComposition *c = QgsProject::instance()->layoutManager()->compositionByName( name );
if ( c )
QgsMasterLayoutInterface *l = QgsProject::instance()->layoutManager()->layoutByName( name );
if ( l )
{
QgsMapLayerAction *action = mAtlasFeatureActions.value( c );
if ( action )
QgsPrintLayout *pl = dynamic_cast< QgsPrintLayout * >( l );
if ( pl )
{
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
delete action;
mAtlasFeatureActions.remove( c );
QgsMapLayerAction *action = mAtlasFeatureActions.value( pl );
if ( action )
{
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
delete action;
mAtlasFeatureActions.remove( pl );
}
}
}
} );
}

void QgisApp::setupAtlasMapLayerAction( QgsComposition *composition, bool enableAction )
void QgisApp::setupAtlasMapLayerAction( QgsPrintLayout *layout, bool enableAction )
{
QgsMapLayerAction *action = mAtlasFeatureActions.value( composition );
QgsMapLayerAction *action = mAtlasFeatureActions.value( layout );
if ( action )
{
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
delete action;
action = nullptr;
mAtlasFeatureActions.remove( composition );
mAtlasFeatureActions.remove( layout );
}

if ( enableAction )
{
action = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( composition->name() ),
this, composition->atlasComposition().coverageLayer(), QgsMapLayerAction::SingleFeature,
action = new QgsMapLayerAction( QString( tr( "Set as atlas feature for %1" ) ).arg( layout->name() ),
this, layout->atlas()->coverageLayer(), QgsMapLayerAction::SingleFeature,
QgsApplication::getThemeIcon( QStringLiteral( "/mIconAtlas.svg" ) ) );
mAtlasFeatureActions.insert( composition, action );
mAtlasFeatureActions.insert( layout, action );
QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this, composition]( QgsMapLayer * layer, const QgsFeature & feat )
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this, layout]( QgsMapLayer * layer, const QgsFeature & feat )
{
setCompositionAtlasFeature( composition, layer, feat );
setLayoutAtlasFeature( layout, layer, feat );
}
);
}
}

void QgisApp::setCompositionAtlasFeature( QgsComposition *composition, QgsMapLayer *layer, const QgsFeature &feat )
void QgisApp::setLayoutAtlasFeature( QgsPrintLayout *layout, QgsMapLayer *layer, const QgsFeature &feat )
{
QgsComposer *composer = openComposer( composition );
composer->setAtlasFeature( layer, feat );
QgsLayoutDesignerDialog *designer = openLayoutDesignerDialog( layout );
designer->setAtlasFeature( layer, feat );
}

void QgisApp::composerMenuAboutToShow()
@@ -81,6 +81,7 @@ class QgsPluginLayer;
class QgsPluginLayer;
class QgsPluginManager;
class QgsPointXY;
class QgsPrintLayout;
class QgsProviderRegistry;
class QgsPythonUtils;
class QgsRasterLayer;
@@ -1780,9 +1781,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

void setupLayoutManagerConnections();

void setupAtlasMapLayerAction( QgsComposition *composition, bool enableAction );
void setupAtlasMapLayerAction( QgsPrintLayout *layout, bool enableAction );

void setCompositionAtlasFeature( QgsComposition *composition, QgsMapLayer *layer, const QgsFeature &feat );
void setLayoutAtlasFeature( QgsPrintLayout *layout, QgsMapLayer *layer, const QgsFeature &feat );

void saveAsVectorFileGeneral( QgsVectorLayer *vlayer = nullptr, bool symbologyOption = true );

@@ -2187,7 +2188,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

QStackedWidget *mCentralContainer = nullptr;

QHash< QgsComposition *, QgsMapLayerAction * > mAtlasFeatureActions;
QHash< QgsPrintLayout *, QgsMapLayerAction * > mAtlasFeatureActions;

int mProjOpen = 0;

0 comments on commit a730eb7

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