31 #include <QMessageBox>
32 #include <QPushButton>
48 setObjectName( QStringLiteral(
"referenced/" ) +
mRelation.
name() );
72 for (
auto it = transactionGroups.constBegin(); it != transactionGroups.constEnd(); ++it )
91 setObjectName( QStringLiteral(
"referenced/" ) +
mRelation.
name() );
231 int index = fields.
indexOf( fieldPair.first );
238 int index = fields.
indexOf( fieldPair.first );
239 linkAttributes.insert( index, f.
attribute( fieldPair.second ) );
296 QStringList deletedFeaturesPks;
307 QString linkingFeaturesRequestExpression;
308 if ( !deletedFeaturesPks.empty() )
315 int relatedLinkingFeaturesCount = 0;
318 relatedLinkingFeaturesCount++;
321 if ( deletedFeaturesPks.size() == 1 && relatedLinkingFeaturesCount > 1 )
323 QMessageBox messageBox( QMessageBox::Question, tr(
"Really delete entry?" ), tr(
"The entry on %1 is still linked to %2 features on %3. Do you want to delete it?" ).arg(
mNmRelation.
referencedLayer()->
name(), QString::number( relatedLinkingFeaturesCount ),
mRelation.
referencedLayer()->
name() ), QMessageBox::NoButton,
this );
324 messageBox.addButton( QMessageBox::Cancel );
325 QAbstractButton *deleteButton = messageBox.addButton( tr(
"Delete" ), QMessageBox::AcceptRole );
328 if ( messageBox.clickedButton() != deleteButton )
331 else if ( deletedFeaturesPks.size() > 1 && relatedLinkingFeaturesCount > deletedFeaturesPks.size() )
333 QMessageBox messageBox( QMessageBox::Question, tr(
"Really delete entries?" ), tr(
"The %1 entries on %2 are still linked to %3 features on %4. Do you want to delete them?" ).arg( QString::number( deletedFeaturesPks.size() ),
mNmRelation.
referencedLayer()->
name(), QString::number( relatedLinkingFeaturesCount ),
mRelation.
referencedLayer()->
name() ), QMessageBox::NoButton,
this );
334 messageBox.addButton( QMessageBox::Cancel );
335 QAbstractButton *deleteButton = messageBox.addButton( tr(
"Delete" ), QMessageBox::AcceptRole );
338 if ( messageBox.clickedButton() != deleteButton )
351 QString childrenInfo;
352 int childrenCount = 0;
353 const auto infoContextLayers = infoContext.
layers();
357 childrenInfo += ( tr(
"%1 feature(s) on layer \"%2\", " ).arg( infoContext.
duplicatedFeatures( chl ).size() ).arg( chl->name() ) );
361 int res = QMessageBox::question(
this, tr(
"Delete at least %1 feature(s) on other layer(s)" ).arg( childrenCount ),
362 tr(
"Delete %1 feature(s) on layer \"%2\", %3 as well\nand all of its other descendants.\nDelete these features?" ).arg( fids.count() ).arg( layer->
name() ).arg( childrenInfo ),
363 QMessageBox::Yes | QMessageBox::No );
364 if ( res != QMessageBox::Yes )
373 if ( contextLayers.size() > 1 )
375 int deletedCount = 0;
376 QString feedbackMessage;
379 feedbackMessage += tr(
"%1 on layer %2. " ).arg( context.
handledFeatures( contextLayer ).size() ).arg( contextLayer->name() );
404 selectionDlg->setAttribute( Qt::WA_DeleteOnClose );
407 selectionDlg->setWindowTitle( tr(
"Link existing child features for parent %1 \"%2\"" ).arg(
mRelation.
referencedLayer()->
name(), displayString ) );
410 selectionDlg->show();
440 int index = fields.
indexOf( fieldPair.first );
449 int index = fields.
indexOf( fieldPair.first );
450 linkAttributes.insert( index, relatedFeature.
attribute( fieldPair.second ) );
459 const auto constNewFeatures = newFeatures;
460 for (
const QgsFeature &f : constNewFeatures )
466 QMap<int, QVariant> keys;
472 keys.insert( idx, val );
490 QMapIterator<int, QVariant> it( keys );
491 while ( it.hasNext() )
516 .setFilterFids( fids )
528 QString filter = QStringLiteral(
"(%1) AND (%2)" ).arg(
530 filters.join( QLatin1String(
" OR " ) ) );
534 .setFilterExpression( filter ) );
550 QMap<int, QgsField> keyFields;
557 QgsDebugMsg( QStringLiteral(
"referencing field %1 not found" ).arg( fieldPair.referencingField() ) );
561 keyFields.insert( idx, fld );
564 const auto constFeatureids = fids;
579 QMapIterator<int, QgsField> it( keyFields );
580 while ( it.hasNext() )
599 Q_UNUSED( newRelation )
600 Q_UNUSED( newFeature )
608 Q_UNUSED( newRelation )
609 Q_UNUSED( newNmRelation )
639 , mRelation( relation )
This class contains context information for attribute editor widgets.
void setFormFeature(const QgsFeature &feature)
Set current feature for the currently edited form or table row.
QgsMessageBar * mainMessageBar()
Returns the main message bar.
const QgsVectorLayerTools * vectorLayerTools() const
Returns the associated vector layer tools.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString expression() const
Returns the original, unmodified expression string.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsExpression * filterExpression() const
Returns the filter expression if set.
QgsFeatureRequest & setFilterFids(const QgsFeatureIds &fids)
Sets feature IDs that should be fetched.
QgsFeatureRequest & setFlags(QgsFeatureRequest::Flags flags)
Sets flags that affect how features will be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsFeatureRequest & setNoAttributes()
Set that no attributes will be fetched.
const QgsFeatureIds & selectedFeatures()
Gets the selected features.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.
int indexFromName(const QString &fieldName) const
Gets the field index from the field name.
int indexOf(const QString &fieldName) const
Gets the field index from the field name.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
QgsField at(int i) const
Gets field at particular index (must be in range 0..N-1)
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
A geometry is the spatial representation of a feature.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
A polymorphic relation consists of the same properties like a normal relation except for the referenc...
QString layerRepresentation(const QgsVectorLayer *layer) const
Returns layer representation as evaluated string.
QString referencedLayerField
static QgsProject * instance()
Returns the QgsProject singleton instance.
QMap< QPair< QString, QString >, QgsTransactionGroup * > transactionGroups()
Map of transaction groups.
Defines a relation between matching fields of the two involved tables of a relation.
QgsVectorLayer * referencedLayer
@ Generated
A generated relation is a child of a polymorphic relation.
@ Normal
A normal relation.
QList< QgsRelation::FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names o...
RelationType type() const
Returns the type of the relation.
QgsPolymorphicRelation polymorphicRelation
QgsAttributeList referencedFields() const
Returns a list of attributes used to form the referenced fields (most likely primary key) on the refe...
QgsVectorLayer * referencingLayer
QgsFeatureRequest getRelatedFeaturesRequest(const QgsFeature &feature) const
Creates a request to return all the features on the referencing (child) layer which have a foreign ke...
Contains mainly the QMap with QgsVectorLayer and QgsFeatureIds do list all the duplicated features.
QgsFeatureIds duplicatedFeatures(QgsVectorLayer *layer) const
Returns the duplicated features in the given layer.
QList< QgsVectorLayer * > layers() const
Returns all the layers on which features have been duplicated.
static QgsFeature duplicateFeature(QgsVectorLayer *layer, const QgsFeature &feature, QgsProject *project, QgsDuplicateFeatureContext &duplicateFeatureContext, const int maxDepth=0, int depth=0, QList< QgsVectorLayer * > referencedLayersBranch=QList< QgsVectorLayer * >())
Duplicates a feature and it's children (one level deep).
static QString getFeatureDisplayString(const QgsVectorLayer *layer, const QgsFeature &feature)
static QgsFeature createFeature(const QgsVectorLayer *layer, const QgsGeometry &geometry=QgsGeometry(), const QgsAttributeMap &attributes=QgsAttributeMap(), QgsExpressionContext *context=nullptr)
Creates a new feature ready for insertion into a layer.
static bool impactsCascadeFeatures(const QgsVectorLayer *layer, const QgsFeatureIds &fids, const QgsProject *project, QgsDuplicateFeatureContext &context, QgsVectorLayerUtils::CascadedFeatureFlags flags=QgsVectorLayerUtils::CascadedFeatureFlags())
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a list of features to the sink.
bool deleteFeatures(const QgsFeatureIds &fids, DeleteContext *context=nullptr)
Deletes a set of features from the layer (but does not commit it)
QgsExpressionContext createExpressionContext() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
bool changeAttributeValue(QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue=QVariant(), bool skipDefaultValues=false)
Changes an attribute value for a feature (but does not immediately commit the changes).
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) FINAL
Adds a single feature to the sink.
Q_INVOKABLE void selectByIds(const QgsFeatureIds &ids, QgsVectorLayer::SelectBehavior behavior=QgsVectorLayer::SetSelection)
Selects matching features using a list of feature IDs.
QMap< int, QVariant > QgsAttributeMap
QList< QgsFeature > QgsFeatureList
QSet< QgsFeatureId > QgsFeatureIds
#define FID_TO_STRING(fid)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList
#define QgsDebugMsgLevel(str, level)
Context for cascade delete features.
QList< QgsVectorLayer * > handledLayers(bool includeAuxiliaryLayers=true) const
Returns a list of all layers affected by the delete operation.
QgsFeatureIds handledFeatures(QgsVectorLayer *layer) const
Returns a list of feature IDs from the specified layer affected by the delete operation.