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 "haskellmanager.h"
#include "haskelltr.h" #include "haskelltr.h"
#include <utils/pathchooser.h>
#include <QGroupBox> #include <QGroupBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget>
namespace Haskell { using namespace Utils;
namespace Internal {
OptionsPage::OptionsPage() namespace Haskell::Internal {
class HaskellOptionsPageWidget : public Core::IOptionsPageWidget
{ {
setId(Constants::OPTIONS_GENERAL); public:
setDisplayName(Tr::tr("General")); HaskellOptionsPageWidget()
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;
auto topLayout = new QVBoxLayout; auto topLayout = new QVBoxLayout;
m_widget->setLayout(topLayout); setLayout(topLayout);
auto generalBox = new QGroupBox(Tr::tr("General")); auto generalBox = new QGroupBox(Tr::tr("General"));
topLayout->addWidget(generalBox); topLayout->addWidget(generalBox);
topLayout->addStretch(10); topLayout->addStretch(10);
@@ -45,19 +38,23 @@ QWidget *OptionsPage::widget()
m_stackPath->setCommandVersionArguments({"--version"}); m_stackPath->setCommandVersionArguments({"--version"});
boxLayout->addWidget(m_stackPath); boxLayout->addWidget(m_stackPath);
} }
return m_widget;
}
void OptionsPage::apply() void apply() final
{ {
if (!m_widget)
return;
HaskellManager::setStackExecutable(m_stackPath->rawFilePath()); 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 } // Haskell::Internal
} // namespace Haskell

View File

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