Skip to content

Commit 436844b

Browse files
committed
QgsMapLayerActionRegistry is no longer a singleton
Moved the global instance to QgsGui::QgsMapLayerActionRegistry()
1 parent a86b93e commit 436844b

15 files changed

+75
-57
lines changed

doc/api_break.dox

+7
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,13 @@ screenUpdateRequested() were removed. These members have had no effect for a num
14451445
- the invalidTransformInput() slot was removed - calling this slot had no effect
14461446
- metadata() was renamed to htmlMetadata()
14471447

1448+
1449+
QgsMapLayerActionRegistry {#qgis_api_break_3_0_QgsMapLayerActionRegistry}
1450+
-------------------------
1451+
1452+
- This class is no longer a singleton and instance() has been removed. Instead use QgsGui::mapLayerActionRegistry().
1453+
1454+
14481455
QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
14491456
--------------------
14501457

python/gui/qgsgui.sip

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class QgsGui
4949
:rtype: QgsLayerTreeEmbeddedWidgetRegistry
5050
%End
5151

52+
static QgsMapLayerActionRegistry *mapLayerActionRegistry();
53+
%Docstring
54+
Returns the global map layer action registry, used for registering map layer actions.
55+
:rtype: QgsMapLayerActionRegistry
56+
%End
57+
5258
~QgsGui();
5359

5460
private:

python/gui/qgsmaplayeractionregistry.sip

+2-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class QgsMapLayerActionRegistry : QObject
6464
%End
6565

6666
public:
67-
//! Returns the instance pointer, creating the object on the first call
68-
static QgsMapLayerActionRegistry *instance();
67+
68+
QgsMapLayerActionRegistry( QObject *parent = 0 );
6969

7070
~QgsMapLayerActionRegistry();
7171

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

86-
protected:
87-
//! protected constructor
88-
QgsMapLayerActionRegistry( QObject *parent = 0 );
89-
9086
signals:
9187
/** Triggered when an action is added or removed from the registry */
9288
void changed();

src/app/qgisapp.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
942942

943943
activateDeactivateLayerRelatedActions( nullptr ); // after members were created
944944

945-
connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgisApp::refreshActionFeatureAction );
945+
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgisApp::refreshActionFeatureAction );
946946

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

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

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

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

