Skip to content

Commit 2d339cc

Browse files
stev-0nyalldawson
authored andcommittedJan 15, 2021
Add options in list config widget for how to deal with empty rows
Allow NULL or empty array (cherry picked from commit 9a8a8c9)
1 parent 915f020 commit 2d339cc

File tree

6 files changed

+149
-13
lines changed

6 files changed

+149
-13
lines changed
 

‎src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ set(QGIS_GUI_SRCS
163163
editorwidgets/qgskeyvaluewidgetwrapper.cpp
164164
editorwidgets/qgslistwidgetfactory.cpp
165165
editorwidgets/qgslistwidgetwrapper.cpp
166+
editorwidgets/qgslistconfigdlg.cpp
166167
editorwidgets/qgsmultiedittoolbutton.cpp
167168
editorwidgets/qgsrangeconfigdlg.cpp
168169
editorwidgets/qgsrangewidgetwrapper.cpp
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/***************************************************************************
2+
qgslistconfigdlg.cpp
3+
--------------------------------------
4+
Date : 9.2020
5+
Copyright : (C) 2020 Stephen Knox
6+
Email : stephenknox73 at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgslistconfigdlg.h"
17+
18+
QgsListConfigDlg::QgsListConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent )
19+
: QgsEditorConfigWidget( vl, fieldIdx, parent )
20+
{
21+
setupUi( this );
22+
connect( mNullBehavior, &QGroupBox::toggled, this, &QgsEditorConfigWidget::changed );
23+
}
24+
25+
26+
QVariantMap QgsListConfigDlg::config()
27+
{
28+
QVariantMap cfg;
29+
30+
cfg.insert( QStringLiteral( "EmptyIsNull" ), mEmptyisNull->isChecked() );
31+
cfg.insert( QStringLiteral( "EmptyIsEmptyArray" ), mEmptyisEmptyArray->isChecked() );
32+
33+
return cfg;
34+
}
35+
36+
void QgsListConfigDlg::setConfig( const QVariantMap &config )
37+
{
38+
mEmptyisNull->setChecked( config.value( QStringLiteral( "EmptyIsNull" ) ).toBool() );
39+
mEmptyisEmptyArray->setChecked( config.value( QStringLiteral( "EmptyIsEmptyArray" ) ).toBool() );
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgstexteditconfigdlg.h
3+
--------------------------------------
4+
Date : 9.2020
5+
Copyright : (C) 2020 Stephen Knox
6+
Email : stephenknox73 at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSLISTCONFIGDLG_H
17+
#define QGSLISTCONFIGDLG_H
18+
19+
#include "ui_qgslistconfigdlg.h"
20+
21+
#include "qgseditorconfigwidget.h"
22+
#include "qgis_gui.h"
23+
24+
SIP_NO_FILE
25+
26+
/**
27+
* A configuration dialog for the List Widget class
28+
* \ingroup gui
29+
* \class QgsListConfigDlg
30+
* \note not available in Python bindings
31+
*
32+
* \since QGIS 3.16
33+
*/
34+
class GUI_EXPORT QgsListConfigDlg : public QgsEditorConfigWidget, private Ui::QgsListConfigDlg
35+
{
36+
Q_OBJECT
37+
38+
public:
39+
40+
/**
41+
* Constructor for QgsListConfigDlg, with the specified \a vector layer and field index.
42+
*/
43+
explicit QgsListConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent = nullptr );
44+
45+
// QgsEditorConfigWidget interface
46+
public:
47+
QVariantMap config() override;
48+
void setConfig( const QVariantMap &config ) override;
49+
};
50+
51+
#endif // QGSLISTCONFIGDLG_H

‎src/gui/editorwidgets/qgslistwidgetfactory.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

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

3636
QgsEditorConfigWidget *QgsListWidgetFactory::configWidget( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) const
3737
{
38-
Q_UNUSED( vl )
39-
Q_UNUSED( fieldIdx )
40-
Q_UNUSED( parent )
41-
return new QgsDummyConfigDlg( vl, fieldIdx, parent, QObject::tr( "List field" ) );
38+
return new QgsListConfigDlg( vl, fieldIdx, parent );
4239
}
4340

4441
unsigned int QgsListWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const

‎src/gui/editorwidgets/qgslistwidgetwrapper.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ QVariant QgsListWidgetWrapper::value() const
7171
QVariant::Type type = field().type();
7272
if ( !mWidget ) return QVariant( type );
7373
const QVariantList list = mWidget->list();
74+
if ( list.size() == 0 && config( QStringLiteral( "EmptyIsNull" ) ).toBool() )
75+
{
76+
return QVariant( );
77+
}
7478
if ( type == QVariant::StringList )
7579
{
7680
QStringList result;
@@ -80,14 +84,7 @@ QVariant QgsListWidgetWrapper::value() const
8084
}
8185
else
8286
{
83-
if ( list.size() == 0 )
84-
{
85-
return QVariant( );
86-
}
87-
else
88-
{
89-
return list;
90-
}
87+
return list;
9188
}
9289
}
9390

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>QgsListConfigDlg</class>
4+
<widget class="QWidget" name="QgsListConfigDlg">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>400</width>
10+
<height>78</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string notr="true">Form</string>
15+
</property>
16+
<layout class="QGridLayout" name="gridLayout">
17+
<item row="0" column="0">
18+
<widget class="QGroupBox" name="mNullBehavior">
19+
<property name="title">
20+
<string>Treatment of Empty Cells</string>
21+
</property>
22+
<layout class="QFormLayout" name="formLayout_2">
23+
<item row="0" column="0">
24+
<widget class="QRadioButton" name="mEmptyisNull">
25+
<property name="text">
26+
<string>NULL</string>
27+
</property>
28+
<property name="checked">
29+
<bool>true</bool>
30+
</property>
31+
</widget>
32+
</item>
33+
<item row="0" column="1">
34+
<widget class="QRadioButton" name="mEmptyisEmptyArray">
35+
<property name="text">
36+
<string>Empty Array</string>
37+
</property>
38+
<property name="checked">
39+
<bool>false</bool>
40+
</property>
41+
</widget>
42+
</item>
43+
</layout>
44+
</widget>
45+
</item>
46+
</layout>
47+
</widget>
48+
<resources/>
49+
<connections/>
50+
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.