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 QString fmt = s->value(group + QLatin1String(Constants::nameForStyle(id)), QString()).toString();
|
||||
Format format;
|
||||
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 {
|
||||
if (!fmt.isEmpty())
|
||||
format.fromString(fmt);
|
||||
}
|
||||
else
|
||||
format = desc.format();
|
||||
m_scheme.setFormatFor(id, format);
|
||||
}
|
||||
|
||||
@@ -274,15 +268,14 @@ void FontSettings::setAntialias(bool antialias)
|
||||
/**
|
||||
* Returns the format for the given font category.
|
||||
*/
|
||||
Format &FontSettings::formatFor(TextStyle category)
|
||||
|
||||
Format FontSettings::formatFor(TextStyle category) const
|
||||
{
|
||||
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) {
|
||||
const TextStyle id = desc.id();
|
||||
if (!m_scheme.contains(id)) {
|
||||
Format format;
|
||||
if (desc.format() == format && m_scheme.contains(C_TEXT)) {
|
||||
format = m_scheme.formatFor(C_TEXT); // Default format -> Text
|
||||
} else {
|
||||
format.setForeground(desc.foreground());
|
||||
format.setBackground(desc.background());
|
||||
Format format = desc.format();
|
||||
if (format == Format() && m_scheme.contains(C_TEXT)) {
|
||||
const Format &textFormat = m_scheme.formatFor(C_TEXT);
|
||||
format.setForeground(textFormat.foreground());
|
||||
format.setBackground(textFormat.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ public:
|
||||
bool antialias() const;
|
||||
void setAntialias(bool antialias);
|
||||
|
||||
Format &formatFor(TextStyle category);
|
||||
Format formatFor(TextStyle category) const;
|
||||
void setFormatFor(TextStyle category, const Format &format);
|
||||
|
||||
QString colorSchemeFileName() const;
|
||||
void setColorSchemeFileName(const QString &fileName);
|
||||
|
||||
@@ -186,27 +186,13 @@ FontSettingsPagePrivate::FontSettingsPagePrivate(const FormatDescriptions &fd,
|
||||
settingsFound = m_value.fromSettings(m_settingsGroup, m_descriptions, settings);
|
||||
|
||||
if (!settingsFound) { // Apply defaults
|
||||
foreach (const FormatDescription &f, m_descriptions) {
|
||||
Format &format = m_value.formatFor(f.id());
|
||||
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());
|
||||
}
|
||||
foreach (const FormatDescription &f, m_descriptions)
|
||||
m_value.setFormatFor(f.id(), f.format());
|
||||
} else if (m_value.colorSchemeFileName().isEmpty()) {
|
||||
// No color scheme was loaded, but one might be imported from the ini file
|
||||
ColorScheme defaultScheme;
|
||||
foreach (const FormatDescription &f, m_descriptions) {
|
||||
Format &format = defaultScheme.formatFor(f.id());
|
||||
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());
|
||||
}
|
||||
foreach (const FormatDescription &f, m_descriptions)
|
||||
defaultScheme.setFormatFor(f.id(), f.format());
|
||||
if (m_value.colorScheme() != defaultScheme) {
|
||||
// Save it as a color scheme file
|
||||
QString schemeFileName = createColorSchemeFileName(QLatin1String("customized%1.xml"));
|
||||
|
||||
Reference in New Issue
Block a user