Skip to content

Commit 5f0ade8

Browse files
committedSep 21, 2016
[Feature] Allow configuring link/unlink feature buttons on relation editor widget
1 parent bdd3b92 commit 5f0ade8

12 files changed

+299
-9
lines changed
 

‎python/core/qgseditformconfig.sip

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ class QgsAttributeEditorContainer : QgsAttributeEditorElement
164164

165165
/**
166166
* Change the name of this container
167-
*
168-
* @param name
169167
*/
170168
void setName( const QString& name );
171169

@@ -284,6 +282,32 @@ class QgsAttributeEditorRelation : QgsAttributeEditorElement
284282
* @return true if the relation was found in the relationmanager
285283
*/
286284
bool init( QgsRelationManager *relManager );
285+
286+
/**
287+
* Determines if the "link feature" button should be shown
288+
*
289+
* @note Added in QGIS 2.18
290+
*/
291+
bool showLinkButton() const;
292+
/**
293+
* Determines if the "link feature" button should be shown
294+
*
295+
* @note Added in QGIS 2.18
296+
*/
297+
void setShowLinkButton( bool showLinkButton );
298+
299+
/**
300+
* Determines if the "unlink feature" button should be shown
301+
*
302+
* @note Added in QGIS 2.18
303+
*/
304+
bool showUnlinkButton() const;
305+
/**
306+
* Determines if the "unlink feature" button should be shown
307+
*
308+
* @note Added in QGIS 2.18
309+
*/
310+
void setShowUnlinkButton( bool showUnlinkButton );
287311
};
288312

289313
class QgsEditFormConfig : QObject

‎python/gui/editorwidgets/qgsrelationwidgetwrapper.sip

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,33 @@ class QgsRelationWidgetWrapper : QgsWidgetWrapper
3737
*
3838
* @note Added in QGIS 2.18
3939
*/
40-
void setShowLabel(bool showLabel);
40+
void setShowLabel( bool showLabel );
41+
42+
/**
43+
* Determines if the "link feature" button should be shown
44+
*
45+
* @note Added in QGIS 2.18
46+
*/
47+
bool showLinkButton() const;
48+
/**
49+
* Determines if the "link feature" button should be shown
50+
*
51+
* @note Added in QGIS 2.18
52+
*/
53+
void setShowLinkButton( bool showLinkButton );
54+
55+
/**
56+
* Determines if the "unlink feature" button should be shown
57+
*
58+
* @note Added in QGIS 2.18
59+
*/
60+
bool showUnlinkButton() const;
61+
/**
62+
* Determines if the "unlink feature" button should be shown
63+
*
64+
* @note Added in QGIS 2.18
65+
*/
66+
void setShowUnlinkButton( bool showUnlinkButton );
4167

4268
protected:
4369
QWidget* createWidget( QWidget* parent );

‎python/gui/qgsrelationeditorwidget.sip

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,31 @@ class QgsRelationEditorWidget : QgsCollapsibleGroupBox
7878
*
7979
* @note Added in QGIS 2.18
8080
*/
81-
void setShowLabel(bool showLabel);
81+
void setShowLabel( bool showLabel );
82+
83+
/**
84+
* Determines if the "link feature" button should be shown
85+
*
86+
* @note Added in QGIS 2.18
87+
*/
88+
bool showLinkButton() const;
89+
/**
90+
* Determines if the "link feature" button should be shown
91+
*
92+
* @note Added in QGIS 2.18
93+
*/
94+
void setShowLinkButton( bool showLinkButton );
95+
96+
/**
97+
* Determines if the "unlink feature" button should be shown
98+
*
99+
* @note Added in QGIS 2.18
100+
*/
101+
bool showUnlinkButton() const;
102+
/**
103+
* Determines if the "unlink feature" button should be shown
104+
*
105+
* @note Added in QGIS 2.18
106+
*/
107+
void setShowUnlinkButton( bool showUnlinkButton );
82108
};

