Skip to content
Permalink
Browse files

[Feature] Allow configuring link/unlink feature buttons on relation e…

…ditor widget
  • Loading branch information
m-kuhn committed Sep 21, 2016
1 parent 1a159ef commit 8069154aadd76aa0fd48d4fb3126109728f26963
@@ -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 );
};
@@ -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 );
@@ -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 );
};
@@ -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;
@@ -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;

@@ -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;
}

@@ -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 );

@@ -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;
}
@@ -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:
@@ -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;
};

/**
@@ -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;
}
@@ -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;
}
@@ -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.
@@ -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;
};


@@ -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" ) )
@@ -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 )
@@ -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 );
}
@@ -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;

0 comments on commit 8069154

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