FakeVim: Use IOptionPage::setWidgetCreator() for user command settings

Change-Id: Ic5d895634cb5ef1b2e1a6fa465cd800a213a7d41
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2023-04-21 13:49:37 +02:00
parent daf1b29b2d
commit d13d48a281

View File

@@ -862,56 +862,29 @@ public:
}
};
class FakeVimUserCommandsPage : public IOptionsPage
class FakeVimUserCommandsPageWidget : public IOptionsPageWidget
{
public:
FakeVimUserCommandsPage()
FakeVimUserCommandsPageWidget(FakeVimUserCommandsModel *model)
: m_model(model)
{
setId(SETTINGS_USER_CMDS_ID);
setDisplayName(Tr::tr("User Command Mapping"));
setCategory(SETTINGS_CATEGORY);
}
void apply() override;
void finish() override {}
QWidget *widget() override;
void initialize() {}
UserCommandMap currentCommandMap() { return m_model->commandMap(); }
private:
QPointer<QWidget> m_widget;
FakeVimUserCommandsModel *m_model = nullptr;
};
QWidget *FakeVimUserCommandsPage::widget()
{
if (!m_widget) {
m_widget = new QWidget;
m_model = new FakeVimUserCommandsModel;
auto widget = new QTreeView;
m_model->setParent(widget);
widget->setModel(m_model);
widget->resizeColumnToContents(0);
auto delegate = new FakeVimUserCommandsDelegate(widget);
widget->setItemDelegateForColumn(1, delegate);
auto layout = new QGridLayout(m_widget);
auto layout = new QGridLayout(this);
layout->addWidget(widget, 0, 0);
m_widget->setLayout(layout);
setLayout(layout);
}
return m_widget;
}
void FakeVimUserCommandsPage::apply()
{
if (!m_widget) // page has not been shown at all
return;
private:
void apply() final
{
// now save the mappings if necessary
const UserCommandMap &current = currentCommandMap();
const UserCommandMap &current = m_model->commandMap();
UserCommandMap &userMap = dd->m_userCommandMap;
if (current != userMap) {
@@ -938,7 +911,25 @@ void FakeVimUserCommandsPage::apply()
userMap.insert(dd->m_defaultUserCommandMap);
userMap.insert(current);
}
}
}
FakeVimUserCommandsModel *m_model;
};
class FakeVimUserCommandsPage : public IOptionsPage
{
public:
FakeVimUserCommandsPage()
{
setId(SETTINGS_USER_CMDS_ID);
setDisplayName(Tr::tr("User Command Mapping"));
setCategory(SETTINGS_CATEGORY);
setWidgetCreator([this] { return new FakeVimUserCommandsPageWidget(&m_model); });
}
private:
FakeVimUserCommandsModel m_model;
};
///////////////////////////////////////////////////////////////////////