refs #413 Decomposed icon-related functions of CValueObject into Mixin::Icon.

This commit is contained in:
Mathew Sutcliffe
2015-05-01 22:30:59 +01:00
parent 75f46068e1
commit fe08792bef
4 changed files with 38 additions and 34 deletions

View File

@@ -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 <QIcon>

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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<Derived *>(this); }
};
template <class Derived, CIcons::IconIndex IconIndex = CIcons::StandardIconUnknown16>
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<const Derived *>(this); }
Derived *derived() { return static_cast<Derived *>(this); }
};
}
/*!
@@ -694,7 +702,8 @@ namespace BlackMisc
public Mixin::LessThanByTuple<Derived, Policy::LessThan::IsMetaTuple<Derived, Base>::value>,
public Mixin::CompareByTuple<Derived, Policy::Compare::IsMetaTuple<Derived, Base>::value>,
public Mixin::String<Derived>,
public Mixin::Index<Derived, std::is_same<Base, CEmpty>::value>
public Mixin::Index<Derived, std::is_same<Base, CEmpty>::value>,
public Mixin::Icon<Derived>
{
static_assert(std::is_same<CEmpty, Base>::value || IsValueObject<Base>::value, "Base must be either CEmpty or derived from CValueObject");
@@ -755,6 +764,12 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::equalsPropertyByIndex
using Mixin::Index<Derived, std::is_same<Base, CEmpty>::value>::equalsPropertyByIndex;
//! \copydoc BlackMisc::Mixin::Icon::toIcon
using Mixin::Icon<Derived>::toIcon;
//! \copydoc BlackMisc::Mixin::Icon::toPixmap
using Mixin::Icon<Derived>::toPixmap;
//! \copydoc BlackMisc::Mixin::MetaType::isA
using Mixin::MetaType<Derived>::isA;
@@ -894,6 +909,16 @@ namespace BlackMisc
{
return derived()->propertyByIndex(index) == compareValue;
}
template <class Derived, CIcons::IconIndex IconIndex>
CIcon Icon<Derived, IconIndex>::toIcon() const
{
return CIconList::iconByIndex(IconIndex);
}
template <class Derived, CIcons::IconIndex IconIndex>
QPixmap Icon<Derived, IconIndex>::toPixmap() const
{
return derived()->toIcon().toPixmap();
}
}
}