Skip to content
Permalink
Browse files

QgsMapLayerActionRegistry is no longer a singleton

Moved the global instance to QgsGui::QgsMapLayerActionRegistry()
  • Loading branch information
nyalldawson committed May 14, 2017
1 parent a86b93e commit 436844b205f310559f178fd75b1a78b1f3d05b71
@@ -1445,6 +1445,13 @@ screenUpdateRequested() were removed. These members have had no effect for a num
- the invalidTransformInput() slot was removed - calling this slot had no effect
- metadata() was renamed to htmlMetadata()


QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}
-------------------------

- This class is no longer a singleton and instance() has been removed. Instead use QgsGui::mapLayerActionRegistry().


QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
--------------------

@@ -49,6 +49,12 @@ class QgsGui
:rtype: QgsLayerTreeEmbeddedWidgetRegistry
%End

static QgsMapLayerActionRegistry *mapLayerActionRegistry();
%Docstring
Returns the global map layer action registry, used for registering map layer actions.
:rtype: QgsMapLayerActionRegistry
%End

~QgsGui();

private:
@@ -64,8 +64,8 @@ class QgsMapLayerActionRegistry : QObject
%End

public:
//! Returns the instance pointer, creating the object on the first call
static QgsMapLayerActionRegistry *instance();

QgsMapLayerActionRegistry( QObject *parent = 0 );

~QgsMapLayerActionRegistry();

@@ -83,10 +83,6 @@ class QgsMapLayerActionRegistry : QObject
/** Returns the default action for a layer*/
QgsMapLayerAction *defaultActionForLayer( QgsMapLayer *layer );

protected:
//! protected constructor
QgsMapLayerActionRegistry( QObject *parent = 0 );

signals:
/** Triggered when an action is added or removed from the registry */
void changed();
@@ -942,7 +942,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

activateDeactivateLayerRelatedActions( nullptr ); // after members were created

connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgisApp::refreshActionFeatureAction );
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgisApp::refreshActionFeatureAction );

// set application's caption
QString caption = tr( "QGIS - %1 ('%2')" ).arg( Qgis::QGIS_VERSION, Qgis::QGIS_RELEASE_NAME );
@@ -6288,7 +6288,7 @@ void QgisApp::updateDefaultFeatureAction( QAction *action )
if ( qgsAction.isValid() )
{
vlayer->actions()->setDefaultAction( QStringLiteral( "Canvas" ), qgsAction.id() );
QgsMapLayerActionRegistry::instance()->setDefaultActionForLayer( vlayer, nullptr );
QgsGui::mapLayerActionRegistry()->setDefaultActionForLayer( vlayer, nullptr );

mActionFeatureAction->setToolTip( tr( "Run feature action<br><b>%1</b>" ).arg( qgsAction.name() ) );

@@ -6303,7 +6303,7 @@ void QgisApp::updateDefaultFeatureAction( QAction *action )
QgsMapLayerAction *mapLayerAction = qobject_cast<QgsMapLayerAction *>( action );
if ( mapLayerAction )
{
QgsMapLayerActionRegistry::instance()->setDefaultActionForLayer( vlayer, mapLayerAction );
QgsGui::mapLayerActionRegistry()->setDefaultActionForLayer( vlayer, mapLayerAction );

if ( !mapLayerAction->text().isEmpty() )
mActionFeatureAction->setToolTip( tr( "Run feature action<br><b>%1</b>" ).arg( mapLayerAction->text() ) );
@@ -6313,7 +6313,7 @@ void QgisApp::updateDefaultFeatureAction( QAction *action )
}
else
{
QgsMapLayerActionRegistry::instance()->setDefaultActionForLayer( vlayer, nullptr );
QgsGui::mapLayerActionRegistry()->setDefaultActionForLayer( vlayer, nullptr );
}
}
}
@@ -6340,7 +6340,7 @@ void QgisApp::refreshFeatureActions()
}

