Utils: Add AspectList::createAndAddItem

Adds a function to add a "default" constructed new item to the list.

Change-Id: I3d826b6f3e3705ae431efa5d778219f431509ea8
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-10-09 15:14:59 +02:00
parent d021f9158b
commit 4aef48de5e
6 changed files with 14 additions and 20 deletions

View File

@@ -3127,6 +3127,11 @@ QList<std::shared_ptr<BaseAspect>> AspectList::volatileItems() const
return d->volatileItems; return d->volatileItems;
} }
std::shared_ptr<BaseAspect> AspectList::createAndAddItem()
{
return addItem(d->createItem());
}
std::shared_ptr<BaseAspect> AspectList::addItem(const std::shared_ptr<BaseAspect> &item) std::shared_ptr<BaseAspect> AspectList::addItem(const std::shared_ptr<BaseAspect> &item)
{ {
if (undoStack()) if (undoStack())

View File

@@ -1026,6 +1026,7 @@ public:
QList<std::shared_ptr<BaseAspect>> items() const; QList<std::shared_ptr<BaseAspect>> items() const;
QList<std::shared_ptr<BaseAspect>> volatileItems() const; QList<std::shared_ptr<BaseAspect>> volatileItems() const;
std::shared_ptr<BaseAspect> createAndAddItem();
std::shared_ptr<BaseAspect> addItem(const std::shared_ptr<BaseAspect> &item); std::shared_ptr<BaseAspect> addItem(const std::shared_ptr<BaseAspect> &item);
std::shared_ptr<BaseAspect> actualAddItem(const std::shared_ptr<BaseAspect> &item); std::shared_ptr<BaseAspect> actualAddItem(const std::shared_ptr<BaseAspect> &item);

View File

@@ -216,7 +216,10 @@ SourceEditorWidget::SourceEditorWidget(const std::shared_ptr<SourceSettings> &se
auto addCompilerButton = new QPushButton; auto addCompilerButton = new QPushButton;
addCompilerButton->setText(Tr::tr("Add compiler")); addCompilerButton->setText(Tr::tr("Add compiler"));
connect(addCompilerButton, &QPushButton::clicked, this, &SourceEditorWidget::addCompiler); connect(addCompilerButton,
&QPushButton::clicked,
&settings->compilers,
&AspectList::createAndAddItem);
auto removeSourceButton = new QPushButton; auto removeSourceButton = new QPushButton;
removeSourceButton->setIcon(Utils::Icons::EDIT_CLEAR.icon()); removeSourceButton->setIcon(Utils::Icons::EDIT_CLEAR.icon());
@@ -575,12 +578,6 @@ void EditorWidget::addSourceEditor(const std::shared_ptr<SourceSettings> &source
setupHelpWidget(); setupHelpWidget();
}); });
connect(sourceEditor, &SourceEditorWidget::addCompiler, this, [sourceSettings]() {
auto newCompiler = std::make_shared<CompilerSettings>(sourceSettings->apiConfigFunction());
newCompiler->setLanguageId(sourceSettings->languageId());
sourceSettings->compilers.addItem(newCompiler);
});
connect(sourceEditor, &SourceEditorWidget::gotFocus, this, [this]() { connect(sourceEditor, &SourceEditorWidget::gotFocus, this, [this]() {
m_actionHandler.updateCurrentEditor(); m_actionHandler.updateCurrentEditor();
}); });
@@ -725,8 +722,8 @@ QWidget *EditorWidget::createHelpWidget() const
auto w = new HelperWidget; auto w = new HelperWidget;
connect(w, connect(w,
&HelperWidget::addSource, &HelperWidget::addSource,
m_document->settings(), &m_document->settings()->m_sources,
&CompilerExplorerSettings::addNewSource); &AspectList::createAndAddItem);
return w; return w;
} }
@@ -792,8 +789,8 @@ QWidget *Editor::toolBar()
connect(newSource, connect(newSource,
&QAction::triggered, &QAction::triggered,
m_document->settings(), &m_document->settings()->m_sources,
&CompilerExplorerSettings::addNewSource); &AspectList::createAndAddItem);
} }
return m_toolBar.get(); return m_toolBar.get();

View File

@@ -130,7 +130,6 @@ public:
signals: signals:
void sourceCodeChanged(); void sourceCodeChanged();
void addCompiler();
void remove(); void remove();
void gotFocus(); void gotFocus();

View File

@@ -337,10 +337,4 @@ CompilerExplorerSettings::CompilerExplorerSettings()
CompilerExplorerSettings::~CompilerExplorerSettings() = default; CompilerExplorerSettings::~CompilerExplorerSettings() = default;
void CompilerExplorerSettings::addNewSource()
{
auto newSource = std::make_shared<SourceSettings>([this] { return apiConfig(); });
m_sources.addItem(newSource);
}
} // namespace CompilerExplorer } // namespace CompilerExplorer

View File

@@ -41,8 +41,6 @@ public:
return Api::Config(m_networkAccessManager, compilerExplorerUrl()); return Api::Config(m_networkAccessManager, compilerExplorerUrl());
} }
void addNewSource();
QNetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; } QNetworkAccessManager *networkAccessManager() const { return m_networkAccessManager; }
private: private: