Skip to content
Permalink
Browse files

Create a default tab layout if none is configured

  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent 5c20f07 commit 633c1a3bbf2822a79fe52ad6fb3a8f6733ac593a
Showing with 44 additions and 20 deletions.
  1. +28 −9 src/core/qgseditformconfig.cpp
  2. +7 −9 src/core/qgseditformconfig.h
  3. +5 −0 src/core/qgseditformconfig_p.h
  4. +4 −2 src/core/qgsvectorlayer.cpp
@@ -53,10 +53,21 @@ QgsEditorWidgetConfig QgsEditFormConfig::widgetConfig( const QString& widgetName
return d->mWidgetConfigs.value( widgetName );
}

void QgsEditFormConfig::setFields( const QgsFields& fields )
void QgsEditFormConfig::setFields( const QgsFields& fields, const QMap<QString, QString>& attributeAliasMap )
{
d.detach();
d->mFields = fields;
d->mAttributeAliasMap = attributeAliasMap;

if ( !d->mConfiguredRootContainer )
{
d->mInvisibleRootContainer->clear();
for ( int i = 0; i < d->mFields.size(); ++i )
{
QgsAttributeEditorField* field = new QgsAttributeEditorField( d->mAttributeAliasMap.value( d->mFields.at( i ).name(), d->mFields.at( i ).name() ), i, d->mInvisibleRootContainer );
d->mInvisibleRootContainer->addChildElement( field );
}
}
}

void QgsEditFormConfig::onRelationsLoaded()
@@ -411,16 +422,24 @@ void QgsEditFormConfig::readXml( const QDomNode& node )
}

// tabs and groups display info
clearTabs();
QDomNode attributeEditorFormNode = node.namedItem( "attributeEditorForm" );
QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();

for ( int i = 0; i < attributeEditorFormNodeList.size(); i++ )
if ( !attributeEditorFormNode.isNull() )
{
QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();

QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, this );
addTab( attributeEditorWidget );
if ( attributeEditorFormNodeList.size() )
{
d->mConfiguredRootContainer = true;
clearTabs();

for ( int i = 0; i < attributeEditorFormNodeList.size(); i++ )
{
QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();

QgsAttributeEditorElement* attributeEditorWidget = attributeEditorElementFromDomElement( elem, nullptr );
addTab( attributeEditorWidget );
}
}
}


@@ -510,7 +529,7 @@ void QgsEditFormConfig::writeXml( QDomNode& node ) const
node.appendChild( editorLayoutElem );

// tabs and groups of edit form
if ( tabs().size() > 0 )
if ( tabs().size() > 0 && d->mConfiguredRootContainer )
{
QDomElement tabsElem = doc.createElement( "attributeEditorForm" );

@@ -241,12 +241,12 @@ class CORE_EXPORT QgsEditFormConfig
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;

/**
* Remove the configuration for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return true if successful, false if the field does not exist
*/
* Remove the configuration for the editor widget used to represent the field at the given index
*
* @param fieldIdx The index of the field
*
* @return true if successful, false if the field does not exist
*/
bool removeWidgetConfig( int fieldIdx );

/**
@@ -411,10 +411,8 @@ class CORE_EXPORT QgsEditFormConfig
/**
* Used internally to set the fields when they change.
* This should only be called from QgsVectorLayer for synchronization reasons
*
* @param fields The fields
*/
void setFields( const QgsFields& fields );
void setFields( const QgsFields& fields, const QMap<QString, QString>& attributeAliasMap );

/**
* Will be called by friend class QgsVectorLayer
@@ -16,6 +16,8 @@
#ifndef QGSEDITFORMCONFIG_P_H
#define QGSEDITFORMCONFIG_P_H

#include <QMap>

#include "qgsfield.h"
#include "qgseditformconfig.h"

@@ -24,6 +26,7 @@ class QgsEditFormConfigPrivate : public QSharedData
public:
QgsEditFormConfigPrivate()
: mInvisibleRootContainer( new QgsAttributeEditorContainer( QString::null, nullptr ) )
, mConfiguredRootContainer( false )
, mEditorLayout( QgsEditFormConfig::GeneratedLayout )
, mInitCodeSource( QgsEditFormConfig::CodeSourceNone )
, mSuppressForm( QgsEditFormConfig::SuppressDefault )
@@ -32,6 +35,7 @@ class QgsEditFormConfigPrivate : public QSharedData
QgsEditFormConfigPrivate( const QgsEditFormConfigPrivate& o )
: QSharedData( o )
, mInvisibleRootContainer( static_cast<QgsAttributeEditorContainer*>( o.mInvisibleRootContainer->clone( nullptr ) ) )
, mConfiguredRootContainer( o.mConfiguredRootContainer )
, mConstraints( o.mConstraints )
, mConstraintsDescription( o.mConstraintsDescription )
, mFieldEditables( o.mFieldEditables )
@@ -84,6 +88,7 @@ class QgsEditFormConfigPrivate : public QSharedData
QgsEditFormConfig::FeatureFormSuppress mSuppressForm;

QgsFields mFields;
QMap<QString, QString> mAttributeAliasMap;

};

@@ -2048,6 +2048,7 @@ void QgsVectorLayer::remAttributeAlias( int attIndex )
if ( mAttributeAliasMap.contains( name ) )
{
mAttributeAliasMap.remove( name );
mEditFormConfig.setFields( mUpdatedFields, mAttributeAliasMap );
emit layerModified();
}
}
@@ -2068,6 +2069,7 @@ void QgsVectorLayer::addAttributeAlias( int attIndex, const QString& aliasString
QString name = fields().at( attIndex ).name();

mAttributeAliasMap.insert( name, aliasString );
mEditFormConfig.setFields( mUpdatedFields, mAttributeAliasMap );
emit layerModified(); // TODO[MD]: should have a different signal?
}

@@ -2078,7 +2080,7 @@ QString QgsVectorLayer::attributeAlias( int attributeIndex ) const

QString name = fields().at( attributeIndex ).name();

return mAttributeAliasMap.value( name, QString() );
return mAttributeAliasMap.value( name );
}

QString QgsVectorLayer::attributeDisplayName( int attributeIndex ) const
@@ -2781,7 +2783,7 @@ void QgsVectorLayer::updateFields()
if ( oldFields != mUpdatedFields )
{
emit updatedFields();
mEditFormConfig.setFields( mUpdatedFields );
mEditFormConfig.setFields( mUpdatedFields, mAttributeAliasMap );
}
}

0 comments on commit 633c1a3

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