22#include <qjsonarray.h>
24#include "moc_qgslistwidgetwrapper.cpp"
26using namespace Qt::StringLiterals;
34 mWidget->setList( QVariantList() );
41 mWidget->setReadOnly( !enabled );
47 QFrame *ret =
new QFrame( parent );
48 ret->setFrameShape( QFrame::StyledPanel );
49 QHBoxLayout *layout =
new QHBoxLayout( ret );
50 layout->setContentsMargins( 0, 0, 0, 0 );
53 if (
field().type() == QMetaType::Type::QString )
55 usedSubType = QMetaType::Type::QString;
58 layout->addWidget(
widget );
63 ret->setMinimumSize( QSize( 320, 110 ) );
70 mWidget = qobject_cast<QgsListWidget *>( editor );
81 return mWidget ? mWidget->valid() :
true;
84void QgsListWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList & )
86 QVariantList listValue =
value.toList();
88 if (
field().type() == QMetaType::Type::QString )
90 const QJsonDocument doc = QJsonDocument::fromJson(
value.toString().toUtf8() );
91 if ( !doc.isNull() && doc.isArray() )
93 listValue = doc.array().toVariantList();
96 mWidget->setList( listValue );
101 const QMetaType::Type type =
field().
type();
104 const QVariantList list = mWidget->list();
105 if ( list.size() == 0 &&
config( u
"EmptyIsNull"_s ).toBool() )
109 if ( type == QMetaType::Type::QStringList )
112 for ( QVariantList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it )
113 result.append( it->toString() );
122void QgsListWidgetWrapper::onValueChanged()
QMetaType::Type subType() const
If the field is a collection, gets its element's type.
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 dataset.