Skip to content
Permalink
Browse files

Add options in list config widget for how to deal with empty rows

Allow NULL or empty array
  • Loading branch information
stev-0 authored and nyalldawson committed Dec 29, 2020
1 parent 4e125eb commit 9a8a8c958c0f3ed0373a59642b03f3e73a82d66d
@@ -163,6 +163,7 @@ set(QGIS_GUI_SRCS
editorwidgets/qgskeyvaluewidgetwrapper.cpp
editorwidgets/qgslistwidgetfactory.cpp
editorwidgets/qgslistwidgetwrapper.cpp
editorwidgets/qgslistconfigdlg.cpp
editorwidgets/qgsmultiedittoolbutton.cpp
editorwidgets/qgsrangeconfigdlg.cpp
editorwidgets/qgsrangewidgetwrapper.cpp
@@ -0,0 +1,40 @@
/***************************************************************************
qgslistconfigdlg.cpp
--------------------------------------
Date : 9.2020
Copyright : (C) 2020 Stephen Knox
Email : stephenknox73 at gmail 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 "qgslistconfigdlg.h"

QgsListConfigDlg::QgsListConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
: QgsEditorConfigWidget( vl, fieldIdx, parent )
{
setupUi( this );
connect( mNullBehavior, &QGroupBox::toggled, this, &QgsEditorConfigWidget::changed );
}


QVariantMap QgsListConfigDlg::config()
{
QVariantMap cfg;

cfg.insert( QStringLiteral( "EmptyIsNull" ), mEmptyisNull->isChecked() );
cfg.insert( QStringLiteral( "EmptyIsEmptyArray" ), mEmptyisEmptyArray->isChecked() );

return cfg;
}

void QgsListConfigDlg::setConfig( const QVariantMap &config )
{
mEmptyisNull->setChecked( config.value( QStringLiteral( "EmptyIsNull" ) ).toBool() );
mEmptyisEmptyArray->setChecked( config.value( QStringLiteral( "EmptyIsEmptyArray" ) ).toBool() );
}
@@ -0,0 +1,51 @@
/***************************************************************************
qgstexteditconfigdlg.h
--------------------------------------
Date : 9.2020
Copyright : (C) 2020 Stephen Knox
Email : stephenknox73 at gmail 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. *
* *
***************************************************************************/

#ifndef QGSLISTCONFIGDLG_H
#define QGSLISTCONFIGDLG_H

#include "ui_qgslistconfigdlg.h"

#include "qgseditorconfigwidget.h"
#include "qgis_gui.h"

SIP_NO_FILE

/**
* A configuration dialog for the List Widget class
* \ingroup gui
* \class QgsListConfigDlg
* \note not available in Python bindings
*
* \since QGIS 3.16
*/
class GUI_EXPORT QgsListConfigDlg : public QgsEditorConfigWidget, private Ui::QgsListConfigDlg
{
Q_OBJECT

public:

/**
* Constructor for QgsListConfigDlg, with the specified \a vector layer and field index.
*/
explicit QgsListConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent = nullptr );

// QgsEditorConfigWidget interface
public:
QVariantMap config() override;
void setConfig( const QVariantMap &config ) override;
};

#endif // QGSLISTCONFIGDLG_H
@@ -15,7 +15,7 @@

#include "qgslistwidgetfactory.h"
#include "qgslistwidgetwrapper.h"
#include "qgsdummyconfigdlg.h"
#include "qgslistconfigdlg.h"
#include "qgsfields.h"
#include "qgsvectorlayer.h"
#include "qgseditorwidgetregistry.h"
@@ -35,10 +35,7 @@ QgsEditorWidgetWrapper *QgsListWidgetFactory::create( QgsVectorLayer *vl, int fi

QgsEditorConfigWidget *QgsListWidgetFactory::configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const
{
Q_UNUSED( vl )
Q_UNUSED( fieldIdx )
Q_UNUSED( parent )
return new QgsDummyConfigDlg( vl, fieldIdx, parent, QObject::tr( "List field" ) );
return new QgsListConfigDlg( vl, fieldIdx, parent );
}

unsigned int QgsListWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
@@ -71,6 +71,10 @@ QVariant QgsListWidgetWrapper::value() const
QVariant::Type type = field().type();
if ( !mWidget ) return QVariant( type );
const QVariantList list = mWidget->list();
if ( list.size() == 0 && config( QStringLiteral( "EmptyIsNull" ) ).toBool() )
{
return QVariant( );
}
if ( type == QVariant::StringList )
{
QStringList result;
@@ -80,14 +84,7 @@ QVariant QgsListWidgetWrapper::value() const
}
else
{
if ( list.size() == 0 )
{
return QVariant( );
}
else
{
return list;
}
return list;
}
}

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsListConfigDlg</class>
<widget class="QWidget" name="QgsListConfigDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>78</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="mNullBehavior">
<property name="title">
<string>Treatment of Empty Cells</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QRadioButton" name="mEmptyisNull">
<property name="text">
<string>NULL</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="mEmptyisEmptyArray">
<property name="text">
<string>Empty Array</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 9a8a8c9

Please sign in to comment.
You can’t perform that action at this time.