//add actions registered in QgsMapLayerActionRegistry
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer );
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
if ( !actions.isEmpty() && registeredActions.size() > 0 )
{
//add a separator between user defined and standard actions
@@ -6350,7 +6350,7 @@ void QgisApp::refreshFeatureActions()
for ( int i = 0; i < registeredActions.size(); i++ )
{
mFeatureActionMenu->addAction( registeredActions.at( i ) );
if ( registeredActions.at( i ) == QgsMapLayerActionRegistry::instance()->defaultActionForLayer( vlayer ) )
if ( registeredActions.at( i ) == QgsGui::mapLayerActionRegistry()->defaultActionForLayer( vlayer ) )
{
mFeatureActionMenu->setActiveAction( registeredActions.at( i ) );
}
@@ -7296,7 +7296,7 @@ void QgisApp::setupLayoutManagerConnections()
QgsMapLayerAction *action = mAtlasFeatureActions.value( c );
if ( action )
{
QgsMapLayerActionRegistry::instance()->removeMapLayerAction( action );
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
delete action;
mAtlasFeatureActions.remove( c );
}
@@ -7309,7 +7309,7 @@ void QgisApp::setupAtlasMapLayerAction( QgsComposition *composition, bool enable
QgsMapLayerAction *action = mAtlasFeatureActions.value( composition );
if ( action )
{
QgsMapLayerActionRegistry::instance()->removeMapLayerAction( action );
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
delete action;
action = nullptr;
mAtlasFeatureActions.remove( composition );
@@ -7321,7 +7321,7 @@ void QgisApp::setupAtlasMapLayerAction( QgsComposition *composition, bool enable
this, composition->atlasComposition().coverageLayer(), QgsMapLayerAction::SingleFeature,
QgsApplication::getThemeIcon( QStringLiteral( "/mIconAtlas.svg" ) ) );
mAtlasFeatureActions.insert( composition, action );
QgsMapLayerActionRegistry::instance()->addMapLayerAction( action );
QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this, composition]( QgsMapLayer * layer, const QgsFeature & feat )
{
setCompositionAtlasFeature( composition, layer, feat );
@@ -11160,7 +11160,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )

bool isEditable = vlayer->isEditable();
bool layerHasSelection = vlayer->selectedFeatureCount() > 0;
bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer ).isEmpty();
bool isSpatial = vlayer->isSpatial();

mActionLocalHistogramStretch->setEnabled( false );
@@ -11458,7 +11458,7 @@ void QgisApp::refreshActionFeatureAction()
if ( !vlayer )
return;

bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer ).isEmpty();
mActionFeatureAction->setEnabled( layerHasActions );
}

@@ -483,7 +483,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
}

//get valid QgsMapLayerActions for this layer
QList< QgsMapLayerAction * > registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer );
QList< QgsMapLayerAction * > registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
QList<QgsAction> actions = vlayer->actions()->actions( QStringLiteral( "Feature" ) );

if ( !vlayer->fields().isEmpty() || !actions.isEmpty() || !registeredActions.isEmpty() )
@@ -1096,7 +1096,7 @@ void QgsIdentifyResultsDialog::contextMenuEvent( QContextMenuEvent *event )
if ( featItem && vlayer )
{
//get valid QgsMapLayerActions for this layer
QList< QgsMapLayerAction * > registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer );
QList< QgsMapLayerAction * > registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );

if ( !registeredActions.isEmpty() )
{
@@ -31,6 +31,7 @@
#include "qgsproject.h"
#include "qgsmaplayeractionregistry.h"
#include "qgisapp.h"
#include "qgsgui.h"

#include <QSettings>
#include <QMouseEvent>
@@ -72,7 +73,7 @@ void QgsMapToolFeatureAction::canvasReleaseEvent( QgsMapMouseEvent *e )
}

QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() && QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty() )
if ( vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() && QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer ).isEmpty() )
{
emit messageEmitted( tr( "The active vector layer has no defined actions" ), QgsMessageBar::INFO );
return;
@@ -146,7 +147,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
}
else
{
QgsMapLayerAction *mapLayerAction = QgsMapLayerActionRegistry::instance()->defaultActionForLayer( layer );
QgsMapLayerAction *mapLayerAction = QgsGui::mapLayerActionRegistry()->defaultActionForLayer( layer );
if ( mapLayerAction )
{
mapLayerAction->triggerForFeature( layer, &feat );
@@ -34,6 +34,7 @@
#include "qgsfeatureselectionmodel.h"
#include "qgsmaplayeractionregistry.h"
#include "qgsfeatureiterator.h"
#include "qgsgui.h"

QgsAttributeTableView::QgsAttributeTableView( QWidget *parent )
: QTableView( parent )
@@ -67,7 +68,7 @@ QgsAttributeTableView::QgsAttributeTableView( QWidget *parent )
connect( verticalHeader(), &QHeaderView::sectionEntered, this, &QgsAttributeTableView::_q_selectRow );
connect( horizontalHeader(), &QHeaderView::sectionResized, this, &QgsAttributeTableView::columnSizeChanged );
connect( horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &QgsAttributeTableView::showHorizontalSortIndicator );
connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgsAttributeTableView::recreateActionWidgets );
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsAttributeTableView::recreateActionWidgets );
}

bool QgsAttributeTableView::eventFilter( QObject *object, QEvent *event )
@@ -196,7 +197,7 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )

// next add any registered actions for this layer
Q_FOREACH ( QgsMapLayerAction *mapLayerAction,
QgsMapLayerActionRegistry::instance()->mapLayerActions( mFilterModel->layer(),
QgsGui::mapLayerActionRegistry()->mapLayerActions( mFilterModel->layer(),
QgsMapLayerAction::SingleFeature ) )
{
QAction *action = new QAction( mapLayerAction->icon(), mapLayerAction->text(), container );
@@ -208,7 +209,7 @@ QWidget *QgsAttributeTableView::createActionWidget( QgsFeatureId fid )
actionList << action;

if ( !defaultAction &&
QgsMapLayerActionRegistry::instance()->defaultActionForLayer( mFilterModel->layer() ) == mapLayerAction )
QgsGui::mapLayerActionRegistry()->defaultActionForLayer( mFilterModel->layer() ) == mapLayerAction )
defaultAction = action;
}

@@ -479,7 +479,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
}

