mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Fix crash in some unit tests from constructing a QPixmap without a QApplication
This commit is contained in:
parent
07903a6324
commit
af1a5790a2
@ -29,7 +29,7 @@ QIconProvider::QIconProvider(const QString& iconResourceString)
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QIconProvider::QIconProvider(const QPixmap& pixmap)
|
||||
: m_iconPixmap(pixmap)
|
||||
: m_iconPixmap(new QPixmap(pixmap))
|
||||
{
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ QIcon QIconProvider::icon() const
|
||||
m_icon = generateIcon();
|
||||
}
|
||||
|
||||
if (!m_active)
|
||||
if (!m_active && isGuiApplication())
|
||||
{
|
||||
QPixmap disabledPixmap = m_icon.pixmap(16, 16, QIcon::Disabled);
|
||||
return QIcon(disabledPixmap);
|
||||
@ -80,7 +80,7 @@ bool QIconProvider::isNull() const
|
||||
{
|
||||
if (!isGuiApplication()) return true;
|
||||
|
||||
if (m_iconPixmap.isNull() && m_iconResourceString.isEmpty()) return true;
|
||||
if (!hasValidPixmap() && m_iconResourceString.isEmpty()) return true;
|
||||
|
||||
return icon().isNull();
|
||||
}
|
||||
@ -107,7 +107,7 @@ void QIconProvider::setIconResourceString(const QString& iconResourceString)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QIconProvider::setPixmap(const QPixmap& pixmap)
|
||||
{
|
||||
m_iconPixmap = pixmap;
|
||||
m_iconPixmap.reset(new QPixmap(pixmap));
|
||||
m_icon = QIcon();
|
||||
}
|
||||
|
||||
@ -119,9 +119,9 @@ QIcon QIconProvider::generateIcon() const
|
||||
{
|
||||
if (isGuiApplication())
|
||||
{
|
||||
if (!m_iconPixmap.isNull())
|
||||
if (hasValidPixmap())
|
||||
{
|
||||
return QIcon(m_iconPixmap);
|
||||
return QIcon(*m_iconPixmap);
|
||||
}
|
||||
return QIcon(m_iconResourceString);
|
||||
}
|
||||
@ -135,3 +135,11 @@ bool QIconProvider::isGuiApplication()
|
||||
{
|
||||
return dynamic_cast<QApplication*>(QCoreApplication::instance()) != nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool QIconProvider::hasValidPixmap() const
|
||||
{
|
||||
return m_iconPixmap && !m_iconPixmap->isNull();
|
||||
}
|
||||
|
@ -39,6 +39,8 @@
|
||||
#include <QPixmap>
|
||||
#include <QString>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
//==================================================================================================
|
||||
@ -61,13 +63,14 @@ public:
|
||||
void setPixmap(const QPixmap& pixmap);
|
||||
|
||||
protected:
|
||||
bool hasValidPixmap() const;
|
||||
virtual QIcon generateIcon() const;
|
||||
static bool isGuiApplication();
|
||||
|
||||
protected:
|
||||
QString m_iconResourceString;
|
||||
QPixmap m_iconPixmap;
|
||||
mutable QIcon m_icon;
|
||||
bool m_active;
|
||||
QString m_iconResourceString;
|
||||
std::unique_ptr<QPixmap> m_iconPixmap;
|
||||
mutable QIcon m_icon;
|
||||
bool m_active;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user