‎src/app/qgsfieldsproperties.cpp

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ QTreeWidgetItem* QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
171171

172172
case QgsAttributeEditorElement::AeTypeRelation:
173173
{
174+
const QgsAttributeEditorRelation* relationEditor = static_cast<const QgsAttributeEditorRelation*>( widgetDef );
174175
DesignerTreeItemData itemData = DesignerTreeItemData( DesignerTreeItemData::Relation, widgetDef->name() );
175176
itemData.setShowLabel( widgetDef->showLabel() );
177+
RelationEditorConfiguration relEdConfig;
178+
relEdConfig.showLinkButton = relationEditor->showLinkButton();
179+
relEdConfig.showUnlinkButton = relationEditor->showUnlinkButton();
180+
itemData.setRelationEditorConfiguration( relEdConfig );
176181

177182
newWidget = mDesignerTree->addItem( parent, itemData );
178183
break;
@@ -183,7 +188,7 @@ QTreeWidgetItem* QgsFieldsProperties::loadAttributeEditorTreeItem( QgsAttributeE
183188
DesignerTreeItemData itemData( DesignerTreeItemData::Container, widgetDef->name() );
184189
itemData.setShowLabel( widgetDef->showLabel() );
185190

186-
const QgsAttributeEditorContainer* container = dynamic_cast<const QgsAttributeEditorContainer*>( widgetDef );
191+
const QgsAttributeEditorContainer* container = static_cast<const QgsAttributeEditorContainer*>( widgetDef );
187192
if ( !container )
188193
break;
189194

@@ -894,7 +899,10 @@ QgsAttributeEditorElement* QgsFieldsProperties::createAttributeEditorWidget( QTr
894899
case DesignerTreeItemData::Relation:
895900
{
896901
QgsRelation relation = QgsProject::instance()->relationManager()->relation( itemData.name() );
897-
widgetDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
902+
QgsAttributeEditorRelation* relDef = new QgsAttributeEditorRelation( itemData.name(), relation, parent );
903+
relDef->setShowLinkButton( itemData.relationEditorConfiguration().showLinkButton );
904+
relDef->setShowUnlinkButton( itemData.relationEditorConfiguration().showUnlinkButton );
905+
widgetDef = relDef;
898906
break;
899907
}
900908

@@ -1355,10 +1363,43 @@ void DesignerTree::onItemDoubleClicked( QTreeWidgetItem* item, int column )
13551363
item->setText( 0, title->text() );
13561364
}
13571365
}
1366+
else if ( itemData.type() == QgsFieldsProperties::DesignerTreeItemData::Relation )
1367+
{
1368+
QDialog dlg;
1369+
dlg.setWindowTitle( tr( "Configure relation editor" ) );
1370+
QFormLayout* layout = new QFormLayout() ;
1371+
dlg.setLayout( layout );
1372+
layout->addWidget( baseWidget );
1373+
1374+
QCheckBox* showLinkButton = new QCheckBox( tr( "Show link button" ) );
1375+
showLinkButton->setChecked( itemData.relationEditorConfiguration().showLinkButton );
1376+
QCheckBox* showUnlinkButton = new QCheckBox( tr( "Show unlink button" ) );
1377+
showUnlinkButton->setChecked( itemData.relationEditorConfiguration().showUnlinkButton );
1378+
layout->addRow( showLinkButton );
1379+
layout->addRow( showUnlinkButton );
1380+
1381+
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
1382+
1383+
connect( buttonBox, SIGNAL( accepted() ), &dlg, SLOT( accept() ) );
1384+
connect( buttonBox, SIGNAL( rejected() ), &dlg, SLOT( reject() ) );
1385+
1386+
dlg.layout()->addWidget( buttonBox );
1387+
1388+
if ( dlg.exec() )
1389+
{
1390+
QgsFieldsProperties::RelationEditorConfiguration relEdCfg;
1391+
relEdCfg.showLinkButton = showLinkButton->isChecked();
1392+
relEdCfg.showUnlinkButton = showUnlinkButton->isChecked();
1393+
itemData.setShowLabel( showLabelCheckbox->isChecked() );
1394+
itemData.setRelationEditorConfiguration( relEdCfg );
1395+
1396+
item->setData( 0, QgsFieldsProperties::DesignerTreeRole, itemData.asQVariant() );
1397+
}
1398+
}
13581399
else
13591400
{
13601401
QDialog dlg;
1361-
dlg.setWindowTitle( tr( "Configure container" ) );
1402+
dlg.setWindowTitle( tr( "Configure field" ) );
13621403
dlg.setLayout( new QGridLayout() );
13631404
dlg.layout()->addWidget( baseWidget );
13641405

@@ -1431,3 +1472,13 @@ void QgsFieldsProperties::DesignerTreeItemData::setVisibilityExpression( const Q
14311472
{
14321473
mVisibilityExpression = visibilityExpression;
14331474
}
1475+
1476+
QgsFieldsProperties::RelationEditorConfiguration QgsFieldsProperties::DesignerTreeItemData::relationEditorConfiguration() const
1477+
{
1478+
return mRelationEditorConfiguration;
1479+
}
1480+
1481+
void QgsFieldsProperties::DesignerTreeItemData::setRelationEditorConfiguration( const QgsFieldsProperties::RelationEditorConfiguration& relationEditorConfiguration )
1482+
{
1483+
mRelationEditorConfiguration = relationEditorConfiguration;
1484+
}

‎src/app/qgsfieldsproperties.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
4242
FieldConfigRole
4343
};
4444

45+
struct RelationEditorConfiguration
46+
{
47+
RelationEditorConfiguration()
48+
: showLinkButton( true )
49+
, showUnlinkButton( true )
50+
{}
51+
bool showLinkButton;
52+
bool showUnlinkButton;
53+
};
54+
4555
class DesignerTreeItemData
4656
{
4757
public:
@@ -87,13 +97,17 @@ class APP_EXPORT QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPrope
8797
QgsOptionalExpression visibilityExpression() const;
8898
void setVisibilityExpression( const QgsOptionalExpression& visibilityExpression );
8999

100+
RelationEditorConfiguration relationEditorConfiguration() const;
101+
void setRelationEditorConfiguration( const RelationEditorConfiguration& relationEditorConfiguration );
102+
90103
private:
91104
Type mType;
92105
QString mName;
93106
int mColumnCount;
94107
bool mShowAsGroupBox;
95108
bool mShowLabel;
96109
QgsOptionalExpression mVisibilityExpression;
110+
RelationEditorConfiguration mRelationEditorConfiguration;
97111
};
98112

99113
/**

‎src/core/qgseditformconfig.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ QgsAttributeEditorElement* QgsEditFormConfig::attributeEditorElementFromDomEleme
459459
// At this time, the relations are not loaded
460460
// So we only grab the id and delegate the rest to onRelationsLoaded()
461461
QString name = elem.attribute( "name" );
462-
newElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
462+
QgsAttributeEditorRelation* relElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
463+
relElement->setShowLinkButton( elem.attribute( "showLinkButton", "1" ).toInt() );
464+
relElement->setShowUnlinkButton( elem.attribute( "showUnlinkButton", "1" ).toInt() );
465+
newElement = relElement;
463466
}
464467

465468
if ( elem.hasAttribute( "showLabel" ) )
@@ -597,15 +600,37 @@ void QgsAttributeEditorElement::setShowLabel( bool showLabel )
597600
void QgsAttributeEditorRelation::saveConfiguration( QDomElement& elem ) const
598601
{
599602
elem.setAttribute( "relation", mRelation.id() );
603+
elem.setAttribute( "showLinkButton", mShowLinkButton );
604+
elem.setAttribute( "showUnlinkButton", mShowUnlinkButton );
600605
}
601606

602607
QString QgsAttributeEditorRelation::typeIdentifier() const
603608
{
604609
return "attributeEditorRelation";
605610
}
606611

612+
bool QgsAttributeEditorRelation::showUnlinkButton() const
613+
{
614+
return mShowUnlinkButton;
615+
}
616+
617+
void QgsAttributeEditorRelation::setShowUnlinkButton( bool showUnlinkButton )
618+
{
619+
mShowUnlinkButton = showUnlinkButton;
620+
}
621+
607622
bool QgsAttributeEditorRelation::init( QgsRelationManager* relationManager )
608623
{
609624
mRelation = relationManager->relation( mRelationId );
610625
return mRelation.isValid();
611626
}
627+
628+
bool QgsAttributeEditorRelation::showLinkButton() const
629+
{
630+
return mShowLinkButton;
631+
}
632+
633+
void QgsAttributeEditorRelation::setShowLinkButton( bool showLinkButton )
634+
{
635+
mShowLinkButton = showLinkButton;
636+
}

‎src/core/qgseditformconfig.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,39 @@ class CORE_EXPORT QgsAttributeEditorRelation : public QgsAttributeEditorElement
307307
*/
308308
bool init( QgsRelationManager *relManager );
309309

310+
/**
311+
* Determines if the "link feature" button should be shown
312+
*
313+
* @note Added in QGIS 2.18
314+
*/
315+
bool showLinkButton() const;
316+
/**
317+
* Determines if the "link feature" button should be shown
318+
*
319+
* @note Added in QGIS 2.18
320+
*/
321+
void setShowLinkButton( bool showLinkButton );
322+
323+
/**
324+
* Determines if the "unlink feature" button should be shown
325+
*
326+
* @note Added in QGIS 2.18
327+
*/
328+
bool showUnlinkButton() const;
329+
/**
330+
* Determines if the "unlink feature" button should be shown
331+
*
332+
* @note Added in QGIS 2.18
333+
*/
334+
void setShowUnlinkButton( bool showUnlinkButton );
335+
310336
private:
311337
virtual void saveConfiguration( QDomElement& elem ) const override;
312338
virtual QString typeIdentifier() const override;
313339
QString mRelationId;
314340
QgsRelation mRelation;
341+
bool mShowLinkButton;
342+
bool mShowUnlinkButton;
315343
};
316344

317345

‎src/gui/editorwidgets/qgsrelationwidgetwrapper.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ void QgsRelationWidgetWrapper::setVisible( bool visible )
4545
mWidget->setVisible( visible );
4646
}
4747

