Skip to content

Commit

Permalink
Revert "Merge pull request #3338 from pvalsecc/editor_widgets_selection"
Browse files Browse the repository at this point in the history
This reverts commit bbafbf4, reversing
changes made to 13ac043.
  • Loading branch information
m-kuhn committed Aug 29, 2016
1 parent b144823 commit a529b44
Show file tree
Hide file tree
Showing 61 changed files with 234 additions and 909 deletions.
17 changes: 0 additions & 17 deletions doc/api_break.dox
Expand Up @@ -507,8 +507,6 @@ place of a null pointer.</li>


<ul> <ul>
<li>Does no longer inherit QObject <li>Does no longer inherit QObject
<li>widgetType() and widgetConfig() now reflect only the user configured values.
QgsEditorWidgetRegistry::instance()->findBest() must be used instead.</li>
</ul> </ul>


\subsection qgis_api_break_3_0_QgsExpression QgsExpression \subsection qgis_api_break_3_0_QgsExpression QgsExpression
Expand Down Expand Up @@ -613,13 +611,6 @@ and the new ramp can be retrieved after executing the dialog by calling ramp().<
plugins calling this method will need to be updated.</li> plugins calling this method will need to be updated.</li>
</ul> </ul>


\subsection qgis_api_break_3_0_QgsEditorWidgetRegistry QgsEditorWidgetRegistry

<ul>
<li>The signature of isFieldSupported() has been changed to return an unsigned (how good it supports the given field)
and to const-correct it.</li>
</ul>

\subsection qgis_api_break_3_0_QgsGroupWMSDataDialog QgsGroupWMSDataDialog \subsection qgis_api_break_3_0_QgsGroupWMSDataDialog QgsGroupWMSDataDialog


<ul> <ul>
Expand Down Expand Up @@ -855,14 +846,6 @@ plugins calling this method will need to be updated.</li>


<ul> <ul>
<li>setMapRenderer() has been removed. Use setMapSettings() instead.</li> <li>setMapRenderer() has been removed. Use setMapSettings() instead.</li>
<li>excludeAttributesWMS() and setExcludeAttributesWMS() have been renamed to excludeAttributesWms() and
setExcludeAttributesWms()</li>
<li>excludeAttributesWFS() and setExcludeAttributesWFS() have been renamed to excludeAttributesWfs() and
setExcludeAttributesWfs()</li>
<li>editorWidgetV2() and editorWidgetV2Config() have been removed and QgsEditorWidgetRegistry::instance()->findBest() must be used instead.</li>
<li>setEditorWidgetV2(), setEditorWidgetV2Config() have been removed and their equivalent in editFormConfig() must be used instead.</li>
<li>setCheckedState() is removed. Use editFormConfig()->setWidgetConfig()` instead.</li>
<li>valueMap(), valueRelation(), dateFormat(), widgetSize() have been removed. Use QgsEditorWidgetRegistry::instance()->findBest().config() instead.</li>
</ul> </ul>


\subsection qgis_api_break_3_0_QgsRenderContext QgsRenderContext \subsection qgis_api_break_3_0_QgsRenderContext QgsRenderContext
Expand Down
48 changes: 39 additions & 9 deletions python/core/qgseditformconfig.sip
Expand Up @@ -142,6 +142,15 @@ class QgsEditFormConfig
*/ */
void setWidgetType( int fieldIdx, const QString& widgetType ); void setWidgetType( int fieldIdx, const QString& widgetType );


/**
* Get the id for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return The id for the editor widget or a NULL string if not applicable
*/
QString widgetType( int fieldIdx ) const;

/** /**
* Get the id for the editor widget used to represent the field at the given index * Get the id for the editor widget used to represent the field at the given index
* *
Expand All @@ -168,14 +177,40 @@ class QgsEditFormConfig
*/ */
void setWidgetConfig( int attrIdx, const QgsEditorWidgetConfig& config ); void setWidgetConfig( int attrIdx, const QgsEditorWidgetConfig& config );


/**
* Set the editor widget config for a widget.
*
* Example:
* \code{.py}
* layer.setWidgetConfig( 'relation_id', { 'nm-rel': 'other_relation' } )
* \endcode
*
* @param widgetName The name of the widget or field to configure
* @param config The config to set for this field
*
* @see setWidgetType() for a list of widgets and choose the widget to see the available options.
*
* @note not available in python bindings
*/
// void setWidgetConfig( const QString& widgetName, const QgsEditorWidgetConfig& config );

/**
* Get the configuration for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return The configuration for the editor widget or an empty config if the field does not exist
*/
QgsEditorWidgetConfig widgetConfig( int fieldIdx ) const;

/** /**
* Get the configuration for the editor widget used to represent the field with the given name * Get the configuration for the editor widget used to represent the field with the given name
* *
* @param fieldName The name of the field. * @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
* *
* @return The configuration for the editor widget or an empty config if the field does not exist * @return The configuration for the editor widget or an empty config if the field does not exist
*/ */
QgsEditorWidgetConfig widgetConfig( const QString& fieldName ) const; QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;


/** /**
* Remove the configuration for the editor widget used to represent the field at the given index * Remove the configuration for the editor widget used to represent the field at the given index
Expand All @@ -189,11 +224,11 @@ class QgsEditFormConfig
/** /**
* Remove the configuration for the editor widget used to represent the field with the given name * Remove the configuration for the editor widget used to represent the field with the given name
* *
* @param fieldName The name of the field. * @param widgetName The name of the widget. This can be a field name or the name of an additional widget.
* *
* @return true if successful, false if the field does not exist * @return true if successful, false if the field does not exist
*/ */
bool removeWidgetConfig( const QString& fieldName ); bool removeWidgetConfig( const QString& widgetName );


/** /**
* This returns true if the field is manually set to read only or if the field * This returns true if the field is manually set to read only or if the field
Expand Down Expand Up @@ -337,9 +372,4 @@ class QgsEditFormConfig
* Deserialize drag and drop designer elements. * Deserialize drag and drop designer elements.
*/ */
QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement* parent ); QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QgsAttributeEditorElement* parent );

/**
* Parse the XML for the config of one editor widget.
*/
static QgsEditorWidgetConfig parseEditorWidgetConfig( const QDomElement& cfgElem );
}; };
45 changes: 0 additions & 45 deletions python/core/qgsfield.sip
@@ -1,35 +1,3 @@
/** \ingroup core
* Holder for the widget type and its configuration for a field.
*/
class QgsEditorWidgetSetup
{
%TypeHeaderCode
#include <qgsfield.h>
%End
public:
/**
* Constructor
*/
QgsEditorWidgetSetup( const QString& type, const QgsEditorWidgetConfig& config );
QgsEditorWidgetSetup();

/**
* @return the widget type to use
*/
QString type() const;

/**
* @return the widget configuration to used
*/
QgsEditorWidgetConfig config() const;

/**
* @return true if there is no widget configured.
*/
bool isNull() const;
};


/** \class QgsField /** \class QgsField
* \ingroup core * \ingroup core
* Encapsulate a field in an attribute table or data source. * Encapsulate a field in an attribute table or data source.
Expand Down Expand Up @@ -211,19 +179,6 @@ class QgsField
//! Allows direct construction of QVariants from fields. //! Allows direct construction of QVariants from fields.
operator QVariant() const; operator QVariant() const;


/**
* Set the editor widget setup for the field.
*
* @param v The value to set
*/
void setEditorWidgetSetup( const QgsEditorWidgetSetup& v );

/**
* Get the editor widget setup for the field.
*
* @return the value
*/
const QgsEditorWidgetSetup& editorWidgetSetup() const;
}; // class QgsField }; // class QgsField




Expand Down
41 changes: 0 additions & 41 deletions python/gui/editorwidgets/core/qgseditorwidgetautoconf.sip

This file was deleted.

14 changes: 4 additions & 10 deletions python/gui/editorwidgets/core/qgseditorwidgetfactory.sip
Expand Up @@ -170,23 +170,17 @@ class QgsEditorWidgetFactory
*/ */
virtual QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx ); virtual QgsEditorWidgetConfig readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );


private:
/** /**
* This method allows disabling this editor widget type for a certain field. * This method allows disabling this editor widget type for a certain field.
* By default, it returns 5 for every fields. * By default, it returns true for all fields.
* Reimplement this if you only support certain fields. * Reimplement this if you only support certain fields.
* *
* Typical return values are:
* * 0: not supported
* * 5: maybe support (for example, Datetime support strings depending on their content)
* * 10: basic support (this is what returns TextEdit for example, since it supports everything in a crude way)
* * 20: specialised support
*
* @param vl * @param vl
* @param fieldIdx * @param fieldIdx
* @return 0 if the field is not supported or a bigger number if it can (the widget with the biggest number will be * @return True if the field is supported.
* taken by default). The default implementation returns 5..
* *
* @see supportsField( QgsVectorLayer* vl, fieldIdx ) * @see supportsField( QgsVectorLayer* vl, fieldIdx )
*/ */
virtual unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const; virtual bool isFieldSupported( QgsVectorLayer* vl, int fieldIdx );
}; };
19 changes: 0 additions & 19 deletions python/gui/editorwidgets/core/qgseditorwidgetregistry.sip
Expand Up @@ -13,7 +13,6 @@
* * * *
***************************************************************************/ ***************************************************************************/



/** /**
* This class manages all known edit widget factories * This class manages all known edit widget factories
*/ */
Expand Down Expand Up @@ -44,17 +43,6 @@ class QgsEditorWidgetRegistry : QObject
*/ */
static void initEditors( QgsMapCanvas* mapCanvas = 0, QgsMessageBar* messageBar = 0 ); static void initEditors( QgsMapCanvas* mapCanvas = 0, QgsMessageBar* messageBar = 0 );


/**
* Find the best editor widget and its configuration for a given field.
*
* @param vl The vector layer for which this widget will be created
* @param fieldIdx The field index on the specified layer for which this widget will be created
*
* @return The id of the widget type to use and its config
*/
QgsEditorWidgetSetup findBest( const QgsVectorLayer* vl, const QString& fieldName ) const;


/** /**
* Create an attribute editor widget wrapper of a given type for a given field. * Create an attribute editor widget wrapper of a given type for a given field.
* The editor may be NULL if you want the widget wrapper to create a default widget. * The editor may be NULL if you want the widget wrapper to create a default widget.
Expand Down Expand Up @@ -128,11 +116,4 @@ class QgsEditorWidgetRegistry : QObject
* @return true, if successful, false, if the widgetId is already in use or widgetFactory is NULL * @return true, if successful, false, if the widgetId is already in use or widgetFactory is NULL
*/ */
bool registerWidget( const QString& widgetId, QgsEditorWidgetFactory* widgetFactory /Transfer/ ); bool registerWidget( const QString& widgetId, QgsEditorWidgetFactory* widgetFactory /Transfer/ );

/**
* Register a new auto-conf plugin.
*
* @param plugin The plugin (ownership is transfered)
*/
void registerAutoConfPlugin( QgsEditorWidgetAutoConfPlugin* plugin );
}; };
1 change: 0 additions & 1 deletion python/gui/gui.sip
Expand Up @@ -258,7 +258,6 @@
%Include effects/qgspainteffectwidget.sip %Include effects/qgspainteffectwidget.sip


%Include editorwidgets/core/qgseditorconfigwidget.sip %Include editorwidgets/core/qgseditorconfigwidget.sip
%Include editorwidgets/core/qgseditorwidgetautoconf.sip
%Include editorwidgets/core/qgseditorwidgetfactory.sip %Include editorwidgets/core/qgseditorwidgetfactory.sip
%Include editorwidgets/core/qgseditorwidgetregistry.sip %Include editorwidgets/core/qgseditorwidgetregistry.sip
%Include editorwidgets/core/qgseditorwidgetwrapper.sip %Include editorwidgets/core/qgseditorwidgetwrapper.sip
Expand Down
10 changes: 4 additions & 6 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -249,9 +249,8 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
bool foundFieldThatCanBeExportedAsDisplayedValue = false; bool foundFieldThatCanBeExportedAsDisplayedValue = false;
for ( int i = 0; i < mLayer->fields().size(); ++i ) for ( int i = 0; i < mLayer->fields().size(); ++i )
{ {
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() ); if ( mLayer->editFormConfig().widgetType( i ) != "TextEdit" &&
if ( setup.type() != "TextEdit" && QgsEditorWidgetRegistry::instance()->factory( mLayer->editFormConfig().widgetType( i ) ) )
QgsEditorWidgetRegistry::instance()->factory( setup.type() ) )
{ {
foundFieldThatCanBeExportedAsDisplayedValue = true; foundFieldThatCanBeExportedAsDisplayedValue = true;
break; break;
Expand Down Expand Up @@ -286,11 +285,10 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx


if ( foundFieldThatCanBeExportedAsDisplayedValue ) if ( foundFieldThatCanBeExportedAsDisplayedValue )
{ {
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields()[i].name() );
QgsEditorWidgetFactory *factory = nullptr; QgsEditorWidgetFactory *factory = nullptr;
if ( flags == Qt::ItemIsEnabled && if ( flags == Qt::ItemIsEnabled &&
setup.type() != "TextEdit" && mLayer->editFormConfig().widgetType( i ) != "TextEdit" &&
( factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() ) ) ) ( factory = QgsEditorWidgetRegistry::instance()->factory( mLayer->editFormConfig().widgetType( i ) ) ) )
{ {
item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) ); item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
item->setFlags(( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable ); item->setFlags(( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -6149,11 +6149,11 @@ QVariant QgisAppFieldValueConverter::convert( int idx, const QVariant& value )
{ {
return value; return value;
} }
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, mLayer->fields().field( idx ).name() ); QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( mLayer->editFormConfig().widgetType( idx ) );
QgsEditorWidgetFactory *factory = QgsEditorWidgetRegistry::instance()->factory( setup.type() );
if ( factory ) if ( factory )
{ {
return QVariant( factory->representValue( mLayer, idx, setup.config(), QVariant(), value ) ); QgsEditorWidgetConfig cfg( mLayer->editFormConfig().widgetConfig( idx ) );
return QVariant( factory->representValue( mLayer, idx, cfg, QVariant(), value ) );
} }
return value; return value;
} }
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsattributetabledialog.cpp
Expand Up @@ -391,7 +391,7 @@ void QgsAttributeTableDialog::columnBoxInit()
if ( idx < 0 ) if ( idx < 0 )
continue; continue;


if ( QgsEditorWidgetRegistry::instance()->findBest( mLayer, field.name() ).type() != "Hidden" ) if ( mLayer->editFormConfig().widgetType( idx ) != "Hidden" )
{ {
QIcon icon = mLayer->fields().iconForField( idx ); QIcon icon = mLayer->fields().iconForField( idx );
QString alias = mLayer->attributeDisplayName( idx ); QString alias = mLayer->attributeDisplayName( idx );
Expand Down Expand Up @@ -527,9 +527,10 @@ void QgsAttributeTableDialog::filterColumnChanged( QObject* filterAction )
int fldIdx = mLayer->fieldNameIndex( fieldName ); int fldIdx = mLayer->fieldNameIndex( fieldName );
if ( fldIdx < 0 ) if ( fldIdx < 0 )
return; return;
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, fieldName ); const QString widgetType = mLayer->editFormConfig().widgetType( fldIdx );
const QgsEditorWidgetConfig widgetConfig = mLayer->editFormConfig().widgetConfig( fldIdx );
mCurrentSearchWidgetWrapper = QgsEditorWidgetRegistry::instance()-> mCurrentSearchWidgetWrapper = QgsEditorWidgetRegistry::instance()->
createSearchWidget( setup.type(), mLayer, fldIdx, setup.config(), mFilterContainer, mEditorContext ); createSearchWidget( widgetType, mLayer, fldIdx, widgetConfig, mFilterContainer, mEditorContext );
if ( mCurrentSearchWidgetWrapper->applyDirectly() ) if ( mCurrentSearchWidgetWrapper->applyDirectly() )
{ {
connect( mCurrentSearchWidgetWrapper, SIGNAL( expressionChanged( QString ) ), SLOT( filterQueryChanged( QString ) ) ); connect( mCurrentSearchWidgetWrapper, SIGNAL( expressionChanged( QString ) ), SLOT( filterQueryChanged( QString ) ) );
Expand Down
9 changes: 4 additions & 5 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -392,9 +392,9 @@ void QgsFieldsProperties::loadRelations()
if ( nmrel.fieldPairs().at( 0 ).referencingField() != relation.fieldPairs().at( 0 ).referencingField() ) if ( nmrel.fieldPairs().at( 0 ).referencingField() != relation.fieldPairs().at( 0 ).referencingField() )
nmCombo->addItem( QString( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() ); nmCombo->addItem( QString( "%1 (%2)" ).arg( nmrel.referencedLayer()->name(), nmrel.fieldPairs().at( 0 ).referencedField() ), nmrel.id() );


const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( mLayer, relation.id() ); QgsEditorWidgetConfig cfg = mLayer->editFormConfig().widgetConfig( relation.id() );


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


int idx = nmCombo->findData( nmrelcfg.toString() ); int idx = nmCombo->findData( nmrelcfg.toString() );


Expand Down Expand Up @@ -1028,9 +1028,8 @@ QgsFieldsProperties::FieldConfig::FieldConfig( QgsVectorLayer* layer, int idx )
mNotNull = layer->editFormConfig().notNull( idx ); mNotNull = layer->editFormConfig().notNull( idx );
mConstraint = layer->editFormConfig().expression( idx ); mConstraint = layer->editFormConfig().expression( idx );
mConstraintDescription = layer->editFormConfig().expressionDescription( idx ); mConstraintDescription = layer->editFormConfig().expressionDescription( idx );
const QgsEditorWidgetSetup setup = QgsEditorWidgetRegistry::instance()->findBest( layer, layer->fields().field( idx ).name() ); mEditorWidgetType = layer->editFormConfig().widgetType( idx );
mEditorWidgetType = setup.type(); mEditorWidgetConfig = layer->editFormConfig().widgetConfig( idx );
mEditorWidgetConfig = setup.config();
} }


/* /*
Expand Down

0 comments on commit a529b44

Please sign in to comment.