Use a better scoped singleton

This commit is contained in:
Martin Tůma 2020-07-01 21:11:09 +02:00
parent 7684f4fdcf
commit fd02b83b47

View File

@ -9,9 +9,9 @@
Loading the sprites atlas image must be deferred until all image plugins Loading the sprites atlas image must be deferred until all image plugins
are loaded, otherwise reading the image will cause a deadlock! are loaded, otherwise reading the image will cause a deadlock!
*/ */
static const QImage *atlas(const QString &fileName) static const QImage &atlas(const QString &fileName)
{ {
static QImage *img = new QImage(fileName); static QImage img(fileName);
return img; return img;
} }
@ -86,18 +86,18 @@ QImage Sprites::icon(const QString &name) const
if (_imageFile.isEmpty()) if (_imageFile.isEmpty())
return QImage(); return QImage();
const QImage *img = atlas(_imageFile); const QImage &img = atlas(_imageFile);
if (img->isNull()) if (img.isNull())
return QImage(); return QImage();
QMap<QString, Sprite>::const_iterator it = _sprites.find(name); QMap<QString, Sprite>::const_iterator it = _sprites.find(name);
if (it == _sprites.constEnd()) if (it == _sprites.constEnd())
return QImage(); return QImage();
if (!img->rect().contains(it->rect())) if (!img.rect().contains(it->rect()))
return QImage(); return QImage();
QImage ret(img->copy(it->rect())); QImage ret(img.copy(it->rect()));
ret.setDevicePixelRatio(it->pixelRatio()); ret.setDevicePixelRatio(it->pixelRatio());
return ret; return ret;