diff --git a/src/plugins/texteditor/fontsettings.cpp b/src/plugins/texteditor/fontsettings.cpp index fd43fe3a10a45270b0ec7003b0d91ff18a156c28..ea21f7d510c38bb24634c7d1143adb66ffefd747 100644 --- a/src/plugins/texteditor/fontsettings.cpp +++ b/src/plugins/texteditor/fontsettings.cpp @@ -70,6 +70,7 @@ void FontSettings::clear() m_fontZoom = 100; m_antialias = DEFAULT_ANTIALIAS; m_scheme.clear(); + m_formatCache.clear(); } void FontSettings::toSettings(const QString &category, @@ -155,8 +156,10 @@ bool FontSettings::equals(const FontSettings &f) 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; if (category == C_TEXT) { @@ -171,6 +174,8 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const tf.setBackground(f.background()); tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal); tf.setFontItalic(f.italic()); + + m_formatCache.insert(category, tf); return tf; } @@ -199,6 +204,7 @@ QString FontSettings::family() const void FontSettings::setFamily(const QString &family) { m_family = family; + m_formatCache.clear(); } /** @@ -212,6 +218,7 @@ int FontSettings::fontSize() const void FontSettings::setFontSize(int size) { m_fontSize = size; + m_formatCache.clear(); } /** @@ -225,6 +232,7 @@ int FontSettings::fontZoom() const void FontSettings::setFontZoom(int zoom) { m_fontZoom = zoom; + m_formatCache.clear(); } QFont FontSettings::font() const @@ -243,6 +251,7 @@ bool FontSettings::antialias() const void FontSettings::setAntialias(bool antialias) { m_antialias = antialias; + m_formatCache.clear(); } /** @@ -279,6 +288,7 @@ void FontSettings::setColorSchemeFileName(const QString &fileName) bool FontSettings::loadColorScheme(const QString &fileName, const FormatDescriptions &descriptions) { + m_formatCache.clear(); bool loaded = true; m_schemeFileName = fileName; @@ -323,6 +333,7 @@ const ColorScheme &FontSettings::colorScheme() const void FontSettings::setColorScheme(const ColorScheme &scheme) { m_scheme = scheme; + m_formatCache.clear(); } static QString defaultFontFamily() diff --git a/src/plugins/texteditor/fontsettings.h b/src/plugins/texteditor/fontsettings.h index 23e746f4e5bdfc9ba5369ac623b0dc5acebf14ce..258fd569293af5b4c7845f53b5ffff9b96975782 100644 --- a/src/plugins/texteditor/fontsettings.h +++ b/src/plugins/texteditor/fontsettings.h @@ -34,8 +34,9 @@ #include "colorscheme.h" -#include <QString> +#include <QHash> #include <QList> +#include <QString> #include <QVector> QT_BEGIN_NAMESPACE @@ -109,6 +110,7 @@ private: int m_fontZoom; bool m_antialias; ColorScheme m_scheme; + mutable QHash<TextStyle, QTextCharFormat> m_formatCache; }; inline bool operator==(const FontSettings &f1, const FontSettings &f2) { return f1.equals(f2); }