CopperSpice API  1.7.4
QFlags< E > Class Template Reference

Provides a type safe mechanism for representing bitwise-or combinations of enum values. More...

Public Typedefs

using enum_type = E
 

Public Methods

constexpr QFlags ()
 
constexpr QFlags (const QFlags &other)
 
constexpr QFlags (E value)
 
constexpr QFlags (EmptyFlag_Type)
 
constexpr QFlags (std::initializer_list< E > list)
 
constexpr QFlags (std::nullptr_t)
 
constexpr operator int_type () const
 
constexpr bool operator! () const
 
constexpr QFlags operator& (E value) const
 
constexpr QFlags operator& (sint_type mask) const
 
constexpr QFlags operator& (uint_type mask) const
 
QFlags & operator&= (sint_type mask)
 
QFlags & operator&= (uint_type mask)
 
QFlags & operator= (const QFlags &other)
 
constexpr QFlags operator^ (E value) const
 
constexpr QFlags operator^ (QFlags other) const
 
QFlags & operator^= (E value)
 
QFlags & operator^= (QFlags other)
 
constexpr QFlags operator| (E value) const
 
constexpr QFlags operator| (QFlags other) const
 
QFlags & operator|= (E value)
 
QFlags & operator|= (QFlags other)
 
constexpr QFlags operator~ () const
 
bool testFlag (E value) const
 

Detailed Description

template<typename E>
class QFlags< E >

The QFlags class provides a type safe mechanism for representing bitwise-or combinations of enum values. The QFlags<E> class is a template class, where E is an enum type.

The traditional C++ approach for storing bitwise-or combinations of enum values is to use an int or uint variable. The draw back with this approach is the inability to type check the bitwise-or combination of enum values.

QFlags enforces that enum values can only be combined with other values from the same enum. For example, QDir::Filters is a typedef for QFlags<QDir::Filter>. This allows code to safely bitwise-or any of the enum values to create a combination.

QDir object;
object->setFilter(QDir::Filters::Files | QDir::Filters::Dirs);

Example

To use QFlags with your own enum types add the using as shown below and call the Q_DECLARE_OPERATORS_FOR_FLAGS() macro. This allows using MyClass::Options to store combinations of MyClass::Option values.

class MyClass {
public:
enum Option {
NoOptions = 0x0,
ShowTabs = 0x1,
ShowAll = 0x2,
SqueezeBlank = 0x4
};
using Options = QFlags<Option>:
};
Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)

Member Typedef Documentation

template<typename E >
QFlags< E >::enum_type

Typedef for the E template type.

Constructor & Destructor Documentation

template<typename E >
constexpr QFlags< E >::QFlags ( )
inlineconstexpr

Constructs a QFlags object with no flags set.

template<typename E >
constexpr QFlags< E >::QFlags ( EmptyFlag_Type  )
inlineconstexpr

Constructs a QFlags object with no flags set.

QFlags<WindowType> type = Qt::EmptyFlag;
template<typename E >
constexpr QFlags< E >::QFlags ( std::nullptr_t  )
inlineconstexpr

Constructs a QFlags object with no flags set.

Note
This constructor should not be used and may be deprecated in a future release. Use the QFlags(EmptyFlag_Type) constructor instead.
template<typename E >
constexpr QFlags< E >::QFlags ( std::initializer_list< E >  list)
inlineconstexpr

Constructs a QFlags object using the values in list.

template<typename E >
constexpr QFlags< E >::QFlags ( value)
inlineconstexpr

Constructs a QFlags object storing the given value.

template<typename E >
constexpr QFlags< E >::QFlags ( const QFlags< E > &  other)
inlineconstexpr

Copy constructs a new QFlags from other.

Method Documentation

template<typename E >
constexpr QFlags< E >::operator int_type ( ) const
inlineconstexpr

Returns the value stored in the QFlags object as an integer.

template<typename E >
constexpr bool QFlags< E >::operator! ( ) const
inlineconstexpr

Returns true if no flag is set, otherwise returns false.

template<typename E >
constexpr QFlags QFlags< E >::operator& ( value) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise AND operation on this object and value.

template<typename E >
constexpr QFlags QFlags< E >::operator& ( sint_type  mask) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise AND operation on this object and mask.

See also
operator&=(), operator|(), operator^(), operator~()
template<typename E >
constexpr QFlags QFlags< E >::operator& ( uint_type  mask) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise AND operation on this object and mask.

template<typename E >
QFlags & QFlags< E >::operator&= ( sint_type  mask)
inline

Performs a bitwise AND operation with mask and stores the result in this QFlags object. Returns a reference to this object.

See also
operator&(), operator|=(), operator^=()
template<typename E >
QFlags & QFlags< E >::operator&= ( uint_type  mask)
inline

Performs a bitwise AND operation with mask and stores the result in this QFlags object. Returns a reference to this object.

template<typename E >
QFlags & QFlags< E >::operator= ( const QFlags< E > &  other)
inline

Copy assigns from other and returns a reference to this object.

template<typename E >
constexpr QFlags QFlags< E >::operator^ ( value) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise XOR operation on this object and value.

template<typename E >
constexpr QFlags QFlags< E >::operator^ ( QFlags< E >  other) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise XOR operation on this object and other.

See also
operator^=(), operator&(), operator|(), operator~()
template<typename E >
QFlags & QFlags< E >::operator^= ( value)
inline

Performs a bitwise XOR operation with value and stores the result in this QFlags object. Returns a reference to this object.

template<typename E >
QFlags & QFlags< E >::operator^= ( QFlags< E >  other)
inline

Performs a bitwise XOR operation with other and stores the result in this QFlags object. Returns a reference to this object.

See also
operator^(), operator&=(), operator|=()
template<typename E >
constexpr QFlags QFlags< E >::operator| ( value) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise OR operation on this object and value.

template<typename E >
constexpr QFlags QFlags< E >::operator| ( QFlags< E >  other) const
inlineconstexpr

Returns a QFlags object containing the result of the bitwise OR operation on this object and other.

See also
operator|=(), operator^(), operator&(), operator~()
template<typename E >
QFlags & QFlags< E >::operator|= ( value)
inline

Performs a bitwise OR operation with value and stores the result in this QFlags object. Returns a reference to this object.

template<typename E >
QFlags & QFlags< E >::operator|= ( QFlags< E >  other)
inline

Performs a bitwise OR operation with other and stores the result in this QFlags object. Returns a reference to this object.

See also
operator|(), operator&=(), operator^=()
template<typename E >
constexpr QFlags QFlags< E >::operator~ ( ) const
inlineconstexpr

Returns a QFlags object that contains the bitwise negation of this object.

See also
operator&(), operator|(), operator^()
template<typename E >
bool QFlags< E >::testFlag ( value) const
inline

Returns true if the value is set, otherwise false.