48+
bool QgsRelationWidgetWrapper::showUnlinkButton() const
49+
{
50+
return mWidget->showUnlinkButton();
51+
}
52+
53+
void QgsRelationWidgetWrapper::setShowUnlinkButton( bool showUnlinkButton )
54+
{
55+
if ( mWidget )
56+
mWidget->setShowUnlinkButton( showUnlinkButton );
57+
}
58+
4859
bool QgsRelationWidgetWrapper::showLabel() const
4960
{
5061
if ( mWidget )
@@ -105,3 +116,14 @@ bool QgsRelationWidgetWrapper::valid() const
105116
{
106117
return mWidget;
107118
}
119+
120+
bool QgsRelationWidgetWrapper::showLinkButton() const
121+
{
122+
return mWidget->showLinkButton();
123+
}
124+
125+
void QgsRelationWidgetWrapper::setShowLinkButton( bool showLinkButton )
126+
{
127+
if ( mWidget )
128+
mWidget->setShowLinkButton( showLinkButton );
129+
}

‎src/gui/editorwidgets/qgsrelationwidgetwrapper.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,32 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
4848
*/
4949
void setShowLabel( bool showLabel );
5050

51+
/**
52+
* Determines if the "link feature" button should be shown
53+
*
54+
* @note Added in QGIS 2.18
55+
*/
56+
bool showLinkButton() const;
57+
/**
58+
* Determines if the "link feature" button should be shown
59+
*
60+
* @note Added in QGIS 2.18
61+
*/
62+
void setShowLinkButton( bool showLinkButton );
63+
64+
/**
65+
* Determines if the "unlink feature" button should be shown
66+
*
67+
* @note Added in QGIS 2.18
68+
*/
69+
bool showUnlinkButton() const;
70+
/**
71+
* Determines if the "unlink feature" button should be shown
72+
*
73+
* @note Added in QGIS 2.18
74+
*/
75+
void setShowUnlinkButton( bool showUnlinkButton );
76+
5177
protected:
5278
QWidget* createWidget( QWidget* parent ) override;
5379
void initWidget( QWidget* editor ) override;

‎src/gui/qgsattributeform.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,14 +1549,16 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
15491549

15501550
case QgsAttributeEditorElement::AeTypeRelation:
15511551
{
1552-
const QgsAttributeEditorRelation* relDef = dynamic_cast<const QgsAttributeEditorRelation*>( widgetDef );
1552+
const QgsAttributeEditorRelation* relDef = static_cast<const QgsAttributeEditorRelation*>( widgetDef );
15531553

15541554
QgsRelationWidgetWrapper* rww = new QgsRelationWidgetWrapper( mLayer, relDef->relation(), nullptr, this );
15551555
QgsEditorWidgetConfig cfg = mLayer->editFormConfig()->widgetConfig( relDef->relation().id() );
15561556
rww->setConfig( cfg );
15571557
rww->setContext( context );
15581558
newWidgetInfo.widget = rww->widget();
15591559
rww->setShowLabel( relDef->showLabel() );
1560+
rww->setShowLinkButton( relDef->showLinkButton() );
1561+
rww->setShowUnlinkButton( relDef->showUnlinkButton() );
15601562
mWidgets.append( rww );
15611563
newWidgetInfo.labelText = QString::null;
15621564
newWidgetInfo.labelOnTop = true;

‎src/gui/qgsrelationeditorwidget.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,26 @@ void QgsRelationEditorWidget::updateUi()
542542
}
543543
}
544544

