Skip to content
Open
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
2 changes: 2 additions & 0 deletions python/PyQt6/core/auto_additions/qgsfieldformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
QgsFieldFormatter.CanProvideAvailableValues = QgsFieldFormatter.Flag.CanProvideAvailableValues
QgsFieldFormatter.Flags = lambda flags=0: QgsFieldFormatter.Flag(flags)
try:
QgsFieldFormatter.__attribute_docs__ = {'NULL_VALUE': "Will be saved in the configuration when a value is NULL.\nIt's the magic UUID {2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"}
QgsFieldFormatter.__annotations__ = {'NULL_VALUE': str}
QgsFieldFormatter.__virtual_methods__ = ['representValue', 'sortValue', 'alignmentFlag', 'createCache', 'availableValues']
QgsFieldFormatter.__abstract_methods__ = ['id']
except (NameError, AttributeError):
Expand Down
2 changes: 0 additions & 2 deletions python/PyQt6/core/auto_additions/qgsvaluemapfieldformatter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# The following has been generated automatically from src/core/fieldformatter/qgsvaluemapfieldformatter.h
try:
QgsValueMapFieldFormatter.__attribute_docs__ = {'NULL_VALUE': "Will be saved in the configuration when a value is NULL.\nIt's the magic UUID {2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"}
QgsValueMapFieldFormatter.__annotations__ = {'NULL_VALUE': str}
QgsValueMapFieldFormatter.__overridden_methods__ = ['id', 'representValue', 'sortValue', 'availableValues']
QgsValueMapFieldFormatter.__group__ = ['fieldformatter']
except (NameError, AttributeError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ the above configuration:
#include "qgsvaluemapfieldformatter.h"
%End
public:
static const QString NULL_VALUE;

QgsValueMapFieldFormatter();
%Docstring
Default constructor of field formatter for a value map field.
Expand Down
2 changes: 2 additions & 0 deletions python/PyQt6/core/auto_generated/qgsfieldformatter.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ This is an abstract base class and will always need to be subclassed.
#include "qgsfieldformatter.h"
%End
public:
static const QString NULL_VALUE;

QgsFieldFormatter();

virtual ~QgsFieldFormatter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ Controls if the constraint result should be visualized on the widget
(mostly editable status)
%End

void updateComboBoxValues( const QVariant &value, QComboBox *comboBox );
%Docstring
Adds a value to the combobox, for example the default value or the value
from :py:func:`QgsEditorWidgetWrapper.setValues()`. Updates the combobox
to show the new value.

:param value: The new value of the attribute
:param comboBox: Pointer to the combobox of the widget
%End

signals:

void valueChanged( const QVariant &value );
Expand Down
2 changes: 0 additions & 2 deletions src/core/fieldformatter/qgsvaluemapfieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

using namespace Qt::StringLiterals;

const QString QgsValueMapFieldFormatter::NULL_VALUE = u"{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"_s;

QgsValueMapFieldFormatter::QgsValueMapFieldFormatter()
{
setFlags( flags() | QgsFieldFormatter::CanProvideAvailableValues );
Expand Down
6 changes: 0 additions & 6 deletions src/core/fieldformatter/qgsvaluemapfieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
class CORE_EXPORT QgsValueMapFieldFormatter : public QgsFieldFormatter
{
public:
/**
* Will be saved in the configuration when a value is NULL.
* It's the magic UUID {2839923C-8B7D-419E-B84B-CA2FE9B80EC7}
*/
static const QString NULL_VALUE;

/**
* Default constructor of field formatter for a value map field.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsfieldformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"

#include <QString>

using namespace Qt::StringLiterals;

const QString QgsFieldFormatter::NULL_VALUE = u"{2839923C-8B7D-419E-B84B-CA2FE9B80EC7}"_s;

QString QgsFieldFormatter::representValue( QgsVectorLayer *layer, int fieldIndex, const QVariantMap &config, const QVariant &cache, const QVariant &value ) const
{
Q_UNUSED( config )
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsfieldformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class CORE_EXPORT QgsFieldFormatterContext
class CORE_EXPORT QgsFieldFormatter
{
public:
/**
* Will be saved in the configuration when a value is NULL.
* It's the magic UUID {2839923C-8B7D-419E-B84B-CA2FE9B80EC7}
*/
static const QString NULL_VALUE;

QgsFieldFormatter() = default;

virtual ~QgsFieldFormatter() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributeformconfig/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,12 @@ void QgsAttributeTypeDialog::defaultExpressionChanged()
return;
}

const QVariant val = exp.evaluate( &context );
if ( exp.hasEvalError() )
{
mDefaultPreviewLabel->setText( "<i>" + exp.evalErrorString() + "</i>" );
return;
}
const QVariant val = exp.evaluate( &context );

// if the expression uses fields and it's not on update,
// there is no warranty that the field will be available
Expand Down
26 changes: 24 additions & 2 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

#include "qgseditorwidgetwrapper.h"

#include "qgsapplication.h"
#include "qgsfieldformatter.h"
#include "qgsfields.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerjoinbuffer.h"
#include "qgsvectorlayerjoininfo.h"
#include "qgsvectorlayerutils.h"

#include <QString>
Expand All @@ -32,6 +32,8 @@ using namespace Qt::StringLiterals;
QgsEditorWidgetWrapper::QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent )
: QgsWidgetWrapper( vl, editor, parent )
, mFieldIdx( fieldIdx )
, mValidConstraint( true )
, mIsBlockingCommit( false )
{}

int QgsEditorWidgetWrapper::fieldIdx() const
Expand Down Expand Up @@ -158,6 +160,26 @@ void QgsEditorWidgetWrapper::updateValues( const QVariant &value, const QVariant
Q_NOWARN_DEPRECATED_POP
}

void QgsEditorWidgetWrapper::updateComboBoxValues( const QVariant &value, QComboBox *comboBox )
{
if ( comboBox )
{
if ( !QgsVariantUtils::isNull( value ) )
{
QString v = value.toString();
if ( comboBox->findData( v ) == -1 )
{
comboBox->addItem( v.prepend( '(' ).append( ')' ), v );
}
}
// The null value is added only when allow null is checked
else if ( config( u"AllowNull"_s ).toBool() && comboBox->findData( QgsFieldFormatter::NULL_VALUE ) == -1 )
{
comboBox->addItem( QgsApplication::nullRepresentation().prepend( '(' ).append( ')' ), QgsFieldFormatter::NULL_VALUE );
}
}
}

QgsEditorWidgetWrapper::ConstraintResult QgsEditorWidgetWrapper::constraintResult() const
{
return mConstraintResult;
Expand Down
10 changes: 10 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "qgis_sip.h"

#include <QComboBox>
#include <QMap>
#include <QObject>
#include <QVariant>
Expand Down Expand Up @@ -235,6 +236,15 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
void setConstraintResultVisible( bool constraintResultVisible );

/**
* Adds a value to the combobox, for example the default value or the value from QgsEditorWidgetWrapper::setValues().
* Updates the combobox to show the new value.
*
* \param value The new value of the attribute
* \param comboBox Pointer to the combobox of the widget
*/
void updateComboBoxValues( const QVariant &value, QComboBox *comboBox );

signals:

/**
Expand Down
13 changes: 13 additions & 0 deletions src/gui/editorwidgets/qgsuniquevaluesconfigdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "qgsuniquevaluesconfigdlg.h"

#include "qgsproject.h"

#include <QString>

#include "moc_qgsuniquevaluesconfigdlg.cpp"
Expand All @@ -26,6 +28,7 @@ QgsUniqueValuesConfigDlg::QgsUniqueValuesConfigDlg( QgsVectorLayer *vl, int fiel
{
setupUi( this );
connect( editableUniqueValues, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( allowNullCheckBox, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
}


Expand All @@ -34,11 +37,21 @@ QVariantMap QgsUniqueValuesConfigDlg::config()
QVariantMap cfg;

cfg.insert( u"Editable"_s, editableUniqueValues->isChecked() );
cfg.insert( u"AllowNull"_s, allowNullCheckBox->isChecked() );

return cfg;
}

void QgsUniqueValuesConfigDlg::setConfig( const QVariantMap &config )
{
editableUniqueValues->setChecked( config.value( u"Editable"_s, false ).toBool() );

QSet<QVariant> uniqueValues = layer()->uniqueValues( field() );
if ( config.value( u"AllowNull"_s ).isNull() )
{
bool uniqueValuesContainNull = uniqueValues.contains( QVariant( QgsVariantUtils::createNullVariant( layer()->fields().at( field() ).type() ) ) );
allowNullCheckBox->setChecked( uniqueValuesContainNull );
}
else
allowNullCheckBox->setChecked( config.value( u"AllowNull"_s ).toBool() );
}
22 changes: 11 additions & 11 deletions src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "qgsuniquevaluewidgetwrapper.h"

#include "qgsapplication.h"
#include "qgsfieldformatter.h"
#include "qgsfilterlineedit.h"
#include "qgsvectorlayer.h"

Expand Down Expand Up @@ -77,7 +78,10 @@ void QgsUniqueValuesWidgetWrapper::initWidget( QWidget *editor )
{
if ( mComboBox )
{
mComboBox->addItem( v.toString(), v );
if ( v != QgsVariantUtils::createNullVariant( layer()->fields().at( fieldIdx() ).type() ) )
{
mComboBox->addItem( v.toString(), v );
}
}

if ( mLineEdit )
Expand Down Expand Up @@ -132,16 +136,12 @@ void QgsUniqueValuesWidgetWrapper::showIndeterminateState()

void QgsUniqueValuesWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
{
if ( mComboBox )
{
mComboBox->setCurrentIndex( mComboBox->findData( value ) );
}

if ( mLineEdit )
QSet<QVariant> uniqueValues = layer()->uniqueValues( fieldIdx() );
bool uniqueValuesContainNull = uniqueValues.contains( QgsVariantUtils::createNullVariant( layer()->fields().at( fieldIdx() ).type() ) );
// Add a null value when the layer was created in an older QGIS version, and the field contains a null value
if ( uniqueValuesContainNull && config( u"AllowNull"_s ).isNull() )
{
if ( QgsVariantUtils::isNull( value ) )
mLineEdit->setText( QgsApplication::nullRepresentation() );
else
mLineEdit->setText( value.toString() );
mComboBox->addItem( QgsApplication::nullRepresentation().prepend( '(' ).append( ')' ), QgsFieldFormatter::NULL_VALUE );
}
updateComboBoxValues( value, mComboBox );
}
22 changes: 11 additions & 11 deletions src/gui/editorwidgets/qgsvaluemapconfigdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include "qgsapplication.h"
#include "qgsattributetypeloaddialog.h"
#include "qgsfieldformatter.h"
#include "qgssettings.h"
#include "qgsvaluemapfieldformatter.h"

#include <QClipboard>
#include <QFileDialog>
Expand Down Expand Up @@ -69,7 +69,7 @@ QVariantMap QgsValueMapConfigDlg::config()

QString ks = ki->text();
if ( ( ks == QgsApplication::nullRepresentation() ) && !( ki->flags() & Qt::ItemIsEditable ) )
ks = QgsValueMapFieldFormatter::NULL_VALUE;
ks = QgsFieldFormatter::NULL_VALUE;

QVariantMap value;

Expand Down Expand Up @@ -134,7 +134,7 @@ void QgsValueMapConfigDlg::vCellChanged( int row, int column )
{
// check cell value
QTableWidgetItem *item = tableWidget->item( row, 0 );
if ( item && item->data( Qt::ItemDataRole::UserRole ) != QgsValueMapFieldFormatter::NULL_VALUE )
if ( item && item->data( Qt::ItemDataRole::UserRole ) != QgsFieldFormatter::NULL_VALUE )
{
const QString validValue = checkValueLength( item->text() );
if ( validValue.length() != item->text().length() )
Expand Down Expand Up @@ -200,7 +200,7 @@ void QgsValueMapConfigDlg::updateMap( const QList<QPair<QString, QVariant>> &lis

if ( insertNull )
{
setRow( row, QgsValueMapFieldFormatter::NULL_VALUE, u"<NULL>"_s );
setRow( row, QgsFieldFormatter::NULL_VALUE, u"<NULL>"_s );
++row;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ void QgsValueMapConfigDlg::updateMap( const QList<QPair<QString, QVariant>> &lis

QString QgsValueMapConfigDlg::checkValueLength( const QString &value )
{
if ( value == QgsValueMapFieldFormatter::NULL_VALUE || value == QgsApplication::nullRepresentation() )
if ( value == QgsFieldFormatter::NULL_VALUE || value == QgsApplication::nullRepresentation() )
{
return value;
}
Expand All @@ -272,7 +272,7 @@ void QgsValueMapConfigDlg::populateComboBox( QComboBox *comboBox, const QVariant
{
const QVariantMap valueMap = value.toMap();

if ( skipNull && valueMap.constBegin().value() == QgsValueMapFieldFormatter::NULL_VALUE )
if ( skipNull && valueMap.constBegin().value() == QgsFieldFormatter::NULL_VALUE )
continue;

comboBox->addItem( valueMap.constBegin().key(), valueMap.constBegin().value() );
Expand All @@ -283,7 +283,7 @@ void QgsValueMapConfigDlg::populateComboBox( QComboBox *comboBox, const QVariant
const QVariantMap map = config.value( u"map"_s ).toMap();
for ( auto it = map.constBegin(); it != map.constEnd(); ++it )
{
if ( skipNull && it.value() == QgsValueMapFieldFormatter::NULL_VALUE )
if ( skipNull && it.value() == QgsFieldFormatter::NULL_VALUE )
continue;

comboBox->addItem( it.key(), it.value() );
Expand Down Expand Up @@ -312,12 +312,12 @@ void QgsValueMapConfigDlg::setRow( int row, const QString &value, const QString
QTableWidgetItem *valueCell = nullptr;
QTableWidgetItem *descriptionCell = new QTableWidgetItem( description );
tableWidget->insertRow( row );
if ( value == QgsValueMapFieldFormatter::NULL_VALUE )
if ( value == QgsFieldFormatter::NULL_VALUE )
{
QFont cellFont;
cellFont.setItalic( true );
valueCell = new QTableWidgetItem( QgsApplication::nullRepresentation() );
valueCell->setData( Qt::ItemDataRole::UserRole, QgsValueMapFieldFormatter::NULL_VALUE );
valueCell->setData( Qt::ItemDataRole::UserRole, QgsFieldFormatter::NULL_VALUE );
valueCell->setFont( cellFont );
valueCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
descriptionCell->setFont( cellFont );
Expand Down Expand Up @@ -359,7 +359,7 @@ void QgsValueMapConfigDlg::copySelectionToClipboard()

void QgsValueMapConfigDlg::addNullButtonPushed()
{
setRow( tableWidget->rowCount() - 1, QgsValueMapFieldFormatter::NULL_VALUE, u"<NULL>"_s );
setRow( tableWidget->rowCount() - 1, QgsFieldFormatter::NULL_VALUE, u"<NULL>"_s );
}

void QgsValueMapConfigDlg::loadFromLayerButtonPushed()
Expand Down Expand Up @@ -413,7 +413,7 @@ void QgsValueMapConfigDlg::loadMapFromCSV( const QString &filePath )
QString key = ceils[0];
QString val = ceils[1];
if ( key == QgsApplication::nullRepresentation() )
key = QgsValueMapFieldFormatter::NULL_VALUE;
key = QgsFieldFormatter::NULL_VALUE;
map.append( qMakePair( key, val ) );
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "qgsvaluemapwidgetwrapper.h"

#include "qgsapplication.h"
#include "qgsfieldformatter.h"
#include "qgsvaluemapconfigdlg.h"
#include "qgsvaluemapfieldformatter.h"

#include <QSettings>

Expand All @@ -38,7 +38,7 @@ QVariant QgsValueMapWidgetWrapper::value() const
v = mComboBox->currentData();
}

if ( v == QgsValueMapFieldFormatter::NULL_VALUE )
if ( v == QgsFieldFormatter::NULL_VALUE )
v = QgsVariantUtils::createNullVariant( field().type() );

return v;
Expand Down Expand Up @@ -81,7 +81,7 @@ void QgsValueMapWidgetWrapper::updateValues( const QVariant &value, const QVaria
{
QString v;
if ( QgsVariantUtils::isNull( value ) )
v = QgsValueMapFieldFormatter::NULL_VALUE;
v = QgsFieldFormatter::NULL_VALUE;
else
v = value.toString();

Expand Down
Loading
Loading