Skip to content
Permalink
Browse files
Added test
  • Loading branch information
domi4484 committed Nov 19, 2021
1 parent 18564a2 commit 976f076163005c8cd26d86418f94c232f254fcb4
@@ -165,6 +165,13 @@ Returns the widget configuration
virtual void setConfig( const QVariantMap &config ) = 0;
%Docstring
Defines the widget configuration
%End

bool multiEditModeActive() const;
%Docstring
Returns true if editing multiple features at a time

.. versionadded:: 3.24
%End

public slots:
@@ -221,13 +228,6 @@ Duplicates a feature
void duplicateFeatures( const QgsFeatureIds &fids );
%Docstring
Duplicates features
%End

bool multiEditModeActive() const;
%Docstring
Returns true if editing multiple features at a time

.. versionadded:: 3.24
%End

protected:
@@ -174,6 +174,11 @@ void QgsAbstractRelationEditorWidget::updateTitle()
{
}

bool QgsAbstractRelationEditorWidget::multiEditModeActive() const
{
return mFeatureList.size() > 1;
}

QgsFeature QgsAbstractRelationEditorWidget::feature() const
{
if ( !mFeatureList.isEmpty() )
@@ -695,11 +700,6 @@ void QgsAbstractRelationEditorWidget::duplicateFeatures( const QgsFeatureIds &fi
}
}

bool QgsAbstractRelationEditorWidget::multiEditModeActive() const
{
return mFeatureList.size() > 1;
}

void QgsAbstractRelationEditorWidget::showEvent( QShowEvent * )
{
updateUi();
@@ -177,6 +177,12 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
*/
virtual void setConfig( const QVariantMap &config ) = 0;

/**
* Returns true if editing multiple features at a time
* \since QGIS 3.24
*/
bool multiEditModeActive() const;

public slots:

/**
@@ -232,12 +238,6 @@ class GUI_EXPORT QgsAbstractRelationEditorWidget : public QWidget
*/
void duplicateFeatures( const QgsFeatureIds &fids );

/**
* Returns true if editing multiple features at a time
* \since QGIS 3.24
*/
bool multiEditModeActive() const;

protected:

QgsAttributeEditorContext mEditorContext;
@@ -657,9 +657,10 @@ void QgsRelationEditorWidget::updateUiMultiEdit()
for ( const QgsFeature &feature : std::as_const( mFeatureList ) )
{
QTreeWidgetItem *treeWidgetItem = new QTreeWidgetItem( mMultiEditTreeWidget );
treeWidgetItem->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ), static_cast<int>( MultiEditFeatureType::Parent ) );
treeWidgetItem->setText( 0, QgsVectorLayerUtils::getFeatureDisplayString( mRelation.referencedLayer(), feature ) );
treeWidgetItem->setIcon( 0, QgsIconUtils::iconForLayer( mRelation.referencedLayer() ) );
initializeMultiEditTreeWidgetItem( treeWidgetItem,
QgsVectorLayerUtils::getFeatureDisplayString( mRelation.referencedLayer(), feature ),
QgsIconUtils::iconForLayer( mRelation.referencedLayer() ),
MultiEditFeatureType::Parent );

// Parent feature items are not selectable
treeWidgetItem->setFlags( Qt::ItemIsEnabled );
@@ -680,10 +681,11 @@ void QgsRelationEditorWidget::updateUiMultiEdit()
while ( featureIteratorFinalChild.nextFeature( featureChildChild ) )
{
QTreeWidgetItem *treeWidgetItemChild = new QTreeWidgetItem( treeWidgetItem );
treeWidgetItemChild->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ), static_cast<int>( MultiEditFeatureType::Child ) );
treeWidgetItemChild->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureId ), featureChildChild.id() );
treeWidgetItemChild->setText( 0, QgsVectorLayerUtils::getFeatureDisplayString( mNmRelation.referencedLayer(), featureChildChild ) );
treeWidgetItemChild->setIcon( 0, QgsIconUtils::iconForLayer( mNmRelation.referencedLayer() ) );
initializeMultiEditTreeWidgetItem( treeWidgetItemChild,
QgsVectorLayerUtils::getFeatureDisplayString( mNmRelation.referencedLayer(), featureChildChild ),
QgsIconUtils::iconForLayer( mNmRelation.referencedLayer() ),
MultiEditFeatureType::Child,
featureChildChild.id() );

treeWidgetItem->addChild( treeWidgetItemChild );

