Skip to content
Permalink
Browse files
Make a new global QgsGui singleton
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 4a5c9a7ba3297af6264b34b49c55ce6f985c6552
Showing with 278 additions and 117 deletions.
  1. +4 −3 doc/api_break.dox
  2. +0 −9 python/gui/editorwidgets/core/qgseditorwidgetregistry.sip
  3. +1 −0 python/gui/gui.sip
  4. +53 −0 python/gui/qgsgui.sip
  5. +5 −5 src/app/ogr/qgsvectorlayersaveasdialog.cpp
  6. +3 −2 src/app/qgisapp.cpp
  7. +4 −3 src/app/qgsattributetabledialog.cpp
  8. +3 −2 src/app/qgsattributetypedialog.cpp
  9. +4 −3 src/app/qgsfieldsproperties.cpp
  10. +5 −4 src/app/qgsidentifyresultsdialog.cpp
  11. +3 −2 src/app/qgsmergeattributesdialog.cpp
  12. +2 −0 src/gui/CMakeLists.txt
  13. +2 −2 src/gui/attributetable/qgsattributetabledelegate.cpp
  14. +3 −3 src/gui/attributetable/qgsattributetablemodel.cpp
  15. +2 −1 src/gui/attributetable/qgsdualview.cpp
  16. +2 −1 src/gui/editorwidgets/core/qgseditorwidgetautoconf.cpp
  17. +16 −24 src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
  18. +8 −10 src/gui/editorwidgets/core/qgseditorwidgetregistry.h
  19. +9 −8 src/gui/qgsattributeform.cpp
  20. +3 −2 src/gui/qgsattributeformeditorwidget.cpp
  21. +2 −1 src/gui/qgsformannotation.cpp
  22. +40 −0 src/gui/qgsgui.cpp
  23. +66 −0 src/gui/qgsgui.h
  24. +2 −1 src/server/qgsserver.cpp
  25. +2 −1 src/server/qgsserverprojectparser.cpp
  26. +2 −1 src/server/services/wms/qgswmsrenderer.cpp
  27. +2 −1 tests/src/app/testqgsvectorlayersaveasdialog.cpp
  28. +2 −1 tests/src/gui/testqgsattributeform.cpp
  29. +2 −1 tests/src/gui/testqgsdualview.cpp
  30. +8 −8 tests/src/gui/testqgseditorwidgetregistry.cpp
  31. +4 −4 tests/src/python/test_provider_postgres.py
  32. +2 −2 tests/src/python/test_qgsattributeformeditorwidget.py
  33. +2 −2 tests/src/python/test_qgsattributetablemodel.py
  34. +5 −5 tests/src/python/test_qgseditwidgets.py
  35. +3 −3 tests/src/python/test_qgsrangewidgets.py
  36. +2 −2 tests/src/python/test_qgsrelationeditwidget.py
@@ -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()
@@ -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.

@@ -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}
@@ -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.
@@ -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
@@ -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 *
************************************************************************/
@@ -23,7 +23,7 @@
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"

#include "qgsgui.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QTextCodec>
@@ -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;
@@ -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 );
@@ -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"
@@ -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 );
@@ -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 );
}
@@ -49,6 +49,7 @@
#include "qgsfields.h"
#include "qgseditorwidgetregistry.h"
#include "qgsfieldproxymodel.h"
#include "qgsgui.h"

QgsExpressionContext QgsAttributeTableDialog::createExpressionContext() const
{
@@ -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 );
@@ -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() )
{
@@ -27,6 +27,7 @@
#include "qgsfieldformatter.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
#include "qgsgui.h"

#include <QTableWidgetItem>
#include <QFile>
@@ -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();
@@ -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 )
{
@@ -29,6 +29,7 @@
#include "qgsvectorlayer.h"
#include "qgsfieldexpressionwidget.h"
#include "qgssettings.h"
#include "qgsgui.h"

#include <QTreeWidgetItem>
#include <QWidget>
@@ -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 );

@@ -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" ) );

@@ -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();
}
@@ -46,6 +46,7 @@
#include "qgsfieldformatterregistry.h"
#include "qgsfieldformatter.h"
#include "qgssettings.h"
#include "qgsgui.h"

#include <QCloseEvent>
#include <QLabel>
@@ -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;
@@ -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 );
@@ -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 );
@@ -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 );
@@ -28,6 +28,7 @@
#include "qgsstatisticalsummary.h"
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"
#include "qgsgui.h"

#include <limits>
#include <QComboBox>
@@ -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 );
@@ -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 ) );
@@ -226,6 +226,7 @@ SET(QGIS_GUI_SRCS
qgsgradientcolorrampdialog.cpp
qgsgradientstopeditor.cpp
qgsgroupwmsdatadialog.cpp
qgsgui.cpp
qgshighlight.cpp
qgshistogramwidget.cpp
qgshelp.cpp
@@ -621,6 +622,7 @@ SET(QGIS_GUI_HDRS
qgsdetaileditemdata.h
qgsexpressionbuilderdialog.h
qgsfiledropedit.h
qgsgui.h
qgshelp.h
qgshighlight.h
qgsmapcanvasitem.h
@@ -29,7 +29,7 @@
#include "qgslogger.h"
#include "qgsvectordataprovider.h"
#include "qgsactionmanager.h"

#include "qgsgui.h"

QgsVectorLayer *QgsAttributeTableDelegate::layer( const QAbstractItemModel *model )
{
@@ -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 );
@@ -33,7 +33,7 @@
#include "qgsvectordataprovider.h"
#include "qgssymbollayerutils.h"
#include "qgsfieldformatterregistry.h"

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

#include <limits>
@@ -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 )
@@ -29,6 +29,7 @@
#include "qgseditorwidgetregistry.h"
#include "qgssettings.h"
#include "qgsscrollarea.h"
#include "qgsgui.h"

#include <QClipboard>
#include <QDialog>
@@ -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();

0 comments on commit 4a5c9a7

Please sign in to comment.