Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui] Insure modified attribute form properties are stored when switching from one field to another #60192

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading