/
qgsrelationadddlg.cpp
92 lines (73 loc) · 3.7 KB
/
qgsrelationadddlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/***************************************************************************
qgsrelationadddlg.cpp - QgsRelationAddDlg
---------------------------------
begin : 4.10.2013
copyright : (C) 2013 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsrelationadddlg.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayerproxymodel.h"
#include <QPushButton>
QgsRelationAddDlg::QgsRelationAddDlg( QWidget *parent )
: QDialog( parent )
{
setupUi( this );
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, mCbxReferencingField, &QgsFieldComboBox::setLayer );
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, mCbxReferencedField, &QgsFieldComboBox::setLayer );
mCbxReferencingLayer->setFilters( QgsMapLayerProxyModel::VectorLayer );
mCbxReferencingField->setLayer( mCbxReferencingLayer->currentLayer() );
mCbxReferencedLayer->setFilters( QgsMapLayerProxyModel::VectorLayer );
mCbxReferencedField->setLayer( mCbxReferencedLayer->currentLayer() );
mCbxRelationStrength->addItem( "Association", QVariant::fromValue( QgsRelation::RelationStrength::Association ) );
mCbxRelationStrength->addItem( "Composition", QVariant::fromValue( QgsRelation::RelationStrength::Composition ) );
mCbxRelationStrength->setToolTip( QStringLiteral( "Composition (child features will be copied too) or Association" ) );
mTxtRelationId->setPlaceholderText( tr( "[Generated automatically]" ) );
checkDefinitionValid();
connect( mCbxReferencingLayer, &QgsMapLayerComboBox::layerChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencingField, &QgsFieldComboBox::fieldChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencedLayer, &QgsMapLayerComboBox::layerChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
connect( mCbxReferencedField, &QgsFieldComboBox::fieldChanged, this, &QgsRelationAddDlg::checkDefinitionValid );
}
QString QgsRelationAddDlg::referencingLayerId()
{
return mCbxReferencingLayer->currentLayer()->id();
}
QString QgsRelationAddDlg::referencedLayerId()
{
return mCbxReferencedLayer->currentLayer()->id();
}
QList< QPair< QString, QString > > QgsRelationAddDlg::references()
{
QList< QPair< QString, QString > > references;
QString referencingField = mCbxReferencingField->currentField();
QString referencedField = mCbxReferencedField->currentField();
references.append( QPair<QString, QString> ( referencingField, referencedField ) );
return references;
}
QString QgsRelationAddDlg::relationId()
{
return mTxtRelationId->text();
}
QString QgsRelationAddDlg::relationName()
{
return mTxtRelationName->text();
}
QgsRelation::RelationStrength QgsRelationAddDlg::relationStrength()
{
return mCbxRelationStrength->currentData().value<QgsRelation::RelationStrength>();
}
void QgsRelationAddDlg::checkDefinitionValid()
{
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mCbxReferencedLayer->currentIndex() != -1
&& mCbxReferencedField->currentIndex() != -1
&& mCbxReferencingLayer->currentIndex() != -1
&& mCbxReferencingField->currentIndex() != -1 );
}