Skip to content

Commit

Permalink
[gui] Insure modified attribute form properties are stored when switc…
Browse files Browse the repository at this point in the history
…hing from one field to another (fixes qgis#60181)
  • Loading branch information
nirvn committed Jan 21, 2025
1 parent 0318ff3 commit ec32d71
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gui/vector/qgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,13 @@ void QgsAttributesFormProperties::loadAttributeSpecificEditor( QgsAttributesDnDT
const Qgis::AttributeFormLayout layout = mEditorLayoutComboBox->currentData().value<Qgis::AttributeFormLayout>();

if ( layout == Qgis::AttributeFormLayout::DragAndDrop )
{
storeAttributeWidgetEdit();
}
if ( mAttributeTypeDialog )
{
storeAttributeTypeDialog();
}

clearAttributeTypeFrame();

Expand Down Expand Up @@ -673,7 +679,9 @@ void QgsAttributesFormProperties::loadAttributeSpecificEditor( QgsAttributesDnDT
{
receiver->selectFirstMatchingItem( itemData );
if ( layout == Qgis::AttributeFormLayout::DragAndDrop )
{
loadAttributeWidgetEdit();
}
loadAttributeTypeDialog();
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/gui/vector/qgsattributesformproperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ class GUI_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpress
QMenu *mAvailableWidgetsTreeContextMenu = nullptr;
QAction *mActionCopyWidgetConfiguration = nullptr;
QAction *mActionPasteWidgetConfiguration = nullptr;

friend class TestQgsAttributesFormProperties;
};


Expand Down
1 change: 1 addition & 0 deletions tests/src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ set(TESTS
testqgsdoublespinbox.cpp
testqgsdualview.cpp
testqgsattributeform.cpp
testqgsattributesformproperties.cpp
testqgsdatetimeedit.cpp
testqgsdockwidget.cpp
testqgsfieldexpressionwidget.cpp
Expand Down
89 changes: 89 additions & 0 deletions tests/src/gui/testqgsattributesformproperties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/***************************************************************************
testqgsattributesformproperties.cpp
--------------------------------------
Date : 2025-01-21
Copyright : (C) 2025 Mathieu Pellerin
Email : paul dot blottiere at oslandia dot com
***************************************************************************
* *
* 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 "qgstest.h"

#include "qgsattributesformproperties.h"
#include "qgsattributetypedialog.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "qgsgui.h"

class TestQgsAttributesFormProperties : public QObject
{
Q_OBJECT
public:
TestQgsAttributesFormProperties() = default;

private slots:
void initTestCase(); // will be called before the first testfunction is executed.
void cleanupTestCase(); // will be called after the last testfunction was executed.
void init(); // will be called before each testfunction is executed.
void cleanup(); // will be called after every testfunction.

void testConfigStored();
};

void TestQgsAttributesFormProperties::initTestCase()
{
QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsAttributesFormProperties::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsAttributesFormProperties::init()
{
}

void TestQgsAttributesFormProperties::cleanup()
{
}

void TestQgsAttributesFormProperties::testConfigStored()
{
QgsVectorLayer *layer = new QgsVectorLayer( QStringLiteral( "Point?field=col0:integer&field=col1:integer" ), QStringLiteral( "test" ), QStringLiteral( "memory" ) );
QgsAttributesFormProperties attributeFormProperties( layer );
attributeFormProperties.init();

// Get the fields
QVERIFY( attributeFormProperties.mAvailableWidgetsTree );
QTreeWidgetItem *fieldsItem = attributeFormProperties.mAvailableWidgetsTree->topLevelItem( 0 );
QVERIFY( fieldsItem );
QCOMPARE( fieldsItem->text( 0 ), QStringLiteral( "Fields" ) );
QCOMPARE( fieldsItem->childCount(), 2 );

// Insure that the configuration was stored when switching from one available widgets tree item to another
attributeFormProperties.mAvailableWidgetsTree->setCurrentItem( fieldsItem->child( 0 ) );
QVERIFY( attributeFormProperties.mAttributeTypeDialog );
attributeFormProperties.mAttributeTypeDialog->setAlias( QStringLiteral( "alias0" ) );
attributeFormProperties.mAvailableWidgetsTree->setCurrentItem( fieldsItem->child( 1 ) );
QVERIFY( attributeFormProperties.mAttributeTypeDialog );
attributeFormProperties.mAttributeTypeDialog->setAlias( QStringLiteral( "alias1" ) );

attributeFormProperties.mAvailableWidgetsTree->setCurrentItem( fieldsItem->child( 0 ) );
QVERIFY( attributeFormProperties.mAttributeTypeDialog );
QCOMPARE( attributeFormProperties.mAttributeTypeDialog->alias(), QStringLiteral( "alias0" ) );
attributeFormProperties.mAvailableWidgetsTree->setCurrentItem( fieldsItem->child( 1 ) );
QVERIFY( attributeFormProperties.mAttributeTypeDialog );
QCOMPARE( attributeFormProperties.mAttributeTypeDialog->alias(), QStringLiteral( "alias1" ) );
}

QGSTEST_MAIN( TestQgsAttributesFormProperties )
#include "testqgsattributesformproperties.moc"

0 comments on commit ec32d71

Please sign in to comment.