forked from qt-creator/qt-creator
Remove use of global state from InfoBar
It is initialized by the core plugin anyhow, so give it enough information there to avoid accessing the global state later. Change-Id: I39e7a9f32ef5c7930faf9ba751e75bebf57b507e Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -159,7 +159,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
addObject(m_editMode);
|
||||
ModeManager::activateMode(m_editMode->id());
|
||||
m_designMode = new DesignMode;
|
||||
InfoBar::initializeGloballySuppressed();
|
||||
InfoBar::initialize(ICore::settings(), creatorTheme());
|
||||
}
|
||||
|
||||
IWizardFactory::initialize();
|
||||
|
||||
@@ -25,13 +25,13 @@
|
||||
|
||||
#include "infobar.h"
|
||||
|
||||
#include "icore.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSettings>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
@@ -43,6 +43,8 @@ using namespace Utils;
|
||||
namespace Core {
|
||||
|
||||
QSet<Id> InfoBar::globallySuppressed;
|
||||
QSettings *InfoBar::m_settings = nullptr;
|
||||
Utils::Theme *InfoBar::m_theme = nullptr;
|
||||
|
||||
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression)
|
||||
: id(_id)
|
||||
@@ -147,17 +149,23 @@ void InfoBar::globallyUnsuppressInfo(Id id)
|
||||
writeGloballySuppressedToSettings();
|
||||
}
|
||||
|
||||
void InfoBar::initializeGloballySuppressed()
|
||||
void InfoBar::initialize(QSettings *settings, Theme *theme)
|
||||
{
|
||||
QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||
foreach (const QString &id, list)
|
||||
globallySuppressed.insert(Id::fromString(id));
|
||||
m_settings = settings;
|
||||
m_theme = theme;
|
||||
|
||||
if (QTC_GUARD(m_settings)) {
|
||||
QStringList list = m_settings->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||
foreach (const QString &id, list)
|
||||
globallySuppressed.insert(Id::fromString(id));
|
||||
}
|
||||
}
|
||||
|
||||
void InfoBar::clearGloballySuppressed()
|
||||
{
|
||||
globallySuppressed.clear();
|
||||
ICore::settings()->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
||||
if (m_settings)
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
||||
}
|
||||
|
||||
bool InfoBar::anyGloballySuppressed()
|
||||
@@ -167,10 +175,12 @@ bool InfoBar::anyGloballySuppressed()
|
||||
|
||||
void InfoBar::writeGloballySuppressedToSettings()
|
||||
{
|
||||
if (!m_settings)
|
||||
return;
|
||||
QStringList list;
|
||||
foreach (Id i, globallySuppressed)
|
||||
list << QLatin1String(i.name());
|
||||
ICore::settings()->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
||||
}
|
||||
|
||||
|
||||
@@ -223,8 +233,10 @@ void InfoBarDisplay::update()
|
||||
QFrame *infoWidget = new QFrame;
|
||||
|
||||
QPalette pal;
|
||||
pal.setColor(QPalette::Window, creatorTheme()->color(Theme::InfoBarBackground));
|
||||
pal.setColor(QPalette::WindowText, creatorTheme()->color(Theme::InfoBarText));
|
||||
if (QTC_GUARD(InfoBar::m_theme)) {
|
||||
pal.setColor(QPalette::Window, InfoBar::m_theme->color(Theme::InfoBarBackground));
|
||||
pal.setColor(QPalette::WindowText, InfoBar::m_theme->color(Theme::InfoBarText));
|
||||
}
|
||||
|
||||
infoWidget->setPalette(pal);
|
||||
infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||
|
||||
@@ -35,8 +35,11 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QBoxLayout;
|
||||
class QSettings;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Utils { class Theme; }
|
||||
|
||||
namespace Core {
|
||||
|
||||
class InfoBar;
|
||||
@@ -91,10 +94,11 @@ public:
|
||||
void clear();
|
||||
static void globallySuppressInfo(Id id);
|
||||
static void globallyUnsuppressInfo(Id id);
|
||||
static void initializeGloballySuppressed();
|
||||
static void clearGloballySuppressed();
|
||||
static bool anyGloballySuppressed();
|
||||
|
||||
static void initialize(QSettings *settings, Utils::Theme *theme);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
@@ -104,7 +108,11 @@ private:
|
||||
private:
|
||||
QList<InfoBarEntry> m_infoBarEntries;
|
||||
QSet<Id> m_suppressed;
|
||||
|
||||
static QSet<Id> globallySuppressed;
|
||||
static QSettings *m_settings;
|
||||
static Utils::Theme *m_theme;
|
||||
|
||||
friend class InfoBarDisplay;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user