Skip to content

Commit

Permalink
Create a default tab layout if none is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 19, 2016
1 parent 5c20f07 commit 633c1a3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
37 changes: 28 additions & 9 deletions src/core/qgseditformconfig.cpp
Expand Up @@ -53,10 +53,21 @@ QgsEditorWidgetConfig QgsEditFormConfig::widgetConfig( const QString& widgetName
return d->mWidgetConfigs.value( 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.detach();
d->mFields = fields; 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() void QgsEditFormConfig::onRelationsLoaded()
Expand Down Expand Up @@ -411,16 +422,24 @@ void QgsEditFormConfig::readXml( const QDomNode& node )
} }


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

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


QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, this ); if ( attributeEditorFormNodeList.size() )
addTab( attributeEditorWidget ); {
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 );
}
}
} }




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


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


Expand Down
16 changes: 7 additions & 9 deletions src/core/qgseditformconfig.h
Expand Up @@ -241,12 +241,12 @@ class CORE_EXPORT QgsEditFormConfig
QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) 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
* *
* @param fieldIdx The index of the field * @param fieldIdx The index of the field
* *
* @return true if successful, false if the field does not exist * @return true if successful, false if the field does not exist
*/ */
bool removeWidgetConfig( int fieldIdx ); bool removeWidgetConfig( int fieldIdx );


/** /**
Expand Down Expand Up @@ -411,10 +411,8 @@ class CORE_EXPORT QgsEditFormConfig
/** /**
* Used internally to set the fields when they change. * Used internally to set the fields when they change.
* This should only be called from QgsVectorLayer for synchronization reasons * 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 * Will be called by friend class QgsVectorLayer
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgseditformconfig_p.h
Expand Up @@ -16,6 +16,8 @@
#ifndef QGSEDITFORMCONFIG_P_H #ifndef QGSEDITFORMCONFIG_P_H
#define QGSEDITFORMCONFIG_P_H #define QGSEDITFORMCONFIG_P_H


#include <QMap>

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


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


QgsFields mFields; QgsFields mFields;
QMap<QString, QString> mAttributeAliasMap;


}; };


Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2048,6 +2048,7 @@ void QgsVectorLayer::remAttributeAlias( int attIndex )
if ( mAttributeAliasMap.contains( name ) ) if ( mAttributeAliasMap.contains( name ) )
{ {
mAttributeAliasMap.remove( name ); mAttributeAliasMap.remove( name );
mEditFormConfig.setFields( mUpdatedFields, mAttributeAliasMap );
emit layerModified(); emit layerModified();
} }
} }
Expand All @@ -2068,6 +2069,7 @@ void QgsVectorLayer::addAttributeAlias( int attIndex, const QString& aliasString
QString name = fields().at( attIndex ).name(); QString name = fields().at( attIndex ).name();


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


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


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


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


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


Expand Down

0 comments on commit 633c1a3

Please sign in to comment.