forked from qt-creator/qt-creator
Utils: Introduce a way to immediate force aspect value saving
Will be used for e.g. valgrinds error categories. These are handled by actions in a menu outside the settings page mechanism. Change-Id: I2dea9b9f13dbc92fa3e9938f85aa083d01d0d99b Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -412,6 +412,22 @@ void BaseAspect::setSettingsKey(const QString &group, const QString &key)
|
|||||||
d->m_settingsKey = group + "/" + key;
|
d->m_settingsKey = group + "/" + key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Immediately writes the value of this aspect into its specified
|
||||||
|
settings, taking a potential container's settings group specification
|
||||||
|
into account.
|
||||||
|
|
||||||
|
\note This is expensive, so it should only be used with good reason.
|
||||||
|
*/
|
||||||
|
void BaseAspect::writeToSettingsImmediatly() const
|
||||||
|
{
|
||||||
|
QStringList groups;
|
||||||
|
if (d->m_container)
|
||||||
|
groups = d->m_container->settingsGroups();
|
||||||
|
const SettingsGroupNester nester(groups);
|
||||||
|
writeSettings();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the string that should be used when this action appears in menus
|
Returns the string that should be used when this action appears in menus
|
||||||
or other places that are typically used with Book style capitalization.
|
or other places that are typically used with Book style capitalization.
|
||||||
@@ -2344,28 +2360,16 @@ void AspectContainer::toMap(QVariantMap &map) const
|
|||||||
|
|
||||||
void AspectContainer::readSettings()
|
void AspectContainer::readSettings()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(theSettings, return);
|
const SettingsGroupNester nester(d->m_settingsGroup);
|
||||||
for (const QString &group : d->m_settingsGroup)
|
|
||||||
theSettings->beginGroup(group);
|
|
||||||
|
|
||||||
for (BaseAspect *aspect : std::as_const(d->m_items))
|
for (BaseAspect *aspect : std::as_const(d->m_items))
|
||||||
aspect->readSettings();
|
aspect->readSettings();
|
||||||
|
|
||||||
for (int i = 0; i != d->m_settingsGroup.size(); ++i)
|
|
||||||
theSettings->endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::writeSettings() const
|
void AspectContainer::writeSettings() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(theSettings, return);
|
const SettingsGroupNester nester(d->m_settingsGroup);
|
||||||
for (const QString &group : d->m_settingsGroup)
|
|
||||||
theSettings->beginGroup(group);
|
|
||||||
|
|
||||||
for (BaseAspect *aspect : std::as_const(d->m_items))
|
for (BaseAspect *aspect : std::as_const(d->m_items))
|
||||||
aspect->writeSettings();
|
aspect->writeSettings();
|
||||||
|
|
||||||
for (int i = 0; i != d->m_settingsGroup.size(); ++i)
|
|
||||||
theSettings->endGroup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::setSettingsGroup(const QString &groupKey)
|
void AspectContainer::setSettingsGroup(const QString &groupKey)
|
||||||
@@ -2378,6 +2382,11 @@ void AspectContainer::setSettingsGroups(const QString &groupKey, const QString &
|
|||||||
d->m_settingsGroup = QStringList{groupKey, subGroupKey};
|
d->m_settingsGroup = QStringList{groupKey, subGroupKey};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList AspectContainer::settingsGroups() const
|
||||||
|
{
|
||||||
|
return d->m_settingsGroup;
|
||||||
|
}
|
||||||
|
|
||||||
void AspectContainer::apply()
|
void AspectContainer::apply()
|
||||||
{
|
{
|
||||||
const bool willChange = isDirty();
|
const bool willChange = isDirty();
|
||||||
@@ -2579,4 +2588,22 @@ void BaseAspect::Data::Ptr::operator=(const Ptr &other)
|
|||||||
m_data = other.m_data->clone();
|
m_data = other.m_data->clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SettingsGroupNester
|
||||||
|
|
||||||
|
SettingsGroupNester::SettingsGroupNester(const QStringList &groups)
|
||||||
|
: m_groupCount(groups.size())
|
||||||
|
{
|
||||||
|
QTC_ASSERT(theSettings, return);
|
||||||
|
for (const QString &group : groups)
|
||||||
|
theSettings->beginGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsGroupNester::~SettingsGroupNester()
|
||||||
|
{
|
||||||
|
QTC_ASSERT(theSettings, return);
|
||||||
|
for (int i = 0; i != m_groupCount; ++i)
|
||||||
|
theSettings->endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@@ -165,6 +165,9 @@ public:
|
|||||||
static void setSettings(QSettings *settings);
|
static void setSettings(QSettings *settings);
|
||||||
static QSettings *settings();
|
static QSettings *settings();
|
||||||
|
|
||||||
|
// This is expensive. Do not use without good reason
|
||||||
|
void writeToSettingsImmediatly() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(); // "internal"
|
void changed(); // "internal"
|
||||||
void volatileValueChanged();
|
void volatileValueChanged();
|
||||||
@@ -728,6 +731,18 @@ private:
|
|||||||
QList<BaseAspect::Data::Ptr> m_data; // Owned.
|
QList<BaseAspect::Data::Ptr> m_data; // Owned.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class QTCREATOR_UTILS_EXPORT SettingsGroupNester
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY_MOVE(SettingsGroupNester)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SettingsGroupNester(const QStringList &groups);
|
||||||
|
~SettingsGroupNester();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int m_groupCount;
|
||||||
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AspectContainer : public QObject
|
class QTCREATOR_UTILS_EXPORT AspectContainer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -758,6 +773,7 @@ public:
|
|||||||
|
|
||||||
void setSettingsGroup(const QString &groupKey);
|
void setSettingsGroup(const QString &groupKey);
|
||||||
void setSettingsGroups(const QString &groupKey, const QString &subGroupKey);
|
void setSettingsGroups(const QString &groupKey, const QString &subGroupKey);
|
||||||
|
QStringList settingsGroups() const;
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
void cancel();
|
void cancel();
|
||||||
|
Reference in New Issue
Block a user