Skip to content

Unique values allow null value checkbox - #62750

Open
MoritzMoreira wants to merge 5 commits into
qgis:masterfrom
MoritzMoreira:unique-values-allow-null-value-checkbox
Open

MoritzMoreira wants to merge 5 commits into
qgis:masterfrom
MoritzMoreira:unique-values-allow-null-value-checkbox

Conversation

@MoritzMoreira

@MoritzMoreira MoritzMoreira commented Aug 1, 2025 •

Copy link
Copy Markdown
Contributor

I first created the PR Value map allow null value checkbox which fixes this issue. As the modified version of the virtual QgsEditorWidgetWrapper::updateValues() can be applied to all widgets with ComboBoxes, I decided to implement my modification as a non-virtual function beside the virtual one, to avoid identical overrides for all 6 widgets with comboboxes.
I decided to create one PR for each widget type, to avoid one very large PR.

There are two motivations for making the change for the other 5 combobox widgets besides value map (unique values,, enumaration, relation reference, classification and value relation) now:

  1. alignment of functionality.
  2. continuation of PR Disable comboboxes with no and one item :
    in the case of only one available value, this value has to be selected by default, because the combobox will be disabled
uniqueValuesCheckbox uniqueComboBox

The null value is represented this way in the combobox, rather then with no representation as of now. Also, one of the available values is set as default on opening the widget editor, rather then setting the comboBox to index -1 (no selection).

The adaptation of the default value preview is done in this PR.

@github-actions github-actions Bot added this to the 4.0.0 milestone Aug 1, 2025
@MoritzMoreira
MoritzMoreira marked this pull request as draft August 1, 2025 12:18
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from 67d1047 to 0b1a434 Compare August 1, 2025 12:37
@github-actions

github-actions Bot commented Aug 1, 2025 •

Copy link
Copy Markdown
Contributor

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
To execute locally, unzip the downloaded zip file and run bin\qgis-bin.exe in the extracted directory.
You might be prompted by Windows Defender click "Run anyway"
(Built from commit e0e83c8)

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This app is not notarized, run sudo xattr -d com.apple.quarantine /Applications/QGIS*.app to avoid the warning
(Built from commit e0e83c8)

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit dcaf537)

🪟 x64-windows — ⚠️ vcpkg failed before producing per-port logs

vcpkg returned a non-zero exit code but no port left a parseable buildtree. This usually means a portfile-execute abort (e.g. find_library REQUIRED, vcpkg_extract_source_archive download failure), or a vcpkg-internal error such as a missing tool or registry/baseline mismatch.

Look at the artifacts and the workflow log:

📑 Download full build-logs-x64-windows artifact · 🔧 Workflow run · 📌 Commit 5bec983

@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from 0b1a434 to cf08eda Compare August 1, 2025 17:00
Comment thread src/core/qgsfieldformatter.cpp Outdated
Comment thread src/core/qgsfieldformatter.h
Comment thread src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp Outdated

@m-kuhn m-kuhn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this pull request.
There are a few things to reconsider regarding where methods live, QgsFieldFormatter and QgsEditorWidgetWrapper are generic base classes, so they should not contain unique values widget specific code.

