Skip to content
Permalink
Browse files

Remove editor widget project loading code from gui

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent 9fd0802 commit c9f8ac2afed0ff232b800fbdd8dc952029249e27
Showing with 2 additions and 775 deletions.
  1. +0 −45 python/gui/editorwidgets/core/qgseditorwidgetfactory.sip
  2. +1 −2 src/core/qgsvectorlayer.cpp
  3. +0 −48 src/gui/editorwidgets/core/qgseditorwidgetfactory.cpp
  4. +0 −45 src/gui/editorwidgets/core/qgseditorwidgetfactory.h
  5. +0 −163 src/gui/editorwidgets/core/qgseditorwidgetregistry.cpp
  6. +0 −51 src/gui/editorwidgets/core/qgseditorwidgetregistry.h
  7. +0 −23 src/gui/editorwidgets/qgscheckboxwidgetfactory.cpp
  8. +0 −2 src/gui/editorwidgets/qgscheckboxwidgetfactory.h
  9. +0 −46 src/gui/editorwidgets/qgsexternalresourcewidgetfactory.cpp
  10. +0 −5 src/gui/editorwidgets/qgsexternalresourcewidgetfactory.h
  11. +0 −17 src/gui/editorwidgets/qgskeyvaluewidgetfactory.cpp
  12. +0 −2 src/gui/editorwidgets/qgskeyvaluewidgetfactory.h
  13. +0 −17 src/gui/editorwidgets/qgslistwidgetfactory.cpp
  14. +0 −2 src/gui/editorwidgets/qgslistwidgetfactory.h
  15. +0 −23 src/gui/editorwidgets/qgsphotowidgetfactory.cpp
  16. +0 −6 src/gui/editorwidgets/qgsphotowidgetfactory.h
  17. +0 −30 src/gui/editorwidgets/qgsrangewidgetfactory.cpp
  18. +0 −2 src/gui/editorwidgets/qgsrangewidgetfactory.h
  19. +0 −62 src/gui/editorwidgets/qgsrelationreferencefactory.cpp
  20. +0 −22 src/gui/editorwidgets/qgsrelationreferencefactory.h
  21. +1 −25 src/gui/editorwidgets/qgstexteditwidgetfactory.cpp
  22. +0 −7 src/gui/editorwidgets/qgstexteditwidgetfactory.h
  23. +0 −20 src/gui/editorwidgets/qgsuniquevaluewidgetfactory.cpp
  24. +0 −2 src/gui/editorwidgets/qgsuniquevaluewidgetfactory.h
  25. +0 −38 src/gui/editorwidgets/qgsvaluemapwidgetfactory.cpp
  26. +0 −5 src/gui/editorwidgets/qgsvaluemapwidgetfactory.h
  27. +0 −35 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.cpp
  28. +0 −2 src/gui/editorwidgets/qgsvaluerelationwidgetfactory.h
  29. +0 −23 src/gui/editorwidgets/qgswebviewwidgetfactory.cpp
  30. +0 −5 src/gui/editorwidgets/qgswebviewwidgetfactory.h
@@ -67,28 +67,6 @@ class QgsEditorWidgetFactory
*/
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const = 0 /Factory/;

/**
* Read the config from an XML file and map it to a proper {@link QVariantMap}.
*
* @param configElement The configuration element from the project file
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*
* @return A configuration object. This will be passed to your widget wrapper later on
*/
QVariantMap readEditorConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );

/**
* Serialize your configuration and save it in a xml doc.
*
* @param config The configuration to serialize
* @param configElement The element, where you can write your configuration into
* @param doc The document. You can use this to create new nodes
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*/
virtual void writeConfig( const QVariantMap& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx );

/**
* Check if this editor widget type supports a certain field.
*
@@ -110,17 +88,6 @@ class QgsEditorWidgetFactory
*/
//virtual QHash<const char*, int> supportedWidgetTypes();

/**
* Read the config from an XML file and map it to a proper {@link QVariantMap}.
*
* @param configElement The configuration element from the project file
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*
* @return A configuration object. This will be passed to your widget wrapper later on
*/
virtual QVariantMap readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );

