27#include <QStringListModel>
29#include "moc_qgsrelationreferencesearchwidgetwrapper.cpp"
52 const QVariantList fkeys = mWidget->foreignKeys();
54 if ( fkeys.isEmpty() )
60 const QList<QgsRelation::FieldPair> fieldPairs = mWidget->relation().fieldPairs();
61 Q_ASSERT( fieldPairs.count() == fkeys.count() );
62 for (
int i = 0; i < fieldPairs.count(); i++ )
64 if ( fieldPairs.at( i ).referencingField() ==
layer()->fields().at(
fieldIndex() ).name() )
88 return fieldName +
" IS NULL";
90 return fieldName +
" IS NOT NULL";
92 const QVariant v =
value();
96 switch ( v.userType() )
98 case QMetaType::Type::Int:
99 case QMetaType::Type::UInt:
100 case QMetaType::Type::Double:
101 case QMetaType::Type::LongLong:
102 case QMetaType::Type::ULongLong:
107 return fieldName +
" IS NULL";
108 return fieldName +
'=' + v.toString();
113 return fieldName +
" IS NOT NULL";
114 return fieldName +
"<>" + v.toString();
122 return fieldName +
"='" + v.toString() +
'\'';
124 return fieldName +
"<>'" + v.toString() +
'\'';
136 mWidget->showIndeterminateState();
144 mWidget->setEnabled( enabled );
155 onValuesChanged( QVariantList() <<
value );
158void QgsRelationReferenceSearchWidgetWrapper::onValuesChanged(
const QVariantList &values )
160 if ( values.isEmpty() )
167 const QgsSettings settings;
169 const QVariant
value = values.at( 0 );
183 if ( exp == nullValue )
189 str = QStringLiteral(
"%1 = '%3'" )
202 mWidget = qobject_cast<QgsRelationReferenceWidget *>( editor );
206 mWidget->setEditorContext(
context(), mCanvas,
nullptr );
208 mWidget->setEmbedForm(
false );
209 mWidget->setReadOnlySelector(
false );
210 mWidget->setAllowMapIdentification(
config( QStringLiteral(
"MapIdentification" ),
false ).toBool() );
211 mWidget->setAllowAddFeatures(
false );
212 mWidget->setOpenFormButtonVisible(
false );
214 const bool fetchLimitActive =
config( QStringLiteral(
"FetchLimitActive" ),
QgsSettings().
value( QStringLiteral(
"maxEntriesRelationWidget" ), 100,
QgsSettings::Gui ).toInt() > 0 ).toBool();
215 if ( fetchLimitActive )
220 if (
config( QStringLiteral(
"FilterFields" ), QVariant() ).isValid() )
222 mWidget->setFilterFields(
config( QStringLiteral(
"FilterFields" ) ).toStringList() );
223 mWidget->setChainFilters(
config( QStringLiteral(
"ChainFilters" ) ).toBool() );
224 mWidget->setFilterExpression(
config( QStringLiteral(
"FilterExpression" ) ).
toString() );
226 mWidget->setOrderExpression(
config( QStringLiteral(
"OrderExpression" ) ).
toString() );
227 mWidget->setSortOrder(
config( QStringLiteral(
"OrderDescending" ),
false ).toBool() ? Qt::DescendingOrder : Qt::AscendingOrder );
233 mWidget->setRelation( relation,
config( QStringLiteral(
"AllowNULL" ) ).toBool() );
235 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.