Skip to content

Commit

Permalink
Use the less confusing QgsRelation::type()
Browse files Browse the repository at this point in the history
  • Loading branch information
suricactus committed Jan 18, 2021
1 parent 9c8d99e commit d092770
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsrelationmanagerdialog.cpp
Expand Up @@ -76,7 +76,7 @@ void QgsRelationManagerDialog::setLayers( const QList< QgsVectorLayer * > &layer
{
// the generated relations for polymorphic relations should be ignored,
// they are generated when the polymorphic relation is added to the table
if ( !rel.polymorphicRelationId().isEmpty() )
if ( rel.type() == QgsRelation::Generated )
continue;

addRelation( rel );
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsrelationmanager.cpp
Expand Up @@ -235,8 +235,8 @@ void QgsRelationManager::writeProject( QDomDocument &doc )
for ( const QgsRelation &relation : qgis::as_const( mRelations ) )
{
// the generated relations for polymorphic relations should be ignored,
// they are generated when a polymorphic relation is added
if ( !relation.polymorphicRelationId().isEmpty() )
// they are generated every time when a polymorphic relation is added
if ( relation.type() == QgsRelation::Generated )
continue;

relation.writeXml( relationsNode, doc );
Expand Down
4 changes: 2 additions & 2 deletions src/core/vector/qgsvectorlayer.cpp
Expand Up @@ -2640,7 +2640,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString
const auto constReferencingRelations { QgsProject::instance()->relationManager()->referencingRelations( this ) };
for ( const auto &rel : constReferencingRelations )
{
if ( rel.polymorphicRelationId().isNull() )
if ( rel.type() == QgsRelation::Normal )
{
QgsWeakRelation::writeXml( this, QgsWeakRelation::Referencing, rel, referencedLayersElement, doc );
}
Expand All @@ -2653,7 +2653,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString
const auto constReferencedRelations { QgsProject::instance()->relationManager()->referencedRelations( this ) };
for ( const auto &rel : constReferencedRelations )
{
if ( rel.polymorphicRelationId().isNull() )
if ( rel.type() == QgsRelation::Normal )
{
QgsWeakRelation::writeXml( this, QgsWeakRelation::Referenced, rel, referencingLayersElement, doc );
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -38,7 +38,7 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl
const auto constReferencingRelations = vl->referencingRelations( fieldIdx );
for ( const QgsRelation &relation : constReferencingRelations )
{
if ( !relation.polymorphicRelationId().isNull() )
if ( relation.type() == QgsRelation::Generated )
continue;

if ( relation.name().isEmpty() )
Expand Down
8 changes: 4 additions & 4 deletions src/gui/editorwidgets/qgsrelationreferencefactory.cpp
Expand Up @@ -56,13 +56,13 @@ QHash<const char *, int> QgsRelationReferenceFactory::supportedWidgetTypes()

unsigned int QgsRelationReferenceFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
{
int nonGeneratedRelationsCount = 0;
int normalRelationsCount = 0;
const QList<QgsRelation> relations = vl->referencingRelations( fieldIdx );
for ( const QgsRelation &rel : relations )
{
if ( rel.polymorphicRelationId().isNull() )
nonGeneratedRelationsCount++;
if ( rel.type() == QgsRelation::Normal )
normalRelationsCount++;
}
// generated relations should not be used for relation reference widget
return nonGeneratedRelationsCount > 0 ? 21 /*A bit stronger than the range widget*/ : 5;
return normalRelationsCount > 0 ? 21 /*A bit stronger than the range widget*/ : 5;
}
26 changes: 13 additions & 13 deletions src/gui/qgsabstractrelationeditorwidget.cpp
Expand Up @@ -223,8 +223,8 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )

if ( mNmRelation.isValid() )
{
// there is no such case where we have polymorphic relations and m:n relation
Q_ASSERT( mNmRelation.polymorphicRelationId().isNull() );
// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

// n:m Relation: first let the user create a new feature on the other table
// and autocreate a new linking feature.
Expand Down Expand Up @@ -261,7 +261,7 @@ void QgsAbstractRelationEditorWidget::addFeature( const QgsGeometry &geometry )
else
{
QgsFields fields = mRelation.referencingLayer()->fields();
if ( ! mRelation.polymorphicRelationId().isNull() )
if ( mRelation.type() == QgsRelation::Normal )
{
QgsPolymorphicRelation polyRel = mRelation.polymorphicRelation();
keyAttrs.insert( fields.indexFromName( polyRel.referencedLayerField() ), polyRel.layerRepresentation( mRelation.referencedLayer() ) );
Expand All @@ -288,8 +288,8 @@ void QgsAbstractRelationEditorWidget::deleteFeatures( const QgsFeatureIds &fids
QgsVectorLayer *layer;
if ( mNmRelation.isValid() )
{
// there is no such case where we have polymorphic relations and m:n relation
Q_ASSERT( mNmRelation.polymorphicRelationId().isNull() );
// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

layer = mNmRelation.referencedLayer();

Expand Down Expand Up @@ -404,8 +404,8 @@ void QgsAbstractRelationEditorWidget::linkFeature()

if ( mNmRelation.isValid() )
{
// there is no such case where we have polymorphic relations and m:n relation
Q_ASSERT( mNmRelation.polymorphicRelationId().isNull() );
// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

layer = mNmRelation.referencedLayer();
}
Expand All @@ -427,8 +427,8 @@ void QgsAbstractRelationEditorWidget::onLinkFeatureDlgAccepted()
QgsFeatureSelectionDlg *selectionDlg = qobject_cast<QgsFeatureSelectionDlg *>( sender() );
if ( mNmRelation.isValid() )
{
// there is no such case where we have polymorphic relations and m:n relation
Q_ASSERT( mNmRelation.polymorphicRelationId().isNull() );
// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

QgsFeatureIterator it = mNmRelation.referencedLayer()->getFeatures(
QgsFeatureRequest()
Expand Down Expand Up @@ -488,7 +488,7 @@ void QgsAbstractRelationEditorWidget::onLinkFeatureDlgAccepted()
for ( QgsFeatureId fid : constSelectedFeatures )
{
QgsVectorLayer *referencingLayer = mRelation.referencingLayer();
if ( ! mRelation.polymorphicRelationId().isNull() )
if ( mRelation.type() == QgsRelation::Normal )
{
QgsPolymorphicRelation polyRel = mRelation.polymorphicRelation();

Expand Down Expand Up @@ -520,8 +520,8 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids
{
if ( mNmRelation.isValid() )
{
// there is no such case where we have polymorphic relations and m:n relation
Q_ASSERT( mNmRelation.polymorphicRelationId().isNull() );
// only normal relations support m:n relation
Q_ASSERT( mNmRelation.type() == QgsRelation::Normal );

QgsFeatureIterator selectedIterator = mNmRelation.referencedLayer()->getFeatures(
QgsFeatureRequest()
Expand Down Expand Up @@ -577,7 +577,7 @@ void QgsAbstractRelationEditorWidget::unlinkFeatures( const QgsFeatureIds &fids
for ( QgsFeatureId fid : constFeatureids )
{
QgsVectorLayer *referencingLayer = mRelation.referencingLayer();
if ( ! mRelation.polymorphicRelationId().isNull() )
if ( mRelation.type() == QgsRelation::Normal )
{
QgsPolymorphicRelation polyRel = mRelation.polymorphicRelation();

Expand Down

0 comments on commit d092770

Please sign in to comment.