forked from qt-creator/qt-creator
Modernize InfoBar code
Use more algorithms, use range based loops where needed Change-Id: I1fec57df18d93c86242e3ba7f8108f77c7e7112f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
|
|
||||||
|
#include <utils/algorithm.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
@@ -92,23 +93,15 @@ void InfoBar::addInfo(const InfoBarEntry &info)
|
|||||||
|
|
||||||
void InfoBar::removeInfo(Id id)
|
void InfoBar::removeInfo(Id id)
|
||||||
{
|
{
|
||||||
QMutableListIterator<InfoBarEntry> it(m_infoBarEntries);
|
const int size = m_infoBarEntries.size();
|
||||||
while (it.hasNext())
|
Utils::erase(m_infoBarEntries, Utils::equal(&InfoBarEntry::id, id));
|
||||||
if (it.next().id == id) {
|
if (size != m_infoBarEntries.size())
|
||||||
it.remove();
|
emit changed();
|
||||||
emit changed();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InfoBar::containsInfo(Id id) const
|
bool InfoBar::containsInfo(Id id) const
|
||||||
{
|
{
|
||||||
QListIterator<InfoBarEntry> it(m_infoBarEntries);
|
return Utils::anyOf(m_infoBarEntries, Utils::equal(&InfoBarEntry::id, id));
|
||||||
while (it.hasNext())
|
|
||||||
if (it.next().id == id)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove and suppress id
|
// Remove and suppress id
|
||||||
@@ -155,9 +148,8 @@ void InfoBar::initialize(QSettings *settings, Theme *theme)
|
|||||||
m_theme = theme;
|
m_theme = theme;
|
||||||
|
|
||||||
if (QTC_GUARD(m_settings)) {
|
if (QTC_GUARD(m_settings)) {
|
||||||
QStringList list = m_settings->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
const QStringList list = m_settings->value(QLatin1String(C_SUPPRESSED_WARNINGS)).toStringList();
|
||||||
foreach (const QString &id, list)
|
globallySuppressed = Utils::transform<QSet>(list, Id::fromString);
|
||||||
globallySuppressed.insert(Id::fromString(id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,9 +169,7 @@ void InfoBar::writeGloballySuppressedToSettings()
|
|||||||
{
|
{
|
||||||
if (!m_settings)
|
if (!m_settings)
|
||||||
return;
|
return;
|
||||||
QStringList list;
|
const QStringList list = Utils::transform<QList>(globallySuppressed, &Id::toString);
|
||||||
foreach (Id i, globallySuppressed)
|
|
||||||
list << QLatin1String(i.name());
|
|
||||||
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
m_settings->setValue(QLatin1String(C_SUPPRESSED_WARNINGS), list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +210,7 @@ void InfoBarDisplay::infoBarDestroyed()
|
|||||||
|
|
||||||
void InfoBarDisplay::update()
|
void InfoBarDisplay::update()
|
||||||
{
|
{
|
||||||
foreach (QWidget *widget, m_infoWidgets) {
|
for (QWidget *widget : m_infoWidgets) {
|
||||||
widget->disconnect(this); // We want no destroyed() signal now
|
widget->disconnect(this); // We want no destroyed() signal now
|
||||||
delete widget;
|
delete widget;
|
||||||
}
|
}
|
||||||
@@ -229,7 +219,7 @@ void InfoBarDisplay::update()
|
|||||||
if (!m_infoBar)
|
if (!m_infoBar)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (const InfoBarEntry &info, m_infoBar->m_infoBarEntries) {
|
for (const InfoBarEntry &info : m_infoBar->m_infoBarEntries) {
|
||||||
QFrame *infoWidget = new QFrame;
|
QFrame *infoWidget = new QFrame;
|
||||||
|
|
||||||
QPalette pal;
|
QPalette pal;
|
||||||
|
|||||||
Reference in New Issue
Block a user