Skip to content

Commit

Permalink
[Feature] Allow configuring link/unlink feature buttons on relation e…
Browse files Browse the repository at this point in the history
…ditor widget
  • Loading branch information
m-kuhn committed Sep 21, 2016
1 parent 1a159ef commit 8069154
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 8 deletions.
26 changes: 26 additions & 0 deletions python/core/qgsattributeeditorelement.sip
Expand Up @@ -325,4 +325,30 @@ class QgsAttributeEditorRelation : QgsAttributeEditorElement
bool init( QgsRelationManager* relManager );

virtual QgsAttributeEditorElement* clone(QgsAttributeEditorElement* parent) const /Factory/;

/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showLinkButton() const;
/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowLinkButton( bool showLinkButton );

/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showUnlinkButton() const;
/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowUnlinkButton( bool showUnlinkButton );
};
28 changes: 27 additions & 1 deletion python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
Expand Up @@ -37,7 +37,33 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
*
* @note Added in QGIS 2.18
*/
void setShowLabel(bool showLabel);
void setShowLabel( bool showLabel );

/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showLinkButton() const;
/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowLinkButton( bool showLinkButton );

/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showUnlinkButton() const;
/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowUnlinkButton( bool showUnlinkButton );

protected:
QWidget* createWidget( QWidget* parent );
Expand Down
28 changes: 27 additions & 1 deletion python/gui/qgsrelationeditorwidget.sip
Expand Up @@ -78,5 +78,31 @@ class QgsRelationEditorWidget : QgsCollapsibleGroupBox
*
* @note Added in QGIS 2.18
*/
void setShowLabel(bool showLabel);
void setShowLabel( bool showLabel );

/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showLinkButton() const;
/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowLinkButton( bool showLinkButton );

/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showUnlinkButton() const;
/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowUnlinkButton( bool showUnlinkButton );
};
57 changes: 54 additions & 3 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -170,8 +170,13 @@ QTreeWidgetItem* QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE

case QgsAttributeEditorElement::AeTypeRelation:
{
const QgsAttributeEditorRelation* relationEditor = static_cast<const QgsAttributeEditorRelation*>( widgetDef );
DesignerTreeItemData itemData = DesignerTreeItemData( DesignerTreeItemData::Relation, widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );
RelationEditorConfiguration relEdConfig;
relEdConfig.showLinkButton = relationEditor->showLinkButton();
relEdConfig.showUnlinkButton = relationEditor->showUnlinkButton();
itemData.setRelationEditorConfiguration( relEdConfig );

newWidget = mDesignerTree->addItem( parent, itemData );
break;
Expand All @@ -182,7 +187,7 @@ QTreeWidgetItem* QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
DesignerTreeItemData itemData( DesignerTreeItemData::Container, widgetDef->name() );
itemData.setShowLabel( widgetDef->showLabel() );

const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
const QgsAttributeEditorContainer* container = static_cast<const QgsAttributeEditorContainer*>( widgetDef );
if ( !container )
break;

Expand Down Expand Up @@ -858,7 +863,10 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
case DesignerTreeItemData::Relation:
{
QgsRelation relation = QgsProject::instance()->relationManager()->relation( itemData.name() );
widgetDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
QgsAttributeEditorRelation* relDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
relDef->setShowLinkButton( itemData.relationEditorConfiguration().showLinkButton );
relDef->setShowUnlinkButton( itemData.relationEditorConfiguration().showUnlinkButton );
widgetDef = relDef;
break;
}

Expand Down Expand Up @@ -1323,10 +1331,43 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
item->setText( 0, title->text() );
}
}
else if ( itemData.type() == QgsFieldsProperties::DesignerTreeItemData::Relation )
{
QDialog dlg;
dlg.setWindowTitle( tr( "Configure relation editor" ) );
QFormLayout* layout = new QFormLayout() ;
dlg.setLayout( layout );
layout->addWidget( baseWidget );

QCheckBox* showLinkButton = new QCheckBox( tr( "Show link button" ) );
showLinkButton->setChecked( itemData.relationEditorConfiguration().showLinkButton );
QCheckBox* showUnlinkButton = new QCheckBox( tr( "Show unlink button" ) );
showUnlinkButton->setChecked( itemData.relationEditorConfiguration().showUnlinkButton );
layout->addRow( showLinkButton );
layout->addRow( showUnlinkButton );

QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );

connect( buttonBox, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );

dlg.layout()->addWidget( buttonBox );

