Make sure icon() and iconPixmap() never crash.

This commit is contained in:
Felix Geyer 2013-07-04 13:31:38 +02:00
parent 755241df5c
commit 1f47033835
2 changed files with 22 additions and 8 deletions

View File

@ -94,8 +94,14 @@ QImage Entry::icon() const
return databaseIcons()->icon(m_data.iconNumber);
}
else {
// TODO: check if database() is 0
return database()->metadata()->customIcon(m_data.customIcon);
Q_ASSERT(database());
if (database()) {
return database()->metadata()->customIcon(m_data.customIcon);
}
else {
return QImage();
}
}
}
@ -105,9 +111,10 @@ QPixmap Entry::iconPixmap() const
return databaseIcons()->iconPixmap(m_data.iconNumber);
}
else {
Q_ASSERT(database());
QPixmap pixmap;
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
// TODO: check if database() is 0
if (database() && !QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
pixmap = QPixmap::fromImage(database()->metadata()->customIcon(m_data.customIcon));
m_pixmapCacheKey = QPixmapCache::insert(pixmap);
}

View File

@ -115,8 +115,14 @@ QImage Group::icon() const
return databaseIcons()->icon(m_data.iconNumber);
}
else {
// TODO: check if m_db is 0
return m_db->metadata()->customIcon(m_data.customIcon);
Q_ASSERT(m_db);
if (m_db) {
return m_db->metadata()->customIcon(m_data.customIcon);
}
else {
return QImage();
}
}
}
@ -126,9 +132,10 @@ QPixmap Group::iconPixmap() const
return databaseIcons()->iconPixmap(m_data.iconNumber);
}
else {
Q_ASSERT(m_db);
QPixmap pixmap;
if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
// TODO: check if m_db is 0
if (m_db && !QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
pixmap = QPixmap::fromImage(m_db->metadata()->customIcon(m_data.customIcon));
m_pixmapCacheKey = QPixmapCache::insert(pixmap);
}