Skip to content
Permalink
Browse files

relation properties

  • Loading branch information
signedav committed Oct 27, 2017
1 parent b198923 commit e251b244370ddd657cca03b7f0f79fa68753166d
@@ -15,6 +15,7 @@ SET(QGIS_APP_SRCS
qgsattributeactiondialog.cpp
qgsattributeactionpropertiesdialog.cpp
qgsattributetypedialog.cpp
qgsattributerelationedit.cpp
qgsattributetabledialog.cpp
qgsbookmarks.cpp
qgsclipboard.cpp
@@ -220,6 +221,7 @@ SET (QGIS_APP_MOC_HDRS
qgsattributeactiondialog.h
qgsattributeactionpropertiesdialog.h
qgsattributetypedialog.h
qgsattributerelationedit.h
qgsattributetabledialog.h
qgsbookmarks.h
qgsclipboard.h
@@ -0,0 +1,24 @@
#include "qgsattributerelationedit.h"
#include "ui_qgsattributerelationedit.h"

QgsAttributeRelationEdit::QgsAttributeRelationEdit(QWidget *parent) :
QWidget(parent),
ui(new Ui::QgsAttributeRelationEdit)
{
ui->setupUi(this);
}

QgsAttributeRelationEdit::~QgsAttributeRelationEdit()
{
delete ui;
}

void QgsAttributeRelationEdit::setCardinality( const QString &cardinality )
{
leCardinality->setText( cardinality );
}

QString QgsAttributeRelationEdit::cardinality()
{
return leCardinality->text();
}
@@ -0,0 +1,44 @@
#ifndef QGSATTRIBUTERELATIONEDIT_H
#define QGSATTRIBUTERELATIONEDIT_H

#include "ui_qgsattributerelationedit.h"

#include "qgseditorconfigwidget.h"
#include "qgsfeature.h"
#include "qgsvectordataprovider.h"
#include "qgshelp.h"
#include "qgis_app.h"
#include <QWidget>

/*
namespace Ui {
class QgsAttributeRelationEdit;
}
class QgsAttributeRelationEdit : public QWidget
{
*/

class APP_EXPORT QgsAttributeRelationEdit: public QWidget, private Ui::QgsAttributeRelationEdit
{
Q_OBJECT

public:
explicit QgsAttributeRelationEdit(QWidget *parent = 0);
~QgsAttributeRelationEdit();

/**
* Setter for lable alias
*/
void setCardinality( const QString &cardinality );

/**
* Getter for lable alias
*/
QString cardinality();

private:
Ui::QgsAttributeRelationEdit *ui;
};

#endif // QGSATTRIBUTERELATIONEDIT_H
@@ -1,5 +1,6 @@
#include "qgsattributesformproperties.h"
#include "qgsattributetypedialog.h"
#include "qgsattributerelationedit.h"

QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
: QWidget( parent )
@@ -34,11 +35,12 @@ QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer,
mAttributeTypeFrame->layout()->setMargin( 0 );
mAttributeTypeFrame->layout()->addWidget( mAttributeTypeDialog );

// RelationConfigDialog
mRelationConfigDialog = new QgsAttributeTypeDialog( mLayer, 0, mAttributeTypeFrame );
mAttributeRelationEdit = new QgsAttributeRelationEdit( mAttributeTypeFrame );
mAttributeRelationEdit->layout()->setMargin( 0 );
mAttributeTypeFrame->layout()->setMargin( 0 );
mAttributeTypeFrame->layout()->addWidget( mAttributeRelationEdit );

connect( mAvailableWidgetsTree, &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 );
}
@@ -53,14 +55,16 @@ void QgsAttributesFormProperties::init()
{
initAvailableWidgetsTree();
initFormLayoutTree();
loadAttributeTypeDialog();

mAttributeTypeDialog->setEnabled( false );
mAttributeRelationEdit->setEnabled( false );
}

void QgsAttributesFormProperties::loadAttributeTypeDialog()
{
QTreeWidgetItem *currentItem = mAvailableWidgetsTree->currentItem();

if ( !currentItem || !( currentItem->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type()==DnDTreeItemData::Field ) )
if ( !currentItem )
mAttributeTypeDialog->setEnabled( false );
else
{
@@ -171,6 +175,42 @@ void QgsAttributesFormProperties::storeAttributeTypeDialog()
item->setData( 0, FieldConfigRole, QVariant::fromValue<FieldConfig>( cfg ) );
++itemIt;
}

}


void QgsAttributesFormProperties::loadAttributeRelationEdit()
{
QTreeWidgetItem *currentItem = mAvailableWidgetsTree->currentItem();

if ( !currentItem )
mAttributeRelationEdit->setEnabled( false );
else
{
mAttributeRelationEdit->setEnabled( true );
mAttributeTypeFrame->layout()->removeWidget( mAttributeRelationEdit );
delete mAttributeRelationEdit;

//oder mit dem? RelationConfig relCfg = configForRelation( itemData.name() );
RelationConfig cfg = mAvailableWidgetsTree->currentItem()->data( 0, RelationConfigRole).value<RelationConfig>();

mAttributeRelationEdit = new QgsAttributeRelationEdit( mAttributeTypeFrame );

//testdave mAttributeRelationEdit->setCardinality( cfg.mCardinality );
//testdave mAttributeRelationEdit->setCardinality( "Cardinal Draft" );

mAttributeRelationEdit->layout()->setMargin( 0 );
mAttributeTypeFrame->layout()->setMargin( 0 );

mAttributeTypeFrame->layout()->addWidget( mAttributeRelationEdit );
}
}


void QgsAttributesFormProperties::storeAttributeRelationEdit()
{
//store it first

}

QgsAttributesFormProperties::FieldConfig QgsAttributesFormProperties::configForChild( int index )
@@ -283,19 +323,20 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
if ( mFormLayoutTree->selectedItems()[0]->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() == DnDTreeItemData::Container )
isAddPossible = true;

storeAttributeTypeDialog(); //or storeRelationConfigDialog
storeAttributeTypeDialog();
storeAttributeRelationEdit();

switch ( mAvailableWidgetsTree->currentItem()->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() )
{
case DnDTreeItemData::Relation:
{
//loadAttributeTypeDialog();
mAttributeTypeFrame->layout()->removeWidget( mAttributeTypeDialog);
//mAttributeTypeFrame->layout()->addWidget( mRelationConfigDialog );
mAttributeTypeDialog->setEnabled( false );
loadAttributeRelationEdit();
break;
}
default:
case DnDTreeItemData::Field:
{
mAttributeRelationEdit->setEnabled( false );
loadAttributeTypeDialog();
break;
}
@@ -446,7 +487,13 @@ QgsAttributeEditorElement *QgsAttributesFormProperties::createAttributeEditorWid

void QgsAttributesFormProperties::apply()
{
storeAttributeTypeDialog();
if( mAttributeTypeDialog )
{
storeAttributeTypeDialog();
}else
{
storeAttributeRelationEdit();
}

QgsEditFormConfig editFormConfig = mLayer->editFormConfig();

@@ -566,7 +613,6 @@ void QgsAttributesFormProperties::apply()

QgsAttributesFormProperties::FieldConfig::FieldConfig()
: mEditable( true )
, mAlias( QString() )
, mEditableEnabled( true )
, mLabelOnTop( false )
, mConstraints( 0 )
@@ -41,6 +41,7 @@
#include "qgsfieldexpressionwidget.h"
#include "qgsaddtaborgroup.h"
#include "qgsattributetypedialog.h"
#include "qgsattributerelationedit.h"
#include "qgsgui.h"
#include "qgseditorwidgetfactory.h"
#include "qgseditorwidgetregistry.h"
@@ -203,13 +204,17 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
DnDTree *mFormLayoutTree = nullptr;

QgsAttributeTypeDialog *mAttributeTypeDialog = nullptr;
QgsAttributeTypeDialog *mRelationConfigDialog = nullptr;
QgsAttributeRelationEdit *mAttributeRelationEdit = nullptr;


private:
void loadAttributeTypeDialog();
void storeAttributeTypeDialog( );

void loadAttributeRelationEdit();
void storeAttributeRelationEdit( );


private slots:
void addTabOrGroupButton();
void removeTabOrGroupButton();
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsAttributeRelationEdit</class>
<widget class="QWidget" name="QgsAttributeRelationEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Relation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Cardinality</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leCardinality"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -45,9 +45,7 @@
</widget>
</item>
<item row="0" column="1" rowspan="6">
<widget class="QWidget" name="mFormLayoutWidget" native="true">
<zorder>mAvailableWidgetsWidget</zorder>
</widget>
<widget class="QWidget" name="mFormLayoutWidget" native="true"/>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="mRemoveTabOrGroupButton">

0 comments on commit e251b24

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