//add actions from QgsMapLayerActionRegistry to context menu
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayer );
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer );
if ( !registeredActions.isEmpty() )
{
//add a separator between user defined and standard actions
@@ -18,6 +18,7 @@
#include "qgsmaplayeractionregistry.h"
#include "qgsactionmanager.h"
#include "qgsfeatureiterator.h"
#include "qgsgui.h"

QgsActionMenu::QgsActionMenu( QgsVectorLayer *layer, const QgsFeature &feature, const QString &actionScope, QWidget *parent )
: QMenu( parent )
@@ -42,7 +43,7 @@ void QgsActionMenu::init()
{
setTitle( tr( "&Actions" ) );

connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );

reloadActions();
}
@@ -123,7 +124,7 @@ void QgsActionMenu::reloadActions()
addAction( qAction );
}

QList<QgsMapLayerAction *> mapLayerActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayer, QgsMapLayerAction::SingleFeature );
QList<QgsMapLayerAction *> mapLayerActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer, QgsMapLayerAction::SingleFeature );

if ( !mapLayerActions.isEmpty() )
{
@@ -18,6 +18,7 @@
#include "qgsgui.h"
#include "qgseditorwidgetregistry.h"
#include "qgslayertreeembeddedwidgetregistry.h"
#include "qgsmaplayeractionregistry.h"
#include "qgsshortcutsmanager.h"

QgsGui *QgsGui::instance()
@@ -41,16 +42,23 @@ QgsLayerTreeEmbeddedWidgetRegistry *QgsGui::layerTreeEmbeddedWidgetRegistry()
return instance()->mLayerTreeEmbeddedWidgetRegistry;
}

QgsMapLayerActionRegistry *QgsGui::mapLayerActionRegistry()
{
return instance()->mMapLayerActionRegistry;
}

QgsGui::~QgsGui()
{
delete mLayerTreeEmbeddedWidgetRegistry;
delete mEditorWidgetRegistry;
delete mMapLayerActionRegistry;
delete mShortcutsManager;
delete mLayerTreeEmbeddedWidgetRegistry;
}

QgsGui::QgsGui()
{
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
mShortcutsManager = new QgsShortcutsManager();
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
}
@@ -23,6 +23,7 @@
class QgsEditorWidgetRegistry;
class QgsShortcutsManager;
class QgsLayerTreeEmbeddedWidgetRegistry;
class QgsMapLayerActionRegistry;

/**
* \ingroup gui
@@ -60,6 +61,11 @@ class GUI_EXPORT QgsGui
*/
static QgsLayerTreeEmbeddedWidgetRegistry *layerTreeEmbeddedWidgetRegistry();

/**
* Returns the global map layer action registry, used for registering map layer actions.
*/
static QgsMapLayerActionRegistry *mapLayerActionRegistry();

~QgsGui();

private:
@@ -69,6 +75,7 @@ class GUI_EXPORT QgsGui
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
QgsShortcutsManager *mShortcutsManager = nullptr;
QgsLayerTreeEmbeddedWidgetRegistry *mLayerTreeEmbeddedWidgetRegistry = nullptr;
QgsMapLayerActionRegistry *mMapLayerActionRegistry = nullptr;

#ifdef SIP_RUN
QgsGui( const QgsGui &other );
@@ -24,11 +24,11 @@
#include "qgsvectorlayer.h"
#include "qgslogger.h"
#include "qgssettings.h"

#include "qgsgui.h"

/// @cond PRIVATE
CustomActionRegistry::CustomActionRegistry( QObject *parent )
: QgsMapLayerActionRegistry( parent )
CustomActionRegistry::CustomActionRegistry()
: QgsMapLayerActionRegistry()
{
}
///@endcond
@@ -43,7 +43,6 @@ QgsIdentifyMenu::QgsIdentifyMenu( QgsMapCanvas *canvas )
, mMaxLayerDisplay( 10 )
, mMaxFeatureDisplay( 10 )
, mDefaultActionName( tr( "Identify" ) )
, mCustomActionRegistry( CustomActionRegistry::instance() )
{
}

@@ -178,7 +177,7 @@ void QgsIdentifyMenu::addRasterLayer( QgsMapLayer *layer )
}
if ( mShowFeatureActions )
{
layerActions.append( QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, QgsMapLayerAction::Layer ) );
layerActions.append( QgsGui::mapLayerActionRegistry()->mapLayerActions( layer, QgsMapLayerAction::Layer ) );
if ( layerActions.count() > nCustomActions )
{
separators.append( layerActions[nCustomActions] );
@@ -245,7 +244,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
}
if ( mShowFeatureActions )
{
layerActions << QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, targets );
layerActions << QgsGui::mapLayerActionRegistry()->mapLayerActions( layer, targets );

if ( layerActions.count() > nCustomActions )
{
@@ -30,7 +30,7 @@ class CustomActionRegistry : public QgsMapLayerActionRegistry
Q_OBJECT

public:
explicit CustomActionRegistry( QObject *parent );
CustomActionRegistry();
// remove all actions
void clear() { mMapLayerActionList.clear(); }
};

0 comments on commit 436844b

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