Skip to content

Commit 4a5c9a7

Browse files
committedMay 14, 2017
Make a new global QgsGui singleton
Move QgsEditorWidgetRegistry from being a singleton itself to instead being a member of the QgsGui singleton
1 parent 280ca31 commit 4a5c9a7

36 files changed

+278
-117
lines changed
 

‎doc/api_break.dox

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}
10111011

10121012
- Does no longer inherit QObject
10131013
- widgetType() and widgetConfig() now reflect only the user configured values.
1014-
QgsEditorWidgetRegistry::instance()->findBest() must be used instead.
1014+
QgsEditorWidgetRegistry::findBest() must be used instead.
10151015
- widgetConfig(), setWidgetType(), setWidgetConfig() and removeWidgetConfig() now only take a string as first parameter. Access by index has been removed.
10161016
- widgetType() has been removed in favor of QgsVectorLayer::editorWidgetSetup()
10171017
- expression(), setExpression(), expressionDescription() and setExpressionDescription()
@@ -1213,6 +1213,7 @@ plugins calling this method will need to be updated.
12131213
QgsEditorWidgetRegistry {#qgis_api_break_3_0_QgsEditorWidgetRegistry}
12141214
-----------------------
12151215

1216+
- The instance() singleton was removed. Use QgsGui::editorWidgetRegistry() instead.
12161217
- The signature of isFieldSupported() has been changed to return an unsigned
12171218
integer (how good it supports the given field) and is now const.
12181219

@@ -1822,10 +1823,10 @@ QgsRenderChecker {#qgis_api_break_3_0_QgsRenderChecker}
18221823
setExcludeAttributesWms()
18231824
- excludeAttributesWFS() and setExcludeAttributesWFS() have been renamed to excludeAttributesWfs() and
18241825
setExcludeAttributesWfs()
1825-
- editorWidgetV2() and editorWidgetV2Config() have been removed and QgsEditorWidgetRegistry::instance()->findBest() must be used instead.
1826+
- editorWidgetV2() and editorWidgetV2Config() have been removed and QgsEditorWidgetRegistry::findBest() must be used instead.
18261827
- setEditorWidgetV2(), setEditorWidgetV2Config() have been removed and their equivalent in editFormConfig() must be used instead.
18271828
- setCheckedState() is removed. Use `editFormConfig()->setWidgetConfig()` instead.
1828-
- valueMap(), valueRelation(), dateFormat(), widgetSize() have been removed. Use QgsEditorWidgetRegistry::instance()->findBest().config() instead.
1829+
- valueMap(), valueRelation(), dateFormat(), widgetSize() have been removed. Use QgsEditorWidgetRegistry::findBest().config() instead.
18291830

18301831

18311832
QgsRenderContext {#qgis_api_break_3_0_QgsRenderContext}

‎python/gui/editorwidgets/core/qgseditorwidgetregistry.sip

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ class QgsEditorWidgetRegistry : QObject
2121
%End
2222
public:
2323

24-
static QgsEditorWidgetRegistry *instance();
25-
%Docstring
26-
This class is a singleton and has therefore to be accessed with this method instead
27-
of a constructor.
28-
29-
:return: The one and only instance of the editor widget registry
30-
:rtype: QgsEditorWidgetRegistry
31-
%End
32-
3324
static void initEditors( QgsMapCanvas *mapCanvas = 0, QgsMessageBar *messageBar = 0 );
3425
%Docstring
3526
Registers all the default widgets.

‎python/gui/gui.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
%Include qgsfloatingwidget.sip
8282
%Include qgsfocuswatcher.sip
8383
%Include qgsformannotation.sip
84+
%Include qgsgui.sip
8485
%Include qgsgeometryrubberband.sip
8586
%Include qgsgradientcolorrampdialog.sip
8687
%Include qgsgradientstopeditor.sip

‎python/gui/qgsgui.sip

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/qgsgui.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsGui
14+
{
15+
%Docstring
16+
QgsGui is a singleton class containing various registry and other global members
17+
related to GUI classes.
18+
.. versionadded:: 3.0
19+
%End
20+
21+
%TypeHeaderCode
22+
#include "qgsgui.h"
23+
%End
24+
public:
25+
26+
27+
28+
static QgsGui *instance();
29+
%Docstring
30+
Returns a pointer to the singleton instance.
31+
:rtype: QgsGui
32+
%End
33+
34+
static QgsEditorWidgetRegistry *editorWidgetRegistry();
35+
%Docstring
36+
Returns the global editor widget registry, used for managing all known edit widget factories.
37+
.. versionadded:: 3.0
38+
:rtype: QgsEditorWidgetRegistry
39+
%End
40+
41+
~QgsGui();
42+
43+
private:
44+
QgsGui( const QgsGui &other );
45+
};
46+
47+
/************************************************************************
48+
* This file has been generated automatically from *
49+
* *
50+
* src/gui/qgsgui.h *
51+
* *
52+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
53+
************************************************************************/

‎src/app/ogr/qgsvectorlayersaveasdialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "qgseditorwidgetfactory.h"
2424
#include "qgseditorwidgetregistry.h"
2525
#include "qgssettings.h"
26-
26+
#include "qgsgui.h"
2727
#include <QMessageBox>
2828
#include <QFileDialog>
2929
#include <QTextCodec>
@@ -379,9 +379,9 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
379379
bool foundFieldThatCanBeExportedAsDisplayedValue = false;
380380
for ( int i = 0; i < mLayer->fields().size(); ++i )
381381
{
382-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() );
382+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
383383
if ( setup.type() != QLatin1String( "TextEdit" ) &&
384-
QgsEditorWidgetRegistry::instance()->factory( setup.type() ) )
384+
QgsGui::editorWidgetRegistry()->factory( setup.type() ) )
385385
{
386386
foundFieldThatCanBeExportedAsDisplayedValue = true;
387387
break;
@@ -416,11 +416,11 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
416416

417417
if ( foundFieldThatCanBeExportedAsDisplayedValue )
418418
{
419-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() );
419+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
420420
QgsEditorWidgetFactory *factory = nullptr;
421421
if ( flags == Qt::ItemIsEnabled &&
422422
setup.type() != QLatin1String( "TextEdit" ) &&
423-
( factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() ) ) )
423+
( factory = QgsGui::editorWidgetRegistry()->factory( setup.type() ) ) )
424424
{
425425
item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
426426
item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
278278
#include "qgsmaprenderertask.h"
279279
#include "qgsmapdecoration.h"
280280
#include "qgsnewnamedialog.h"
281+
#include "qgsgui.h"
281282

282283
#include "qgssublayersdialog.h"
283284
#include "ogr/qgsopenvectorlayerdialog.h"
@@ -924,7 +925,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
924925
mVectorLayerTools = new QgsGuiVectorLayerTools();
925926

926927
// Init the editor widget types
927-
QgsEditorWidgetRegistry::initEditors( mMapCanvas, mInfoBar );
928+
QgsGui::editorWidgetRegistry()->initEditors( mMapCanvas, mInfoBar );
928929

929930
mInternalClipboard = new QgsClipboard; // create clipboard
930931
connect( mInternalClipboard, &QgsClipboard::changed, this, &QgisApp::clipboardChanged );
@@ -6810,7 +6811,7 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant &value )
68106811
{
68116812
return value;
68126813
}
6813-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() );
6814+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields().field( idx ).name() );
68146815
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
68156816
return fieldFormatter->representValue( mLayer, idx, setup.config(), QVariant(), value );
68166817
}

