Haskell: Use IOptionPage::setWidgetCreator() for settings

Change-Id: I4565cfca2bc58fd78e4c35fa1abda43532c113b6
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2023-04-20 10:53:02 +02:00
parent 69d53245f2
commit 214742e943
2 changed files with 28 additions and 46 deletions

View File

@@ -7,31 +7,24 @@
#include "haskellmanager.h"
#include "haskelltr.h"
#include <utils/pathchooser.h>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
namespace Haskell {
namespace Internal {
OptionsPage::OptionsPage()
{
setId(Constants::OPTIONS_GENERAL);
setDisplayName(Tr::tr("General"));
setCategory("J.Z.Haskell");
setDisplayCategory(Tr::tr("Haskell"));
setCategoryIconPath(":/haskell/images/settingscategory_haskell.png");
}
QWidget *OptionsPage::widget()
{
using namespace Utils;
if (!m_widget) {
m_widget = new QWidget;
namespace Haskell::Internal {
class HaskellOptionsPageWidget : public Core::IOptionsPageWidget
{
public:
HaskellOptionsPageWidget()
{
auto topLayout = new QVBoxLayout;
m_widget->setLayout(topLayout);
setLayout(topLayout);
auto generalBox = new QGroupBox(Tr::tr("General"));
topLayout->addWidget(generalBox);
topLayout->addStretch(10);
@@ -45,19 +38,23 @@ QWidget *OptionsPage::widget()
m_stackPath->setCommandVersionArguments({"--version"});
boxLayout->addWidget(m_stackPath);
}
return m_widget;
}
void OptionsPage::apply()
void apply() final
{
if (!m_widget)
return;
HaskellManager::setStackExecutable(m_stackPath->rawFilePath());
}
void OptionsPage::finish()
QPointer<Utils::PathChooser> m_stackPath;
};
OptionsPage::OptionsPage()
{
setId(Constants::OPTIONS_GENERAL);
setDisplayName(Tr::tr("General"));
setCategory("J.Z.Haskell");
setDisplayCategory(Tr::tr("Haskell"));
setCategoryIconPath(":/haskell/images/settingscategory_haskell.png");
setWidgetCreator([] { return new HaskellOptionsPageWidget; });
}
} // namespace Internal
} // namespace Haskell
} // Haskell::Internal

View File

@@ -4,28 +4,13 @@
#pragma once
#include <coreplugin/dialogs/ioptionspage.h>
#include <utils/pathchooser.h>
#include <QPointer>
namespace Haskell {
namespace Internal {
namespace Haskell::Internal {
class OptionsPage : public Core::IOptionsPage
{
Q_OBJECT
public:
OptionsPage();
QWidget *widget() override;
void apply() override;
void finish() override;
private:
QPointer<QWidget> m_widget;
QPointer<Utils::PathChooser> m_stackPath;
};
} // namespace Internal
} // namespace Haskell
} // Haskell::Internal