Issue #77 Break dependency of pixmap on statusmessage

This commit is contained in:
Mat Sutcliffe
2020-08-28 18:07:02 +01:00
parent 2391d242ed
commit 43bb72788e
3 changed files with 5 additions and 31 deletions

View File

@@ -7,7 +7,6 @@
*/
#include "blackmisc/pixmap.h"
#include "blackmisc/statusmessage.h"
#include <QBuffer>
#include <QFile>
@@ -75,31 +74,6 @@ namespace BlackMisc
return "Pixmap";
}
CPixmap CPixmap::loadFromFile(const QString &filePath, CStatusMessage &msg)
{
if (filePath.isEmpty())
{
msg = CStatusMessage(CStatusMessage::SeverityError, u"no file path");
return CPixmap();
}
if (!QFile(filePath).exists())
{
msg = CStatusMessage().error(u"file %1 does not exist") << filePath;
return CPixmap();
}
QPixmap pm;
if (pm.load(filePath))
{
msg = CStatusMessage().info(u"file %1 loaded") << filePath;
return CPixmap(pm);
}
else
{
msg = CStatusMessage().error(u"file %1 not loaded") << filePath;
return CPixmap();
}
}
QPixmap CPixmap::toPixmap() const
{
return this->pixmap();

View File

@@ -60,9 +60,6 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! Load from file
static CPixmap loadFromFile(const QString &filePath, CStatusMessage &msg);
private:
//! Init the byte array with data
void fillByteArray();

View File

@@ -569,10 +569,13 @@ namespace BlackMisc
CPixmap CAircraftModel::loadIcon(CStatusMessage &success) const
{
static const CStatusMessage noIcon(this, CStatusMessage::SeverityInfo, u"no icon");
static const CStatusMessage loaded(this, CStatusMessage::SeverityInfo, u"icon loaded");
if (m_iconFile.isEmpty()) { success = noIcon; return CPixmap(); }
if (!QFile(m_iconFile).exists()) { success = noIcon; return CPixmap(); }
// load from file
const CPixmap pm(CPixmap::loadFromFile(m_iconFile, success));
QPixmap pm;
if (!pm.load(m_iconFile)) { success = noIcon; return CPixmap(); }
success = loaded;
return pm;
}