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 bdd3b92 commit 5f0ade8
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 9 deletions.
28 changes: 26 additions & 2 deletions python/core/qgseditformconfig.sip
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class QgsAttributeEditorContainer : QgsAttributeEditorElement

/**
* Change the name of this container
*
* @param name
*/
void setName( const QString& name );

Expand Down Expand Up @@ -284,6 +282,32 @@ class QgsAttributeEditorRelation : QgsAttributeEditorElement
* @return true if the relation was found in the relationmanager
*/
bool init( QgsRelationManager *relManager );

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

class QgsEditFormConfig : QObject
Expand Down
28 changes: 27 additions & 1 deletion python/gui/editorwidgets/qgsrelationwidgetwrapper.sip
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,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 @@ -183,7 +188,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 @@ -894,7 +899,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 @@ -1355,10 +1363,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 @@ -1431,3 +1472,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
Original file line number Diff line number Diff line change
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
27 changes: 26 additions & 1 deletion src/core/qgseditformconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,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 Expand Up @@ -597,15 +600,37 @@ 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::showUnlinkButton() const
{
return mShowUnlinkButton;
}

void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
{
mShowUnlinkButton = showUnlinkButton;
}

bool QgsAttributeEditorRelation::init( QgsRelationManager* relationManager )
{
mRelation = relationManager->relation( mRelationId );
return mRelation.isValid();
}

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

void QgsAttributeEditorRelation::setShowLinkButton( bool showLinkButton )
{
mShowLinkButton = showLinkButton;
}
28 changes: 28 additions & 0 deletions src/core/qgseditformconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,39 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
*/
bool init( QgsRelationManager *relManager );

/**
* 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:
virtual void saveConfiguration( QDomElement& elem ) const override;
virtual QString typeIdentifier() const override;
QString mRelationId;
QgsRelation mRelation;
bool mShowLinkButton;
bool mShowUnlinkButton;
};


Expand Down
22 changes: 22 additions & 0 deletions src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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 @@ -105,3 +116,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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 5f0ade8

Please sign in to comment.