forked from qt-creator/qt-creator
Editor: Simplify Format handling.
Use setter instead of getter with references. Increases the readability and is closer to the common codestyle across creator. Change-Id: I3cbbd1154524da73383fbf28470ef64ebe5bc336 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -125,16 +125,10 @@ bool FontSettings::fromSettings(const QString &category,
|
|||||||
const TextStyle id = desc.id();
|
const TextStyle id = desc.id();
|
||||||
const QString fmt = s->value(group + QLatin1String(Constants::nameForStyle(id)), QString()).toString();
|
const QString fmt = s->value(group + QLatin1String(Constants::nameForStyle(id)), QString()).toString();
|
||||||
Format format;
|
Format format;
|
||||||
if (fmt.isEmpty()) {
|
if (!fmt.isEmpty())
|
||||||
format.setForeground(desc.foreground());
|
|
||||||
format.setBackground(desc.background());
|
|
||||||
format.setBold(desc.format().bold());
|
|
||||||
format.setItalic(desc.format().italic());
|
|
||||||
format.setUnderlineColor(desc.format().underlineColor());
|
|
||||||
format.setUnderlineStyle(desc.format().underlineStyle());
|
|
||||||
} else {
|
|
||||||
format.fromString(fmt);
|
format.fromString(fmt);
|
||||||
}
|
else
|
||||||
|
format = desc.format();
|
||||||
m_scheme.setFormatFor(id, format);
|
m_scheme.setFormatFor(id, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,15 +268,14 @@ void FontSettings::setAntialias(bool antialias)
|
|||||||
/**
|
/**
|
||||||
* Returns the format for the given font category.
|
* Returns the format for the given font category.
|
||||||
*/
|
*/
|
||||||
Format &FontSettings::formatFor(TextStyle category)
|
Format FontSettings::formatFor(TextStyle category) const
|
||||||
|
|
||||||
{
|
{
|
||||||
return m_scheme.formatFor(category);
|
return m_scheme.formatFor(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
Format FontSettings::formatFor(TextStyle category) const
|
void FontSettings::setFormatFor(TextStyle category, const Format &format)
|
||||||
{
|
{
|
||||||
return m_scheme.formatFor(category);
|
m_scheme.setFormatFor(category, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -319,17 +312,12 @@ bool FontSettings::loadColorScheme(const QString &fileName,
|
|||||||
foreach (const FormatDescription &desc, descriptions) {
|
foreach (const FormatDescription &desc, descriptions) {
|
||||||
const TextStyle id = desc.id();
|
const TextStyle id = desc.id();
|
||||||
if (!m_scheme.contains(id)) {
|
if (!m_scheme.contains(id)) {
|
||||||
Format format;
|
Format format = desc.format();
|
||||||
if (desc.format() == format && m_scheme.contains(C_TEXT)) {
|
if (format == Format() && m_scheme.contains(C_TEXT)) {
|
||||||
format = m_scheme.formatFor(C_TEXT); // Default format -> Text
|
const Format &textFormat = m_scheme.formatFor(C_TEXT);
|
||||||
} else {
|
format.setForeground(textFormat.foreground());
|
||||||
format.setForeground(desc.foreground());
|
format.setBackground(textFormat.background());
|
||||||
format.setBackground(desc.background());
|
|
||||||
}
|
}
|
||||||
format.setBold(desc.format().bold());
|
|
||||||
format.setItalic(desc.format().italic());
|
|
||||||
format.setUnderlineColor(desc.format().underlineColor());
|
|
||||||
format.setUnderlineStyle(desc.format().underlineStyle());
|
|
||||||
m_scheme.setFormatFor(id, format);
|
m_scheme.setFormatFor(id, format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ public:
|
|||||||
bool antialias() const;
|
bool antialias() const;
|
||||||
void setAntialias(bool antialias);
|
void setAntialias(bool antialias);
|
||||||
|
|
||||||
Format &formatFor(TextStyle category);
|
|
||||||
Format formatFor(TextStyle category) const;
|
Format formatFor(TextStyle category) const;
|
||||||
|
void setFormatFor(TextStyle category, const Format &format);
|
||||||
|
|
||||||
QString colorSchemeFileName() const;
|
QString colorSchemeFileName() const;
|
||||||
void setColorSchemeFileName(const QString &fileName);
|
void setColorSchemeFileName(const QString &fileName);
|
||||||
|
|||||||
@@ -186,27 +186,13 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const FormatDescriptions &fd,
|
|||||||
settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
|
settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
|
||||||
|
|
||||||
if (!settingsFound) { // Apply defaults
|
if (!settingsFound) { // Apply defaults
|
||||||
foreach (const FormatDescription &f, m_descriptions) {
|
foreach (const FormatDescription &f, m_descriptions)
|
||||||
Format &format = m_value.formatFor(f.id());
|
m_value.setFormatFor(f.id(), f.format());
|
||||||
format.setForeground(f.foreground());
|
|
||||||
format.setBackground(f.background());
|
|
||||||
format.setBold(f.format().bold());
|
|
||||||
format.setItalic(f.format().italic());
|
|
||||||
format.setUnderlineColor(f.format().underlineColor());
|
|
||||||
format.setUnderlineStyle(f.format().underlineStyle());
|
|
||||||
}
|
|
||||||
} else if (m_value.colorSchemeFileName().isEmpty()) {
|
} else if (m_value.colorSchemeFileName().isEmpty()) {
|
||||||
// No color scheme was loaded, but one might be imported from the ini file
|
// No color scheme was loaded, but one might be imported from the ini file
|
||||||
ColorScheme defaultScheme;
|
ColorScheme defaultScheme;
|
||||||
foreach (const FormatDescription &f, m_descriptions) {
|
foreach (const FormatDescription &f, m_descriptions)
|
||||||
Format &format = defaultScheme.formatFor(f.id());
|
defaultScheme.setFormatFor(f.id(), f.format());
|
||||||
format.setForeground(f.foreground());
|
|
||||||
format.setBackground(f.background());
|
|
||||||
format.setBold(f.format().bold());
|
|
||||||
format.setItalic(f.format().italic());
|
|
||||||
format.setUnderlineColor(f.format().underlineColor());
|
|
||||||
format.setUnderlineStyle(f.format().underlineStyle());
|
|
||||||
}
|
|
||||||
if (m_value.colorScheme() != defaultScheme) {
|
if (m_value.colorScheme() != defaultScheme) {
|
||||||
// Save it as a color scheme file
|
// Save it as a color scheme file
|
||||||
QString schemeFileName = createColorSchemeFileName(QLatin1String("customized%1.xml"));
|
QString schemeFileName = createColorSchemeFileName(QLatin1String("customized%1.xml"));
|
||||||
|
|||||||
Reference in New Issue
Block a user