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 idx )
110void QgsExternalResourceConfigDlg::chooseDefaultPath()
113 if ( !mRootPath->text().isEmpty() )
115 dir = mRootPath->text();
120 dir =
QgsSettings().
value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( path ) ) ).toString();
123 const QString rootName = QFileDialog::getExistingDirectory(
this, tr(
"Select a Directory" ), dir, QFileDialog::Options() );
125 if ( !rootName.isNull() )
126 mRootPath->setText( rootName );
129void QgsExternalResourceConfigDlg::enableCbxItem( QComboBox *comboBox,
int index,
bool enabled )
132 const auto *model = qobject_cast<QStandardItemModel *>( comboBox->model() );
137 auto *item = model->item( index );
141 item->setEnabled( enabled );
144void QgsExternalResourceConfigDlg::enableRelativeDefault()
146 bool relativePathActive =
false;
148 if ( mRootPathPropertyOverrideButton->isActive() )
150 if ( !mRootPathExpression->text().isEmpty() )
151 relativePathActive =
true;
155 if ( !mRootPath->text().isEmpty() )
156 relativePathActive =
true;
159 enableCbxItem( mStoragePathCbx, 2, relativePathActive );
166 cfg.insert( QStringLiteral(
"StorageType" ), mStorageType->currentData() );
167 cfg.insert( QStringLiteral(
"StorageAuthConfigId" ), mAuthSettingsProtocol->configId() );
168 if ( !mStorageUrl->text().isEmpty() )
169 cfg.insert( QStringLiteral(
"StorageUrl" ), mStorageUrl->text() );
171 cfg.insert( QStringLiteral(
"FileWidget" ), mFileWidgetGroupBox->isChecked() );
172 cfg.insert( QStringLiteral(
"FileWidgetButton" ), mFileWidgetButtonGroupBox->isChecked() );
173 cfg.insert( QStringLiteral(
"FileWidgetFilter" ), mFileWidgetFilterLineEdit->text() );
175 if ( mUseLink->isChecked() )
177 cfg.insert( QStringLiteral(
"UseLink" ), mUseLink->isChecked() );
178 if ( mFullUrl->isChecked() )
179 cfg.insert( QStringLiteral(
"FullUrl" ), mFullUrl->isChecked() );
184 if ( !mRootPath->text().isEmpty() )
185 cfg.insert( QStringLiteral(
"DefaultRoot" ), mRootPath->text() );
187 if ( !mStorageType->currentIndex() )
190 cfg.insert( QStringLiteral(
"StorageMode" ), mStorageModeCbx->currentData().toInt() );
192 cfg.insert( QStringLiteral(
"RelativeStorage" ), mStoragePathCbx->currentData().toInt() );
201 cfg.insert( QStringLiteral(
"DocumentViewer" ), mDocumentViewerContentComboBox->currentData().toInt() );
202 cfg.insert( QStringLiteral(
"DocumentViewerHeight" ), mDocumentViewerHeight->value() );
203 cfg.insert( QStringLiteral(
"DocumentViewerWidth" ), mDocumentViewerWidth->value() );
211 if (
config.contains( QStringLiteral(
"StorageType" ) ) )
213 const int index = mStorageType->findData(
config.value( QStringLiteral(
"StorageType" ) ) );
215 mStorageType->setCurrentIndex( index );
218 mAuthSettingsProtocol->setConfigId(
config.value( QStringLiteral(
"StorageAuthConfigId" ) ).toString() );
219 mStorageUrl->setText(
config.value( QStringLiteral(
"StorageUrl" ) ).toString() );
221 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
223 mFileWidgetGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidget" ) ).toBool() );
225 if (
config.contains( QStringLiteral(
"FileWidget" ) ) )
227 mFileWidgetButtonGroupBox->setChecked(
config.value( QStringLiteral(
"FileWidgetButton" ) ).toBool() );
229 if (
config.contains( QStringLiteral(
"FileWidgetFilter" ) ) )
231 mFileWidgetFilterLineEdit->setText(
config.value( QStringLiteral(
"FileWidgetFilter" ) ).toString() );
234 if (
config.contains( QStringLiteral(
"UseLink" ) ) )
236 mUseLink->setChecked(
config.value( QStringLiteral(
"UseLink" ) ).toBool() );
237 if (
config.contains( QStringLiteral(
"FullUrl" ) ) )
238 mFullUrl->setChecked(
true );
244 mRootPath->setText(
config.value( QStringLiteral(
"DefaultRoot" ) ).toString() );
247 if (
config.contains( QStringLiteral(
"RelativeStorage" ) ) )
249 const int relative =
config.value( QStringLiteral(
"RelativeStorage" ) ).toInt();
250 mStoragePathCbx->setCurrentIndex( relative );
254 if (
config.contains( QStringLiteral(
"StorageMode" ) ) )
256 const int mode =
config.value( QStringLiteral(
"StorageMode" ) ).toInt();
257 mStorageModeCbx->setCurrentIndex( mode );
261 if (
config.contains( QStringLiteral(
"DocumentViewer" ) ) )
264 const int idx = mDocumentViewerContentComboBox->findData( content );
267 mDocumentViewerContentComboBox->setCurrentIndex( idx );
269 if (
config.contains( QStringLiteral(
"DocumentViewerHeight" ) ) )
271 mDocumentViewerHeight->setValue(
config.value( QStringLiteral(
"DocumentViewerHeight" ) ).toInt() );
273 if (
config.contains( QStringLiteral(
"DocumentViewerWidth" ) ) )
275 mDocumentViewerWidth->setValue(
config.value( QStringLiteral(
"DocumentViewerWidth" ) ).toInt() );
293void QgsExternalResourceConfigDlg::changeStorageType(
int storageTypeIndex )
296 mExternalStorageGroupBox->setVisible( storageTypeIndex > 0 );
299 mStorageModeCbx->setVisible( !storageTypeIndex );
300 mStorageModeLbl->setVisible( !storageTypeIndex );
303 mStoragePathCbx->setVisible( !storageTypeIndex );
304 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 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.
Abstract interface for external storage - to be implemented by various backends and registered in Qgs...
static QgsProject * instance()
Returns the QgsProject singleton instance.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to 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.