Skip to content

Commit

Permalink
Avoid include of QSize
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 17, 2024
1 parent 4aacb31 commit 84ee29c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 14 deletions.
76 changes: 65 additions & 11 deletions Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafIconProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,50 @@ using namespace caf;
class caf::IconProvider::Impl
{
public:
bool m_active;
QString m_iconResourceString;
QString m_overlayResourceString;
std::vector<QString> m_backgroundColorStrings;
QSize m_preferredSize;
QPixmap m_pixmap;
Impl()
: m_active( false )
, m_preferredSize( QSize( 16, 16 ) )
{
}
Impl( const Impl& rhs )
{
m_active = rhs.m_active;
m_iconResourceString = rhs.m_iconResourceString;
m_overlayResourceString = rhs.m_overlayResourceString;
m_backgroundColorStrings = rhs.m_backgroundColorStrings;
m_preferredSize = rhs.m_preferredSize;
if ( rhs.m_pixmap )
{
m_pixmap = std::make_unique<QPixmap>( *rhs.m_pixmap );
}
}

bool m_active;
QString m_iconResourceString;
QString m_overlayResourceString;
std::vector<QString> m_backgroundColorStrings;
QSize m_preferredSize;
std::unique_ptr<QPixmap> m_pixmap;
};

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
IconProvider::IconProvider()
: m_impl( new Impl )
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
IconProvider::IconProvider( const QString& iconResourceString )
: m_impl( new Impl )
{
m_impl->m_active = true;
m_impl->m_iconResourceString = iconResourceString;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -82,7 +118,7 @@ caf::IconProvider::IconProvider( const QPixmap& pixmap )
: m_impl( new Impl )
{
m_impl->m_active = true;
m_impl->m_pixmap = pixmap;
m_impl->m_pixmap = std::make_unique<QPixmap>( pixmap );
m_impl->m_preferredSize = pixmap.size();
}

Expand All @@ -102,14 +138,21 @@ IconProvider::IconProvider( const IconProvider& rhs )
m_impl = std::make_unique<Impl>( *rhs.m_impl );
else
m_impl = std::make_unique<Impl>();

copyPixmap( rhs );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
IconProvider& IconProvider::operator=( const IconProvider& rhs )
{
*m_impl = *rhs.m_impl;
m_impl->m_active = rhs.m_impl->m_active;
m_impl->m_iconResourceString = rhs.m_impl->m_iconResourceString;
m_impl->m_overlayResourceString = rhs.m_impl->m_overlayResourceString;
m_impl->m_backgroundColorStrings = rhs.m_impl->m_backgroundColorStrings;
m_impl->m_preferredSize = rhs.m_impl->m_preferredSize;
copyPixmap( rhs );

return *this;
}
Expand All @@ -129,7 +172,7 @@ bool caf::IconProvider::valid() const
{
if ( isGuiApplication() )
{
if ( !m_impl->m_pixmap.isNull() ) return true;
if ( m_impl->m_pixmap && !m_impl->m_pixmap->isNull() ) return true;

if ( backgroundColorsAreValid() )
{
Expand Down Expand Up @@ -170,7 +213,7 @@ std::unique_ptr<QIcon> IconProvider::icon( const QSize& size ) const
return nullptr;
}

if ( !m_impl->m_pixmap.isNull() ) return std::unique_ptr<QIcon>( new QIcon( m_impl->m_pixmap ) );
if ( m_impl->m_pixmap ) return std::unique_ptr<QIcon>( new QIcon( *m_impl->m_pixmap ) );

QPixmap pixmap( size );

Expand Down Expand Up @@ -287,7 +330,7 @@ void IconProvider::setBackgroundColorGradient( const std::vector<QString>& color
//--------------------------------------------------------------------------------------------------
void caf::IconProvider::setPixmap( const QPixmap& pixmap )
{
m_impl->m_pixmap = pixmap;
m_impl->m_pixmap.reset( new QPixmap( pixmap ) );
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -298,6 +341,17 @@ bool caf::IconProvider::isGuiApplication()
return dynamic_cast<QApplication*>( QCoreApplication::instance() ) != nullptr;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void IconProvider::copyPixmap( const IconProvider& rhs )
{
if ( rhs.m_impl->m_pixmap )
{
m_impl->m_pixmap = std::unique_ptr<QPixmap>( new QPixmap( *rhs.m_impl->m_pixmap ) );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafIconProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
//##################################################################################################
#pragma once

#include <QSize>
#include <memory>
#include <vector>

class QIcon;
class QPixmap;
class QString;
class QSize;

namespace caf
{
Expand All @@ -52,8 +52,10 @@ namespace caf
class IconProvider
{
public:
IconProvider( const QSize& preferredSize = QSize( 16, 16 ) );
IconProvider( const QString& iconResourceString, const QSize& preferredSize = QSize( 16, 16 ) );
IconProvider();
IconProvider( const QSize& preferredSize );
IconProvider( const QString& iconResourceString );
IconProvider( const QString& iconResourceString, const QSize& preferredSize );
IconProvider( const QPixmap& pixmap );
IconProvider( const IconProvider& rhs );
IconProvider& operator=( const IconProvider& rhs );
Expand All @@ -75,6 +77,7 @@ class IconProvider

private:
static bool isGuiApplication();
void copyPixmap( const IconProvider& rhs );

bool backgroundColorsAreValid() const;

Expand Down

0 comments on commit 84ee29c

Please sign in to comment.