QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgslistwidgetwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslistwidgetwrapper.cpp
3 --------------------------------------
4 Date : 09.2016
5 Copyright : (C) 2016 Patrick Valsecchi
6 Email : patrick.valsecchi@camptocamp.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
17#include "moc_qgslistwidgetwrapper.cpp"
18#include "qgslistwidget.h"
19#include "qgsattributeform.h"
20
21QgsListWidgetWrapper::QgsListWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent ):
22 QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
23{
24}
25
27{
28 mWidget->setList( QVariantList() );
29}
30
32{
33 if ( mWidget )
34 {
35 mWidget->setReadOnly( !enabled );
36 }
37}
38
39QWidget *QgsListWidgetWrapper::createWidget( QWidget *parent )
40{
41 QFrame *ret = new QFrame( parent );
42 ret->setFrameShape( QFrame::StyledPanel );
43 QHBoxLayout *layout = new QHBoxLayout( ret );
44 layout->setContentsMargins( 0, 0, 0, 0 );
45 QgsListWidget *widget = new QgsListWidget( field().subType(), ret );
46 layout->addWidget( widget );
47
48 if ( isInTable( parent ) )
49 {
50 // if to be put in a table, set a decent size
51 ret->setMinimumSize( QSize( 320, 110 ) );
52 }
53 return ret;
54}
55
56void QgsListWidgetWrapper::initWidget( QWidget *editor )
57{
58 mWidget = qobject_cast<QgsListWidget *>( editor );
59 if ( !mWidget )
60 {
61 mWidget = editor->findChild<QgsListWidget *>();
62 }
63
64 connect( mWidget, &QgsListWidget::valueChanged, this, &QgsListWidgetWrapper::onValueChanged );
65}
66
68{
69 return mWidget ? mWidget->valid() : true;
70}
71
72void QgsListWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
73{
74 mWidget->setList( value.toList() );
75}
76
78{
79 const QMetaType::Type type = field().type();
80 if ( !mWidget ) return QgsVariantUtils::createNullVariant( type );
81 const QVariantList list = mWidget->list();
82 if ( list.size() == 0 && config( QStringLiteral( "EmptyIsNull" ) ).toBool() )
83 {
84 return QVariant( );
85 }
86 if ( type == QMetaType::Type::QStringList )
87 {
88 QStringList result;
89 for ( QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
90 result.append( it->toString() );
91 return result;
92 }
93 else
94 {
95 return list;
96 }
97}
98
99void QgsListWidgetWrapper::onValueChanged()
100{
102}
103
104void QgsListWidgetWrapper::updateConstraintWidgetStatus()
105{
106 // Nothing
107}
Manages an editor widget Widget and wrapper share the same parent.
static bool isInTable(const QWidget *parent)
Check if the given widget or one of its parent is a QTableView.
void emitValueChanged()
Will call the value() method to determine the emitted value.
QgsField field() const
Access the field.
QMetaType::Type type
Definition qgsfield.h:60
QgsListWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsListWidgetWrapper.
QVariant value() const override
Will be used to access the widget's value.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
bool valid() const override
Returns true if the widget has been properly initialized.
void setEnabled(bool enabled) override
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
Widget allowing to edit a QVariantList, using a table.
bool valid() const
Check the content is valid.
QVariantList list
void setReadOnly(bool readOnly) override
void setList(const QVariantList &list)
Set the initial value of the widget.
void valueChanged()
Emitted each time a key or a value is changed.
static QVariant createNullVariant(QMetaType::Type metaType)
Helper method to properly create a null QVariant from a metaType Returns the created QVariant.
Represents a vector layer which manages a vector based data sets.
QWidget * widget()
Access the widget managed by this wrapper.
QVariantMap config() const
Returns the whole config.