30#include "moc_qgsexternalresourcewidgetwrapper.cpp"
32using namespace Qt::StringLiterals;
36 , mMessageBar( messageBar )
43 return mQgsWidget->documentPath(
field().type() );
54 return mLineEdit->text();
81 return mLineEdit || mLabel || mQgsWidget;
84void QgsExternalResourceWidgetWrapper::updateProperties(
const QgsFeature &feature )
89 expressionContext.setFeature( feature );
106 if ( dvcString.compare(
"image"_L1, Qt::CaseInsensitive ) == 0 )
110 else if ( dvcString.compare(
"audio"_L1, Qt::CaseInsensitive ) == 0 )
114 else if ( dvcString.compare(
"video"_L1, Qt::CaseInsensitive ) == 0 )
118 else if ( dvcString.compare(
"web"_L1, Qt::CaseInsensitive ) == 0 )
126 mQgsWidget->setDocumentViewerContent( dvc );
134 updateProperties( feature );
145 mForm = qobject_cast<QgsAttributeForm *>( parent );
155 mLineEdit = qobject_cast<QLineEdit *>( editor );
156 mLabel = qobject_cast<QLabel *>( editor );
157 mQgsWidget = qobject_cast<QgsExternalResourceWidget *>( editor );
168 mLineEdit = editor->findChild<QLineEdit *>();
172 mQgsWidget->setMessageBar( mMessageBar );
176 const QVariantMap cfg =
config();
179 mQgsWidget->setStorageType( cfg.value( u
"StorageType"_s ).toString() );
180 mQgsWidget->setStorageAuthConfigId( cfg.value( u
"StorageAuthConfigId"_s ).toString() );
182 mQgsWidget->fileWidget()->setStorageUrlExpression(
189 if ( cfg.contains( u
"UseLink"_s ) )
191 mQgsWidget->fileWidget()->setUseLink( cfg.value( u
"UseLink"_s ).toBool() );
193 if ( cfg.contains( u
"FullUrl"_s ) )
195 mQgsWidget->fileWidget()->setFullUrl( cfg.value( u
"FullUrl"_s ).toBool() );
200 mQgsWidget->setDefaultRoot( cfg.value( u
"DefaultRoot"_s ).toString() );
202 if ( cfg.contains( u
"StorageMode"_s ) )
206 if ( cfg.contains( u
"RelativeStorage"_s ) )
210 if ( cfg.contains( u
"FileWidget"_s ) )
212 mQgsWidget->setFileWidgetVisible( cfg.value( u
"FileWidget"_s ).toBool() );
214 if ( cfg.contains( u
"FileWidgetButton"_s ) )
216 mQgsWidget->fileWidget()->setFileWidgetButtonVisible( cfg.value( u
"FileWidgetButton"_s ).toBool() );
218 if ( cfg.contains( u
"DocumentViewer"_s ) )
222 if ( cfg.contains( u
"FileWidgetFilter"_s ) )
224 mQgsWidget->fileWidget()->setFilter( cfg.value( u
"FileWidgetFilter"_s ).toString() );
226 if ( cfg.contains( u
"DocumentViewerHeight"_s ) )
228 mQgsWidget->setDocumentViewerHeight( cfg.value( u
"DocumentViewerHeight"_s ).toInt() );
230 if ( cfg.contains( u
"DocumentViewerWidth"_s ) )
232 mQgsWidget->setDocumentViewerWidth( cfg.value( u
"DocumentViewerWidth"_s ).toInt() );
237 connect( mLineEdit, &QLineEdit::textChanged,
this, [
this](
const QString &
value ) {
245void QgsExternalResourceWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList & )
255 mLineEdit->setText(
value.toString() );
261 mLabel->setText(
value.toString() );
276 mQgsWidget->setDocumentPath(
value.toString() );
284 mLineEdit->setReadOnly( !enabled );
287 mQgsWidget->setReadOnly( !enabled );
292 Q_UNUSED( newValue );
293 if ( attributeChanged )
300 const QgsFeature feature = mForm->currentFormFeature();
301 updateProperties( feature );
312 widget()->setStyleSheet( QString() );
319 mLineEdit->setStyleSheet( QString() );
323 mLineEdit->setStyleSheet( u
"QgsFilterLineEdit { background-color: #dd7777; }"_s );
327 mLineEdit->setStyleSheet( u
"QgsFilterLineEdit { background-color: #ffd85d; }"_s );
336 if ( !mQgsWidget || !
layer() )
342 if (
context().parentFormFeature().isValid() )
347 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 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...
static 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 QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
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.