Treat FileProviderSettingsController::settingsViewWidget as a factory method

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-09-04 18:28:41 +08:00
parent 20f89c6999
commit 94ce3da9c5
No known key found for this signature in database
GPG key ID: C839200C384636B0
3 changed files with 12 additions and 22 deletions

View file

@ -199,11 +199,12 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
#if defined(BUILD_FILE_PROVIDER_MODULE)
if (Mac::FileProvider::fileProviderAvailable()) {
const auto fpSettingsWidget = Mac::FileProviderSettingsController::instance()->settingsViewWidget();
const auto fpSettingsLayout = new QVBoxLayout(_ui->fileProviderTab);
const auto fileProviderTab = _ui->fileProviderTab;
const auto fpSettingsLayout = new QVBoxLayout(fileProviderTab);
const auto fpSettingsWidget = Mac::FileProviderSettingsController::instance()->settingsViewWidget(fileProviderTab);
fpSettingsLayout->setMargin(0);
fpSettingsLayout->addWidget(fpSettingsWidget);
_ui->fileProviderTab->setLayout(fpSettingsLayout);
fileProviderTab->setLayout(fpSettingsLayout);
} else {
disguiseTabWidget();
}

View file

@ -28,18 +28,15 @@ class FileProviderSettingsController : public QObject
public:
static FileProviderSettingsController *instance();
[[nodiscard]] QQuickWidget *settingsViewWidget();
[[nodiscard]] QQuickWidget *settingsViewWidget(QWidget *const parent = nullptr,
const QQuickWidget::ResizeMode resizeMode = QQuickWidget::SizeRootObjectToView);
private:
explicit FileProviderSettingsController(QObject *parent = nullptr);
~FileProviderSettingsController() override;
void instantiateSettingsWidget();
class MacImplementation;
std::unique_ptr<MacImplementation> d;
std::unique_ptr<QQuickWidget> _settingsViewWidget;
};
} // Mac

View file

@ -68,21 +68,13 @@ FileProviderSettingsController::FileProviderSettingsController(QObject *parent)
d = std::make_unique<FileProviderSettingsController::MacImplementation>(this);
}
void FileProviderSettingsController::instantiateSettingsWidget()
QQuickWidget *FileProviderSettingsController::settingsViewWidget(QWidget *const parent, const QQuickWidget::ResizeMode resizeMode)
{
_settingsViewWidget = std::make_unique<QQuickWidget>(Systray::instance()->trayEngine(), nullptr);
_settingsViewWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
_settingsViewWidget->setSource(QUrl(fpSettingsQmlPath));
_settingsViewWidget->rootContext()->setContextProperty(fpSettingsControllerProp, this);
}
QQuickWidget *FileProviderSettingsController::settingsViewWidget()
{
if (!_settingsViewWidget) {
instantiateSettingsWidget();
}
return _settingsViewWidget.get();
const auto settingsViewWidget = new QQuickWidget(Systray::instance()->trayEngine(), parent);
settingsViewWidget->setResizeMode(resizeMode);
settingsViewWidget->setSource(QUrl(fpSettingsQmlPath));
settingsViewWidget->rootContext()->setContextProperty(fpSettingsControllerProp, this);
return settingsViewWidget;
}
} // namespace Mac