Skip to content

Commit

Permalink
Make a new global QgsGui singleton
Browse files Browse the repository at this point in the history
Move QgsEditorWidgetRegistry from being a singleton itself to
instead being a member of the QgsGui singleton
  • Loading branch information
nyalldawson committed May 14, 2017
1 parent 280ca31 commit 4a5c9a7
Show file tree
Hide file tree
Showing 36 changed files with 278 additions and 117 deletions.
7 changes: 4 additions & 3 deletions doc/api_break.dox
Expand Up @@ -1011,7 +1011,7 @@ QgsEditFormConfig {#qgis_api_break_3_0_QgsEditFormConfig}

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

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

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


QgsRenderContext {#qgis_api_break_3_0_QgsRenderContext}
Expand Down
9 changes: 0 additions & 9 deletions python/gui/editorwidgets/core/qgseditorwidgetregistry.sip
Expand Up @@ -21,15 +21,6 @@ class QgsEditorWidgetRegistry : QObject
%End
public:

static QgsEditorWidgetRegistry *instance();
%Docstring
This class is a singleton and has therefore to be accessed with this method instead
of a constructor.

:return: The one and only instance of the editor widget registry
:rtype: QgsEditorWidgetRegistry
%End

static void initEditors( QgsMapCanvas *mapCanvas = 0, QgsMessageBar *messageBar = 0 );
%Docstring
Registers all the default widgets.
Expand Down
1 change: 1 addition & 0 deletions python/gui/gui.sip
Expand Up @@ -81,6 +81,7 @@
%Include qgsfloatingwidget.sip
%Include qgsfocuswatcher.sip
%Include qgsformannotation.sip
%Include qgsgui.sip
%Include qgsgeometryrubberband.sip
%Include qgsgradientcolorrampdialog.sip
%Include qgsgradientstopeditor.sip
Expand Down
53 changes: 53 additions & 0 deletions python/gui/qgsgui.sip
@@ -0,0 +1,53 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsgui.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsGui
{
%Docstring
QgsGui is a singleton class containing various registry and other global members
related to GUI classes.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsgui.h"
%End
public:



static QgsGui *instance();
%Docstring
Returns a pointer to the singleton instance.
:rtype: QgsGui
%End

static QgsEditorWidgetRegistry *editorWidgetRegistry();
%Docstring
Returns the global editor widget registry, used for managing all known edit widget factories.
.. versionadded:: 3.0
:rtype: QgsEditorWidgetRegistry
%End

~QgsGui();

private:
QgsGui( const QgsGui &other );
};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgsgui.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
10 changes: 5 additions & 5 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -23,7 +23,7 @@
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"

#include "qgsgui.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QTextCodec>
Expand Down Expand Up @@ -379,9 +379,9 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
bool foundFieldThatCanBeExportedAsDisplayedValue = false;
for ( int i = 0; i < mLayer->fields().size(); ++i )
{
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() );
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
if ( setup.type() != QLatin1String( "TextEdit" ) &&
QgsEditorWidgetRegistry::instance()->factory( setup.type() ) )
QgsGui::editorWidgetRegistry()->factory( setup.type() ) )
{
foundFieldThatCanBeExportedAsDisplayedValue = true;
break;
Expand Down Expand Up @@ -416,11 +416,11 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx

if ( foundFieldThatCanBeExportedAsDisplayedValue )
{
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() );
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields()[i].name() );
QgsEditorWidgetFactory *factory = nullptr;
if ( flags == Qt::ItemIsEnabled &&
setup.type() != QLatin1String( "TextEdit" ) &&
( factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() ) ) )
( factory = QgsGui::editorWidgetRegistry()->factory( setup.type() ) ) )
{
item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
item->setFlags( ( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgisapp.cpp
Expand Up @@ -278,6 +278,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsmaprenderertask.h"
#include "qgsmapdecoration.h"
#include "qgsnewnamedialog.h"
#include "qgsgui.h"

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

// Init the editor widget types
QgsEditorWidgetRegistry::initEditors( mMapCanvas, mInfoBar );
QgsGui::editorWidgetRegistry()->initEditors( mMapCanvas, mInfoBar );

mInternalClipboard = new QgsClipboard; // create clipboard
connect( mInternalClipboard, &QgsClipboard::changed, this, &QgisApp::clipboardChanged );
Expand Down Expand Up @@ -6810,7 +6811,7 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant &value )
{
return value;
}
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() );
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, mLayer->fields().field( idx ).name() );
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( setup.type() );
return fieldFormatter->representValue( mLayer, idx, setup.config(), QVariant(), value );
}
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -49,6 +49,7 @@
#include "qgsfields.h"
#include "qgseditorwidgetregistry.h"
#include "qgsfieldproxymodel.h"
#include "qgsgui.h"

QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
{
Expand Down Expand Up @@ -412,7 +413,7 @@ void QgsAttributeTableDialog::columnBoxInit()
if ( idx < 0 )
continue;

if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
if ( QgsGui::editorWidgetRegistry()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
{
QIcon icon = mLayer->fields().iconForField( idx );
QString alias = mLayer->attributeDisplayName( idx );
Expand Down Expand Up @@ -560,8 +561,8 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject *filterAction )
int fldIdx = mLayer->fields().lookupField( fieldName );
if ( fldIdx < 0 )
return;
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, fieldName );
mCurrentSearchWidgetWrapper = QgsEditorWidgetRegistry::instance()->
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mLayer, fieldName );
mCurrentSearchWidgetWrapper = QgsGui::editorWidgetRegistry()->
createSearchWidget( setup.type(), mLayer, fldIdx, setup.config(), mFilterContainer, mEditorContext );
if ( mCurrentSearchWidgetWrapper->applyDirectly() )
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -27,6 +27,7 @@
#include "qgsfieldformatter.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgsgui.h"

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

QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsEditorWidgetRegistry::instance()->factories() );
QMapIterator<QString, QgsEditorWidgetFactory *> it( QgsGui::editorWidgetRegistry()->factories() );
while ( it.hasNext() )
{
it.next();
Expand Down Expand Up @@ -160,7 +161,7 @@ void QgsAttributeTypeDialog::setEditorWidgetType( const QString &type )
}
else
{
QgsEditorConfigWidget *cfgWdg = QgsEditorWidgetRegistry::instance()->createConfigWidget( type, mLayer, mFieldIdx, this );
QgsEditorConfigWidget *cfgWdg = QgsGui::editorWidgetRegistry()->createConfigWidget( type, mLayer, mFieldIdx, this );

if ( cfgWdg )
{
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgsvectorlayer.h"
#include "qgsfieldexpressionwidget.h"
#include "qgssettings.h"
#include "qgsgui.h"

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

FieldConfig cfg( mLayer, idx );
QPushButton *pb = nullptr;
pb = new QPushButton( QgsEditorWidgetRegistry::instance()->name( cfg.mEditorWidgetType ) );
pb = new QPushButton( QgsGui::editorWidgetRegistry()->name( cfg.mEditorWidgetType ) );
cfg.mButton = pb;
mFieldsList->setCellWidget( row, AttrEditTypeCol, pb );

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

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

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

Expand Down Expand Up @@ -1102,7 +1103,7 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer *layer, int idx )
mConstraintStrength.insert( QgsFieldConstraints::ConstraintUnique, constraints.constraintStrength( QgsFieldConstraints::ConstraintUnique ) );
mConstraintStrength.insert( QgsFieldConstraints::ConstraintExpression, constraints.constraintStrength( QgsFieldConstraints::ConstraintExpression ) );
mConstraintDescription = constraints.constraintDescription();
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer, layer->fields().field( idx ).name() );
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( layer, layer->fields().field( idx ).name() );
mEditorWidgetType = setup.type();
mEditorWidgetConfig = setup.config();
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -46,6 +46,7 @@
#include "qgsfieldformatterregistry.h"
#include "qgsfieldformatter.h"
#include "qgssettings.h"
#include "qgsgui.h"

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

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

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

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

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

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

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

QgsTreeWidgetItem *treeItem = static_cast< QgsTreeWidgetItem * >( item );
Expand Down
5 changes: 3 additions & 2 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsstatisticalsummary.h"
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"
#include "qgsgui.h"

#include <limits>
#include <QComboBox>
Expand Down Expand Up @@ -115,7 +116,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
mHiddenAttributes.clear();
for ( int idx = 0; idx < mFields.count(); ++idx )
{
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mVectorLayer, mFields.at( idx ).name() );
const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( mVectorLayer, mFields.at( idx ).name() );
if ( setup.type() == QLatin1String( "Hidden" ) || setup.type() == QLatin1String( "Immutable" ) )
{
mHiddenAttributes.insert( idx );
Expand Down Expand Up @@ -155,7 +156,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
QTableWidgetItem *attributeValItem = new QTableWidgetItem( attrs.at( idx ).toString() );
attributeValItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
mTableWidget->setItem( i + 1, j, attributeValItem );
QgsEditorWidgetWrapper *eww = QgsEditorWidgetRegistry::instance()->create( mVectorLayer, idx, nullptr, mTableWidget, context );
QgsEditorWidgetWrapper *eww = QgsGui::editorWidgetRegistry()->create( mVectorLayer, idx, nullptr, mTableWidget, context );
if ( eww )
{
eww->setValue( attrs.at( idx ) );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -226,6 +226,7 @@ SET(QGIS_GUI_SRCS
qgsgradientcolorrampdialog.cpp
qgsgradientstopeditor.cpp
qgsgroupwmsdatadialog.cpp
qgsgui.cpp
qgshighlight.cpp
qgshistogramwidget.cpp
qgshelp.cpp
Expand Down Expand Up @@ -621,6 +622,7 @@ SET(QGIS_GUI_HDRS
qgsdetaileditemdata.h
qgsexpressionbuilderdialog.h
qgsfiledropedit.h
qgsgui.h
qgshelp.h
qgshighlight.h
qgsmapcanvasitem.h
Expand Down
4 changes: 2 additions & 2 deletions src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -29,7 +29,7 @@
#include "qgslogger.h"
#include "qgsvectordataprovider.h"
#include "qgsactionmanager.h"

#include "qgsgui.h"

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

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

w->setAutoFillBackground( true );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -33,7 +33,7 @@
#include "qgsvectordataprovider.h"
#include "qgssymbollayerutils.h"
#include "qgsfieldformatterregistry.h"

#include "qgsgui.h"
#include <QVariant>

#include <limits>
Expand Down Expand Up @@ -351,8 +351,8 @@ void QgsAttributeTableModel::loadAttributes()

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

if ( widgetFactory )
Expand Down
3 changes: 2 additions & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -29,6 +29,7 @@
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"
#include "qgsscrollarea.h"
#include "qgsgui.h"

#include <QClipboard>
#include <QDialog>
Expand Down Expand Up @@ -148,7 +149,7 @@ void QgsDualView::columnBoxInit()
if ( fieldIndex == -1 )
continue;

if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
if ( QgsGui::editorWidgetRegistry()->findBest( mLayer, field.name() ).type() != QLatin1String( "Hidden" ) )
{
QIcon icon = mLayer->fields().iconForField( fieldIndex );
QString text = field.name();
Expand Down

0 comments on commit 4a5c9a7

Please sign in to comment.