545+
bool QgsRelationEditorWidget::showLinkButton() const
546+
{
547+
return mLinkFeatureButton->isVisible();
548+
}
549+
550+
void QgsRelationEditorWidget::setShowLinkButton( bool showLinkButton )
551+
{
552+
mLinkFeatureButton->setVisible( showLinkButton );
553+
}
554+
555+
bool QgsRelationEditorWidget::showUnlinkButton() const
556+
{
557+
return mUnlinkFeatureButton->isVisible();
558+
}
559+
560+
void QgsRelationEditorWidget::setShowUnlinkButton( bool showUnlinkButton )
561+
{
562+
mUnlinkFeatureButton->setVisible( showUnlinkButton );
563+
}
564+
545565
bool QgsRelationEditorWidget::showLabel() const
546566
{
547567
return mShowLabel;

‎src/gui/qgsrelationeditorwidget.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsCollapsibleGroupBox
8989
*/
9090
void setShowLabel( bool showLabel );
9191

92+
/**
93+
* Determines if the "link feature" button should be shown
94+
*
95+
* @note Added in QGIS 2.18
96+
*/
97+
bool showLinkButton() const;
98+
/**
99+
* Determines if the "link feature" button should be shown
100+
*
101+
* @note Added in QGIS 2.18
102+
*/
103+
void setShowLinkButton( bool showLinkButton );
104+
105+
/**
106+
* Determines if the "unlink feature" button should be shown
107+
*
108+
* @note Added in QGIS 2.18
109+
*/
110+
bool showUnlinkButton() const;
111+
/**
112+
* Determines if the "unlink feature" button should be shown
113+
*
114+
* @note Added in QGIS 2.18
115+
*/
116+
void setShowUnlinkButton( bool showUnlinkButton );
117+
92118
private slots:
93119
void setViewMode( int mode ) {setViewMode( static_cast<QgsDualView::ViewMode>( mode ) );}
94120
void updateButtons();

0 commit comments

Comments
 (0)
Please sign in to comment.