17#include "moc_qgsexternalresourceconfigdlg.cpp"
41 mStorageType->addItem( tr(
"Select Existing file" ), QString() );
44 mStorageType->addItem( storage->displayName(), storage->type() );
47 mExternalStorageGroupBox->setVisible(
false );
50 mStorageUrlPropertyOverrideButton->registerVisibleWidget( mStorageUrlExpression );
51 mStorageUrlPropertyOverrideButton->registerExpressionWidget( mStorageUrlExpression );
52 mStorageUrlPropertyOverrideButton->registerVisibleWidget( mStorageUrl,
false );
53 mStorageUrlPropertyOverrideButton->registerExpressionContextGenerator(
this );
56 mUseLink->setChecked(
false );
57 mFullUrl->setChecked(
false );
61 mRootPath->setPlaceholderText(
QgsSettings().value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( defpath ) ) ).toString() );
63 connect( mRootPathButton, &QToolButton::clicked,
this, &QgsExternalResourceConfigDlg::chooseDefaultPath );
66 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPathExpression );
67 mRootPathPropertyOverrideButton->registerExpressionWidget( mRootPathExpression );
68 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPath,
false );
69 mRootPathPropertyOverrideButton->registerEnabledWidget( mRootPathButton,
false );
72 mDocumentViewerContentPropertyOverrideButton->registerVisibleWidget( mDocumentViewerContentExpression );
73 mDocumentViewerContentPropertyOverrideButton->registerExpressionWidget( mDocumentViewerContentExpression );
74 mDocumentViewerContentPropertyOverrideButton->registerEnabledWidget( mDocumentViewerContentComboBox,
false );
77 connect( mRootPath, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
78 connect( mRootPathExpression, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
88 enableCbxItem( mStoragePathCbx, 2,
false );
90 connect( mStorageType,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsExternalResourceConfigDlg::changeStorageType );
100 connect( mDocumentViewerContentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
104 mDocumentViewerContentSettingsWidget->setEnabled( hasSizeSettings );
117void QgsExternalResourceConfigDlg::chooseDefaultPath()
120 if ( !mRootPath->text().isEmpty() )
122 dir = mRootPath->text();
127 dir =
QgsSettings().
value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( path ) ) ).toString();
130 const QString rootName = QFileDialog::getExistingDirectory(
this, tr(
"Select a Directory" ), dir, QFileDialog::Options() );
132 if ( !rootName.isNull() )
133 mRootPath->setText( rootName );
136void QgsExternalResourceConfigDlg::enableCbxItem( QComboBox *comboBox,
int index,
bool enabled )
139 const auto *model = qobject_cast<QStandardItemModel *>( comboBox->model() );
144 auto *item = model->item( index );
148 item->setEnabled( enabled );
151void QgsExternalResourceConfigDlg::enableRelativeDefault()
153 bool relativePathActive =
false;
155 if ( mRootPathPropertyOverrideButton->isActive() )
157 if ( !mRootPathExpression->text().isEmpty() )
158 relativePathActive =
true;
162 if ( !mRootPath->text().isEmpty() )
163 relativePathActive =
true;
166 enableCbxItem( mStoragePathCbx, 2, relativePathActive );
173 cfg.insert( QStringLiteral(
"StorageType" ), mStorageType->currentData() );
174 cfg.insert( QStringLiteral(
"StorageAuthConfigId" ), mAuthSettingsProtocol->configId() );
175 if ( !mStorageUrl->text().isEmpty() )
176 cfg.insert( QStringLiteral(
"StorageUrl" ), mStorageUrl->text() );
178 cfg.insert( QStringLiteral(
"FileWidget" ), mFileWidgetGroupBox->isChecked() );
179 cfg.insert( QStringLiteral(
"FileWidgetButton" ), mFileWidgetButtonGroupBox->isChecked() );
180 cfg.insert( QStringLiteral(
"FileWidgetFilter" ), mFileWidgetFilterLineEdit->text() );
182 if ( mUseLink->isChecked() )
184 cfg.insert( QStringLiteral(
"UseLink" ), mUseLink->isChecked() );
185 if ( mFullUrl->isChecked() )
186 cfg.insert( QStringLiteral(
"FullUrl" ), mFullUrl->isChecked() );
191 if ( !mRootPath->text().isEmpty() )
192 cfg.insert( QStringLiteral(
"DefaultRoot" ), mRootPath->text() );
194 if ( !mStorageType->currentIndex() )
197 cfg.insert( QStringLiteral(
"StorageMode" ), mStorageModeCbx->currentData().toInt() );
199 cfg.insert( QStringLiteral(
"RelativeStorage" ), mStoragePathCbx->currentData().toInt() );
208 cfg.insert( QStringLiteral(
"DocumentViewer" ), mDocumentViewerContentComboBox->currentData().toInt() );
209 cfg.insert( QStringLiteral(
"DocumentViewerHeight" ), mDocumentViewerHeight->value() );
210 cfg.insert( QStringLiteral(
"DocumentViewerWidth" ), mDocumentViewerWidth->value() );
218 if (
config.contains( QStringLiteral(
"StorageType" ) ) )
220 const int index = mStorageType->findData(
config.value( QStringLiteral(
"StorageType" ) ) );
222 mStorageType->setCurrentIndex( index );
225 mAuthSettingsProtocol->setConfigId(
config.value( QStringLiteral(
"StorageAuthConfigId" ) ).toString() );
226 mStorageUrl->setText(
config.value( QStringLiteral(
"StorageUrl" ) ).toString() );
228 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
230 mFileWidgetGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidget" ) ).toBool() );
232 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
234 mFileWidgetButtonGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidgetButton" ) ).toBool() );
236 if (
config.contains( QStringLiteral(
"FileWidgetFilter" ) ) )
238 mFileWidgetFilterLineEdit->setText(
config.value( QStringLiteral(
"FileWidgetFilter" ) ).toString() );
241 if (
config.contains( QStringLiteral(
"UseLink" ) ) )
243 mUseLink->setChecked(
config.value( QStringLiteral(
"UseLink" ) ).toBool() );
244 if (
config.contains( QStringLiteral(
"FullUrl" ) ) )
245 mFullUrl->setChecked(
true );
251 mRootPath->setText(
config.value( QStringLiteral(
"DefaultRoot" ) ).toString() );
254 if (
config.contains( QStringLiteral(
"RelativeStorage" ) ) )
256 const int relative =
config.value( QStringLiteral(
"RelativeStorage" ) ).toInt();
257 mStoragePathCbx->setCurrentIndex( relative );
261 if (
config.contains( QStringLiteral(
"StorageMode" ) ) )
263 const int mode =
config.value( QStringLiteral(
"StorageMode" ) ).toInt();
264 mStorageModeCbx->setCurrentIndex( mode );
268 if (
config.contains( QStringLiteral(
"DocumentViewer" ) ) )
271 const int idx = mDocumentViewerContentComboBox->findData( content );
274 mDocumentViewerContentComboBox->setCurrentIndex( idx );
276 if (
config.contains( QStringLiteral(
"DocumentViewerHeight" ) ) )
278 mDocumentViewerHeight->setValue(
config.value( QStringLiteral(
"DocumentViewerHeight" ) ).toInt() );
280 if (
config.contains( QStringLiteral(
"DocumentViewerWidth" ) ) )
282 mDocumentViewerWidth->setValue(
config.value( QStringLiteral(
"DocumentViewerWidth" ) ).toInt() );
294 context << fileWidgetScope;
300void QgsExternalResourceConfigDlg::changeStorageType(
int storageTypeIndex )
303 mExternalStorageGroupBox->setVisible( storageTypeIndex > 0 );
306 mStorageModeCbx->setVisible( !storageTypeIndex );
307 mStorageModeLbl->setVisible( !storageTypeIndex );
310 mStoragePathCbx->setVisible( !storageTypeIndex );
311 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.