FontSettings: Globally cache textcharformats

Change-Id: I02ca646322b07eeb21c2cdd4ef5594b754234e12
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-01-20 17:03:45 +01:00
parent 3fa6b6737c
commit 13ee70652c
2 changed files with 15 additions and 2 deletions

View File

@@ -70,6 +70,7 @@ void FontSettings::clear()
m_fontZoom = 100; m_fontZoom = 100;
m_antialias = DEFAULT_ANTIALIAS; m_antialias = DEFAULT_ANTIALIAS;
m_scheme.clear(); m_scheme.clear();
m_formatCache.clear();
} }
void FontSettings::toSettings(const QString &category, void FontSettings::toSettings(const QString &category,
@@ -155,8 +156,10 @@ bool FontSettings::equals(const FontSettings &f) const
*/ */
QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
{ {
const Format &f = m_scheme.formatFor(category); if (m_formatCache.contains(category))
return m_formatCache.value(category);
const Format &f = m_scheme.formatFor(category);
QTextCharFormat tf; QTextCharFormat tf;
if (category == C_TEXT) { if (category == C_TEXT) {
@@ -171,6 +174,8 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
tf.setBackground(f.background()); tf.setBackground(f.background());
tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal); tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal);
tf.setFontItalic(f.italic()); tf.setFontItalic(f.italic());
m_formatCache.insert(category, tf);
return tf; return tf;
} }
@@ -199,6 +204,7 @@ QString FontSettings::family() const
void FontSettings::setFamily(const QString &family) void FontSettings::setFamily(const QString &family)
{ {
m_family = family; m_family = family;
m_formatCache.clear();
} }
/** /**
@@ -212,6 +218,7 @@ int FontSettings::fontSize() const
void FontSettings::setFontSize(int size) void FontSettings::setFontSize(int size)
{ {
m_fontSize = size; m_fontSize = size;
m_formatCache.clear();
} }
/** /**
@@ -225,6 +232,7 @@ int FontSettings::fontZoom() const
void FontSettings::setFontZoom(int zoom) void FontSettings::setFontZoom(int zoom)
{ {
m_fontZoom = zoom; m_fontZoom = zoom;
m_formatCache.clear();
} }
QFont FontSettings::font() const QFont FontSettings::font() const
@@ -243,6 +251,7 @@ bool FontSettings::antialias() const
void FontSettings::setAntialias(bool antialias) void FontSettings::setAntialias(bool antialias)
{ {
m_antialias = antialias; m_antialias = antialias;
m_formatCache.clear();
} }
/** /**
@@ -279,6 +288,7 @@ void FontSettings::setColorSchemeFileName(const QString &fileName)
bool FontSettings::loadColorScheme(const QString &fileName, bool FontSettings::loadColorScheme(const QString &fileName,
const FormatDescriptions &descriptions) const FormatDescriptions &descriptions)
{ {
m_formatCache.clear();
bool loaded = true; bool loaded = true;
m_schemeFileName = fileName; m_schemeFileName = fileName;
@@ -323,6 +333,7 @@ const ColorScheme &FontSettings::colorScheme() const
void FontSettings::setColorScheme(const ColorScheme &scheme) void FontSettings::setColorScheme(const ColorScheme &scheme)
{ {
m_scheme = scheme; m_scheme = scheme;
m_formatCache.clear();
} }
static QString defaultFontFamily() static QString defaultFontFamily()

View File

@@ -34,8 +34,9 @@
#include "colorscheme.h" #include "colorscheme.h"
#include <QString> #include <QHash>
#include <QList> #include <QList>
#include <QString>
#include <QVector> #include <QVector>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -109,6 +110,7 @@ private:
int m_fontZoom; int m_fontZoom;
bool m_antialias; bool m_antialias;
ColorScheme m_scheme; ColorScheme m_scheme;
mutable QHash<TextStyle, QTextCharFormat> m_formatCache;
}; };
inline bool operator==(const FontSettings &f1, const FontSettings &f2) { return f1.equals(f2); } inline bool operator==(const FontSettings &f1, const FontSettings &f2) { return f1.equals(f2); }