/**
* This method allows disabling this editor widget type for a certain field.
* By default, it returns 5 for every fields.
@@ -140,16 +107,4 @@ class QgsEditorWidgetFactory
* @see supportsField( QgsVectorLayer* vl, fieldIdx )
*/
virtual unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const;

protected:

/**
* Copy the given config element to a XML attribute.
*/
static void config2xml( const QVariantMap& config, QDomElement& configElement, const QString& fieldName );

/**
* Copy the given XML attribute to the configuration element.
*/
static void xml2config( const QDomElement& configElement, QVariantMap& config, const QString& fieldName );
};
@@ -1977,9 +1977,8 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
{
( void )writeStyle( node, doc, errorMessage );

QgsFields dataProviderFields = mDataProvider->fields();

QDomElement fieldConfigurationElement = doc.createElement( QStringLiteral( "fieldConfiguration" ) );
node.appendChild( fieldConfigurationElement );

int index = 0;
Q_FOREACH ( const QgsField& field, mFields )
@@ -46,57 +46,9 @@ QString QgsEditorWidgetFactory::name()
return mName;
}

QVariantMap QgsEditorWidgetFactory::readEditorConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
return readConfig( configElement, layer, fieldIdx );
}

void QgsEditorWidgetFactory::writeConfig( const QVariantMap& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx )
{
Q_UNUSED( config );
Q_UNUSED( configElement );
Q_UNUSED( doc );
Q_UNUSED( layer );
Q_UNUSED( fieldIdx );
}

QVariantMap QgsEditorWidgetFactory::readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx )
{
Q_UNUSED( configElement );
Q_UNUSED( layer );
Q_UNUSED( fieldIdx );

return QVariantMap();
}

unsigned int QgsEditorWidgetFactory::fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const
{
Q_UNUSED( vl )
Q_UNUSED( fieldIdx )
return 5;
}

void QgsEditorWidgetFactory::config2xml( const QVariantMap& config, QDomElement& configElement, const QString& fieldName )
{
const QVariant value = config.value( fieldName );
if ( value.isValid() )
{
if ( value.type() == QVariant::Bool )
{
configElement.setAttribute( fieldName, value.toBool() ? "1" : "0" );
}
else
{
configElement.setAttribute( fieldName, value.toString() );
}
}
}

void QgsEditorWidgetFactory::xml2config( const QDomElement& configElement, QVariantMap& config, const QString& fieldName )
{
const QString value = configElement.attribute( fieldName );
if ( !value.isNull() )
{
config.insert( fieldName, value );
}
}
@@ -84,28 +84,6 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual QgsEditorConfigWidget* configWidget( QgsVectorLayer* vl, int fieldIdx, QWidget* parent ) const = 0;

/**
* Read the config from an XML file and map it to a proper {@link QVariantMap}.
*
* @param configElement The configuration element from the project file
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*
* @return A configuration object. This will be passed to your widget wrapper later on
*/
QVariantMap readEditorConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );

/**
* Serialize your configuration and save it in a xml doc.
*
* @param config The configuration to serialize
* @param configElement The element, where you can write your configuration into
* @param doc The document. You can use this to create new nodes
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*/
virtual void writeConfig( const QVariantMap& config, QDomElement& configElement, QDomDocument& doc, const QgsVectorLayer* layer, int fieldIdx );

/**
* Check if this editor widget type supports a certain field.
*
@@ -127,17 +105,6 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual QHash<const char*, int> supportedWidgetTypes() { return QHash<const char*, int>(); }

/**
* Read the config from an XML file and map it to a proper {@link QVariantMap}.
*
* @param configElement The configuration element from the project file
* @param layer The layer for which this configuration applies
* @param fieldIdx The field on the layer for which this configuration applies
*
* @return A configuration object. This will be passed to your widget wrapper later on
*/
virtual QVariantMap readConfig( const QDomElement& configElement, QgsVectorLayer* layer, int fieldIdx );

