Skip to content

Commit

Permalink
Relation Cardinality without own gui
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Oct 27, 2017
1 parent 6af4bb8 commit b198923
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
35 changes: 29 additions & 6 deletions src/app/qgsattributesformproperties.cpp
Expand Up @@ -34,8 +34,11 @@ QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer,
mAttributeTypeFrame->layout()->setMargin( 0 );
mAttributeTypeFrame->layout()->addWidget( mAttributeTypeDialog );

// RelationConfigDialog
mRelationConfigDialog = new QgsAttributeTypeDialog( mLayer, 0, mAttributeTypeFrame );

connect( mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
connect( mFormLayoutTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
//connect( mFormLayoutTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
connect( mAddTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::addTabOrGroupButton );
connect( mRemoveTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::removeTabOrGroupButton );
}
Expand Down Expand Up @@ -188,7 +191,7 @@ QgsAttributesFormProperties::FieldConfig QgsAttributesFormProperties::configForC
return FieldConfig();
}

QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelationChild( const QString &relationName )
QgsAttributesFormProperties::RelationConfig QgsAttributesFormProperties::configForRelation( const QString &relationName )
{
QTreeWidgetItemIterator itemIt( mAvailableWidgetsTree );
while ( *itemIt )
Expand Down Expand Up @@ -280,8 +283,23 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
if ( mFormLayoutTree->selectedItems()[0]->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() == DnDTreeItemData::Container )
isAddPossible = true;

storeAttributeTypeDialog();
loadAttributeTypeDialog();
storeAttributeTypeDialog(); //or storeRelationConfigDialog

switch ( mAvailableWidgetsTree->currentItem()->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() )
{
case DnDTreeItemData::Relation:
{
//loadAttributeTypeDialog();
mAttributeTypeFrame->layout()->removeWidget( mAttributeTypeDialog);
//mAttributeTypeFrame->layout()->addWidget( mRelationConfigDialog );
break;
}
default:
{
loadAttributeTypeDialog();
break;
}
}
}

void QgsAttributesFormProperties::initAvailableWidgetsTree()
Expand Down Expand Up @@ -508,7 +526,7 @@ void QgsAttributesFormProperties::apply()
QTreeWidgetItem *relationItem = relationContainer->child( i );
DnDTreeItemData itemData= relationItem->data( 0, DnDTreeRole ).value<DnDTreeItemData>();

RelationConfig relCfg = configForRelChild( itemData.name() );
RelationConfig relCfg = configForRelation( itemData.name() );

QVariantMap cfg;
cfg[QStringLiteral( "nm-rel" )]=relCfg.mCardinality;
Expand Down Expand Up @@ -548,6 +566,7 @@ void QgsAttributesFormProperties::apply()

QgsAttributesFormProperties::FieldConfig::FieldConfig()
: mEditable( true )
, mAlias( QString() )
, mEditableEnabled( true )
, mLabelOnTop( false )
, mConstraints( 0 )
Expand Down Expand Up @@ -581,10 +600,14 @@ QgsAttributesFormProperties::FieldConfig::operator QVariant()
return QVariant::fromValue<QgsAttributesFormProperties::FieldConfig>( *this );
}


/*
* RelationConfig implementation
*/
QgsAttributesFormProperties::RelationConfig::RelationConfig()
: mCardinality( QString() )
{
}

QgsAttributesFormProperties::RelationConfig::RelationConfig( QgsVectorLayer *layer, const QString &relationId )
{
const QVariant nmrelcfg = layer->editFormConfig().widgetConfig( relationId ).value( QStringLiteral( "nm-rel" ) );
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgsattributesformproperties.h
Expand Up @@ -194,7 +194,7 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
FieldConfig configForChild( int index );
void setConfigForChild( int index, const FieldConfig &cfg );

RelationConfig configForRelationChild( const QString &relationName );
RelationConfig configForRelation( const QString &relationName );

//QList<QgsRelation> mRelations;
QgsVectorLayer *mLayer = nullptr;
Expand All @@ -203,6 +203,7 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
DnDTree *mFormLayoutTree = nullptr;

QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
QgsAttributeTypeDialog *mRelationConfigDialog = nullptr;


private:
Expand Down Expand Up @@ -269,6 +270,7 @@ class DnDTree : public QTreeWidget


Q_DECLARE_METATYPE( QgsAttributesFormProperties::FieldConfig )
Q_DECLARE_METATYPE( QgsAttributesFormProperties::RelationConfig )
Q_DECLARE_METATYPE( QgsAttributesFormProperties::DnDTreeItemData )

#endif // QGSATTRIBUTESFORMPROPERTIES_H
2 changes: 1 addition & 1 deletion src/ui/qgsattributetypeedit.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>751</width>
<height>487</height>
<height>620</height>
</rect>
</property>
<property name="windowTitle">
Expand Down

0 comments on commit b198923

Please sign in to comment.