20#include <QDialogButtonBox> 
   22#include <QSortFilterProxyModel> 
   30  , mConnection( connection )
 
   46    if ( cardinalities.contains( cardinality ) )
 
   57    if ( strengths.contains( strength ) )
 
   64    mForwardLabelLineEdit->hide();
 
   65    mForwardLabel->hide();
 
   70    mBackwardLabelLineEdit->hide();
 
   71    mReverseLabel->hide();
 
   75  mRelatedTableTypeCombo->addItems( relatedTableTypes );
 
   77  mProxyModel = 
new QSortFilterProxyModel( mTableModel );
 
   78  mProxyModel->setSourceModel( mTableModel );
 
   79  mProxyModel->setDynamicSortFilter( 
true );
 
   80  mProxyModel->setSortCaseSensitivity( Qt::CaseInsensitive );
 
   81  mProxyModel->setSortRole( Qt::DisplayRole );
 
   82  mProxyModel->sort( 0 );
 
   84  mLeftTableCombo->setModel( mProxyModel );
 
   85  mRightTableCombo->setModel( mProxyModel );
 
   87  connect( mNameEdit, &QLineEdit::textChanged, 
this, [ = ]
 
   91  connect( mLeftTableCombo, qOverload< int >( &QComboBox::currentIndexChanged ), 
this, [ = ]( 
int )
 
   93    mLeftFieldsCombo->setFields( mConnection->
fields( QString(), mLeftTableCombo->currentText() ) );
 
   96  connect( mRightTableCombo, qOverload< int >( &QComboBox::currentIndexChanged ), 
this, [ = ]( 
int )
 
   98    mRightFieldsCombo->setFields( mConnection->
fields( QString(), mRightTableCombo->currentText() ) );
 
  102  for ( QComboBox *combo :
 
  105          qobject_cast< QComboBox *>( mLeftFieldsCombo ),
 
  106          qobject_cast< QComboBox *>( mRightFieldsCombo ),
 
  108          mRelatedTableTypeCombo
 
  111    connect( combo, qOverload< int >( &QComboBox::currentIndexChanged ), 
this, [ = ]( 
int )
 
  117  mLeftFieldsCombo->setFields( mConnection->
fields( QString(), mLeftTableCombo->currentText() ) );
 
  118  mRightFieldsCombo->setFields( mConnection->
fields( QString(), mRightTableCombo->currentText() ) );
 
  124  mNameEdit->setText( mRelation.
name() );
 
  125  mNameEdit->setEnabled( 
false );
 
  126  mStrengthCombo->setCurrentIndex( mStrengthCombo->findData( QVariant::fromValue( mRelation.
strength() ) ) );
 
  129  mLeftTableCombo->setCurrentText( parts.value( QStringLiteral( 
"layerName" ) ).toString() );
 
  131  mRightTableCombo->setCurrentText( parts.value( QStringLiteral( 
"layerName" ) ).toString() );
 
  133  mCardinalityCombo->setCurrentIndex( mCardinalityCombo->findData( QVariant::fromValue( mRelation.
cardinality() ) ) );
 
  144                          mRelation.
name().isEmpty() ? mNameEdit->text() : mRelation.
name(),
 
  148                          mConnection->
tableUri( QString(), mRightTableCombo->currentText() ),
 
  152                          mConnection->
tableUri( QString(), mLeftTableCombo->currentText() ),
 
  165  if ( mRelatedTableTypeCombo->currentIndex() >= 0 )
 
  172  if ( mNameEdit->text().trimmed().isEmpty() )
 
  175  if ( mLeftTableCombo->currentText().isEmpty() )
 
  178  if ( mRightTableCombo->currentText().isEmpty() )
 
  181  if ( mLeftTableCombo->currentText() == mRightTableCombo->currentText() )
 
  184  if ( mLeftFieldsCombo->currentText().isEmpty() )
 
  187  if ( mRightFieldsCombo->currentText().isEmpty() )
 
  199  : QDialog( parent, flags )
 
  201  setObjectName( QStringLiteral( 
"QgsDbRelationDialog" ) );
 
  203  QVBoxLayout *vLayout = 
new QVBoxLayout();
 
  205  vLayout->addWidget( mWidget, 1 );
 
  207  mButtonBox = 
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
 
  208  connect( mButtonBox, &QDialogButtonBox::accepted, 
this, &QDialog::accept );
 
  209  connect( mButtonBox, &QDialogButtonBox::rejected, 
this, &QDialog::reject );
 
  210  vLayout->addWidget( mButtonBox );
 
  212  setLayout( vLayout );
 
  214  validityChanged( mWidget->
isValid() );
 
  237void QgsDbRelationDialog::validityChanged( 
bool isValid )
 
  239  mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
 
RelationshipStrength
Relationship strength.
 
@ Composition
Fix relation, related elements are part of the parent and a parent copy will copy any children or del...
 
@ Association
Loose relation, related elements are not part of the parent and a parent copy will not copy any child...
 
@ BackwardPathLabel
Supports backward path labels.
 
@ ForwardPathLabel
Supports forward path labels.
 
RelationshipCardinality
Relationship cardinality.
 
@ ManyToMany
Many to many relationship.
 
@ ManyToOne
Many to one relationship.
 
@ OneToOne
One to one relationship.
 
@ OneToMany
One to many relationship.
 
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
 
QString providerKey() const
Returns the provider key.
 
virtual QStringList relatedTableTypes() const
Returns a list of the related table types supported by the database format.
 
virtual QgsFields fields(const QString &schema, const QString &table, QgsFeedback *feedback=nullptr) const SIP_THROW(QgsProviderConnectionException)
Returns the fields of a table and schema.
 
virtual Qgis::RelationshipCapabilities supportedRelationshipCapabilities() const
Returns the relationship capabilities supported by the provider.
 
virtual QList< Qgis::RelationshipCardinality > supportedRelationshipCardinalities() const
Returns a list of relationship cardinalities which are supported by the provider.
 
virtual QList< Qgis::RelationshipStrength > supportedRelationshipStrengths() const
Returns a list of relationship strengths which are supported by the provider.
 
virtual QString tableUri(const QString &schema, const QString &name) const SIP_THROW(QgsProviderConnectionException)
Returns the URI string for the given table and schema.
 
A model containing tables from a database connection.
 
QgsDbRelationDialog(QgsAbstractDatabaseProviderConnection *connection, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsDbRelationDialog, with the specified parent widget and window flags,...
 
QgsWeakRelation relationship() const
Returns the relationship as defined in the dialog.
 
void setRelationship(const QgsWeakRelation &relationship)
Sets the current relationship to show properties for in the dialog.
 
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
 
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
 
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
 
static QString cardinalityToDisplayString(Qgis::RelationshipCardinality cardinality)
Returns a user-friendly translated string representing a relationship cardinality.
 
static QString strengthToDisplayString(Qgis::RelationshipStrength strength)
Returns a user-friendly translated string representing a relationship strength.
 
The QgsWeakRelation class represent a QgsRelation with possibly unresolved layers or unmatched fields...
 
void setMappingTable(const QgsVectorLayerRef &table)
Sets a weak reference to the mapping table, which forms the middle table in many-to-many relationship...
 
QStringList mappingReferencingLayerFields() const
Returns the list of fields from the mappingTable() involved in the relationship.
 
void setForwardPathLabel(const QString &label)
Sets the label of the forward path for the relationship.
 
void setMappingReferencingLayerFields(const QStringList &fields)
Sets the list of fields from the mappingTable() involved in the relationship.
 
void setBackwardPathLabel(const QString &label)
Sets the label of the backward path for the relationship.
 
QString relatedTableType() const
Returns the type string of the related table.
 
void setReferencingLayerFields(const QStringList &fields)
Sets the list of fields from the referencingLayer() involved in the relationship.
 
QString name() const
Returns the relationship's name.
 
QString backwardPathLabel() const
Returns the label of the backward path for the relationship.
 
void setMappingReferencedLayerFields(const QStringList &fields)
Sets the list of fields from the mappingTable() involved in the relationship.
 
QString referencedLayerSource() const
Returns the source URI for the referenced (or "parent" / "left") layer.
 
QString referencingLayerSource() const
Returns the source URI for the referencing (or "child" / "right") layer.
 
QString id() const
Returns the relationship's ID.
 
QString forwardPathLabel() const
Returns the label of the forward path for the relationship.
 
Qgis::RelationshipCardinality cardinality() const
Returns the relationship's cardinality.
 
QgsVectorLayerRef mappingTable() const
Returns a weak reference to the mapping table, which forms the middle table in many-to-many relations...
 
void setCardinality(Qgis::RelationshipCardinality cardinality)
Sets the relationship's cardinality.
 
QStringList referencedLayerFields() const
Returns the list of fields from the referencedLayer() involved in the relationship.
 
QStringList mappingReferencedLayerFields() const
Returns the list of fields from the mappingTable() involved in the relationship.
 
void setRelatedTableType(const QString &type)
Sets the type string of the related table.
 
QStringList referencingLayerFields() const
Returns the list of fields from the referencingLayer() involved in the relationship.
 
void setReferencedLayerFields(const QStringList &fields)
Sets the list of fields from the referencedLayer() involved in the relationship.
 
Qgis::RelationshipStrength strength() const
Returns the strength of the relation.