qskinny/src/common/QskAspect.h

681 lines
19 KiB
C
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#ifndef QSK_ASPECT_H
#define QSK_ASPECT_H
2019-04-17 15:37:03 +02:00
#include "QskGlobal.h"
2018-07-19 14:10:48 +02:00
#include <qmetaobject.h>
#include <qnamespace.h>
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
class QSK_EXPORT QskAspect
2017-07-21 18:21:34 +02:00
{
2020-12-21 16:06:58 +01:00
Q_GADGET
2020-12-21 16:06:58 +01:00
public:
2017-07-21 18:21:34 +02:00
enum Type : quint8
{
Flag = 0,
Metric = 1,
Color = 2,
};
2020-12-21 16:06:58 +01:00
Q_ENUM( Type )
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
static constexpr uint typeCount = 3;
2020-12-18 08:50:23 +01:00
enum Primitive : quint8
2017-07-21 18:21:34 +02:00
{
NoPrimitive = 0,
2017-07-21 18:21:34 +02:00
Alignment,
Direction,
2017-07-21 18:21:34 +02:00
Style,
GraphicRole,
FontRole,
2017-07-21 18:21:34 +02:00
TextColor,
StyleColor,
LinkColor,
2017-07-21 18:21:34 +02:00
StrutSize,
2017-07-21 18:21:34 +02:00
Size,
Position,
Margin,
Padding,
Spacing,
Shadow,
Shape,
Border
2017-07-21 18:21:34 +02:00
};
Q_ENUM( Primitive )
2017-07-21 18:21:34 +02:00
enum Placement : quint8
{
NoPlacement = 0,
Vertical = Qt::Vertical,
Horizontal = Qt::Horizontal,
Top = 1,
Left = 2,
Right = 3,
Bottom = 4
};
2020-12-21 16:06:58 +01:00
Q_ENUM( Placement )
enum Subcontrol : quint16
{
Control = 0,
LastSubcontrol = ( 1 << 12 ) - 1
};
Q_ENUM( Subcontrol )
2017-07-21 18:21:34 +02:00
enum State : quint16
{
2018-08-03 08:15:28 +02:00
NoState = 0,
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
FirstSystemState = 1 << 0,
FirstUserState = 1 << 4,
LastUserState = 1 << 11,
LastSystemState = 1 << 15,
2017-07-21 18:21:34 +02:00
2018-08-03 08:15:28 +02:00
AllStates = 0xFFFF
2017-07-21 18:21:34 +02:00
};
2020-12-21 16:06:58 +01:00
Q_ENUM( State )
Q_DECLARE_FLAGS( States, State )
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr QskAspect() noexcept;
constexpr QskAspect( Subcontrol ) noexcept;
constexpr QskAspect( Type ) noexcept;
constexpr QskAspect( Placement ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr QskAspect( const QskAspect& ) noexcept = default;
constexpr QskAspect( QskAspect&& ) noexcept = default;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
QskAspect& operator=( const QskAspect& ) noexcept = default;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
bool operator==( const QskAspect& ) const noexcept;
bool operator!=( const QskAspect& ) const noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
bool operator<( const QskAspect& ) const noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr QskAspect operator|( Subcontrol ) const noexcept;
constexpr QskAspect operator|( Type ) const noexcept;
constexpr QskAspect operator|( Primitive ) const noexcept;
2020-12-21 16:06:58 +01:00
constexpr QskAspect operator|( Placement ) const noexcept;
2022-03-28 20:33:42 +02:00
2020-12-21 16:06:58 +01:00
constexpr QskAspect operator|( State ) const noexcept;
2022-03-28 20:33:42 +02:00
QskAspect& operator|=( State ) noexcept;
constexpr QskAspect operator&( State ) const noexcept;
QskAspect& operator&=( State ) noexcept;
constexpr QskAspect operator|( States ) const noexcept;
2022-03-28 20:33:42 +02:00
QskAspect& operator|=( States ) noexcept;
constexpr QskAspect operator&( States ) const noexcept;
QskAspect& operator&=( States ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-26 12:57:08 +01:00
constexpr QskAspect stateless() const noexcept;
constexpr QskAspect trunk() const noexcept;
2020-12-21 16:06:58 +01:00
constexpr quint64 value() const noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr bool isAnimator() const noexcept;
void setAnimator( bool on ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr Subcontrol subControl() const noexcept;
void setSubControl( Subcontrol ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr Type type() const noexcept;
void setType( Type ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr bool isMetric() const noexcept;
constexpr bool isColor() const noexcept;
constexpr bool isFlag() const noexcept;
2020-12-21 16:06:58 +01:00
constexpr Placement placement() const noexcept;
void setPlacement( Placement ) noexcept;
2017-07-21 18:21:34 +02:00
constexpr States states() const noexcept;
constexpr bool hasStates() const noexcept;
2017-07-21 18:21:34 +02:00
State topState() const noexcept;
2020-12-21 16:06:58 +01:00
void clearState( State ) noexcept;
void setStates( States ) noexcept;
void addStates( States ) noexcept;
void clearStates( States = AllStates ) noexcept;
constexpr Primitive primitive() const noexcept;
void setPrimitive( Type, Primitive primitive ) noexcept;
2020-12-21 16:06:58 +01:00
void clearPrimitive() noexcept;
2017-07-21 18:21:34 +02:00
constexpr Primitive flagPrimitive() const noexcept;
constexpr Primitive colorPrimitive() const noexcept;
constexpr Primitive metricPrimitive() const noexcept;
2020-12-21 16:06:58 +01:00
const char* toPrintable() const;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
static State registerState( const QMetaObject*, State, const char* );
static Subcontrol nextSubcontrol( const QMetaObject*, const char* );
2020-12-21 16:06:58 +01:00
static QByteArray subControlName( Subcontrol );
static QVector< QByteArray > subControlNames( const QMetaObject* = nullptr );
static QVector< Subcontrol > subControls( const QMetaObject* );
2017-07-21 18:21:34 +02:00
static quint8 primitiveCount();
static void reservePrimitives( quint8 count );
2018-08-03 08:15:28 +02:00
2020-12-21 16:06:58 +01:00
private:
constexpr QskAspect( Subcontrol, Type, Placement ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
constexpr QskAspect( uint subControl, uint type, bool isAnimator,
uint primitive, uint placement, uint states ) noexcept;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
struct Bits
{
uint subControl : 12;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
uint type : 3;
uint isAnimator : 1;
2020-12-21 16:06:58 +01:00
uint primitive : 5;
uint placement : 3;
uint reserved1 : 8;
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
uint states : 16;
uint reserved2 : 16;
2017-12-07 11:54:06 +01:00
};
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
union
2017-07-21 18:21:34 +02:00
{
2020-12-21 16:06:58 +01:00
Bits m_bits;
quint64 m_value;
};
};
2017-07-21 18:21:34 +02:00
Q_DECLARE_TYPEINFO( QskAspect, Q_MOVABLE_TYPE );
Q_DECLARE_OPERATORS_FOR_FLAGS( QskAspect::States )
constexpr inline QskAspect::State operator<<( QskAspect::State a, const int b ) noexcept
{
using underlying = typename std::underlying_type< QskAspect::State >::type;
return static_cast< QskAspect::State >( static_cast< underlying >( a ) << b );
}
constexpr inline QskAspect::State operator>>( QskAspect::State a, const int b ) noexcept
{
using underlying = typename std::underlying_type< QskAspect::State >::type;
return static_cast< QskAspect::State >( static_cast< underlying >( a ) >> b );
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect() noexcept
: QskAspect( Control, Flag, NoPlacement )
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect( Subcontrol subControl ) noexcept
: QskAspect( subControl, Flag, NoPlacement )
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect( Type type ) noexcept
: QskAspect( Control, type, NoPlacement )
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect( Placement placement ) noexcept
: QskAspect( Control, Flag, placement )
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect(
Subcontrol subControl, Type type, Placement placement ) noexcept
: QskAspect( subControl, type, false, 0, placement, NoState )
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::QskAspect( uint subControl, uint type, bool isAnimator,
uint primitive, uint placement, uint states ) noexcept
: m_bits { subControl, type, isAnimator, primitive, placement, 0, states, 0 }
{
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline bool QskAspect::operator==( const QskAspect& other ) const noexcept
{
return m_value == other.m_value;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline bool QskAspect::operator!=( const QskAspect& other ) const noexcept
{
return m_value != other.m_value;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline bool QskAspect::operator<( const QskAspect& other ) const noexcept
{
return m_value < other.m_value;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect QskAspect::operator|( Subcontrol subControl ) const noexcept
{
return QskAspect( subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states );
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect QskAspect::operator|( Type type ) const noexcept
{
return QskAspect( m_bits.subControl, type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states );
}
inline constexpr QskAspect QskAspect::operator|( Primitive primitive ) const noexcept
2020-12-21 16:06:58 +01:00
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
primitive, m_bits.placement, m_bits.states );
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect QskAspect::operator|( Placement placement ) const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, placement, m_bits.states );
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect QskAspect::operator|( State state ) const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states | state );
}
2017-07-21 18:21:34 +02:00
2022-03-28 20:33:42 +02:00
inline QskAspect& QskAspect::operator|=( State state ) noexcept
{
m_bits.states |= state;
return *this;
}
inline constexpr QskAspect QskAspect::operator&( State state ) const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states & state );
}
inline QskAspect& QskAspect::operator&=( State state ) noexcept
{
m_bits.states &= state;
return *this;
}
inline constexpr QskAspect QskAspect::operator|( States states ) const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states | states );
}
2022-03-28 20:33:42 +02:00
inline QskAspect& QskAspect::operator|=( States states ) noexcept
{
m_bits.states |= states;
return *this;
}
inline constexpr QskAspect QskAspect::operator&( States states ) const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, m_bits.states & states );
}
inline QskAspect& QskAspect::operator&=( States states ) noexcept
{
m_bits.states &= states;
return *this;
}
2020-12-26 12:57:08 +01:00
inline constexpr QskAspect QskAspect::stateless() const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, m_bits.placement, 0 );
}
inline constexpr QskAspect QskAspect::trunk() const noexcept
{
return QskAspect( m_bits.subControl, m_bits.type, m_bits.isAnimator,
m_bits.primitive, 0, 0 );
}
2020-12-21 16:06:58 +01:00
inline constexpr quint64 QskAspect::value() const noexcept
{
return m_value;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr bool QskAspect::isAnimator() const noexcept
{
return m_bits.isAnimator;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline void QskAspect::setAnimator( bool on ) noexcept
{
m_bits.isAnimator = on;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::Subcontrol QskAspect::subControl() const noexcept
{
return static_cast< Subcontrol >( m_bits.subControl );
}
2020-12-21 16:06:58 +01:00
inline void QskAspect::setSubControl( Subcontrol subControl ) noexcept
{
m_bits.subControl = subControl;
}
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::Type QskAspect::type() const noexcept
{
return static_cast< Type >( m_bits.type );
}
2020-12-21 16:06:58 +01:00
inline void QskAspect::setType( Type type ) noexcept
{
m_bits.type = type;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr bool QskAspect::isMetric() const noexcept
{
return type() == Metric;
}
2020-12-20 16:05:05 +01:00
2020-12-21 16:06:58 +01:00
inline constexpr bool QskAspect::isColor() const noexcept
{
return type() == Color;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr bool QskAspect::isFlag() const noexcept
{
return type() == Flag;
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect::States QskAspect::states() const noexcept
2020-12-21 16:06:58 +01:00
{
return static_cast< States >( m_bits.states );
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline void QskAspect::setStates( States states ) noexcept
2020-12-21 16:06:58 +01:00
{
m_bits.states = states;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline void QskAspect::addStates( States states ) noexcept
2020-12-21 16:06:58 +01:00
{
m_bits.states |= states;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline constexpr bool QskAspect::hasStates() const noexcept
2020-12-23 09:28:17 +01:00
{
return m_bits.states;
}
2020-12-21 16:06:58 +01:00
inline void QskAspect::clearState( State state ) noexcept
{
m_bits.states &= ~state;
}
2017-07-21 18:21:34 +02:00
inline void QskAspect::clearStates( States states ) noexcept
2020-12-21 16:06:58 +01:00
{
m_bits.states &= ~states;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect::Primitive QskAspect::primitive() const noexcept
2020-12-21 16:06:58 +01:00
{
return static_cast< QskAspect::Primitive >( m_bits.primitive );
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline void QskAspect::setPrimitive( Type type, QskAspect::Primitive primitive ) noexcept
2020-12-21 16:06:58 +01:00
{
m_bits.type = type;
m_bits.primitive = primitive;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect::Primitive QskAspect::flagPrimitive() const noexcept
2020-12-21 16:06:58 +01:00
{
return ( m_bits.type == Flag )
2021-08-04 09:31:16 +02:00
? static_cast< Primitive >( m_bits.primitive ) : NoPrimitive;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect::Primitive QskAspect::colorPrimitive() const noexcept
2020-12-21 16:06:58 +01:00
{
return ( m_bits.type == Color )
2021-08-04 09:31:16 +02:00
? static_cast< Primitive >( m_bits.primitive ) : NoPrimitive;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect::Primitive QskAspect::metricPrimitive() const noexcept
2020-12-21 16:06:58 +01:00
{
return ( m_bits.type == Metric )
? static_cast< Primitive >( m_bits.primitive ) : NoPrimitive;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline void QskAspect::clearPrimitive() noexcept
{
m_bits.primitive = NoPrimitive;
2020-12-21 16:06:58 +01:00
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect::Placement QskAspect::placement() const noexcept
{
return static_cast< Placement >( m_bits.placement );
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline void QskAspect::setPlacement( Placement placement ) noexcept
{
m_bits.placement = placement;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::State state, const QskAspect& aspect ) noexcept
{
return aspect | state;
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect operator|(
QskAspect::States states, const QskAspect& aspect ) noexcept
{
return aspect | states;
}
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, const QskAspect& aspect ) noexcept
{
return aspect | subControl;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Type type, const QskAspect& aspect ) noexcept
{
return aspect | type;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Placement placement, const QskAspect& aspect ) noexcept
{
return aspect | placement;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, QskAspect::Type type ) noexcept
{
return QskAspect( subControl ) | type;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Type type, QskAspect::Subcontrol subControl ) noexcept
{
return subControl | type;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, QskAspect::State state ) noexcept
{
return QskAspect( subControl ) | state;
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, QskAspect::States states ) noexcept
{
return QskAspect( subControl ) | states;
}
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Type type, QskAspect::Placement placement ) noexcept
{
return QskAspect( type ) | placement;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Placement placement, QskAspect::Type type ) noexcept
{
return type | placement;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::State state, QskAspect::Subcontrol subControl ) noexcept
{
return subControl | state;
}
2017-07-21 18:21:34 +02:00
inline constexpr QskAspect operator|(
QskAspect::States states, QskAspect::Subcontrol subControl ) noexcept
{
return subControl | states;
}
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, QskAspect::Primitive primitive ) noexcept
2020-12-21 16:06:58 +01:00
{
return QskAspect( subControl ) | primitive;
}
2017-07-21 18:21:34 +02:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Primitive primitive, QskAspect::Subcontrol subControl ) noexcept
2020-12-21 16:06:58 +01:00
{
return subControl | primitive;
}
2020-12-18 13:09:22 +01:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Subcontrol subControl, QskAspect::Placement placement ) noexcept
{
return QskAspect( subControl ) | placement;
}
2020-12-18 13:09:22 +01:00
2020-12-21 16:06:58 +01:00
inline constexpr QskAspect operator|(
QskAspect::Placement placement, QskAspect::Subcontrol subControl ) noexcept
{
return subControl | placement;
2017-07-21 18:21:34 +02:00
}
namespace std
{
2020-12-21 16:06:58 +01:00
template< > struct hash< QskAspect >
2017-07-21 18:21:34 +02:00
{
2020-12-21 16:06:58 +01:00
constexpr size_t operator()( const QskAspect& aspect ) const noexcept
2017-07-21 18:21:34 +02:00
{
return aspect.value();
}
};
}
2022-03-29 08:08:06 +02:00
inline QskHashValue qHash( const QskAspect aspect, QskHashValue seed = 0 ) noexcept
{
return qHash( aspect.value(), seed );
}
2017-07-21 18:21:34 +02:00
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
2020-12-21 16:06:58 +01:00
QSK_EXPORT QDebug operator<<( QDebug, QskAspect );
2020-12-18 13:09:22 +01:00
QSK_EXPORT QDebug operator<<( QDebug, QskAspect::Type );
QSK_EXPORT QDebug operator<<( QDebug, QskAspect::Subcontrol );
QSK_EXPORT QDebug operator<<( QDebug, QskAspect::Primitive );
2020-12-18 13:09:22 +01:00
QSK_EXPORT QDebug operator<<( QDebug, QskAspect::Placement );
QSK_EXPORT QDebug operator<<( QDebug, QskAspect::States );
2017-07-21 18:21:34 +02:00
QSK_EXPORT void qskDebugStates( QDebug, const QMetaObject*, QskAspect::States );
2020-12-21 16:06:58 +01:00
QSK_EXPORT void qskDebugAspect( QDebug, const QMetaObject*, QskAspect );
2017-07-21 18:21:34 +02:00
#endif
#define QSK_SUBCONTROL( type, name ) \
const QskAspect::Subcontrol type::name = \
QskAspect::nextSubcontrol( &type::staticMetaObject, #type "::" #name );
#define QSK_STATE( type, name, value ) \
2019-04-02 17:50:08 +02:00
static_assert( \
2021-07-14 14:43:12 +02:00
( ( value ) >= QskAspect::FirstUserState ) && ( ( value ) <= QskAspect::LastUserState ), \
2019-04-02 17:50:08 +02:00
"Invalid state" \
); \
2017-07-21 18:21:34 +02:00
const QskAspect::State type::name = \
QskAspect::registerState( &type::staticMetaObject, value, #type "::" #name );
2018-10-03 14:24:25 +02:00
2019-04-02 17:50:08 +02:00
#define QSK_SYSTEM_STATE( type, name, value ) \
static_assert( \
2021-07-14 14:43:12 +02:00
( ( value ) >= QskAspect::FirstSystemState && ( value ) < QskAspect::FirstUserState ) || \
( ( value ) > QskAspect::LastUserState && ( value ) <= QskAspect::LastSystemState ), \
"Invalid system state" \
); \
2019-04-02 17:50:08 +02:00
const QskAspect::State type::name = \
QskAspect::registerState( &type::staticMetaObject, value, #type "::" #name );
2020-12-05 15:09:31 +01:00
2019-01-04 13:42:16 +01:00
#if !defined( _MSC_VER )
2018-10-03 14:24:25 +02:00
#define QSK_SUBCONTROLS( ... ) static const QskAspect::Subcontrol __VA_ARGS__;
#define QSK_STATES( ... ) static const QskAspect::State __VA_ARGS__;
#else
/*
Working around a MSVC bug: when static member are defined in one statement
only the first one is exported. Unfortuately the code below is also not
compliant with ISO C++11 and gcc -pedantic f.e. would fail.
*/
#define _QSK_EXPAND(x) x
#define _QSK_EVAL_0( m, x, ... ) m(x)
#define _QSK_EVAL_1( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_0( m, __VA_ARGS__ ) )
#define _QSK_EVAL_2( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_1( m, __VA_ARGS__ ) )
#define _QSK_EVAL_3( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_2( m, __VA_ARGS__ ) )
#define _QSK_EVAL_4( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_3( m, __VA_ARGS__ ) )
#define _QSK_EVAL_5( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_4( m, __VA_ARGS__ ) )
#define _QSK_EVAL_6( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_5( m, __VA_ARGS__ ) )
#define _QSK_EVAL_7( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_6( m, __VA_ARGS__ ) )
#define _QSK_EVAL_8( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_7( m, __VA_ARGS__ ) )
#define _QSK_EVAL_9( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_8( m, __VA_ARGS__ ) )
#define _QSK_EVAL_A( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_9( m, __VA_ARGS__ ) )
#define _QSK_EVAL_B( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_A( m, __VA_ARGS__ ) )
#define _QSK_EVAL_C( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_B( m, __VA_ARGS__ ) )
#define _QSK_EVAL_D( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_C( m, __VA_ARGS__ ) )
#define _QSK_EVAL_E( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_D( m, __VA_ARGS__ ) )
#define _QSK_EVAL_F( m, x, ... ) m(x) _QSK_EXPAND( _QSK_EVAL_E( m, __VA_ARGS__ ) )
#define _QSK_EVAL_NARG( ... ) _QSK_EVAL_NARG_( __VA_ARGS__, _QSK_EVAL_RSEQ_N() )
#define _QSK_EVAL_NARG_( ... ) _QSK_EXPAND( _QSK_EVAL_ARG_N( __VA_ARGS__ ) )
#define _QSK_EVAL_ARG_N( _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, A, B, C, D, E, F, N, ... ) N
#define _QSK_EVAL_RSEQ_N() F, E, D, C, B, A, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
2019-01-04 13:42:16 +01:00
#define _QSK_CAT(x,y) x ## y
2018-10-03 14:24:25 +02:00
#define _QSK_EVAL_( N, m, ... ) _QSK_EXPAND( _QSK_CAT( _QSK_EVAL_, N )( m, __VA_ARGS__ ) )
#define _QSK_EVAL( m, ... ) _QSK_EVAL_( _QSK_EVAL_NARG( __VA_ARGS__ ), m, __VA_ARGS__ )
#define _QSK_SUBCONTROLS_HELPER( name ) static const QskAspect::Subcontrol name;
#define QSK_SUBCONTROLS( ... ) _QSK_EVAL( _QSK_SUBCONTROLS_HELPER, __VA_ARGS__ )
#define _QSK_STATES_HELPER( name ) static const QskAspect::State name;
#define QSK_STATES( ... ) _QSK_EVAL( _QSK_STATES_HELPER, __VA_ARGS__ )
#endif
2017-07-21 18:21:34 +02:00
#endif