Skip to content

Conversation

agiudiceandrea
Copy link
Member

Description

  • set UTF-8 codec when reading the CSV file

  • correctly handle CSV file with a single column without a trailing comma, like

1
2
3

while currently only a CSV like the following one is allowed

1,
2,
3,

Fixes #60765.

(proposed again after #61568 and #62591 were closed by the stale bot)

P.S. @nyalldawson, it seems to me using QString( "" ) (instead of QString() as you proposed) is needed: it is due to the fact that QgsValueMapConfigDlg::config() behaves differently if the QTableWidgetItem.text() of the value is a QString()

if ( !vi || vi->text().isNull() )
{
value.insert( ks, ks );
}
else
{
value.insert( vi->text(), ks );
}

When a row like 1, is loaded, the regex has 2 matches: 1 for the key and an empty (not null) QString for the value. The output of QgsValueMapConfigDlg::config() will contain a map with the key 1 and an empty (not null) QString as the value.

When a row like 1 is loaded, the regex has 1 match: 1 for the key.
If we use a null QString for the value, then the output of QgsValueMapConfigDlg::config() will contain a map with the key 1 and also 1 as the value, instead of a map with the key 1 and an empty QString as the value.
We need to use an empty (not null) QString as the value, in order to make QgsValueMapConfigDlg::config() output the same map like when a row like 1, is loaded.

@github-actions github-actions bot added this to the 4.0.0 milestone Sep 21, 2025
Copy link
Contributor

github-actions bot commented Sep 21, 2025

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit a5ca450)

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This installer is not signed, control+click > open the app to avoid the warning
(Built from commit a5ca450)

@nyalldawson
Copy link
Collaborator

When a row like 1, is loaded, the regex has 2 matches: 1 for the key and an empty (not null) QString for the value. The output of QgsValueMapConfigDlg::config() will contain a map with the key 1 and an empty (not null) QString as the value.

When a row like 1 is loaded, the regex has 1 match: 1 for the key.
If we use a null QString for the value, then the output of QgsValueMapConfigDlg::config() will contain a map with the key 1 and also 1 as the value, instead of a map with the key 1 and an empty QString as the value.
We need to use an empty (not null) QString as the value, in order to make QgsValueMapConfigDlg::config() output the same map like when a row like 1, is loaded.

This is very messy, and it's part of the reason why null QString logic is discouraged. From the qt docs: https://doc.qt.io/qt-6/qstring.html#distinction-between-null-and-empty-strings "We recommend that you always use the isEmpty() function and avoid isNull()."

Can the dialog be reworked to avoid the null strings entirely?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load Data from CSV File into a Value Map Widget under a layers Properties > Attribute Form
2 participants