Changeset View
Changeset View
Standalone View
Standalone View
src/part/FontsCache.cpp
Show All 10 Lines | 1 | /* This file is part of KGraphViewer. | |||
---|---|---|---|---|---|
11 | General Public License for more details. | 11 | General Public License for more details. | ||
12 | 12 | | |||
13 | You should have received a copy of the GNU General Public License | 13 | You should have received a copy of the GNU General Public License | ||
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA | 16 | 02110-1301, USA | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | | ||||
20 | #include "FontsCache.h" | 19 | #include "FontsCache.h" | ||
21 | 20 | | |||
22 | #include "dot2qtconsts.h" | 21 | #include "dot2qtconsts.h" | ||
23 | 22 | | |||
24 | FontsCache::~FontsCache() | 23 | FontsCache::~FontsCache() | ||
25 | { | 24 | { | ||
26 | FontsCache::iterator it, it_end; | 25 | FontsCache::iterator it, it_end; | ||
27 | it = begin(); it_end = end(); | 26 | it = begin(); | ||
28 | for (; it != it_end; it++) | 27 | it_end = end(); | ||
29 | { | 28 | for (; it != it_end; it++) { | ||
30 | delete (*it); | 29 | delete (*it); | ||
31 | } | 30 | } | ||
32 | } | 31 | } | ||
33 | 32 | | |||
34 | QFont* FontsCache::cachedFont(const QFont& font) | 33 | QFont *FontsCache::cachedFont(const QFont &font) | ||
35 | { | 34 | { | ||
36 | if (find(font.key()) == end()) | 35 | if (find(font.key()) == end()) { | ||
37 | { | | |||
38 | (*this)[font.key()] = new QFont(font); | 36 | (*this)[font.key()] = new QFont(font); | ||
39 | } | 37 | } | ||
40 | return (*this)[font.key()]; | 38 | return (*this)[font.key()]; | ||
41 | } | 39 | } | ||
42 | 40 | | |||
43 | QFont* FontsCache::fromName(const QString& fontName) | 41 | QFont *FontsCache::fromName(const QString &fontName) | ||
44 | { | 42 | { | ||
45 | if (m_namesToFonts.find(fontName) == m_namesToFonts.end()) | 43 | if (m_namesToFonts.find(fontName) == m_namesToFonts.end()) { | ||
46 | { | | |||
47 | QFont font(Dot2QtConsts::componentData().qtFont(fontName)); | 44 | QFont font(Dot2QtConsts::componentData().qtFont(fontName)); | ||
48 | m_namesToFonts[fontName] = cachedFont(font); | 45 | m_namesToFonts[fontName] = cachedFont(font); | ||
49 | } | 46 | } | ||
50 | return m_namesToFonts[fontName]; | 47 | return m_namesToFonts[fontName]; | ||
51 | } | 48 | } |