Comment thread src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp Outdated
Comment thread src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp Outdated
Comment thread src/gui/editorwidgets/core/qgseditorwidgetwrapper.h Outdated
Comment thread src/core/qgsfieldformatter.cpp Outdated
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch 3 times, most recently from da8c72e to 0b0d78f Compare August 5, 2025 17:37
Comment thread python/core/auto_additions/qgsfieldformatter.py Outdated
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch 3 times, most recently from 15ed34e to 7a131eb Compare August 6, 2025 16:38
@MoritzMoreira
MoritzMoreira marked this pull request as ready for review August 7, 2025 06:47
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from 7a131eb to 31c3f3a Compare August 7, 2025 12:07
@MoritzMoreira
MoritzMoreira marked this pull request as draft August 8, 2025 06:22
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from 31c3f3a to 05ec425 Compare August 8, 2025 08:24
@MoritzMoreira
MoritzMoreira marked this pull request as ready for review August 9, 2025 07:30
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from 05ec425 to da6acff Compare August 9, 2025 12:02
if ( comboBox->findData( v ) == -1 )
{
// v != "" is to check for the autogenerated null value, which should be represented as "()" instead of "(Null)".
if ( allowNull && !v.isEmpty() )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get that. On line 157 you set v to the NULL_VALUE in case it's null. Otherwise it's a string. Why is this check here needed?

@MoritzMoreira MoritzMoreira Aug 11, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, I cannot reproduce the situation where this autogenerated value is passed anymore. I have simplified the function accordingly and I think I have tested all cases (0/1 entry in value map table, allow null (un)checked, (un)valid default value, and all their combinations).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about backwards compatibility btw.? Is it concerned when the allowNull setting is not set (because configured with older QGIS) but NULL values are in the list?

@MoritzMoreira MoritzMoreira Aug 12, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, the NULL values from the table are added to the combobox, even when allow NULL is unchecked. Should the user get a message about it, and/or the addition of the null values be blocked? I think the rows should not be deleted automatically, because the user might want to go back to the old QGIS, correct?

@signedav signedav Aug 12, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-kuhn What do you think about that? (the backwards compatibility part)

@signedav signedav Sep 24, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MoritzMoreira Could you implement the backwards compatibility here? Means that you are able to load old projects: e.g on widget init set allow null if you have a null value (and remove the null value) and same in the widget configuration (but then stored again the new way). So you are able to use older project on newer QGIS versions (not being able to use new projects on old QGIS versions is fine I guess).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I hope I will get to do this soon, but I am not sure when I'll have the time. I will continue this whole project and some point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the backwards compatibility.

@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from da6acff to cd17a17 Compare August 11, 2025 15:13
@MoritzMoreira
MoritzMoreira marked this pull request as draft August 11, 2025 15:38
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from cd17a17 to 26cb2f4 Compare August 12, 2025 10:23
@MoritzMoreira
MoritzMoreira marked this pull request as ready for review August 12, 2025 10:29
// check if the value was already added to the combobox
if ( comboBox->findData( v ) == -1 )
{
// only if "allow null" is checked a null value is added

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this add NULL multiple times?

@MoritzMoreira MoritzMoreira Aug 12, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not produce the situation, I think it is because the function only get's called once. Should I add
&& comboBox->findData( QgsFieldFormatter::NULL_VALUE ) == -1 )
just in case, before adding NULL?

Maybe this would be necessary in the case of a set default value and the call of QgsEditorWidgetWrapper::setValues()? I could not work out how to do the latter in the python console and have it reflected in the added layer in the GUI yet.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure, but I thinks that it should check if QgsFieldFormatter::NULL_VALUE is already in the list.

It's in my opinion a little bit confusing structured. See below.

Comment on lines +154 to +167
QString v = value.toString();

if ( comboBox )
{
// check if the value was already added to the combobox
if ( comboBox->findData( v ) == -1 )
{
// only if "allow null" is checked a null value is added
if ( config( QStringLiteral( "AllowNull" ) ).toBool() )
comboBox->addItem( QgsApplication::nullRepresentation().prepend( '(' ).append( ')' ), QgsFieldFormatter::NULL_VALUE );
// add the value
if ( !QgsVariantUtils::isNull( value ) )
comboBox->addItem( v.prepend( '(' ).append( ')' ), v );
}

@signedav signedav Aug 12, 2025 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rather structure it like this (just draft - and untested)

  if ( comboBox )
  {
    if ( !QgsVariantUtils::isNull( value ) )
    {
      QString v = value.toString();
      if ( comboBox->findData( v ) == -1 )
      {
        comboBox->addItem( v.prepend( '(' ).append( ')' ), v );
      }
    }
    else  if ( config( QStringLiteral( "AllowNull" ) ).toBool()  && comboBox->findData( QgsFieldFormatter::NULL_VALUE) == -1 )
    {
      comboBox->addItem( QgsApplication::nullRepresentation().prepend( '(' ).append( ')' ), QgsFieldFormatter::NULL_VALUE );
    }
  }

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that is better. I have tested commited the changes.

@github-actions github-actions Bot added stale Uh oh! Seems this work is abandoned, and the PR is about to close. and removed stale Uh oh! Seems this work is abandoned, and the PR is about to close. labels Dec 27, 2025
@github-actions

Copy link
Copy Markdown
Contributor

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions Bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jan 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

While we hate to see this happen, this PR has been automatically closed because it has not had any activity in the last 21 days. If this pull request should be reconsidered, please follow the guidelines in the previous comment and reopen this pull request. Or, if you have any further questions, just ask! We love to help, and if there's anything the QGIS project can do to help push this PR forward please let us know how we can assist.

@github-actions github-actions Bot closed this Jan 20, 2026
@github-actions github-actions Bot added stale Uh oh! Seems this work is abandoned, and the PR is about to close. GUI/UX Related to QGIS application GUI or User Experience Form and removed stale Uh oh! Seems this work is abandoned, and the PR is about to close. labels Sep 12, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions Bot added stale Uh oh! Seems this work is abandoned, and the PR is about to close. and removed stale Uh oh! Seems this work is abandoned, and the PR is about to close. labels Oct 2, 2026
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch 2 times, most recently from 5bec983 to c191eb3 Compare October 16, 2026 14:18
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch 4 times, most recently from 34bcd05 to b04091f Compare October 28, 2026 13:49
Non-virtual version of updateValues() specific for all the widgets with
a combobox and allow-null-value configuration parameter.
Addition of a "Add NULL value" checkbox, enabling the addition of a NULL
value to the combobox when there are no features.
- the widget's combobox offers a null value for layers from older
  versions when there is a null value in the field
- when opening the configuration widget for the first time, the allow
  null checkbox is set accordingly
- Null values are no longer added to the combobox in qgsuniquevaluewidgetwrapper:initWidget()
As of now the unit test contains only tests for the unique values widget.
Tests for the other widget types will be added in the respective PRs.
@MoritzMoreira
MoritzMoreira force-pushed the unique-values-allow-null-value-checkbox branch from b04091f to 320dcf2 Compare October 28, 2026 16:38
@MoritzMoreira
MoritzMoreira marked this pull request as ready for review October 28, 2026 18:26
@MoritzMoreira

Copy link
Copy Markdown
Contributor Author

Is there anything I can do about the failed WASM check ?

@elpaso

elpaso commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Is there anything I can do about the failed WASM check ?

Just ignore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Form GUI/UX Related to QGIS application GUI or User Experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Value map widget always adds a NULL value automatically

5 participants