40 mStorageType->addItem( tr(
"Select Existing file" ), QString() );
43 mStorageType->addItem( storage->displayName(), storage->type() );
46 mExternalStorageGroupBox->setVisible(
false );
49 mStorageUrlPropertyOverrideButton->registerVisibleWidget( mStorageUrlExpression );
50 mStorageUrlPropertyOverrideButton->registerExpressionWidget( mStorageUrlExpression );
51 mStorageUrlPropertyOverrideButton->registerVisibleWidget( mStorageUrl,
false );
52 mStorageUrlPropertyOverrideButton->registerExpressionContextGenerator(
this );
55 mUseLink->setChecked(
false );
56 mFullUrl->setChecked(
false );
60 mRootPath->setPlaceholderText(
QgsSettings().value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( defpath ) ) ).toString() );
62 connect( mRootPathButton, &QToolButton::clicked,
this, &QgsExternalResourceConfigDlg::chooseDefaultPath );
65 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPathExpression );
66 mRootPathPropertyOverrideButton->registerExpressionWidget( mRootPathExpression );
67 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPath,
false );
68 mRootPathPropertyOverrideButton->registerEnabledWidget( mRootPathButton,
false );
71 mDocumentViewerContentPropertyOverrideButton->registerVisibleWidget( mDocumentViewerContentExpression );
72 mDocumentViewerContentPropertyOverrideButton->registerExpressionWidget( mDocumentViewerContentExpression );
73 mDocumentViewerContentPropertyOverrideButton->registerEnabledWidget( mDocumentViewerContentComboBox,
false );
76 connect( mRootPath, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
77 connect( mRootPathExpression, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
87 enableCbxItem( mStoragePathCbx, 2,
false );
89 connect( mStorageType,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsExternalResourceConfigDlg::changeStorageType );
99 connect( mDocumentViewerContentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
103 mDocumentViewerContentSettingsWidget->setEnabled( hasSizeSettings );
116void QgsExternalResourceConfigDlg::chooseDefaultPath()
119 if ( !mRootPath->text().isEmpty() )
121 dir = mRootPath->text();
126 dir =
QgsSettings().
value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( path ) ) ).toString();
129 const QString rootName = QFileDialog::getExistingDirectory(
this, tr(
"Select a Directory" ), dir, QFileDialog::Options() );
131 if ( !rootName.isNull() )
132 mRootPath->setText( rootName );
135void QgsExternalResourceConfigDlg::enableCbxItem( QComboBox *comboBox,
int index,
bool enabled )
138 const auto *model = qobject_cast<QStandardItemModel *>( comboBox->model() );
143 auto *item = model->item( index );
147 item->setEnabled( enabled );
150void QgsExternalResourceConfigDlg::enableRelativeDefault()
152 bool relativePathActive =
false;
154 if ( mRootPathPropertyOverrideButton->isActive() )
156 if ( !mRootPathExpression->text().isEmpty() )
157 relativePathActive =
true;
161 if ( !mRootPath->text().isEmpty() )
162 relativePathActive =
true;
165 enableCbxItem( mStoragePathCbx, 2, relativePathActive );
172 cfg.insert( QStringLiteral(
"StorageType" ), mStorageType->currentData() );
173 cfg.insert( QStringLiteral(
"StorageAuthConfigId" ), mAuthSettingsProtocol->configId() );
174 if ( !mStorageUrl->text().isEmpty() )
175 cfg.insert( QStringLiteral(
"StorageUrl" ), mStorageUrl->text() );
177 cfg.insert( QStringLiteral(
"FileWidget" ), mFileWidgetGroupBox->isChecked() );
178 cfg.insert( QStringLiteral(
"FileWidgetButton" ), mFileWidgetButtonGroupBox->isChecked() );
179 cfg.insert( QStringLiteral(
"FileWidgetFilter" ), mFileWidgetFilterLineEdit->text() );
181 if ( mUseLink->isChecked() )
183 cfg.insert( QStringLiteral(
"UseLink" ), mUseLink->isChecked() );
184 if ( mFullUrl->isChecked() )
185 cfg.insert( QStringLiteral(
"FullUrl" ), mFullUrl->isChecked() );
190 if ( !mRootPath->text().isEmpty() )
191 cfg.insert( QStringLiteral(
"DefaultRoot" ), mRootPath->text() );
193 if ( !mStorageType->currentIndex() )
196 cfg.insert( QStringLiteral(
"StorageMode" ), mStorageModeCbx->currentData().toInt() );
198 cfg.insert( QStringLiteral(
"RelativeStorage" ), mStoragePathCbx->currentData().toInt() );
207 cfg.insert( QStringLiteral(
"DocumentViewer" ), mDocumentViewerContentComboBox->currentData().toInt() );
208 cfg.insert( QStringLiteral(
"DocumentViewerHeight" ), mDocumentViewerHeight->value() );
209 cfg.insert( QStringLiteral(
"DocumentViewerWidth" ), mDocumentViewerWidth->value() );
217 if (
config.contains( QStringLiteral(
"StorageType" ) ) )
219 const int index = mStorageType->findData(
config.value( QStringLiteral(
"StorageType" ) ) );
221 mStorageType->setCurrentIndex( index );
224 mAuthSettingsProtocol->setConfigId(
config.value( QStringLiteral(
"StorageAuthConfigId" ) ).toString() );
225 mStorageUrl->setText(
config.value( QStringLiteral(
"StorageUrl" ) ).toString() );
227 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
229 mFileWidgetGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidget" ) ).toBool() );
231 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
233 mFileWidgetButtonGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidgetButton" ) ).toBool() );
235 if (
config.contains( QStringLiteral(
"FileWidgetFilter" ) ) )
237 mFileWidgetFilterLineEdit->setText(
config.value( QStringLiteral(
"FileWidgetFilter" ) ).toString() );
240 if (
config.contains( QStringLiteral(
"UseLink" ) ) )
242 mUseLink->setChecked(
config.value( QStringLiteral(
"UseLink" ) ).toBool() );
243 if (
config.contains( QStringLiteral(
"FullUrl" ) ) )
244 mFullUrl->setChecked(
true );
250 mRootPath->setText(
config.value( QStringLiteral(
"DefaultRoot" ) ).toString() );
253 if (
config.contains( QStringLiteral(
"RelativeStorage" ) ) )
255 const int relative =
config.value( QStringLiteral(
"RelativeStorage" ) ).toInt();
256 mStoragePathCbx->setCurrentIndex( relative );
260 if (
config.contains( QStringLiteral(
"StorageMode" ) ) )
262 const int mode =
config.value( QStringLiteral(
"StorageMode" ) ).toInt();
263 mStorageModeCbx->setCurrentIndex( mode );
267 if (
config.contains( QStringLiteral(
"DocumentViewer" ) ) )
270 const int idx = mDocumentViewerContentComboBox->findData( content );
273 mDocumentViewerContentComboBox->setCurrentIndex( idx );
275 if (
config.contains( QStringLiteral(
"DocumentViewerHeight" ) ) )
277 mDocumentViewerHeight->setValue(
config.value( QStringLiteral(
"DocumentViewerHeight" ) ).toInt() );
279 if (
config.contains( QStringLiteral(
"DocumentViewerWidth" ) ) )
281 mDocumentViewerWidth->setValue(
config.value( QStringLiteral(
"DocumentViewerWidth" ) ).toInt() );
293 context << fileWidgetScope;
299void QgsExternalResourceConfigDlg::changeStorageType(
int storageTypeIndex )
302 mExternalStorageGroupBox->setVisible( storageTypeIndex > 0 );
305 mStorageModeCbx->setVisible( !storageTypeIndex );
306 mStorageModeLbl->setVisible( !storageTypeIndex );
309 mStoragePathCbx->setVisible( !storageTypeIndex );
310 mStoragePathLbl->setVisible( !storageTypeIndex );
static QgsExternalStorageRegistry * externalStorageRegistry()
Returns registry of available external storage implementations.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QStringList variableNames() const
Returns a list of variable names contained within the scope.
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...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
QVariantMap config() override
Create a configuration from the current GUI state.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsExternalResourceConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Constructor for QgsExternalResourceConfigDlg.
QList< QgsExternalStorage * > externalStorages() const
Returns a list of registered project storage implementations.
Abstract interface for external storage - to be implemented by various backends and registered in Qgs...
static QgsProject * instance()
Returns the QgsProject singleton instance.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const final
Saves this property collection to a QVariantMap, wrapped in a QVariant.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) final
Loads this property collection from a QVariantMap, wrapped in a QVariant.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Represents a vector layer which manages a vector based data sets.