28#include <QStringListModel>
30#include "moc_qgsrelationreferencesearchwidgetwrapper.cpp"
32using namespace Qt::StringLiterals;
54 const QVariantList fkeys = mWidget->foreignKeys();
56 if ( fkeys.isEmpty() )
62 const QList<QgsRelation::FieldPair> fieldPairs = mWidget->relation().fieldPairs();
63 Q_ASSERT( fieldPairs.count() == fkeys.count() );
64 for (
int i = 0; i < fieldPairs.count(); i++ )
66 if ( fieldPairs.at( i ).referencingField() ==
layer()->fields().at(
fieldIndex() ).name() )
90 return fieldName +
" IS NULL";
92 return fieldName +
" IS NOT NULL";
94 const QVariant v =
value();
98 switch ( v.userType() )
100 case QMetaType::Type::Int:
101 case QMetaType::Type::UInt:
102 case QMetaType::Type::Double:
103 case QMetaType::Type::LongLong:
104 case QMetaType::Type::ULongLong:
109 return fieldName +
" IS NULL";
110 return fieldName +
'=' + v.toString();
115 return fieldName +
" IS NOT NULL";
116 return fieldName +
"<>" + v.toString();
124 return fieldName +
"='" + v.toString() +
'\'';
126 return fieldName +
"<>'" + v.toString() +
'\'';
138 mWidget->showIndeterminateState();
146 mWidget->setEnabled( enabled );
157 onValuesChanged( QVariantList() <<
value );
160void QgsRelationReferenceSearchWidgetWrapper::onValuesChanged(
const QVariantList &values )
162 if ( values.isEmpty() )
169 const QgsSettings settings;
171 const QVariant
value = values.at( 0 );
185 if ( exp == nullValue )
203 mWidget = qobject_cast<QgsRelationReferenceWidget *>( editor );
207 mWidget->setEditorContext(
context(), mCanvas,
nullptr );
209 mWidget->setEmbedForm(
false );
210 mWidget->setReadOnlySelector(
false );
211 mWidget->setAllowMapIdentification(
config( u
"MapIdentification"_s,
false ).toBool() );
212 mWidget->setAllowAddFeatures(
false );
213 mWidget->setOpenFormButtonVisible(
false );
216 if ( fetchLimitActive )
221 if (
config( u
"FilterFields"_s, QVariant() ).isValid() )
223 mWidget->setFilterFields(
config( u
"FilterFields"_s ).toStringList() );
224 mWidget->setChainFilters(
config( u
"ChainFilters"_s ).toBool() );
225 mWidget->setFilterExpression(
config( u
"FilterExpression"_s ).
toString() );
227 mWidget->setOrderExpression(
config( u
"OrderExpression"_s ).
toString() );
228 mWidget->setSortOrder(
config( u
"OrderDescending"_s,
false ).toBool() ? Qt::DescendingOrder : Qt::AscendingOrder );
234 mWidget->setRelation( relation,
config( u
"AllowNULL"_s ).toBool() );
236 mWidget->showIndeterminateState();
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Map canvas is a class for displaying all GIS data types on a canvas.
QgsRelationManager * relationManager
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsRelation relation(const QString &id) const
Gets access to a relation by its id.
Represents a relationship between two vector layers.
Stores settings for use within QGIS.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.