18#include "moc_qgsrelationreferencewidgetwrapper.cpp"
27 , mMessageBar( messageBar )
28 , mIndeterminateState( false )
52 const bool showForm =
config( QStringLiteral(
"ShowForm" ),
false ).toBool();
53 const bool mapIdent =
config( QStringLiteral(
"MapIdentification" ),
false ).toBool();
54 const bool readOnlyWidget =
config( QStringLiteral(
"ReadOnly" ),
false ).toBool();
55 const bool showOpenFormButton =
config( QStringLiteral(
"ShowOpenFormButton" ),
true ).toBool();
62 const bool fetchLimitActive =
config( QStringLiteral(
"FetchLimitActive" ),
QgsSettings().
value( QStringLiteral(
"maxEntriesRelationWidget" ), 100,
QgsSettings::Gui ).toInt() > 0 ).toBool();
63 if ( fetchLimitActive )
68 if (
config( QStringLiteral(
"FilterFields" ), QVariant() ).isValid() )
73 if ( !
config( QStringLiteral(
"FilterExpression" ) ).toString().isEmpty() )
79 const QVariant relationName =
config( QStringLiteral(
"Relation" ) );
88 if ( relationName.isValid() )
111 if ( !
config( QStringLiteral(
"AllowNULL" ) ).isValid() )
117 mWidget->
setRelation( relation,
config( QStringLiteral(
"AllowNULL" ) ).toBool() );
130 if ( fkeys.isEmpty() )
137 Q_ASSERT( fieldPairs.count() == fkeys.count() );
138 for (
int i = 0; i < fieldPairs.count(); i++ )
140 if ( fieldPairs.at( i ).referencingField() ==
field().name() )
141 return fkeys.at( i );
158 mIndeterminateState =
true;
169 for (
int i = 0; i < mWidget->
relation().fieldPairs().count(); i++ )
171 values << QVariant();
179 const int fieldCount = std::min( fieldPairs.count(), values.count() );
180 for (
int i = 0; i < fieldCount; i++ )
182 if ( fieldPairs.at( i ).referencingField() ==
field().name() )
184 values.removeAt( i );
195 return QStringList();
199 for (
int i = 0; i < fieldPairs.count(); i++ )
201 if ( fieldPairs.at( i ).referencingField() ==
field().name() )
204 fields << fieldPairs.at( i ).referencingField();
209void QgsRelationReferenceWidgetWrapper::updateValues(
const QVariant &val,
const QVariantList &additionalValues )
214 mIndeterminateState =
false;
216 QVariantList values = additionalValues;
218 for (
int i = 0; i < fieldPairs.count(); i++ )
220 if ( fieldPairs.at( i ).referencingField() ==
field().name() )
222 values.insert( i, val );
226 Q_ASSERT( values.count() == fieldPairs.count() );
242void QgsRelationReferenceWidgetWrapper::foreignKeysChanged(
const QVariantList &values )
244 if ( mBlockChanges != 0 )
258 QVariantList additionalValues = values;
260 for (
int i = 0; i < fieldPairs.count(); i++ )
262 if ( fieldPairs.at( i ).referencingField() ==
field().name() )
263 mainValue = additionalValues.takeAt( i );
265 Q_ASSERT( additionalValues.count() == values.count() - 1 );
279 widget()->setStyleSheet( QString() );
286 mWidget->setStyleSheet( QString() );
290 mWidget->setStyleSheet( QStringLiteral(
".QComboBox { background-color: #dd7777; }" ) );
294 mWidget->setStyleSheet( QStringLiteral(
".QComboBox { background-color: #ffd85d; }" ) );
This class contains context information for attribute editor widgets.
const QgsAttributeEditorContext * parentContext() const
const QgsRelation & relation() const
Returns the attribute relation.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
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.
QList< QgsRelation::FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names o...
bool referencingFieldsAllowNull() const
Returns true if none of the referencing fields has a NOT NULL constraint.
This class is a composition of two QSettings instances:
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
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 data sets.
QList< QgsRelation > referencingRelations(int idx) const
Returns the layer's relations, where the foreign key is on this layer.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH