diff --git a/src/blackmisc/icon.h b/src/blackmisc/icon.h index c08dbef57..19c5c001b 100644 --- a/src/blackmisc/icon.h +++ b/src/blackmisc/icon.h @@ -9,11 +9,12 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_ICON_H #define BLACKMISC_ICON_H #include "blackmiscexport.h" -#include "valueobject.h" #include "icons.h" #include diff --git a/src/blackmisc/iconlist.h b/src/blackmisc/iconlist.h index 0a9b4727f..86f2a718f 100644 --- a/src/blackmisc/iconlist.h +++ b/src/blackmisc/iconlist.h @@ -9,6 +9,8 @@ //! \file +#include "valueobject.h" // outside include guard due to cyclic dependency hack (MS) + #ifndef BLACKMISC_ICONLIST_H #define BLACKMISC_ICONLIST_H diff --git a/src/blackmisc/valueobject.cpp b/src/blackmisc/valueobject.cpp deleted file mode 100644 index df3f1a696..000000000 --- a/src/blackmisc/valueobject.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "valueobject.h" -#include "iconlist.h" - -namespace BlackMisc -{ - CIcon CEmpty::toIcon() const - { - return CIconList::iconByIndex(CIcons::StandardIconUnknown16); - } - - QPixmap CEmpty::toPixmap() const - { - return this->toIcon().toPixmap(); - } -} diff --git a/src/blackmisc/valueobject.h b/src/blackmisc/valueobject.h index 41ee99915..50ac5c54a 100644 --- a/src/blackmisc/valueobject.h +++ b/src/blackmisc/valueobject.h @@ -16,6 +16,7 @@ #include "dbus.h" #include "tuple.h" #include "json.h" +#include "icons.h" #include "blackmiscfreefunctions.h" #include "valueobject_private.h" #include "valueobject_policy.h" @@ -72,14 +73,6 @@ namespace BlackMisc //! Base class is alias of itself using base_type = CEmpty; - //! As icon, not implemented by all classes - //! \todo Here because incomplete type. Move to policy class during policy refactoring. - virtual CIcon toIcon() const; - - //! As pixmap, required for most GUI views - //! \todo Here because incomplete type. Move to policy class during policy refactoring. - virtual QPixmap toPixmap() const; - //! Parse from string, e.g. 100km/h //! \todo Here to avoid name hiding in PQ classes. Fix during policy refactoring. virtual void parseFromString(const QString &) { qFatal("Not implemented"); } @@ -672,6 +665,21 @@ namespace BlackMisc Derived *derived() { return static_cast(this); } }; + template + class Icon + { + public: + //! As icon, not implemented by all classes + virtual CIcon toIcon() const; // implemented later due to cyclic include dependency + + //! As pixmap, required for most GUI views + virtual QPixmap toPixmap() const; // implemented later due to cyclic include dependency + + private: + const Derived *derived() const { return static_cast(this); } + Derived *derived() { return static_cast(this); } + }; + } /*! @@ -694,7 +702,8 @@ namespace BlackMisc public Mixin::LessThanByTuple::value>, public Mixin::CompareByTuple::value>, public Mixin::String, - public Mixin::Index::value> + public Mixin::Index::value>, + public Mixin::Icon { static_assert(std::is_same::value || IsValueObject::value, "Base must be either CEmpty or derived from CValueObject"); @@ -755,6 +764,12 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::equalsPropertyByIndex using Mixin::Index::value>::equalsPropertyByIndex; + //! \copydoc BlackMisc::Mixin::Icon::toIcon + using Mixin::Icon::toIcon; + + //! \copydoc BlackMisc::Mixin::Icon::toPixmap + using Mixin::Icon::toPixmap; + //! \copydoc BlackMisc::Mixin::MetaType::isA using Mixin::MetaType::isA; @@ -894,6 +909,16 @@ namespace BlackMisc { return derived()->propertyByIndex(index) == compareValue; } + template + CIcon Icon::toIcon() const + { + return CIconList::iconByIndex(IconIndex); + } + template + QPixmap Icon::toPixmap() const + { + return derived()->toIcon().toPixmap(); + } } }