mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2024-11-24 03:35:54 +01:00
Improved error handling
This commit is contained in:
parent
6f5bedb82b
commit
ccfcc370d6
@ -61,9 +61,13 @@ bool Sprites::load(const QString &jsonFile, const QString &imageFile)
|
|||||||
for (QJsonObject::const_iterator it = json.constBegin();
|
for (QJsonObject::const_iterator it = json.constBegin();
|
||||||
it != json.constEnd(); it++) {
|
it != json.constEnd(); it++) {
|
||||||
QJsonValue val(*it);
|
QJsonValue val(*it);
|
||||||
if (val.isObject())
|
if (val.isObject()) {
|
||||||
_sprites.insert(it.key(), Sprite(val.toObject()));
|
Sprite s(val.toObject());
|
||||||
else
|
if (s.rect().isValid())
|
||||||
|
_sprites.insert(it.key(), s);
|
||||||
|
else
|
||||||
|
qWarning() << it.key() << ": invalid sprite definition";
|
||||||
|
} else
|
||||||
qWarning() << it.key() << ": invalid sprite definition";
|
qWarning() << it.key() << ": invalid sprite definition";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +86,8 @@ QImage Sprites::icon(const QString &name) const
|
|||||||
if (it == _sprites.constEnd())
|
if (it == _sprites.constEnd())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
if (!img.rect().contains(it->rect())) {
|
if (!img.rect().contains(it->rect()))
|
||||||
qWarning() << it->rect() << ": invalid sprite rect";
|
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
|
||||||
|
|
||||||
return img.copy(it->rect());
|
return img.copy(it->rect());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user