31#include "moc_qgsexternalresourcewidgetwrapper.cpp"
33using namespace Qt::StringLiterals;
37 , mMessageBar( messageBar )
44 return mQgsWidget->documentPath(
field().type() );
55 return mLineEdit->text();
82 return mLineEdit || mLabel || mQgsWidget;
85void QgsExternalResourceWidgetWrapper::updateProperties(
const QgsFeature &feature )
90 expressionContext.setFeature( feature );
114 auto evaluatedContent = CONTENT_MAP.lookup( dvcString );
116 if ( evaluatedContent )
118 dvc = *evaluatedContent;
121 mQgsWidget->setDocumentViewerContent( dvc );
129 updateProperties( feature );
140 mForm = qobject_cast<QgsAttributeForm *>( parent );
150 mLineEdit = qobject_cast<QLineEdit *>( editor );
151 mLabel = qobject_cast<QLabel *>( editor );
152 mQgsWidget = qobject_cast<QgsExternalResourceWidget *>( editor );
163 mLineEdit = editor->findChild<QLineEdit *>();
167 mQgsWidget->setMessageBar( mMessageBar );
171 const QVariantMap cfg =
config();
174 mQgsWidget->setStorageType( cfg.value( u
"StorageType"_s ).toString() );
175 mQgsWidget->setStorageAuthConfigId( cfg.value( u
"StorageAuthConfigId"_s ).toString() );
177 mQgsWidget->fileWidget()->setStorageUrlExpression(
184 if ( cfg.contains( u
"UseLink"_s ) )
186 mQgsWidget->fileWidget()->setUseLink( cfg.value( u
"UseLink"_s ).toBool() );
188 if ( cfg.contains( u
"FullUrl"_s ) )
190 mQgsWidget->fileWidget()->setFullUrl( cfg.value( u
"FullUrl"_s ).toBool() );
195 mQgsWidget->setDefaultRoot( cfg.value( u
"DefaultRoot"_s ).toString() );
197 if ( cfg.contains( u
"StorageMode"_s ) )
201 if ( cfg.contains( u
"RelativeStorage"_s ) )
205 if ( cfg.contains( u
"FileWidget"_s ) )
207 mQgsWidget->setFileWidgetVisible( cfg.value( u
"FileWidget"_s ).toBool() );
209 if ( cfg.contains( u
"FileWidgetButton"_s ) )
211 mQgsWidget->fileWidget()->setFileWidgetButtonVisible( cfg.value( u
"FileWidgetButton"_s ).toBool() );
213 if ( cfg.contains( u
"DocumentViewer"_s ) )
217 if ( cfg.contains( u
"FileWidgetFilter"_s ) )
219 mQgsWidget->fileWidget()->setFilter( cfg.value( u
"FileWidgetFilter"_s ).toString() );
221 if ( cfg.contains( u
"DocumentViewerHeight"_s ) )
223 mQgsWidget->setDocumentViewerHeight( cfg.value( u
"DocumentViewerHeight"_s ).toInt() );
225 if ( cfg.contains( u
"DocumentViewerWidth"_s ) )
227 mQgsWidget->setDocumentViewerWidth( cfg.value( u
"DocumentViewerWidth"_s ).toInt() );
232 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString &
value ) {
240void QgsExternalResourceWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList & )
250 mLineEdit->setText(
value.toString() );
256 mLabel->setText(
value.toString() );
271 mQgsWidget->setDocumentPath(
value.toString() );
279 mLineEdit->setReadOnly( !enabled );
282 mQgsWidget->setReadOnly( !enabled );
287 Q_UNUSED( newValue );
288 if ( attributeChanged )
295 const QgsFeature feature = mForm->currentFormFeature();
296 updateProperties( feature );
307 widget()->setStyleSheet( QString() );
314 mLineEdit->setStyleSheet( QString() );
318 mLineEdit->setStyleSheet( u
"QgsFilterLineEdit { background-color: #dd7777; }"_s );
322 mLineEdit->setStyleSheet( u
"QgsFilterLineEdit { background-color: #ffd85d; }"_s );
331 if ( !mQgsWidget || !
layer() )
337 if (
context().parentFormFeature().isValid() )
342 mQgsWidget->fileWidget()->setExpressionContext( expressionContext );
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
static QString nullRepresentation()
Returns the string used to represent the value NULL throughout QGIS.
static std::vector< std::unique_ptr< QgsExpressionContextScope > > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
static std::unique_ptr< QgsExpressionContextScope > formScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current attribute form/table form...
static std::unique_ptr< QgsExpressionContextScope > parentFormScope(const QgsFeature &formFeature=QgsFeature(), const QString &formMode=QString())
Creates a new scope which contains functions and variables from the current parent attribute form/tab...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Handles parsing and evaluation of expressions (formerly called "search strings").
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
void setNullValue(const QString &nullValue)
Sets the string representation for null values in the widget.
A bar for displaying non-blocking messages to the user.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
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 dataset.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
constexpr QgsDataDefinedStringDecoder< V, N > makeDataDefinedStringDecoder(const DataDefinedDecoderEntry< V >(&values)[N])
Creates a QgsDataDefinedStringDecoder from a hardcoded lookup table.