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);
|
addObject(m_editMode);
|
||||||
ModeManager::activateMode(m_editMode->id());
|
ModeManager::activateMode(m_editMode->id());
|
||||||
m_designMode = new DesignMode;
|
m_designMode = new DesignMode;
|
||||||
InfoBar::initializeGloballySuppressed();
|
InfoBar::initialize(ICore::settings(), creatorTheme());
|
||||||
}
|
}
|
||||||
|
|
||||||
IWizardFactory::initialize();
|
IWizardFactory::initialize();
|
||||||
|
|||||||
@@ -25,13 +25,13 @@
|
|||||||
|
|
||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
|
|
||||||
#include "icore.h"
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QSettings>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@@ -43,6 +43,8 @@ using namespace Utils;
|
|||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
QSet<Id> InfoBar::globallySuppressed;
|
QSet<Id> InfoBar::globallySuppressed;
|
||||||
|
QSettings *InfoBar::m_settings = nullptr;
|
||||||
|
Utils::Theme *InfoBar::m_theme = nullptr;
|
||||||
|
|
||||||
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression)
|
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression)
|
||||||
: id(_id)
|
: id(_id)
|
||||||
@@ -147,17 +149,23 @@ void InfoBar::globallyUnsuppressInfo(Id id)
|
|||||||
writeGloballySuppressedToSettings();
|
writeGloballySuppressedToSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBar::initializeGloballySuppressed()
|
void InfoBar::initialize(QSettings *settings, Theme *theme)
|
||||||
{
|
{
|
||||||
QStringList list = ICore::settings()->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
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)
|
foreach (const QString &id, list)
|
||||||
globallySuppressed.insert(Id::fromString(id));
|
globallySuppressed.insert(Id::fromString(id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfoBar::clearGloballySuppressed()
|
void InfoBar::clearGloballySuppressed()
|
||||||
{
|
{
|
||||||
globallySuppressed.clear();
|
globallySuppressed.clear();
|
||||||
ICore::settings()->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
if (m_settings)
|
||||||
|
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), QStringList());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InfoBar::anyGloballySuppressed()
|
bool InfoBar::anyGloballySuppressed()
|
||||||
@@ -167,10 +175,12 @@ bool InfoBar::anyGloballySuppressed()
|
|||||||
|
|
||||||
void InfoBar::writeGloballySuppressedToSettings()
|
void InfoBar::writeGloballySuppressedToSettings()
|
||||||
{
|
{
|
||||||
|
if (!m_settings)
|
||||||
|
return;
|
||||||
QStringList list;
|
QStringList list;
|
||||||
foreach (Id i, globallySuppressed)
|
foreach (Id i, globallySuppressed)
|
||||||
list << QLatin1String(i.name());
|
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;
|
QFrame *infoWidget = new QFrame;
|
||||||
|
|
||||||
QPalette pal;
|
QPalette pal;
|
||||||
pal.setColor(QPalette::Window, creatorTheme()->color(Theme::InfoBarBackground));
|
if (QTC_GUARD(InfoBar::m_theme)) {
|
||||||
pal.setColor(QPalette::WindowText, creatorTheme()->color(Theme::InfoBarText));
|
pal.setColor(QPalette::Window, InfoBar::m_theme->color(Theme::InfoBarBackground));
|
||||||
|
pal.setColor(QPalette::WindowText, InfoBar::m_theme->color(Theme::InfoBarText));
|
||||||
|
}
|
||||||
|
|
||||||
infoWidget->setPalette(pal);
|
infoWidget->setPalette(pal);
|
||||||
infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
|
infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
|
||||||
|
|||||||
@@ -35,8 +35,11 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QBoxLayout;
|
class QBoxLayout;
|
||||||
|
class QSettings;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
namespace Utils { class Theme; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class InfoBar;
|
class InfoBar;
|
||||||
@@ -91,10 +94,11 @@ public:
|
|||||||
void clear();
|
void clear();
|
||||||
static void globallySuppressInfo(Id id);
|
static void globallySuppressInfo(Id id);
|
||||||
static void globallyUnsuppressInfo(Id id);
|
static void globallyUnsuppressInfo(Id id);
|
||||||
static void initializeGloballySuppressed();
|
|
||||||
static void clearGloballySuppressed();
|
static void clearGloballySuppressed();
|
||||||
static bool anyGloballySuppressed();
|
static bool anyGloballySuppressed();
|
||||||
|
|
||||||
|
static void initialize(QSettings *settings, Utils::Theme *theme);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
@@ -104,7 +108,11 @@ private:
|
|||||||
private:
|
private:
|
||||||
QList<InfoBarEntry> m_infoBarEntries;
|
QList<InfoBarEntry> m_infoBarEntries;
|
||||||
QSet<Id> m_suppressed;
|
QSet<Id> m_suppressed;
|
||||||
|
|
||||||
static QSet<Id> globallySuppressed;
|
static QSet<Id> globallySuppressed;
|
||||||
|
static QSettings *m_settings;
|
||||||
|
static Utils::Theme *m_theme;
|
||||||
|
|
||||||
friend class InfoBarDisplay;
|
friend class InfoBarDisplay;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user