if ( dlg.exec() )
{
QgsFieldsProperties::RelationEditorConfiguration relEdCfg;
relEdCfg.showLinkButton = showLinkButton->isChecked();
relEdCfg.showUnlinkButton = showUnlinkButton->isChecked();
itemData.setShowLabel( showLabelCheckbox->isChecked() );
itemData.setRelationEditorConfiguration( relEdCfg );

item->setData( 0, QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant() );
}
}
else
{
QDialog dlg;
dlg.setWindowTitle( tr( "Configure container" ) );
dlg.setWindowTitle( tr( "Configure field" ) );
dlg.setLayout( new QGridLayout() );
dlg.layout()->addWidget( baseWidget );

Expand Down Expand Up @@ -1399,3 +1440,13 @@ void QgsFieldsProperties::DesignerTreeItemData::setVisibilityExpression( const Q
{
mVisibilityExpression = visibilityExpression;
}

QgsFieldsProperties::RelationEditorConfiguration QgsFieldsProperties::DesignerTreeItemData::relationEditorConfiguration() const
{
return mRelationEditorConfiguration;
}

void QgsFieldsProperties::DesignerTreeItemData::setRelationEditorConfiguration( const QgsFieldsProperties::RelationEditorConfiguration& relationEditorConfiguration )
{
mRelationEditorConfiguration = relationEditorConfiguration;
}
14 changes: 14 additions & 0 deletions src/app/qgsfieldsproperties.h
Expand Up @@ -42,6 +42,16 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
FieldConfigRole
};

struct RelationEditorConfiguration
{
RelationEditorConfiguration()
: showLinkButton( true )
, showUnlinkButton( true )
{}
bool showLinkButton;
bool showUnlinkButton;
};

class DesignerTreeItemData
{
public:
Expand Down Expand Up @@ -87,13 +97,17 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
QgsOptionalExpression visibilityExpression() const;
void setVisibilityExpression( const QgsOptionalExpression& visibilityExpression );

RelationEditorConfiguration relationEditorConfiguration() const;
void setRelationEditorConfiguration( const RelationEditorConfiguration& relationEditorConfiguration );

private:
Type mType;
QString mName;
int mColumnCount;
bool mShowAsGroupBox;
bool mShowLabel;
QgsOptionalExpression mVisibilityExpression;
RelationEditorConfiguration mRelationEditorConfiguration;
};

/**
Expand Down
24 changes: 24 additions & 0 deletions src/core/qgsattributeeditorelement.cpp
Expand Up @@ -84,6 +84,8 @@ QgsAttributeEditorElement* QgsAttributeEditorRelation::clone( QgsAttributeEditor
{
QgsAttributeEditorRelation* element = new QgsAttributeEditorRelation( name(), mRelationId, parent );
element->mRelation = mRelation;
element->mShowLinkButton = mShowLinkButton;
element->mShowUnlinkButton = mShowUnlinkButton;

return element;
}
Expand Down Expand Up @@ -120,9 +122,31 @@ void QgsAttributeEditorElement::setShowLabel( bool showLabel )
void QgsAttributeEditorRelation::saveConfiguration( QDomElement& elem ) const
{
elem.setAttribute( "relation", mRelation.id() );
elem.setAttribute( "showLinkButton", mShowLinkButton );
elem.setAttribute( "showUnlinkButton", mShowUnlinkButton );
}

QString QgsAttributeEditorRelation::typeIdentifier() const
{
return "attributeEditorRelation";
}

bool QgsAttributeEditorRelation::showLinkButton() const
{
return mShowLinkButton;
}

void QgsAttributeEditorRelation::setShowLinkButton( bool showLinkButton )
{
mShowLinkButton = showLinkButton;
}

bool QgsAttributeEditorRelation::showUnlinkButton() const
{
return mShowUnlinkButton;
}

void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
{
mShowUnlinkButton = showUnlinkButton;
}
34 changes: 33 additions & 1 deletion src/core/qgsattributeeditorelement.h
Expand Up @@ -298,7 +298,10 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
*/
QgsAttributeEditorRelation( const QString& name, const QString &relationId, QgsAttributeEditorElement* parent )
: QgsAttributeEditorElement( AeTypeRelation, name, parent )
, mRelationId( relationId ) {}
, mRelationId( relationId )
, mShowLinkButton( true )
, mShowUnlinkButton( true )
{}

/**
* Creates a new element which embeds a relation.
Expand Down Expand Up @@ -332,11 +335,40 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement

virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const override;

/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showLinkButton() const;
/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowLinkButton( bool showLinkButton );

/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showUnlinkButton() const;
/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowUnlinkButton( bool showUnlinkButton );


private:
void saveConfiguration( QDomElement& elem ) const override;
QString typeIdentifier() const override;
QString mRelationId;
QgsRelation mRelation;
bool mShowLinkButton;
bool mShowUnlinkButton;
};


Expand Down
5 changes: 4 additions & 1 deletion src/core/qgseditformconfig.cpp
Expand Up @@ -605,7 +605,10 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
// At this time, the relations are not loaded
// So we only grab the id and delegate the rest to onRelationsLoaded()
QString name = elem.attribute( "name" );
newElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
QgsAttributeEditorRelation* relElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
relElement->setShowLinkButton( elem.attribute( "showLinkButton", "1" ).toInt() );
relElement->setShowUnlinkButton( elem.attribute( "showUnlinkButton", "1" ).toInt() );
newElement = relElement;
}

if ( elem.hasAttribute( "showLabel" ) )
Expand Down
22 changes: 22 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Expand Up @@ -46,6 +46,17 @@ void QgsRelationWidgetWrapper::setVisible( bool visible )
mWidget->setVisible( visible );
}

bool QgsRelationWidgetWrapper::showUnlinkButton() const
{
return mWidget->showUnlinkButton();
}

void QgsRelationWidgetWrapper::setShowUnlinkButton( bool showUnlinkButton )
{
if ( mWidget )
mWidget->setShowUnlinkButton( showUnlinkButton );
}

bool QgsRelationWidgetWrapper::showLabel() const
{
if ( mWidget )
Expand Down Expand Up @@ -106,3 +117,14 @@ bool QgsRelationWidgetWrapper::valid() const
{
return mWidget;
}

bool QgsRelationWidgetWrapper::showLinkButton() const
{
return mWidget->showLinkButton();
}

void QgsRelationWidgetWrapper::setShowLinkButton( bool showLinkButton )
{
if ( mWidget )
mWidget->setShowLinkButton( showLinkButton );
}
26 changes: 26 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.h
Expand Up @@ -48,6 +48,32 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
*/
void setShowLabel( bool showLabel );

/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showLinkButton() const;
/**
* Determines if the "link feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowLinkButton( bool showLinkButton );

/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
bool showUnlinkButton() const;
/**
* Determines if the "unlink feature" button should be shown
*
* @note Added in QGIS 2.18
*/
void setShowUnlinkButton( bool showUnlinkButton );

protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
Expand Down

0 comments on commit 8069154

Please sign in to comment.