MinimizableInfoBars: Remove dependency on CppToolsSettings

They were only used in the info bars, so move them there.

Change-Id: I584c98c70d1db2a5b741842da9d629469f0de73c
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Eike Ziller
2022-05-03 11:01:24 +02:00
parent 5790905d6e
commit 2d6a36742b
6 changed files with 52 additions and 45 deletions

View File

@@ -99,7 +99,6 @@ const char CPPEDITOR_SETTINGSGROUP[] = "CppTools";
const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles"; const char LOWERCASE_CPPFILES_KEY[] = "LowerCaseFiles";
const bool LOWERCASE_CPPFILES_DEFAULT = true; const bool LOWERCASE_CPPFILES_DEFAULT = true;
const char CPPEDITOR_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview"; const char CPPEDITOR_SORT_EDITOR_DOCUMENT_OUTLINE[] = "SortedMethodOverview";
const char CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT[] = "ShowInfoBarForNoProject";
const char CPPEDITOR_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage"; const char CPPEDITOR_MODEL_MANAGER_PCH_USAGE[] = "PCHUsage";
const char CPPEDITOR_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS[] const char CPPEDITOR_INTERPRET_AMBIGIUOUS_HEADERS_AS_C_HEADERS[]
= "InterpretAmbiguousHeadersAsCHeaders"; = "InterpretAmbiguousHeadersAsCHeaders";

View File

@@ -128,6 +128,8 @@ CppEditorDocument::CppEditorDocument()
connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged, connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged,
this, &CppEditorDocument::reparseWithPreferredParseContext); this, &CppEditorDocument::reparseWithPreferredParseContext);
m_minimizableInfoBars.setSettingsGroup(Constants::CPPEDITOR_SETTINGSGROUP);
// See also onFilePathChanged() for more initialization // See also onFilePathChanged() for more initialization
} }

View File