/**
* This method allows disabling this editor widget type for a certain field.
* By default, it returns 5 for every fields.
@@ -158,18 +125,6 @@ class GUI_EXPORT QgsEditorWidgetFactory
*/
virtual unsigned int fieldScore( const QgsVectorLayer* vl, int fieldIdx ) const;

protected:

/**
* Copy the given config element to a XML attribute.
*/
static void config2xml( const QVariantMap& config, QDomElement& configElement, const QString& fieldName );

/**
* Copy the given XML attribute to the configuration element.
*/
static void xml2config( const QDomElement& configElement, QVariantMap& config, const QString& fieldName );

private:
QString mName;
};
@@ -80,11 +80,6 @@ void QgsEditorWidgetRegistry::initEditors( QgsMapCanvas *mapCanvas, QgsMessageBa

QgsEditorWidgetRegistry::QgsEditorWidgetRegistry()
{
// connect( QgsProject::instance(), SIGNAL( readMapLayer( QgsMapLayer*, const QDomElement& ) ), this, SLOT( readMapLayer( QgsMapLayer*, const QDomElement& ) ) );
// connect( QgsProject::instance(), SIGNAL( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ), this, SLOT( writeMapLayer( QgsMapLayer*, QDomElement&, QDomDocument& ) ) );

connect( QgsProject::instance(), SIGNAL( layerWillBeRemoved( QgsMapLayer* ) ), this, SLOT( mapLayerWillBeRemoved( QgsMapLayer* ) ) );
connect( QgsProject::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( mapLayerAdded( QgsMapLayer* ) ) );
}

QgsEditorWidgetRegistry::~QgsEditorWidgetRegistry()
@@ -222,164 +217,6 @@ bool QgsEditorWidgetRegistry::registerWidget( const QString& widgetId, QgsEditor
}
}

