28#include <QStringListModel>
30#include "moc_qgsrelationreferencesearchwidgetwrapper.cpp"
32using namespace Qt::StringLiterals;
55 const QVariantList fkeys = mWidget->foreignKeys();
57 if ( fkeys.isEmpty() )
63 const QList<QgsRelation::FieldPair> fieldPairs = mWidget->relation().fieldPairs();
64 Q_ASSERT( fieldPairs.count() == fkeys.count() );
65 for (
int i = 0; i < fieldPairs.count(); i++ )
67 if ( fieldPairs.at( i ).referencingField() ==
layer()->fields().at(
fieldIndex() ).name() )
91 return fieldName +
" IS NULL";
93 return fieldName +
" IS NOT NULL";
95 const QVariant v =
value();
99 switch ( v.userType() )
101 case QMetaType::Type::Int:
102 case QMetaType::Type::UInt:
103 case QMetaType::Type::Double:
104 case QMetaType::Type::LongLong:
105 case QMetaType::Type::ULongLong:
110 return fieldName +
" IS NULL";
111 return fieldName +
'=' + v.toString();
116 return fieldName +
" IS NOT NULL";
117 return fieldName +
"<>" + v.toString();
125 return fieldName +
"='" + v.toString() +
'\'';
127 return fieldName +
"<>'" + v.toString() +
'\'';
139 mWidget->showIndeterminateState();
147 mWidget->setEnabled( enabled );
158 onValuesChanged( QVariantList() <<
value );
161void QgsRelationReferenceSearchWidgetWrapper::onValuesChanged(
const QVariantList &values )
163 if ( values.isEmpty() )
170 const QgsSettings settings;
172 const QVariant
value = values.at( 0 );
186 if ( exp == nullValue )
205 mWidget = qobject_cast<QgsRelationReferenceWidget *>( editor );
209 mWidget->setEditorContext(
context(), mCanvas,
nullptr );
211 mWidget->setEmbedForm(
false );
212 mWidget->setReadOnlySelector(
false );
213 mWidget->setAllowMapIdentification(
config( u
"MapIdentification"_s,
false ).toBool() );
214 mWidget->setAllowAddFeatures(
false );
215 mWidget->setOpenFormButtonVisible(
false );
218 if ( fetchLimitActive )
223 if (
config( u
"FilterFields"_s, QVariant() ).isValid() )
225 mWidget->setFilterFields(
config( u
"FilterFields"_s ).toStringList() );
226 mWidget->setChainFilters(
config( u
"ChainFilters"_s ).toBool() );
227 mWidget->setFilterExpression(
config( u
"FilterExpression"_s ).
toString() );
229 mWidget->setOrderExpression(
config( u
"OrderExpression"_s ).
toString() );
230 mWidget->setSortOrder(
config( u
"OrderDescending"_s,
false ).toBool() ? Qt::DescendingOrder : Qt::AscendingOrder );
236 mWidget->setRelation( relation,
config( u
"AllowNULL"_s ).toBool() );
238 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.