forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconCache.cpp
More file actions
22 lines (18 loc) · 731 Bytes
/
IconCache.cpp
File metadata and controls
22 lines (18 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "IconCache.h"
QIcon IconCache::null_icon;
std::unordered_map<std::string, QIcon> IconCache::icons;
const QIcon& IconCache::get(const std::string& name)
{
// Check if we already have an icon object with that name in the cache. If so, just return that
auto it = icons.find(name);
if(it != icons.end())
return it->second;
// If now, try to load an icon with that name and insert it into the cache
QIcon icon(":/icons/" + QString::fromStdString(name));
auto ins = icons.insert({name, icon});
// If the insertion was successful, return the inserted icon object. If it was not, return a null icon.
if(ins.second)
return ins.first->second;
else
return null_icon;
}