‎src/app/qgsattributetabledialog.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "qgsfields.h"
5050
#include "qgseditorwidgetregistry.h"
5151
#include "qgsfieldproxymodel.h"
52+
#include "qgsgui.h"
5253

5354
QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
5455
{
@@ -412,7 +413,7 @@ void QgsAttributeTableDialog::columnBoxInit()
412413
if ( idx < 0 )
413414
continue;
414415

415-
if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
416+
if ( QgsGui::editorWidgetRegistry()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
416417
{
417418
QIcon icon = mLayer->fields().iconForField( idx );
418419
QString alias = mLayer->attributeDisplayName( idx );
@@ -560,8 +561,8 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject *filterAction )
560561
int fldIdx = mLayer->fields().lookupField( fieldName );
561562
if ( fldIdx < 0 )
562563
return;
563-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, fieldName );
564-
mCurrentSearchWidgetWrapper = QgsEditorWidgetRegistry::instance()->
564+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldName );
565+
mCurrentSearchWidgetWrapper = QgsGui::editorWidgetRegistry()->
565566
createSearchWidget( setup.type(), mLayer, fldIdx, setup.config(), mFilterContainer, mEditorContext );
566567
if ( mCurrentSearchWidgetWrapper->applyDirectly() )
567568
{

‎src/app/qgsattributetypedialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "qgsfieldformatter.h"
2828
#include "qgseditorwidgetfactory.h"
2929
#include "qgseditorwidgetregistry.h"
30+
#include "qgsgui.h"
3031

3132
#include <QTableWidgetItem>
3233
#include <QFile>
@@ -46,7 +47,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
4647
setupUi( this );
4748
setWindowTitle( tr( "Edit Widget Properties - %1 (%2)" ).arg( vl->fields().at( fieldIdx ).name(), vl->name() ) );
4849

49-
QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsEditorWidgetRegistry::instance()->factories() );
50+
QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsGui::editorWidgetRegistry()->factories() );
5051
while ( it.hasNext() )
5152
{
5253
it.next();
@@ -160,7 +161,7 @@ void QgsAttributeTypeDialog::setEditorWidgetType( const QString &type )
160161
}
161162
else
162163
{
163-
QgsEditorConfigWidget *cfgWdg = QgsEditorWidgetRegistry::instance()->createConfigWidget( type, mLayer, mFieldIdx, this );
164+
QgsEditorConfigWidget *cfgWdg = QgsGui::editorWidgetRegistry()->createConfigWidget( type, mLayer, mFieldIdx, this );
164165

165166
if ( cfgWdg )
166167
{

‎src/app/qgsfieldsproperties.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsvectorlayer.h"
3030
#include "qgsfieldexpressionwidget.h"
3131
#include "qgssettings.h"
32+
#include "qgsgui.h"
3233

3334
#include <QTreeWidgetItem>
3435
#include <QWidget>
@@ -339,7 +340,7 @@ void QgsFieldsProperties::setRow( int row, int idx, const QgsField &field )
339340

340341
FieldConfig cfg( mLayer, idx );
341342
QPushButton *pb = nullptr;
342-
pb = new QPushButton( QgsEditorWidgetRegistry::instance()->name( cfg.mEditorWidgetType ) );
343+
pb = new QPushButton( QgsGui::editorWidgetRegistry()->name( cfg.mEditorWidgetType ) );
343344
cfg.mButton = pb;
344345
mFieldsList->setCellWidget( row, AttrEditTypeCol, pb );
345346

@@ -398,7 +399,7 @@ void QgsFieldsProperties::loadRelations()
398399
if ( nmrel.fieldPairs().at( 0 ).referencingField() != relation.fieldPairs().at( 0 ).referencingField() )
399400
nmCombo->addItem( QStringLiteral( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() );
400401

401-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, relation.id() );
402+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, relation.id() );
402403

403404
const QVariant nmrelcfg = setup.config().value( QStringLiteral( "nm-rel" ) );
404405

@@ -1102,7 +1103,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer *layer, int idx )
11021103
mConstraintStrength.insert( QgsFieldConstraints::ConstraintUnique, constraints.constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
11031104
mConstraintStrength.insert( QgsFieldConstraints::ConstraintExpression, constraints.constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
11041105
mConstraintDescription = constraints.constraintDescription();
1105-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer, layer->fields().field( idx ).name() );
1106+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( layer, layer->fields().field( idx ).name() );
11061107
mEditorWidgetType = setup.type();
11071108
mEditorWidgetConfig = setup.config();
11081109
}

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "qgsfieldformatterregistry.h"
4747
#include "qgsfieldformatter.h"
4848
#include "qgssettings.h"
49+
#include "qgsgui.h"
4950

5051
#include <QCloseEvent>
5152
#include <QLabel>
@@ -535,7 +536,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
535536
if ( i >= fields.count() )
536537
break;
537538