@@ -694,10 +696,11 @@ void QgsRelationEditorWidget::updateUiMultiEdit()
else
{
QTreeWidgetItem *treeWidgetItemChild = new QTreeWidgetItem( treeWidgetItem );
treeWidgetItemChild->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ), static_cast<int>( MultiEditFeatureType::Child ) );
treeWidgetItemChild->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureId ), featureChild.id() );
treeWidgetItemChild->setText( 0, QgsVectorLayerUtils::getFeatureDisplayString( mRelation.referencingLayer(), featureChild ) );
treeWidgetItemChild->setIcon( 0, QgsIconUtils::iconForLayer( mRelation.referencingLayer() ) );
initializeMultiEditTreeWidgetItem( treeWidgetItemChild,
QgsVectorLayerUtils::getFeatureDisplayString( mRelation.referencingLayer(), featureChild ),
QgsIconUtils::iconForLayer( mRelation.referencingLayer() ),
MultiEditFeatureType::Child,
featureChild.id() );
treeWidgetItem->addChild( treeWidgetItemChild );

featureIdsMixedValues.insert( featureChild.id() );
@@ -708,34 +711,40 @@ void QgsRelationEditorWidget::updateUiMultiEdit()
mMultiEditTreeWidget->addTopLevelItem( treeWidgetItem );
}

// Check for mixed values
// Set mixed values indicator (Green or Orange)
//
// Green:
// n:m and 1:n: 0 child features available
// n:m with no mixed values
// Orange:
// n:m with mixed values
// 1:n always, including when we pseudo know that feature are related (just added feature)
//
// See https://github.com/qgis/QGIS/pull/45703
//
if ( mNmRelation.isValid() )
{
QgsFeatureIds featureIdsNotMixed;
for ( const QgsFeatureId &featureId : featureIdsMixedValues )
QgsFeatureIds::iterator iterator = featureIdsMixedValues.begin();
while ( iterator != featureIdsMixedValues.end() )
{
bool mixedValues = false;
for ( QTreeWidgetItem *parentTreeWidgetItem : parentTreeWidgetItems )
{
if ( ! multimapChildFeatures.values( parentTreeWidgetItem ).contains( featureId ) )
if ( ! multimapChildFeatures.values( parentTreeWidgetItem ).contains( *iterator ) )
{
mixedValues = true;
break;
}
}

if ( !mixedValues )
featureIdsNotMixed.insert( featureId );

{
iterator = featureIdsMixedValues.erase( iterator );
continue;
}

++iterator;
}

featureIdsMixedValues -= featureIdsNotMixed;
}
else
{
for ( const QgsFeatureId &featureIdJustAdded : std::as_const( mMultiEdit1NJustAddedIds ) )
featureIdsMixedValues.remove( featureIdJustAdded );
}

// Set multiedit info label
@@ -769,6 +778,18 @@ void QgsRelationEditorWidget::updateUiMultiEdit()
}
}

void QgsRelationEditorWidget::initializeMultiEditTreeWidgetItem( QTreeWidgetItem *treeWidgetItem,
const QString &text,
const QIcon &icon,
MultiEditFeatureType type,
const QVariant &featureId )
{
treeWidgetItem->setText( 0, text );
treeWidgetItem->setIcon( 0, icon );
treeWidgetItem->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureType ), static_cast<int>( type ) );
treeWidgetItem->setData( 0, static_cast<int>( MultiEditTreeWidgetRole::FeatureId ), featureId );
}

void QgsRelationEditorWidget::onKeyPressed( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Escape )
@@ -213,12 +213,6 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
void multiEditItemSelectionChanged();

private:
void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
void setMapTool( QgsMapTool *mapTool );
void unsetMapTool();
QgsFeatureIds selectedChildFeatureIds() const;
void updateUiSingleEdit();
void updateUiMultiEdit();

enum class MultiEditFeatureType : int
{
@@ -232,6 +226,18 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge
FeatureId = Qt::UserRole + 2
};

void initDualView( QgsVectorLayer *layer, const QgsFeatureRequest &request );
void setMapTool( QgsMapTool *mapTool );
void unsetMapTool();
QgsFeatureIds selectedChildFeatureIds() const;
void updateUiSingleEdit();
void updateUiMultiEdit();
void initializeMultiEditTreeWidgetItem( QTreeWidgetItem *treeWidgetItem,
const QString &text,
const QIcon &icon,
MultiEditFeatureType type,
const QVariant &featureId = QVariant() );

QgsDualView *mDualView = nullptr;
QPointer<QgsMessageBarItem> mMessageBarItem;
QgsDualView::ViewMode mViewMode = QgsDualView::AttributeEditor;
@@ -260,6 +266,8 @@ class GUI_EXPORT QgsRelationEditorWidget : public QgsAbstractRelationEditorWidge

QList<QTreeWidgetItem *> mMultiEditPreviousSelectedItems;
QgsFeatureIds mMultiEdit1NJustAddedIds;

friend class TestQgsRelationEditorWidget;
};


@@ -59,6 +59,7 @@ set(TESTS
testqgslayoutview.cpp
testqgsvaluemapwidgetwrapper.cpp
testqgsvaluerelationwidgetwrapper.cpp
testqgsrelationeditorwidget.cpp
testqgsrelationreferencewidget.cpp
testqgsfeaturelistcombobox.cpp
testqgstexteditwrapper.cpp
Loading

0 comments on commit 976f076

Please sign in to comment.