63426342
//add actions registered in QgsMapLayerActionRegistry
6343-
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer );
6343+
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer );
63446344
if ( !actions.isEmpty() && registeredActions.size() > 0 )
63456345
{
63466346
//add a separator between user defined and standard actions
@@ -6350,7 +6350,7 @@ void QgisApp::refreshFeatureActions()
63506350
for ( int i = 0; i < registeredActions.size(); i++ )
63516351
{
63526352
mFeatureActionMenu->addAction( registeredActions.at( i ) );
6353-
if ( registeredActions.at( i ) == QgsMapLayerActionRegistry::instance()->defaultActionForLayer( vlayer ) )
6353+
if ( registeredActions.at( i ) == QgsGui::mapLayerActionRegistry()->defaultActionForLayer( vlayer ) )
63546354
{
63556355
mFeatureActionMenu->setActiveAction( registeredActions.at( i ) );
63566356
}
@@ -7296,7 +7296,7 @@ void QgisApp::setupLayoutManagerConnections()
72967296
QgsMapLayerAction *action = mAtlasFeatureActions.value( c );
72977297
if ( action )
72987298
{
7299-
QgsMapLayerActionRegistry::instance()->removeMapLayerAction( action );
7299+
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
73007300
delete action;
73017301
mAtlasFeatureActions.remove( c );
73027302
}
@@ -7309,7 +7309,7 @@ void QgisApp::setupAtlasMapLayerAction( QgsComposition *composition, bool enable
73097309
QgsMapLayerAction *action = mAtlasFeatureActions.value( composition );
73107310
if ( action )
73117311
{
7312-
QgsMapLayerActionRegistry::instance()->removeMapLayerAction( action );
7312+
QgsGui::mapLayerActionRegistry()->removeMapLayerAction( action );
73137313
delete action;
73147314
action = nullptr;
73157315
mAtlasFeatureActions.remove( composition );
@@ -7321,7 +7321,7 @@ void QgisApp::setupAtlasMapLayerAction( QgsComposition *composition, bool enable
73217321
this, composition->atlasComposition().coverageLayer(), QgsMapLayerAction::SingleFeature,
73227322
QgsApplication::getThemeIcon( QStringLiteral( "/mIconAtlas.svg" ) ) );
73237323
mAtlasFeatureActions.insert( composition, action );
7324-
QgsMapLayerActionRegistry::instance()->addMapLayerAction( action );
7324+
QgsGui::mapLayerActionRegistry()->addMapLayerAction( action );
73257325
connect( action, &QgsMapLayerAction::triggeredForFeature, this, [this, composition]( QgsMapLayer * layer, const QgsFeature & feat )
73267326
{
73277327
setCompositionAtlasFeature( composition, layer, feat );
@@ -11160,7 +11160,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer *layer )
1116011160

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

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

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

src/app/qgsidentifyresultsdialog.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
483483
}
484484

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

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

11011101
if ( !registeredActions.isEmpty() )
11021102
{

src/app/qgsmaptoolfeatureaction.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgsproject.h"
3232
#include "qgsmaplayeractionregistry.h"
3333
#include "qgisapp.h"
34+
#include "qgsgui.h"
3435

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

7475
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
75-
if ( vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() && QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty() )
76+
if ( vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() && QgsGui::mapLayerActionRegistry()->mapLayerActions( vlayer ).isEmpty() )
7677
{
7778
emit messageEmitted( tr( "The active vector layer has no defined actions" ), QgsMessageBar::INFO );
7879
return;
@@ -146,7 +147,7 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
146147
}
147148
else
148149
{
149-
QgsMapLayerAction *mapLayerAction = QgsMapLayerActionRegistry::instance()->defaultActionForLayer( layer );
150+
QgsMapLayerAction *mapLayerAction = QgsGui::mapLayerActionRegistry()->defaultActionForLayer( layer );
150151
if ( mapLayerAction )
151152
{
152153
mapLayerAction->triggerForFeature( layer, &feat );

src/gui/attributetable/qgsattributetableview.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "qgsfeatureselectionmodel.h"
3535
#include "qgsmaplayeractionregistry.h"
3636
#include "qgsfeatureiterator.h"
37+
#include "qgsgui.h"
3738

3839
QgsAttributeTableView::QgsAttributeTableView( QWidget *parent )
3940
: QTableView( parent )
@@ -67,7 +68,7 @@ QgsAttributeTableView::QgsAttributeTableView( QWidget *parent )
6768
connect( verticalHeader(), &QHeaderView::sectionEntered, this, &QgsAttributeTableView::_q_selectRow );
6869
connect( horizontalHeader(), &QHeaderView::sectionResized, this, &QgsAttributeTableView::columnSizeChanged );
6970
connect( horizontalHeader(), &QHeaderView::sortIndicatorChanged, this, &QgsAttributeTableView::showHorizontalSortIndicator );
70-
connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgsAttributeTableView::recreateActionWidgets );
71+
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsAttributeTableView::recreateActionWidgets );
7172
}
7273

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

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

210211
if ( !defaultAction &&
211-
QgsMapLayerActionRegistry::instance()->defaultActionForLayer( mFilterModel->layer() ) == mapLayerAction )
212+
QgsGui::mapLayerActionRegistry()->defaultActionForLayer( mFilterModel->layer() ) == mapLayerAction )
212213
defaultAction = action;
213214
}
214215

src/gui/attributetable/qgsdualview.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu *menu, const QModelIndex &atInd
479479
}
480480

481481
//add actions from QgsMapLayerActionRegistry to context menu
482-
QList<QgsMapLayerAction *> registeredActions = QgsMapLayerActionRegistry::instance()->mapLayerActions( mLayer );
482+
QList<QgsMapLayerAction *> registeredActions = QgsGui::mapLayerActionRegistry()->mapLayerActions( mLayer );
483483
if ( !registeredActions.isEmpty() )
484484
{
485485
//add a separator between user defined and standard actions

src/gui/qgsactionmenu.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmaplayeractionregistry.h"
1919
#include "qgsactionmanager.h"
2020
#include "qgsfeatureiterator.h"
21+
#include "qgsgui.h"
2122

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

45-
connect( QgsMapLayerActionRegistry::instance(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );
46+
connect( QgsGui::mapLayerActionRegistry(), &QgsMapLayerActionRegistry::changed, this, &QgsActionMenu::reloadActions );
4647

4748
reloadActions();
4849
}
@@ -123,7 +124,7 @@ void QgsActionMenu::reloadActions()
123124
addAction( qAction );
124125
}
125126

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

128129
if ( !mapLayerActions.isEmpty() )
129130
{

src/gui/qgsgui.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsgui.h"
1919
#include "qgseditorwidgetregistry.h"
2020
#include "qgslayertreeembeddedwidgetregistry.h"
21+
#include "qgsmaplayeractionregistry.h"
2122
#include "qgsshortcutsmanager.h"
2223

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

45+
QgsMapLayerActionRegistry *QgsGui::mapLayerActionRegistry()
46+
{
47+
return instance()->mMapLayerActionRegistry;
48+
}
49+
4450
QgsGui::~QgsGui()
4551
{
52+
delete mLayerTreeEmbeddedWidgetRegistry;
4653
delete mEditorWidgetRegistry;
54+
delete mMapLayerActionRegistry;
4755
delete mShortcutsManager;
48-
delete mLayerTreeEmbeddedWidgetRegistry;
4956
}
5057

5158
QgsGui::QgsGui()
5259
{
5360
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
5461
mShortcutsManager = new QgsShortcutsManager();
5562
mLayerTreeEmbeddedWidgetRegistry = new QgsLayerTreeEmbeddedWidgetRegistry();
63+
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
5664
}

src/gui/qgsgui.h

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class QgsEditorWidgetRegistry;
2424
class QgsShortcutsManager;
2525
class QgsLayerTreeEmbeddedWidgetRegistry;
26+
class QgsMapLayerActionRegistry;
2627

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

64+
/**
65+
* Returns the global map layer action registry, used for registering map layer actions.
66+
*/
67+
static QgsMapLayerActionRegistry *mapLayerActionRegistry();
68+
6369
~QgsGui();
6470

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

7380
#ifdef SIP_RUN
7481
QgsGui( const QgsGui &other );

src/gui/qgsidentifymenu.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#include "qgsvectorlayer.h"
2525
#include "qgslogger.h"
2626
#include "qgssettings.h"
27-
27+
#include "qgsgui.h"
2828

2929
/// @cond PRIVATE
30-
CustomActionRegistry::CustomActionRegistry( QObject *parent )
31-
: QgsMapLayerActionRegistry( parent )
30+
CustomActionRegistry::CustomActionRegistry()
31+
: QgsMapLayerActionRegistry()
3232
{
3333
}
3434
///@endcond
@@ -43,7 +43,6 @@ QgsIdentifyMenu::QgsIdentifyMenu( QgsMapCanvas *canvas )
4343
, mMaxLayerDisplay( 10 )
4444
, mMaxFeatureDisplay( 10 )
4545
, mDefaultActionName( tr( "Identify" ) )
46-
, mCustomActionRegistry( CustomActionRegistry::instance() )
4746
{
4847
}
4948

@@ -178,7 +177,7 @@ void QgsIdentifyMenu::addRasterLayer( QgsMapLayer *layer )
178177
}
179178
if ( mShowFeatureActions )
180179
{
181-
layerActions.append( QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, QgsMapLayerAction::Layer ) );
180+
layerActions.append( QgsGui::mapLayerActionRegistry()->mapLayerActions( layer, QgsMapLayerAction::Layer ) );
182181
if ( layerActions.count() > nCustomActions )
183182
{
184183
separators.append( layerActions[nCustomActions] );
@@ -245,7 +244,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
245244
}
246245
if ( mShowFeatureActions )
247246
{
248-
layerActions << QgsMapLayerActionRegistry::instance()->mapLayerActions( layer, targets );
247+
layerActions << QgsGui::mapLayerActionRegistry()->mapLayerActions( layer, targets );
249248

250249
if ( layerActions.count() > nCustomActions )
251250
{

src/gui/qgsidentifymenu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CustomActionRegistry : public QgsMapLayerActionRegistry
3030
Q_OBJECT
3131

3232
public:
33-
explicit CustomActionRegistry( QObject *parent );
33+
CustomActionRegistry();
3434
// remove all actions
3535
void clear() { mMapLayerActionList.clear(); }
3636
};

0 commit comments

Comments
 (0)