Only get the icon for add/geocode once

Each time we searched for an icon on the qt resource
we had to open, inflate, create, store, delete the icon.
now we search for it only once, use as cache and make
the world a better place.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2015-09-25 12:19:41 -03:00 committed by Dirk Hohndel
parent fc420927ff
commit a5d2003e3a

View file

@ -301,6 +301,9 @@ void DiveLocationModel::resetModel()
QVariant DiveLocationModel::data(const QModelIndex& index, int role) const
{
static const QIcon plusIcon(":plus");
static const QIcon geoCode(":geocode");
if(index.row() <= 1) { // two special cases.
if(index.column() == UUID) {
return RECENTLY_ADDED_DIVESITE;
@ -308,7 +311,7 @@ QVariant DiveLocationModel::data(const QModelIndex& index, int role) const
switch(role) {
case Qt::DisplayRole : return new_ds_value[index.row()];
case Qt::ToolTipRole : return "Create a new dive site";
case Qt::DecorationRole : return QIcon(":plus");
case Qt::DecorationRole : return plusIcon;
}
}
@ -328,7 +331,7 @@ QVariant DiveLocationModel::data(const QModelIndex& index, int role) const
break;
case Qt::DecorationRole : {
if (dive_site_has_gps_location(ds))
return QIcon(":geocode");
return geoCode;
}
}
return QVariant();