26 #include <QFileDialog> 36 mUseLink->setChecked(
false );
37 mFullUrl->setChecked(
false );
41 mRootPath->setPlaceholderText(
QgsSettings().
value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath( defpath ) ) ).toString() );
43 connect( mRootPathButton, &QToolButton::clicked,
this, &QgsExternalResourceConfigDlg::chooseDefaultPath );
46 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPathExpression );
47 mRootPathPropertyOverrideButton->registerExpressionWidget( mRootPathExpression );
48 mRootPathPropertyOverrideButton->registerVisibleWidget( mRootPath,
false );
49 mRootPathPropertyOverrideButton->registerEnabledWidget( mRootPathButton,
false );
53 mDocumentViewerContentPropertyOverrideButton->registerVisibleWidget( mDocumentViewerContentExpression );
54 mDocumentViewerContentPropertyOverrideButton->registerExpressionWidget( mDocumentViewerContentExpression );
55 mDocumentViewerContentPropertyOverrideButton->registerEnabledWidget( mDocumentViewerContentComboBox,
false );
58 connect( mRootPath, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
59 connect( mRootPathExpression, &QLineEdit::textChanged,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
60 connect( mRelativeGroupBox, &QGroupBox::toggled,
this, &QgsExternalResourceConfigDlg::enableRelativeDefault );
65 mStoreFilesButton->setChecked(
true );
70 mRelativeProject->setChecked(
true );
78 connect( mStorageButtonGroup,
static_cast<void ( QButtonGroup::* )(
int )
>( &QButtonGroup::buttonClicked ),
this, &
QgsEditorConfigWidget::changed );
81 connect( mDocumentViewerContentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int idx )
91 void QgsExternalResourceConfigDlg::chooseDefaultPath()
94 if ( !mRootPath->text().isEmpty() )
96 dir = mRootPath->text();
100 dir =
QgsSettings().
value( QStringLiteral(
"/UI/lastExternalResourceWidgetDefaultPath" ), QDir::toNativeSeparators( QDir::cleanPath(
QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString();
103 QString rootName = QFileDialog::getExistingDirectory(
this, tr(
"Select a directory" ), dir, QFileDialog::ShowDirsOnly );
105 if ( !rootName.isNull() )
106 mRootPath->setText( rootName );
109 void QgsExternalResourceConfigDlg::enableRelativeDefault()
111 bool relativePathActive =
false;
113 if ( mRootPathPropertyOverrideButton->isActive() )
115 if ( !mRootPathExpression->text().isEmpty() )
116 relativePathActive =
true;
120 if ( !mRootPath->text().isEmpty() )
121 relativePathActive =
true;
125 if ( mRelativeGroupBox->isChecked() )
126 mRelativeDefault->setEnabled( relativePathActive );
129 if ( !relativePathActive )
130 mRelativeProject->toggle();
137 cfg.insert( QStringLiteral(
"FileWidget" ), mFileWidgetGroupBox->isChecked() );
138 cfg.insert( QStringLiteral(
"FileWidgetButton" ), mFileWidgetButtonGroupBox->isChecked() );
139 cfg.insert( QStringLiteral(
"FileWidgetFilter" ), mFileWidgetFilterLineEdit->text() );
141 if ( mUseLink->isChecked() )
143 cfg.insert( QStringLiteral(
"UseLink" ), mUseLink->isChecked() );
144 if ( mFullUrl->isChecked() )
145 cfg.insert( QStringLiteral(
"FullUrl" ), mFullUrl->isChecked() );
150 if ( !mRootPath->text().isEmpty() )
151 cfg.insert( QStringLiteral(
"DefaultRoot" ), mRootPath->text() );
154 cfg.insert( QStringLiteral(
"StorageMode" ), mStorageButtonGroup->checkedId() );
157 if ( mRelativeGroupBox->isChecked() )
159 cfg.insert( QStringLiteral(
"RelativeStorage" ), mRelativeButtonGroup->checkedId() );
166 cfg.insert( QStringLiteral(
"DocumentViewer" ), mDocumentViewerContentComboBox->currentData().toInt() );
167 cfg.insert( QStringLiteral(
"DocumentViewerHeight" ), mDocumentViewerHeight->value() );
168 cfg.insert( QStringLiteral(
"DocumentViewerWidth" ), mDocumentViewerWidth->value() );
176 if ( config.contains( QStringLiteral(
"FileWidget" ) ) )
178 mFileWidgetGroupBox->setChecked( config.value( QStringLiteral(
"FileWidget" ) ).toBool() );
180 if ( config.contains( QStringLiteral(
"FileWidget" ) ) )
182 mFileWidgetButtonGroupBox->setChecked( config.value( QStringLiteral(
"FileWidgetButton" ) ).toBool() );
184 if ( config.contains( QStringLiteral(
"FileWidgetFilter" ) ) )
186 mFileWidgetFilterLineEdit->setText( config.value( QStringLiteral(
"FileWidgetFilter" ) ).toString() );
189 if ( config.contains( QStringLiteral(
"UseLink" ) ) )
191 mUseLink->setChecked( config.value( QStringLiteral(
"UseLink" ) ).toBool() );
192 if ( config.contains( QStringLiteral(
"FullUrl" ) ) )
193 mFullUrl->setChecked(
true );
199 mRootPath->setText( config.value( QStringLiteral(
"DefaultRoot" ) ).toString() );
202 if ( config.contains( QStringLiteral(
"RelativeStorage" ) ) )
204 int relative = config.value( QStringLiteral(
"RelativeStorage" ) ).toInt();
207 mRelativeGroupBox->setChecked(
false );
211 mRelativeGroupBox->setChecked(
true );
212 mRelativeButtonGroup->button( relative )->setChecked(
true );
217 if ( config.contains( QStringLiteral(
"StorageMode" ) ) )
219 int mode = config.value( QStringLiteral(
"StorageMode" ) ).toInt();
220 mStorageButtonGroup->button( mode )->setChecked(
true );
224 if ( config.contains( QStringLiteral(
"DocumentViewer" ) ) )
227 int idx = mDocumentViewerContentComboBox->findData( content );
230 mDocumentViewerContentComboBox->setCurrentIndex( idx );
232 if ( config.contains( QStringLiteral(
"DocumentViewerHeight" ) ) )
234 mDocumentViewerHeight->setValue( config.value( QStringLiteral(
"DocumentViewerHeight" ) ).toInt() );
236 if ( config.contains( QStringLiteral(
"DocumentViewerWidth" ) ) )
238 mDocumentViewerWidth->setValue( config.value( QStringLiteral(
"DocumentViewerWidth" ) ).toInt() );
This class is a composition of two QSettings instances:
QgsExternalResourceConfigDlg(QgsVectorLayer *vl, int fieldIdx, QWidget *parent=nullptr)
Constructor for QgsExternalResourceConfigDlg.
void setConfig(const QVariantMap &config) override
Update the configuration widget to represent the given configuration.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QVariantMap config() override
Create a configuration from the current GUI state.
QFileInfo fileInfo() const
Returns QFileInfo object for the project's associated file.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Represents a vector layer which manages a vector based data sets.