Skip to content

Commit

Permalink
relation properties
Browse files Browse the repository at this point in the history
  • Loading branch information
signedav committed Oct 27, 2017
1 parent b198923 commit e251b24
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -15,6 +15,7 @@ SET(QGIS_APP_SRCS
qgsattributeactiondialog.cpp qgsattributeactiondialog.cpp
qgsattributeactionpropertiesdialog.cpp qgsattributeactionpropertiesdialog.cpp
qgsattributetypedialog.cpp qgsattributetypedialog.cpp
qgsattributerelationedit.cpp
qgsattributetabledialog.cpp qgsattributetabledialog.cpp
qgsbookmarks.cpp qgsbookmarks.cpp
qgsclipboard.cpp qgsclipboard.cpp
Expand Down Expand Up @@ -220,6 +221,7 @@ SET (QGIS_APP_MOC_HDRS
qgsattributeactiondialog.h qgsattributeactiondialog.h
qgsattributeactionpropertiesdialog.h qgsattributeactionpropertiesdialog.h
qgsattributetypedialog.h qgsattributetypedialog.h
qgsattributerelationedit.h
qgsattributetabledialog.h qgsattributetabledialog.h
qgsbookmarks.h qgsbookmarks.h
qgsclipboard.h qgsclipboard.h
Expand Down
24 changes: 24 additions & 0 deletions src/app/qgsattributerelationedit.cpp
@@ -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();
}
44 changes: 44 additions & 0 deletions src/app/qgsattributerelationedit.h
@@ -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
70 changes: 58 additions & 12 deletions src/app/qgsattributesformproperties.cpp
@@ -1,5 +1,6 @@
#include "qgsattributesformproperties.h" #include "qgsattributesformproperties.h"
#include "qgsattributetypedialog.h" #include "qgsattributetypedialog.h"
#include "qgsattributerelationedit.h"


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


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


connect( mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged ); connect( mAvailableWidgetsTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
//connect( mFormLayoutTree, &QTreeWidget::itemSelectionChanged, this, &QgsAttributesFormProperties::onAttributeSelectionChanged );
connect( mAddTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::addTabOrGroupButton ); connect( mAddTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::addTabOrGroupButton );
connect( mRemoveTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::removeTabOrGroupButton ); connect( mRemoveTabOrGroupButton, &QAbstractButton::clicked, this, &QgsAttributesFormProperties::removeTabOrGroupButton );
} }
Expand All @@ -53,14 +55,16 @@ void QgsAttributesFormProperties::init()
{ {
initAvailableWidgetsTree(); initAvailableWidgetsTree();
initFormLayoutTree(); initFormLayoutTree();
loadAttributeTypeDialog();
mAttributeTypeDialog->setEnabled( false );
mAttributeRelationEdit->setEnabled( false );
} }


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


if ( !currentItem || !( currentItem->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type()==DnDTreeItemData::Field ) ) if ( !currentItem )
mAttributeTypeDialog->setEnabled( false ); mAttributeTypeDialog->setEnabled( false );
else else
{ {
Expand Down Expand Up @@ -171,6 +175,42 @@ void QgsAttributesFormProperties::storeAttributeTypeDialog()
item->setData( 0, FieldConfigRole, QVariant::fromValue<FieldConfig>( cfg ) ); item->setData( 0, FieldConfigRole, QVariant::fromValue<FieldConfig>( cfg ) );
++itemIt; ++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 ) QgsAttributesFormProperties::FieldConfig QgsAttributesFormProperties::configForChild( int index )
Expand Down Expand Up @@ -283,19 +323,20 @@ void QgsAttributesFormProperties::onAttributeSelectionChanged()
if ( mFormLayoutTree->selectedItems()[0]->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() == DnDTreeItemData::Container ) if ( mFormLayoutTree->selectedItems()[0]->data( 0, DnDTreeRole ).value<DnDTreeItemData>().type() == DnDTreeItemData::Container )
isAddPossible = true; isAddPossible = true;


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


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


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


QgsEditFormConfig editFormConfig = mLayer->editFormConfig(); QgsEditFormConfig editFormConfig = mLayer->editFormConfig();


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


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


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




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


void loadAttributeRelationEdit();
void storeAttributeRelationEdit( );


private slots: private slots:
void addTabOrGroupButton(); void addTabOrGroupButton();
void removeTabOrGroupButton(); void removeTabOrGroupButton();
Expand Down
40 changes: 40 additions & 0 deletions src/ui/qgsattributerelationedit.ui
@@ -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>
4 changes: 1 addition & 3 deletions src/ui/qgsattributesformproperties.ui
Expand Up @@ -45,9 +45,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="1" rowspan="6"> <item row="0" column="1" rowspan="6">
<widget class="QWidget" name="mFormLayoutWidget" native="true"> <widget class="QWidget" name="mFormLayoutWidget" native="true"/>
<zorder>mAvailableWidgetsWidget</zorder>
</widget>
</item> </item>
<item row="2" column="2"> <item row="2" column="2">
<widget class="QToolButton" name="mRemoveTabOrGroupButton"> <widget class="QToolButton" name="mRemoveTabOrGroupButton">
Expand Down

0 comments on commit e251b24

Please sign in to comment.