QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 : [email protected]
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 "qgslistwidgetwrapper.h"
17 #include "qgslistwidget.h"
18 #include "qgsattributeform.h"
19 
20 QgsListWidgetWrapper::QgsListWidgetWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent ):
21  QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
22 {
23 }
24 
26 {
27  mWidget->setList( QVariantList() );
28 }
29 
30 QWidget *QgsListWidgetWrapper::createWidget( QWidget *parent )
31 {
32  if ( isInTable( parent ) )
33  {
34  // if to be put in a table, draw a border and set a decent size
35  QFrame *ret = new QFrame( parent );
36  ret->setFrameShape( QFrame::StyledPanel );
37  QHBoxLayout *layout = new QHBoxLayout( ret );
38  layout->addWidget( new QgsListWidget( field().subType(), ret ) );
39  ret->setMinimumSize( QSize( 320, 110 ) );
40  return ret;
41  }
42  else
43  {
44  return new QgsListWidget( field().subType(), parent );
45  }
46 }
47 
48 void QgsListWidgetWrapper::initWidget( QWidget *editor )
49 {
50  mWidget = qobject_cast<QgsListWidget *>( editor );
51  if ( !mWidget )
52  {
53  mWidget = editor->findChild<QgsListWidget *>();
54  }
55 
56  connect( mWidget, &QgsListWidget::valueChanged, this, &QgsListWidgetWrapper::onValueChanged );
57 }
58 
60 {
61  return mWidget ? mWidget->valid() : true;
62 }
63 
64 void QgsListWidgetWrapper::updateValues( const QVariant &value, const QVariantList & )
65 {
66  mWidget->setList( value.toList() );
67 }
68 
70 {
71  const QVariant::Type type = field().type();
72  if ( !mWidget ) return QVariant( type );
73  const QVariantList list = mWidget->list();
74  if ( list.size() == 0 && config( QStringLiteral( "EmptyIsNull" ) ).toBool() )
75  {
76  return QVariant( );
77  }
78  if ( type == QVariant::StringList )
79  {
80  QStringList result;
81  for ( QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
82  result.append( it->toString() );
83  return result;
84  }
85  else
86  {
87  return list;
88  }
89 }
90 
91 void QgsListWidgetWrapper::onValueChanged()
92 {
94 }
95 
96 void QgsListWidgetWrapper::updateConstraintWidgetStatus()
97 {
98  // Nothing
99 }
qgsattributeform.h
QgsListWidget::valid
bool valid() const
Check the content is valid.
Definition: qgslistwidget.h:105
QgsEditorWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.
Definition: qgseditorwidgetwrapper.h:47
QgsListWidgetWrapper::valid
bool valid() const override
Returns true if the widget has been properly initialized.
Definition: qgslistwidgetwrapper.cpp:59
qgslistwidget.h
QgsListWidgetWrapper::showIndeterminateState
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
Definition: qgslistwidgetwrapper.cpp:25
QgsListWidget
Widget allowing to edit a QVariantList, using a table.
Definition: qgslistwidget.h:66
QgsEditorWidgetWrapper::field
QgsField field() const
Access the field.
Definition: qgseditorwidgetwrapper.cpp:39
QgsListWidgetWrapper::createWidget
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
Definition: qgslistwidgetwrapper.cpp:30
QgsListWidget::list
QVariantList list
Definition: qgslistwidget.h:82
QgsEditorWidgetWrapper::emitValueChanged
void emitValueChanged()
Will call the value() method to determine the emitted value.
Definition: qgseditorwidgetwrapper.cpp:91
QgsTableWidgetBase::valueChanged
void valueChanged()
Emitted each time a key or a value is changed.
qgslistwidgetwrapper.h
QgsListWidgetWrapper::value
QVariant value() const override
Will be used to access the widget's value.
Definition: qgslistwidgetwrapper.cpp:69
QgsWidgetWrapper::config
QVariantMap config() const
Returns the whole config.
Definition: qgswidgetwrapper.cpp:82
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsListWidgetWrapper::QgsListWidgetWrapper
QgsListWidgetWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsListWidgetWrapper.
Definition: qgslistwidgetwrapper.cpp:20
QgsListWidget::setList
void setList(const QVariantList &list)
Set the initial value of the widget.
Definition: qgslistwidget.cpp:26
QgsListWidgetWrapper::initWidget
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
Definition: qgslistwidgetwrapper.cpp:48
QgsField::type
QVariant::Type type
Definition: qgsfield.h:58
QgsEditorWidgetWrapper::isInTable
static bool isInTable(const QWidget *parent)
Check if the given widget or one of its parent is a QTableView.
Definition: qgseditorwidgetwrapper.cpp:282