538-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( vlayer, fields[i].name() );
539+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( vlayer, fields[i].name() );
539540
if ( setup.type() == QLatin1String( "Hidden" ) )
540541
{
541542
continue;
@@ -603,7 +604,7 @@ void QgsIdentifyResultsDialog::addFeature( QgsVectorLayer *vlayer, const QgsFeat
603604
continue;
604605

605606
QString value = fields.at( i ).displayString( attrs.at( i ) );
606-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( vlayer, fields.at( i ).name() );
607+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( vlayer, fields.at( i ).name() );
607608
QString value2 = representValue( vlayer, setup, fields.at( i ).name(), value );
608609

609610
tblResults->setRowCount( j + 1 );
@@ -710,7 +711,7 @@ QString QgsIdentifyResultsDialog::representValue( QgsVectorLayer *vlayer, const
710711
QVariant cache;
711712
QMap<QString, QVariant> &layerCaches = mWidgetCaches[vlayer->id()];
712713

713-
QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
714+
QgsEditorWidgetFactory *factory = QgsGui::editorWidgetRegistry()->factory( setup.type() );
714715
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
715716

716717
int idx = vlayer->fields().lookupField( fieldName );
@@ -1542,7 +1543,7 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,
15421543

15431544
if ( item->data( 0, Qt::UserRole + 1 ).toInt() == idx )
15441545
{
1545-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( vlayer, fld.name() );
1546+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( vlayer, fld.name() );
15461547
value = representValue( vlayer, setup, fld.name(), val );
15471548

15481549
QgsTreeWidgetItem *treeItem = static_cast< QgsTreeWidgetItem * >( item );

‎src/app/qgsmergeattributesdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsstatisticalsummary.h"
2929
#include "qgseditorwidgetregistry.h"
3030
#include "qgssettings.h"
31+
#include "qgsgui.h"
3132

3233
#include <limits>
3334
#include <QComboBox>
@@ -115,7 +116,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
115116
mHiddenAttributes.clear();
116117
for ( int idx = 0; idx < mFields.count(); ++idx )
117118
{
118-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mVectorLayer, mFields.at( idx ).name() );
119+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mVectorLayer, mFields.at( idx ).name() );
119120
if ( setup.type() == QLatin1String( "Hidden" ) || setup.type() == QLatin1String( "Immutable" ) )
120121
{
121122
mHiddenAttributes.insert( idx );
@@ -155,7 +156,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
155156
QTableWidgetItem *attributeValItem = new QTableWidgetItem( attrs.at( idx ).toString() );
156157
attributeValItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
157158
mTableWidget->setItem( i + 1, j, attributeValItem );
158-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( mVectorLayer, idx, nullptr, mTableWidget, context );
159+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( mVectorLayer, idx, nullptr, mTableWidget, context );
159160
if ( eww )
160161
{
161162
eww->setValue( attrs.at( idx ) );

‎src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ SET(QGIS_GUI_SRCS
226226
qgsgradientcolorrampdialog.cpp
227227
qgsgradientstopeditor.cpp
228228
qgsgroupwmsdatadialog.cpp
229+
qgsgui.cpp
229230
qgshighlight.cpp
230231
qgshistogramwidget.cpp
231232
qgshelp.cpp
@@ -621,6 +622,7 @@ SET(QGIS_GUI_HDRS
621622
qgsdetaileditemdata.h
622623
qgsexpressionbuilderdialog.h
623624
qgsfiledropedit.h
625+
qgsgui.h
624626
qgshelp.h
625627
qgshighlight.h
626628
qgsmapcanvasitem.h

‎src/gui/attributetable/qgsattributetabledelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "qgslogger.h"
3030
#include "qgsvectordataprovider.h"
3131
#include "qgsactionmanager.h"
32-
32+
#include "qgsgui.h"
3333

3434
QgsVectorLayer *QgsAttributeTableDelegate::layer( const QAbstractItemModel *model )
3535
{
@@ -67,7 +67,7 @@ QWidget *QgsAttributeTableDelegate::createEditor( QWidget *parent, const QStyleO
6767
int fieldIdx = index.model()->data( index, QgsAttributeTableModel::FieldIndexRole ).toInt();
6868

6969
QgsAttributeEditorContext context( masterModel( index.model() )->editorContext(), QgsAttributeEditorContext::Popup );
70-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( vl, fieldIdx, nullptr, parent, context );
70+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( vl, fieldIdx, nullptr, parent, context );
7171
QWidget *w = eww->widget();
7272

7373
w->setAutoFillBackground( true );

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "qgsvectordataprovider.h"
3434
#include "qgssymbollayerutils.h"
3535
#include "qgsfieldformatterregistry.h"
36-
36+
#include "qgsgui.h"
3737
#include <QVariant>
3838

3939
#include <limits>
@@ -351,8 +351,8 @@ void QgsAttributeTableModel::loadAttributes()
351351

352352
for ( int idx = 0; idx < fields.count(); ++idx )
353353
{
354-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer(), fields[idx].name() );
355-
QgsEditorWidgetFactory *widgetFactory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
354+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( layer(), fields[idx].name() );
355+
QgsEditorWidgetFactory *widgetFactory = QgsGui::editorWidgetRegistry()->factory( setup.type() );
356356
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
357357

358358
if ( widgetFactory )

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgseditorwidgetregistry.h"
3030
#include "qgssettings.h"
3131
#include "qgsscrollarea.h"
32+
#include "qgsgui.h"
3233

3334
#include <QClipboard>
3435
#include <QDialog>
@@ -148,7 +149,7 @@ void QgsDualView::columnBoxInit()
148149
if ( fieldIndex == -1 )
149150
continue;
150151

151-
if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
152+
if ( QgsGui::editorWidgetRegistry()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
152153
{
153154
QIcon icon = mLayer->fields().iconForField( fieldIndex );
154155
QString text = field.name();

‎src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "qgseditorwidgetautoconf.h"
1616
#include "qgseditorwidgetregistry.h"
1717
#include "qgsvectordataprovider.h"
18+
#include "qgsgui.h"
1819

1920
/** \ingroup gui
2021
* Widget auto conf plugin that guesses what widget type to use in function of what the widgets support.
@@ -29,7 +30,7 @@ class FromFactoriesPlugin: public QgsEditorWidgetAutoConfPlugin
2930
{
3031
int bestScore = 0;
3132
QString bestType;
32-
const QMap<QString, QgsEditorWidgetFactory *> factories = QgsEditorWidgetRegistry::instance()->factories();
33+
const QMap<QString, QgsEditorWidgetFactory *> factories = QgsGui::editorWidgetRegistry()->factories();
3334
for ( QMap<QString, QgsEditorWidgetFactory *>::const_iterator i = factories.begin(); i != factories.end(); ++i )
3435
{
3536
const int index = vl->fields().lookupField( fieldName );

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,24 @@
4040
#include "qgsvaluemapwidgetfactory.h"
4141
#include "qgsvaluerelationwidgetfactory.h"
4242

43-
44-
QgsEditorWidgetRegistry *QgsEditorWidgetRegistry::instance()
45-
{
46-
static QgsEditorWidgetRegistry sInstance;
47-
return &sInstance;
48-
}
49-
5043
void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBar *messageBar )
5144
{
52-
QgsEditorWidgetRegistry *reg = instance();
53-
reg->registerWidget( QStringLiteral( "TextEdit" ), new QgsTextEditWidgetFactory( tr( "Text Edit" ) ) );
54-
reg->registerWidget( QStringLiteral( "Classification" ), new QgsClassificationWidgetWrapperFactory( tr( "Classification" ) ) );
55-
reg->registerWidget( QStringLiteral( "Range" ), new QgsRangeWidgetFactory( tr( "Range" ) ) );
56-
reg->registerWidget( QStringLiteral( "UniqueValues" ), new QgsUniqueValueWidgetFactory( tr( "Unique Values" ) ) );
57-
reg->registerWidget( QStringLiteral( "ValueMap" ), new QgsValueMapWidgetFactory( tr( "Value Map" ) ) );
58-
reg->registerWidget( QStringLiteral( "Enumeration" ), new QgsEnumerationWidgetFactory( tr( "Enumeration" ) ) );
59-
reg->registerWidget( QStringLiteral( "Hidden" ), new QgsHiddenWidgetFactory( tr( "Hidden" ) ) );
60-
reg->registerWidget( QStringLiteral( "CheckBox" ), new QgsCheckboxWidgetFactory( tr( "Check Box" ) ) );
61-
reg->registerWidget( QStringLiteral( "ValueRelation" ), new QgsValueRelationWidgetFactory( tr( "Value Relation" ) ) );
62-
reg->registerWidget( QStringLiteral( "UuidGenerator" ), new QgsUuidWidgetFactory( tr( "Uuid Generator" ) ) );
63-
reg->registerWidget( QStringLiteral( "Color" ), new QgsColorWidgetFactory( tr( "Color" ) ) );
64-
reg->registerWidget( QStringLiteral( "RelationReference" ), new QgsRelationReferenceFactory( tr( "Relation Reference" ), mapCanvas, messageBar ) );
65-
reg->registerWidget( QStringLiteral( "DateTime" ), new QgsDateTimeEditFactory( tr( "Date/Time" ) ) );
66-
reg->registerWidget( QStringLiteral( "ExternalResource" ), new QgsExternalResourceWidgetFactory( tr( "Attachment" ) ) );
67-
reg->registerWidget( QStringLiteral( "KeyValue" ), new QgsKeyValueWidgetFactory( tr( "Key/Value" ) ) );
68-
reg->registerWidget( QStringLiteral( "List" ), new QgsListWidgetFactory( tr( "List" ) ) );
45+
registerWidget( QStringLiteral( "TextEdit" ), new QgsTextEditWidgetFactory( tr( "Text Edit" ) ) );
46+
registerWidget( QStringLiteral( "Classification" ), new QgsClassificationWidgetWrapperFactory( tr( "Classification" ) ) );
47+
registerWidget( QStringLiteral( "Range" ), new QgsRangeWidgetFactory( tr( "Range" ) ) );
48+
registerWidget( QStringLiteral( "UniqueValues" ), new QgsUniqueValueWidgetFactory( tr( "Unique Values" ) ) );
49+
registerWidget( QStringLiteral( "ValueMap" ), new QgsValueMapWidgetFactory( tr( "Value Map" ) ) );
50+
registerWidget( QStringLiteral( "Enumeration" ), new QgsEnumerationWidgetFactory( tr( "Enumeration" ) ) );
51+
registerWidget( QStringLiteral( "Hidden" ), new QgsHiddenWidgetFactory( tr( "Hidden" ) ) );
52+
registerWidget( QStringLiteral( "CheckBox" ), new QgsCheckboxWidgetFactory( tr( "Check Box" ) ) );
53+
registerWidget( QStringLiteral( "ValueRelation" ), new QgsValueRelationWidgetFactory( tr( "Value Relation" ) ) );
54+
registerWidget( QStringLiteral( "UuidGenerator" ), new QgsUuidWidgetFactory( tr( "Uuid Generator" ) ) );
55+
registerWidget( QStringLiteral( "Color" ), new QgsColorWidgetFactory( tr( "Color" ) ) );
56+
registerWidget( QStringLiteral( "RelationReference" ), new QgsRelationReferenceFactory( tr( "Relation Reference" ), mapCanvas, messageBar ) );
57+
registerWidget( QStringLiteral( "DateTime" ), new QgsDateTimeEditFactory( tr( "Date/Time" ) ) );
58+
registerWidget( QStringLiteral( "ExternalResource" ), new QgsExternalResourceWidgetFactory( tr( "Attachment" ) ) );
59+
registerWidget( QStringLiteral( "KeyValue" ), new QgsKeyValueWidgetFactory( tr( "Key/Value" ) ) );
60+
registerWidget( QStringLiteral( "List" ), new QgsListWidgetFactory( tr( "List" ) ) );
6961
}
7062

7163
QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()

‎src/gui/editorwidgets/core/qgseditorwidgetregistry.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class QgsVectorLayer;
3636

3737

3838
/** \ingroup gui
39-
* This class manages all known edit widget factories
39+
* This class manages all known edit widget factories.
40+
*
41+
* QgsEditorWidgetRegistry is not usually directly created, but rather accessed through
42+
* QgsGui::editorWidgetRegistry().
4043
*/
4144
class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
4245
{
@@ -45,12 +48,10 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
4548
public:
4649

4750
/**
48-
* This class is a singleton and has therefore to be accessed with this method instead
49-
* of a constructor.
50-
*
51-
* \returns The one and only instance of the editor widget registry
51+
* Constructor for QgsEditorWidgetRegistry. QgsEditorWidgetRegistry is not usually directly created, but rather accessed through
52+
* QgsGui::editorWidgetRegistry().
5253
*/
53-
static QgsEditorWidgetRegistry *instance();
54+
QgsEditorWidgetRegistry();
5455

5556
/**
5657
* Registers all the default widgets.
@@ -62,7 +63,7 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
6263
* \since QGIS 2.8
6364
* \note Not required for plugins, the QGIS application does that already
6465
*/
65-
static void initEditors( QgsMapCanvas *mapCanvas = nullptr, QgsMessageBar *messageBar = nullptr );
66+
void initEditors( QgsMapCanvas *mapCanvas = nullptr, QgsMessageBar *messageBar = nullptr );
6667

6768
/**
6869
* Destructor
@@ -180,9 +181,6 @@ class GUI_EXPORT QgsEditorWidgetRegistry : public QObject
180181
*/
181182
void registerAutoConfPlugin( QgsEditorWidgetAutoConfPlugin *plugin ) { mAutoConf.registerPlugin( plugin ); }
182183

183-
protected:
184-
QgsEditorWidgetRegistry();
185-
186184
private:
187185
QString findSuitableWrapper( QWidget *editor, const QString &defaultWidget );
188186

‎src/gui/qgsattributeform.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgstabwidget.h"
3333
#include "qgssettings.h"
3434
#include "qgsscrollarea.h"
35+
#include "qgsgui.h"
3536

3637
#include <QDir>
3738
#include <QTextStream>
@@ -1233,7 +1234,7 @@ void QgsAttributeForm::init()
12331234
//show attribute alias if available
12341235
QString fieldName = mLayer->attributeDisplayName( idx );
12351236

1236-
const QgsEditorWidgetSetup widgetSetup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() );
1237+
const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, field.name() );
12371238

12381239
if ( widgetSetup.type() == QLatin1String( "Hidden" ) )
12391240
continue;
@@ -1242,7 +1243,7 @@ void QgsAttributeForm::init()
12421243

12431244
// This will also create the widget
12441245
QLabel *l = new QLabel( fieldName );
1245-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( widgetSetup.type(), mLayer, idx, widgetSetup.config(), nullptr, this, mContext );
1246+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( widgetSetup.type(), mLayer, idx, widgetSetup.config(), nullptr, this, mContext );
12461247

12471248
QWidget *w = nullptr;
12481249
if ( eww )
@@ -1281,7 +1282,7 @@ void QgsAttributeForm::init()
12811282
Q_FOREACH ( const QgsRelation &rel, QgsProject::instance()->relationManager()->referencedRelations( mLayer ) )
12821283
{
12831284
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, rel, nullptr, this );
1284-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, rel.id() );
1285+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, rel.id() );
12851286
rww->setConfig( setup.config() );
12861287
rww->setContext( mContext );
12871288
gridLayout->addWidget( rww->widget(), row++, 0, 1, 2 );
@@ -1534,9 +1535,9 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
15341535
int fldIdx = vl->fields().lookupField( fieldDef->name() );
15351536
if ( fldIdx < vl->fields().count() && fldIdx >= 0 )
15361537
{
1537-
const QgsEditorWidgetSetup widgetSetup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, fieldDef->name() );
1538+
const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldDef->name() );
15381539

1539-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( widgetSetup.type(), mLayer, fldIdx, widgetSetup.config(), nullptr, this, mContext );
1540+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( widgetSetup.type(), mLayer, fldIdx, widgetSetup.config(), nullptr, this, mContext );
15401541
QgsAttributeFormEditorWidget *w = new QgsAttributeFormEditorWidget( eww, this );
15411542
mFormEditorWidgets.insert( fldIdx, w );
15421543

@@ -1560,7 +1561,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
15601561
const QgsAttributeEditorRelation *relDef = static_cast<const QgsAttributeEditorRelation *>( widgetDef );
15611562

15621563
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, relDef->relation(), nullptr, this );
1563-
const QgsEditorWidgetSetup widgetSetup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, relDef->relation().id() );
1564+
const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, relDef->relation().id() );
15641565
rww->setConfig( widgetSetup.config() );
15651566
rww->setContext( context );
15661567
newWidgetInfo.widget = rww->widget();
@@ -1723,7 +1724,7 @@ void QgsAttributeForm::createWrappers()
17231724
if ( relation.isValid() )
17241725
{
17251726
QgsRelationWidgetWrapper *rww = new QgsRelationWidgetWrapper( mLayer, relation, myWidget, this );
1726-
const QgsEditorWidgetSetup widgetSetup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, relation.id() );
1727+
const QgsEditorWidgetSetup widgetSetup = QgsGui::editorWidgetRegistry()->findBest( mLayer, relation.id() );
17271728
rww->setConfig( widgetSetup.config() );
17281729
rww->setContext( mContext );
17291730
rww->widget(); // Will initialize the widget
@@ -1738,7 +1739,7 @@ void QgsAttributeForm::createWrappers()
17381739
{
17391740
int idx = mLayer->fields().lookupField( field.name() );
17401741

1741-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( mLayer, idx, myWidget, this, mContext );
1742+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( mLayer, idx, myWidget, this, mContext );
17421743
addWidgetWrapper( eww );
17431744
}
17441745
}

‎src/gui/qgsattributeformeditorwidget.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgssearchwidgetwrapper.h"
2222
#include "qgsattributeeditorcontext.h"
2323
#include "qgseditorwidgetregistry.h"
24+
#include "qgsgui.h"
2425
#include <QLayout>
2526
#include <QLabel>
2627
#include <QStackedWidget>
@@ -96,14 +97,14 @@ QgsAttributeFormEditorWidget::~QgsAttributeFormEditorWidget()
9697

9798
void QgsAttributeFormEditorWidget::createSearchWidgetWrappers( const QString &widgetId, int fieldIdx, const QVariantMap &config, const QgsAttributeEditorContext &context )
9899
{
99-
QgsSearchWidgetWrapper *sww = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetId, layer(), fieldIdx, config,
100+
QgsSearchWidgetWrapper *sww = QgsGui::editorWidgetRegistry()->createSearchWidget( widgetId, layer(), fieldIdx, config,
100101
mSearchFrame, context );
101102
setSearchWidgetWrapper( sww );
102103
if ( sww->supportedFlags() & QgsSearchWidgetWrapper::Between ||
103104
sww->supportedFlags() & QgsSearchWidgetWrapper::IsNotBetween )
104105
{
105106
// create secondary widget for between type searches
106-
QgsSearchWidgetWrapper *sww2 = QgsEditorWidgetRegistry::instance()->createSearchWidget( widgetId, layer(), fieldIdx, config,
107+
QgsSearchWidgetWrapper *sww2 = QgsGui::editorWidgetRegistry()->createSearchWidget( widgetId, layer(), fieldIdx, config,
107108
mSearchFrame, context );
108109
mSearchWidgets << sww2;
109110
mSearchFrame->layout()->addWidget( sww2->widget() );

‎src/gui/qgsformannotation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsproject.h"
2727
#include "qgsmaptool.h"
2828
#include "qgsvectorlayer.h"
29+
#include "qgsgui.h"
2930
#include <QDomElement>
3031
#include <QDir>
3132
#include <QFile>
@@ -94,7 +95,7 @@ QWidget *QgsFormAnnotation::createDesignerWidget( const QString &filePath )
9495
QWidget *attWidget = widget->findChild<QWidget *>( fields.at( i ).name() );
9596
if ( attWidget )
9697
{
97-
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( vectorLayer, i, attWidget, widget, context );
98+
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( vectorLayer, i, attWidget, widget, context );
9899
if ( eww )
99100
{
100101
eww->setValue( attrs.at( i ) );

‎src/gui/qgsgui.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgsgui.cpp
3+
----------
4+
begin : May 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsgui.h"
19+
#include "qgseditorwidgetregistry.h"
20+
21+
QgsGui *QgsGui::instance()
22+
{
23+
static QgsGui *sInstance( new QgsGui() );
24+
return sInstance;
25+
}
26+
27+
QgsEditorWidgetRegistry *QgsGui::editorWidgetRegistry()
28+
{
29+
return instance()->mEditorWidgetRegistry;
30+
}
31+
32+
QgsGui::~QgsGui()
33+
{
34+
delete mEditorWidgetRegistry;
35+
}
36+
37+
QgsGui::QgsGui()
38+
{
39+
mEditorWidgetRegistry = new QgsEditorWidgetRegistry();
40+
}

‎src/gui/qgsgui.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/***************************************************************************
2+
qgsgui.h
3+
--------
4+
begin : May 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSGUI_H
19+
#define QGSGUI_H
20+
21+
#include "qgis_gui.h"
22+
23+
class QgsEditorWidgetRegistry;
24+
25+
/**
26+
* \ingroup gui
27+
* QgsGui is a singleton class containing various registry and other global members
28+
* related to GUI classes.
29+
* \since QGIS 3.0
30+
*/
31+
class GUI_EXPORT QgsGui
32+
{
33+
public:
34+
35+
//! QgsGui cannot be copied
36+
QgsGui( const QgsGui &other ) = delete;
37+
38+
//! QgsGui cannot be copied
39+
QgsGui &operator=( const QgsGui &other ) = delete;
40+
41+
/**
42+
* Returns a pointer to the singleton instance.
43+
*/
44+
static QgsGui *instance();
45+
46+
/**
47+
* Returns the global editor widget registry, used for managing all known edit widget factories.
48+
* \since QGIS 3.0
49+
*/
50+
static QgsEditorWidgetRegistry *editorWidgetRegistry();
51+
52+
~QgsGui();
53+
54+
private:
55+
56+
QgsGui();
57+
58+
QgsEditorWidgetRegistry *mEditorWidgetRegistry = nullptr;
59+
60+
#ifdef SIP_RUN
61+
QgsGui( const QgsGui &other );
62+
#endif
63+
64+
};
65+
66+
#endif // QGSGUI_H

‎src/server/qgsserver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "qgsfilterresponsedecorator.h"
4141
#include "qgsservice.h"
4242
#include "qgsserverprojectutils.h"
43+
#include "qgsgui.h"
4344

4445
#include <QDomDocument>
4546
#include <QNetworkDiskCache>
@@ -271,7 +272,7 @@ bool QgsServer::init( )
271272
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Roman" ) << QStringLiteral( "Bold" ) );
272273
#endif
273274

274-
QgsEditorWidgetRegistry::initEditors();
275+
QgsGui::editorWidgetRegistry()->initEditors();
275276

276277
sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, &sServiceRegistry, &sSettings );
277278

‎src/server/qgsserverprojectparser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "qgslayertreegroup.h"
3232
#include "qgslogger.h"
3333
#include "qgseditorwidgetsetup.h"
34+
#include "qgsgui.h"
3435

3536
#include <QDomDocument>
3637
#include <QFileInfo>
@@ -272,7 +273,7 @@ QgsMapLayer *QgsServerProjectParser::createLayerFromElement( const QDomElement &
272273
if ( layer->type() == QgsMapLayer::VectorLayer )
273274
{
274275
// see QgsEditorWidgetRegistry::mapLayerAdded()
275-
QObject::connect( layer, SIGNAL( readCustomSymbology( const QDomElement &, QString & ) ), QgsEditorWidgetRegistry::instance(), SLOT( readSymbology( const QDomElement &, QString & ) ) );
276+
QObject::connect( layer, SIGNAL( readCustomSymbology( const QDomElement &, QString & ) ), QgsGui::editorWidgetRegistry(), SLOT( readSymbology( const QDomElement &, QString & ) ) );
276277
}
277278

278279
QgsReadWriteContext context;

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "qgsmaprendererjobproxy.h"
5858
#include "qgswmsserviceexception.h"
5959
#include "qgsserverprojectutils.h"
60+
#include "qgsgui.h"
6061

6162
#include <QImage>
6263
#include <QPainter>
@@ -2532,7 +2533,7 @@ namespace QgsWms
25322533
QString QgsRenderer::replaceValueMapAndRelation( QgsVectorLayer *vl, int idx, const QString &attributeVal )
25332534
{
25342535
// TODO Could we get rid of QgsEditorWidgetRegistry dependency ?
2535-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( vl, vl->fields().field( idx ).name() );
2536+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( vl, vl->fields().field( idx ).name() );
25362537
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
25372538
QString value( fieldFormatter->representValue( vl, idx, setup.config(), QVariant(), attributeVal ) );
25382539

‎tests/src/app/testqgsvectorlayersaveasdialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "qgseditorwidgetregistry.h"
2424
#include "qgsproject.h"
2525
#include "qgsmapcanvas.h"
26+
#include "qgsgui.h"
2627

2728
/** \ingroup UnitTests
2829
* This is a unit test for the save as dialog
@@ -59,7 +60,7 @@ void TestQgsVectorLayerSaveAsDialog::initTestCase()
5960
QgsApplication::init();
6061
QgsApplication::initQgis();
6162
mQgisApp = new QgisApp();
62-
QgsEditorWidgetRegistry::initEditors();
63+
QgsGui::editorWidgetRegistry()->initEditors();
6364
}
6465

6566
//runs after all tests

‎tests/src/gui/testqgsattributeform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <qgsvectorlayer.h>
2525
#include "qgsvectordataprovider.h"
2626
#include <qgsfeature.h>
27+
#include "qgsgui.h"
2728

2829
class TestQgsAttributeForm : public QObject
2930
{
@@ -46,7 +47,7 @@ void TestQgsAttributeForm::initTestCase()
4647
{
4748
QgsApplication::init();
4849
QgsApplication::initQgis();
49-
QgsEditorWidgetRegistry::initEditors();
50+
QgsGui::editorWidgetRegistry()->initEditors();
5051
}
5152

5253
void TestQgsAttributeForm::cleanupTestCase()

‎tests/src/gui/testqgsdualview.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgsvectordataprovider.h"
2727
#include <qgsmapcanvas.h>
2828
#include <qgsfeature.h>
29+
#include "qgsgui.h"
2930

3031
#include "qgstest.h"
3132

@@ -72,7 +73,7 @@ void TestQgsDualView::initTestCase()
7273
QgsApplication::initQgis();
7374
QgsApplication::showSettings();
7475

75-
QgsEditorWidgetRegistry::initEditors();
76+
QgsGui::editorWidgetRegistry()->initEditors();
7677

7778
// Setup a map canvas with a vector layer loaded...
7879
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt

‎tests/src/gui/testqgseditorwidgetregistry.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgseditorwidgetautoconf.h"
1919
#include "qgsproject.h"
2020
#include "qgsrelationmanager.h"
21-
21+
#include "qgsgui.h"
2222

2323
class TestQgsEditorWidgetRegistry: public QObject
2424
{
@@ -46,8 +46,8 @@ class TestQgsEditorWidgetRegistry: public QObject
4646
{
4747
QgsApplication::init();
4848
QgsApplication::initQgis();
49-
QgsEditorWidgetRegistry::initEditors();
50-
QgsEditorWidgetRegistry::instance()->registerAutoConfPlugin( new DummyPlugin() );
49+
QgsGui::editorWidgetRegistry()->initEditors();
50+
QgsGui::editorWidgetRegistry()->registerAutoConfPlugin( new DummyPlugin() );
5151
}
5252

5353
void cleanupTestCase()
@@ -97,15 +97,15 @@ class TestQgsEditorWidgetRegistry: public QObject
9797

9898
vl.setEditorWidgetSetup( 1, QgsEditorWidgetSetup( QStringLiteral( "FooEdit" ), config ) );
9999

100-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( &vl, QStringLiteral( "col1" ) );
100+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( &vl, QStringLiteral( "col1" ) );
101101
QCOMPARE( setup.type(), QString( "FooEdit" ) );
102102
QCOMPARE( setup.config(), config );
103103
}
104104

105105
void wrongFieldName()
106106
{
107107
const QgsVectorLayer vl( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=col1:string" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) );
108-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( &vl, QStringLiteral( "col2" ) );
108+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( &vl, QStringLiteral( "col2" ) );
109109
// an unknown fields leads to a default setup with a TextEdit
110110
QCOMPARE( setup.type(), QString( "TextEdit" ) );
111111
QCOMPARE( setup.config().count(), 0 );
@@ -130,15 +130,15 @@ class TestQgsEditorWidgetRegistry: public QObject
130130
QgsProject::instance()->relationManager()->addRelation( relation );
131131

132132
//check the guessed editor widget type for vl1.fk is RelationReference
133-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( &vl1, QStringLiteral( "fk" ) );
133+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( &vl1, QStringLiteral( "fk" ) );
134134
QCOMPARE( setup.type(), QString( "RelationReference" ) );
135135
QCOMPARE( setup.config(), QVariantMap() );
136136
}
137137

138138
void typeFromPlugin()
139139
{
140140
const QgsVectorLayer vl( QStringLiteral( "LineString?crs=epsg:3111&field=pk:int&field=special:string" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) );
141-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( &vl, QStringLiteral( "special" ) );
141+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( &vl, QStringLiteral( "special" ) );
142142
QCOMPARE( setup.type(), QString( "Special" ) );
143143
}
144144

@@ -147,7 +147,7 @@ class TestQgsEditorWidgetRegistry: public QObject
147147
static void checkSimple( const QString &dataType, const QString &widgetType )
148148
{
149149
const QgsVectorLayer vl( "LineString?crs=epsg:3111&field=pk:int&field=col1:" + dataType, QStringLiteral( "vl" ), QStringLiteral( "memory" ) );
150-
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( &vl, QStringLiteral( "col1" ) );
150+
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( &vl, QStringLiteral( "col1" ) );
151151
QCOMPARE( setup.type(), widgetType );
152152
QCOMPARE( setup.config().count(), 0 );
153153
}

‎tests/src/python/test_provider_postgres.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
QgsSettings,
3131
QgsTransactionGroup
3232
)
33-
from qgis.gui import QgsEditorWidgetRegistry
33+
from qgis.gui import QgsGui
3434
from qgis.PyQt.QtCore import QDate, QTime, QDateTime, QVariant, QDir
3535
from qgis.testing import start_app, unittest
3636
from utilities import unitTestDataPath
@@ -55,7 +55,7 @@ def setUpClass(cls):
5555
cls.poly_vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POLYGON table="qgis_test"."some_poly_data" (geom) sql=', 'test', 'postgres')
5656
assert cls.poly_vl.isValid()
5757
cls.poly_provider = cls.poly_vl.dataProvider()
58-
QgsEditorWidgetRegistry.instance().initEditors()
58+
QgsGui.editorWidgetRegistry().initEditors()
5959
cls.con = psycopg2.connect(cls.dbconn)
6060

6161
@classmethod
@@ -379,13 +379,13 @@ def testEditorWidgetTypes(self):
379379
self.assertEqual(setup1.type(), "FooEdit")
380380
self.assertEqual(setup1.config(), {"param1": "value1", "param2": "2"})
381381

382-
best1 = QgsEditorWidgetRegistry.instance().findBest(vl, "fld1")
382+
best1 = QgsGui.editorWidgetRegistry().findBest(vl, "fld1")
383383
self.assertEqual(best1.type(), "FooEdit")
384384
self.assertEqual(best1.config(), setup1.config())
385385

386386
self.assertTrue(fields.field("fld2").editorWidgetSetup().isNull())
387387

388-
best2 = QgsEditorWidgetRegistry.instance().findBest(vl, "fld2")
388+
best2 = QgsGui.editorWidgetRegistry().findBest(vl, "fld2")
389389
self.assertEqual(best2.type(), "TextEdit")
390390

391391
def testHstore(self):

‎tests/src/python/test_qgsattributeformeditorwidget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
QgsAttributeFormEditorWidget,
1919
QgsDefaultSearchWidgetWrapper,
2020
QgsAttributeForm,
21-
QgsEditorWidgetRegistry
21+
QgsGui
2222
)
2323
from qgis.core import (QgsVectorLayer)
2424
from qgis.PyQt.QtWidgets import QWidget, QDateTimeEdit
2525
from qgis.PyQt.QtCore import QDateTime, QDate, QTime
2626
from qgis.testing import start_app, unittest
2727

2828
start_app()
29-
QgsEditorWidgetRegistry.instance().initEditors()
29+
QgsGui.editorWidgetRegistry().initEditors()
3030

3131

3232
class PyQgsAttributeFormEditorWidget(unittest.TestCase):

‎tests/src/python/test_qgsattributetablemodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from qgis.gui import (
1616
QgsAttributeTableModel,
17-
QgsEditorWidgetRegistry
17+
QgsGui
1818
)
1919
from qgis.core import (
2020
QgsFeature,
@@ -35,7 +35,7 @@ class TestQgsAttributeTableModel(unittest.TestCase):
3535

3636
@classmethod
3737
def setUpClass(cls):
38-
QgsEditorWidgetRegistry.initEditors()
38+
QgsGui.editorWidgetRegistry().initEditors()
3939

4040
def setUp(self):
4141
self.layer = self.createLayer()

‎tests/src/python/test_qgseditwidgets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import qgis # NOQA
1616

1717
from qgis.core import (QgsProject, QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, NULL, QgsField)
18-
from qgis.gui import QgsEditorWidgetRegistry
18+
from qgis.gui import QgsGui
1919

2020
from qgis.testing import start_app, unittest
2121
from qgis.PyQt.QtCore import QVariant
@@ -30,7 +30,7 @@ class TestQgsTextEditWidget(unittest.TestCase):
3030

3131
@classmethod
3232
def setUpClass(cls):
33-
QgsEditorWidgetRegistry.initEditors()
33+
QgsGui.editorWidgetRegistry().initEditors()
3434

3535
def createLayerWithOnePoint(self):
3636
self.layer = QgsVectorLayer("Point?field=fldtxt:string&field=fldint:integer",
@@ -44,7 +44,7 @@ def createLayerWithOnePoint(self):
4444
return self.layer
4545

4646
def doAttributeTest(self, idx, expected):
47-
reg = QgsEditorWidgetRegistry.instance()
47+
reg = QgsGui.editorWidgetRegistry()
4848
configWdg = reg.createConfigWidget('TextEdit', self.layer, idx, None)
4949
config = configWdg.config()
5050
editwidget = reg.create('TextEdit', self.layer, idx, config, None, None)
@@ -76,7 +76,7 @@ def testStringWithMaxLen(self):
7676
layer.updateFields()
7777
QgsProject.instance().addMapLayer(layer)
7878

79-
reg = QgsEditorWidgetRegistry.instance()
79+
reg = QgsGui.editorWidgetRegistry()
8080
config = {'IsMultiline': 'True'}
8181

8282
# first test for field without character limit
@@ -98,7 +98,7 @@ def test_ValueMap_set_get(self):
9898
layer = QgsVectorLayer("none?field=number:integer", "layer", "memory")
9999
assert layer.isValid()
100100
QgsProject.instance().addMapLayer(layer)
101-
reg = QgsEditorWidgetRegistry.instance()
101+
reg = QgsGui.editorWidgetRegistry()
102102
configWdg = reg.createConfigWidget('ValueMap', layer, 0, None)
103103

104104
config = {'map': {'two': '2', 'twoandhalf': '2.5', 'NULL text': 'NULL',

‎tests/src/python/test_qgsrangewidgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import qgis # NOQA
1616

1717
from qgis.core import QgsFeature, QgsGeometry, QgsPoint, QgsVectorLayer, NULL
18-
from qgis.gui import QgsEditorWidgetRegistry
18+
from qgis.gui import QgsGui
1919
from qgis.testing import start_app, unittest
2020

2121
start_app()
@@ -25,7 +25,7 @@ class TestQgsRangeWidget(unittest.TestCase):
2525

2626
@classmethod
2727
def setUpClass(cls):
28-
QgsEditorWidgetRegistry.initEditors()
28+
QgsGui.editorWidgetRegistry().initEditors()
2929

3030
def setUp(self):
3131
"""
@@ -42,7 +42,7 @@ def __createRangeWidget(self, allownull=False):
4242
"""
4343
create a range widget
4444
"""
45-
reg = QgsEditorWidgetRegistry.instance()
45+
reg = QgsGui.editorWidgetRegistry()
4646
configWdg = reg.createConfigWidget('Range', self.layer, 1, None)
4747
config = configWdg.config()
4848

‎tests/src/python/test_qgsrelationeditwidget.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
)
2828

2929
from qgis.gui import (
30-
QgsEditorWidgetRegistry,
30+
QgsGui,
3131
QgsRelationWidgetWrapper,
3232
QgsAttributeEditorContext
3333
)
@@ -47,7 +47,7 @@ def setUpClass(cls):
4747
Setup the involved layers and relations for a n:m relation
4848
:return:
4949
"""
50-
QgsEditorWidgetRegistry.initEditors()
50+
QgsGui.editorWidgetRegistry().initEditors()
5151
cls.dbconn = 'service=\'qgis_test\''
5252
if 'QGIS_PGTEST_DB' in os.environ:
5353
cls.dbconn = os.environ['QGIS_PGTEST_DB']

0 commit comments

Comments
 (0)
Please sign in to comment.