@@ -25,42 +25,50 @@
#include "cppminimizableinfobars.h" #include "cppminimizableinfobars.h"
#include "cpptoolssettings.h"
#include <QToolButton> #include <QToolButton>
#include <coreplugin/icore.h>
#include <utils/infobar.h> #include <utils/infobar.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
const char NO_PROJECT_CONFIGURATION[] = "CppEditor.NoProjectConfiguration"; const char NO_PROJECT_CONFIGURATION[] = "CppEditor.NoProjectConfiguration";
const char CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT[] = "ShowInfoBarForNoProject";
const bool kShowInInfoBarDefault = true;
using namespace Core;
using namespace Utils; using namespace Utils;
namespace CppEditor { namespace CppEditor {
namespace Internal { namespace Internal {
static CppToolsSettings *settings() { return CppToolsSettings::instance(); } MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar)
: m_infoBar(infoBar)
MinimizableInfoBars::MinimizableInfoBars(InfoBar &infoBar, QObject *parent)
: QObject(parent)
, m_infoBar(infoBar)
{ {
connect(settings(), &CppToolsSettings::showNoProjectInfoBarChanged,
this, &MinimizableInfoBars::updateNoProjectConfiguration);
createActions(); createActions();
} }
void MinimizableInfoBars::setSettingsGroup(const QString &settingsGroup)
{
m_settingsGroup = settingsGroup;
}
void MinimizableInfoBars::createActions() void MinimizableInfoBars::createActions()
{ {
auto action = new QAction(this); auto action = new QAction(this);
action->setToolTip(tr("File is not part of any project.")); action->setToolTip(tr("File is not part of any project."));
action->setIcon(Icons::WARNING_TOOLBAR.pixmap()); action->setIcon(Icons::WARNING_TOOLBAR.pixmap());
connect(action, &QAction::triggered, []() { settings()->setShowNoProjectInfoBar(true); }); connect(action, &QAction::triggered, this, [this]() { setShowNoProjectInfoBar(true); });
action->setVisible(!settings()->showNoProjectInfoBar()); action->setVisible(!showNoProjectInfoBar());
m_actions.insert(NO_PROJECT_CONFIGURATION, action); m_actions.insert(NO_PROJECT_CONFIGURATION, action);
} }
QString MinimizableInfoBars::settingsKey(const QString &id) const
{
QTC_CHECK(!m_settingsGroup.isEmpty());
return m_settingsGroup + '/' + id;
}
void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const void MinimizableInfoBars::createShowInfoBarActions(const ActionCreator &actionCreator) const
{ {
QTC_ASSERT(actionCreator, return ); QTC_ASSERT(actionCreator, return );
@@ -89,7 +97,7 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
bool show = false; bool show = false;
if (!m_hasProjectPart) { if (!m_hasProjectPart) {
if (settings()->showNoProjectInfoBar()) if (showNoProjectInfoBar())
addNoProjectConfigurationEntry(id); addNoProjectConfigurationEntry(id);
else else
show = true; show = true;
@@ -102,6 +110,7 @@ void MinimizableInfoBars::updateNoProjectConfiguration()
static InfoBarEntry createMinimizableInfo(const Id &id, static InfoBarEntry createMinimizableInfo(const Id &id,
const QString &text, const QString &text,
QObject *guard,
std::function<void()> minimizer) std::function<void()> minimizer)
{ {
QTC_CHECK(minimizer); QTC_CHECK(minimizer);
@@ -111,8 +120,9 @@ static InfoBarEntry createMinimizableInfo(const Id &id,
// The minimizer() might delete the "Minimize" button immediately and as // The minimizer() might delete the "Minimize" button immediately and as
// result invalid reads will happen in QToolButton::mouseReleaseEvent(). // result invalid reads will happen in QToolButton::mouseReleaseEvent().
// Avoid this by running the minimizer in the next event loop iteration. // Avoid this by running the minimizer in the next event loop iteration.
info.addCustomButton(MinimizableInfoBars::tr("Minimize"), [minimizer] { info.addCustomButton(MinimizableInfoBars::tr("Minimize"), [guard, minimizer] {
QMetaObject::invokeMethod(settings(), [minimizer] { minimizer(); }, Qt::QueuedConnection); QMetaObject::invokeMethod(
guard, [minimizer] { minimizer(); }, Qt::QueuedConnection);
}); });
return info; return info;
@@ -123,9 +133,23 @@ void MinimizableInfoBars::addNoProjectConfigurationEntry(const Id &id)
const QString text = tr("<b>Warning</b>: This file is not part of any project. " const QString text = tr("<b>Warning</b>: This file is not part of any project. "
"The code model might have issues parsing this file properly."); "The code model might have issues parsing this file properly.");
m_infoBar.addInfo(createMinimizableInfo(id, text, []() { m_infoBar.addInfo(
settings()->setShowNoProjectInfoBar(false); createMinimizableInfo(id, text, this, [this]() { setShowNoProjectInfoBar(false); }));
})); }
bool MinimizableInfoBars::showNoProjectInfoBar() const
{
return ICore::settings()
->value(settingsKey(CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT), kShowInInfoBarDefault)
.toBool();
}
void MinimizableInfoBars::setShowNoProjectInfoBar(bool show)
{
ICore::settings()->setValueWithDefault(settingsKey(CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT),
show,
kShowInInfoBarDefault);
updateNoProjectConfiguration();
} }
} // namespace Internal } // namespace Internal

View File

@@ -48,8 +48,9 @@ public:
using ActionCreator = std::function<QAction *(QWidget *widget)>; using ActionCreator = std::function<QAction *(QWidget *widget)>;
public: public:
explicit MinimizableInfoBars(Utils::InfoBar &infoBar, QObject *parent = nullptr); explicit MinimizableInfoBars(Utils::InfoBar &infoBar);
void setSettingsGroup(const QString &settingsGroup);
void createShowInfoBarActions(const ActionCreator &actionCreator) const; void createShowInfoBarActions(const ActionCreator &actionCreator) const;
void processHasProjectPart(bool hasProjectPart); void processHasProjectPart(bool hasProjectPart);
@@ -57,12 +58,19 @@ public:
private: private:
void createActions(); void createActions();
QString settingsKey(const QString &id) const;
bool showHeaderErrorInfoBar() const;
void setShowHeaderErrorInfoBar(bool show);
bool showNoProjectInfoBar() const;
void setShowNoProjectInfoBar(bool show);
void updateNoProjectConfiguration(); void updateNoProjectConfiguration();
void addNoProjectConfigurationEntry(const Utils::Id &id); void addNoProjectConfigurationEntry(const Utils::Id &id);
private: private:
Utils::InfoBar &m_infoBar; Utils::InfoBar &m_infoBar;
QString m_settingsGroup;
QHash<Utils::Id, QAction *> m_actions; QHash<Utils::Id, QAction *> m_actions;
bool m_hasProjectPart = true; bool m_hasProjectPart = true;

View File

@@ -44,7 +44,6 @@
static const char idKey[] = "CppGlobal"; static const char idKey[] = "CppGlobal";
const bool kSortEditorDocumentOutlineDefault = true; const bool kSortEditorDocumentOutlineDefault = true;
const bool kShowNoProjectInfoBarDefault = true;
using namespace Core; using namespace Core;
using namespace TextEditor; using namespace TextEditor;
@@ -264,24 +263,4 @@ void CppToolsSettings::setSortedEditorDocumentOutline(bool sorted)
emit editorDocumentOutlineSortingChanged(sorted); emit editorDocumentOutlineSortingChanged(sorted);
} }
static QString showNoProjectInfoBarKey()
{
return QLatin1String(Constants::CPPEDITOR_SETTINGSGROUP)
+ QLatin1Char('/')
+ QLatin1String(Constants::CPPEDITOR_SHOW_INFO_BAR_FOR_FOR_NO_PROJECT);
}
bool CppToolsSettings::showNoProjectInfoBar() const
{
return ICore::settings()->value(showNoProjectInfoBarKey(), kShowNoProjectInfoBarDefault).toBool();
}
void CppToolsSettings::setShowNoProjectInfoBar(bool show)
{
ICore::settings()->setValueWithDefault(showNoProjectInfoBarKey(),
show,
kShowNoProjectInfoBarDefault);
emit showNoProjectInfoBarChanged(show);
}
} // namespace CppEditor } // namespace CppEditor

View File

@@ -58,13 +58,8 @@ public:
bool sortedEditorDocumentOutline() const; bool sortedEditorDocumentOutline() const;
void setSortedEditorDocumentOutline(bool sorted); void setSortedEditorDocumentOutline(bool sorted);
bool showNoProjectInfoBar() const;
void setShowNoProjectInfoBar(bool show);
signals: signals:
void editorDocumentOutlineSortingChanged(bool isSorted); void editorDocumentOutlineSortingChanged(bool isSorted);
void showHeaderErrorInfoBarChanged(bool isShown);
void showNoProjectInfoBarChanged(bool isShown);
private: private:
Internal::CppToolsSettingsPrivate *d; Internal::CppToolsSettingsPrivate *d;