void QgsEditorWidgetRegistry::readMapLayer( QgsMapLayer* mapLayer, const QDomElement& layerElem )
{
if ( mapLayer->type() != QgsMapLayer::VectorLayer )
{
return;
}

QgsVectorLayer* vectorLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
Q_ASSERT( vectorLayer );

QDomNodeList editTypeNodes = layerElem.namedItem( QStringLiteral( "edittypes" ) ).childNodes();

QgsEditFormConfig formConfig = vectorLayer->editFormConfig();

for ( int i = 0; i < editTypeNodes.size(); i++ )
{
QDomNode editTypeNode = editTypeNodes.at( i );
QDomElement editTypeElement = editTypeNode.toElement();

QString name = editTypeElement.attribute( QStringLiteral( "name" ) );

int idx = vectorLayer->fields().lookupField( name );
if ( idx == -1 )
continue;

QString ewv2Type = editTypeElement.attribute( QStringLiteral( "widgetv2type" ) );
QVariantMap cfg;

if ( mWidgetFactories.contains( ewv2Type ) )
{
formConfig.setWidgetType( name, ewv2Type );
QDomElement ewv2CfgElem = editTypeElement.namedItem( QStringLiteral( "widgetv2config" ) ).toElement();

if ( !ewv2CfgElem.isNull() )
{
cfg = mWidgetFactories[ewv2Type]->readEditorConfig( ewv2CfgElem, vectorLayer, idx );
}

formConfig.setReadOnly( idx, ewv2CfgElem.attribute( QStringLiteral( "fieldEditable" ), QStringLiteral( "1" ) ) != QLatin1String( "1" ) );
formConfig.setLabelOnTop( idx, ewv2CfgElem.attribute( QStringLiteral( "labelOnTop" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
if ( ewv2CfgElem.attribute( QStringLiteral( "notNull" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) )
{
// upgrade from older config
vectorLayer->setFieldConstraint( idx, QgsFieldConstraints::ConstraintNotNull );
}
if ( !ewv2CfgElem.attribute( QStringLiteral( "constraint" ), QString() ).isEmpty() )
{
// upgrade from older config
vectorLayer->setConstraintExpression( idx, ewv2CfgElem.attribute( QStringLiteral( "constraint" ), QString() ),
ewv2CfgElem.attribute( QStringLiteral( "constraintDescription" ), QString() ) );
}

formConfig.setWidgetConfig( name, cfg );
}
else
{
QgsMessageLog::logMessage( tr( "Unknown attribute editor widget '%1'" ).arg( ewv2Type ) );
}
}

vectorLayer->setEditFormConfig( formConfig );
}

void QgsEditorWidgetRegistry::writeMapLayer( QgsMapLayer* mapLayer, QDomElement& layerElem, QDomDocument& doc ) const
{
if ( mapLayer->type() != QgsMapLayer::VectorLayer )
{
return;
}

QgsVectorLayer* vectorLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
if ( !vectorLayer )
{
return;
}

QDomNode editTypesNode = doc.createElement( QStringLiteral( "edittypes" ) );

QgsFields fields = vectorLayer->fields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
const QgsField field = fields.at( idx );
const QString& widgetType = vectorLayer->editFormConfig().widgetType( field.name() );
if ( widgetType.isNull() )
{
// Don't save widget config if it is not manually edited
continue;
}
if ( !mWidgetFactories.contains( widgetType ) )
{
QgsMessageLog::logMessage( tr( "Could not save unknown editor widget type '%1'." ).arg( widgetType ) );
continue;
}


QDomElement editTypeElement = doc.createElement( QStringLiteral( "edittype" ) );
editTypeElement.setAttribute( QStringLiteral( "name" ), field.name() );
editTypeElement.setAttribute( QStringLiteral( "widgetv2type" ), widgetType );

if ( mWidgetFactories.contains( widgetType ) )
{
QDomElement ewv2CfgElem = doc.createElement( QStringLiteral( "widgetv2config" ) );
ewv2CfgElem.setAttribute( QStringLiteral( "fieldEditable" ), !vectorLayer->editFormConfig().readOnly( idx ) );
ewv2CfgElem.setAttribute( QStringLiteral( "labelOnTop" ), vectorLayer->editFormConfig().labelOnTop( idx ) );

mWidgetFactories[widgetType]->writeConfig( vectorLayer->editFormConfig().widgetConfig( field.name() ), ewv2CfgElem, doc, vectorLayer, idx );

editTypeElement.appendChild( ewv2CfgElem );
}

editTypesNode.appendChild( editTypeElement );
}

layerElem.appendChild( editTypesNode );
}

void QgsEditorWidgetRegistry::mapLayerWillBeRemoved( QgsMapLayer* mapLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );

if ( vl )
{
disconnect( vl, SIGNAL( readCustomSymbology( const QDomElement&, QString& ) ), this, SLOT( readSymbology( const QDomElement&, QString& ) ) );
disconnect( vl, SIGNAL( writeCustomSymbology( QDomElement&, QDomDocument&, QString& ) ), this, SLOT( writeSymbology( QDomElement&, QDomDocument&, QString& ) ) );
}
}

void QgsEditorWidgetRegistry::mapLayerAdded( QgsMapLayer* mapLayer )
{
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mapLayer );

if ( vl )
{
connect( vl, SIGNAL( readCustomSymbology( const QDomElement&, QString& ) ), this, SLOT( readSymbology( const QDomElement&, QString& ) ) );
connect( vl, SIGNAL( writeCustomSymbology( QDomElement&, QDomDocument&, QString& ) ), this, SLOT( writeSymbology( QDomElement&, QDomDocument&, QString& ) ) );
}
}

void QgsEditorWidgetRegistry::readSymbology( const QDomElement& element, QString& errorMessage )
{
Q_UNUSED( errorMessage )
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( sender() );

Q_ASSERT( vl );

readMapLayer( vl, element );
}

void QgsEditorWidgetRegistry::writeSymbology( QDomElement& element, QDomDocument& doc, QString& errorMessage )
{
Q_UNUSED( errorMessage )
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( sender() );

Q_ASSERT( vl );

writeMapLayer( vl, element, doc );
}

QString QgsEditorWidgetRegistry::findSuitableWrapper( QWidget* editor, const QString& defaultWidget )
{
QMap<const char*, QPair<int, QString> >::ConstIterator it;

0 comments on commit c9f8ac2

Please sign in to comment.
You can’t perform that action at this time.