MythTV  master
enum.h
Go to the documentation of this file.
1 // Program Name: enum.h
3 // Created : July 25, 2014
4 //
5 // Copyright (c) 2014 David Blain <dblain@mythtv.org>
6 //
7 // Licensed under the GPL v2 or later, see LICENSE for details
8 //
10 
11 #ifndef ENUMLIST_H_
12 #define ENUMLIST_H_
13 
14 #include <QVariantList>
15 
19 
20 namespace DTC
21 {
22 
23 class SERVICE_PUBLIC Enum : public QObject
24 {
25  Q_OBJECT
26  Q_CLASSINFO( "version", "1.0" );
27 
28  // Q_CLASSINFO Used to augment Metadata for properties.
29  // See datacontracthelper.h for details
30 
31  Q_CLASSINFO( "EnumItems", "type=DTC::Enum");
32 
33  Q_PROPERTY( QString Type READ Type WRITE setType )
34  Q_PROPERTY( QVariantList EnumItems READ EnumItems )
35 
36 
37  PROPERTYIMP_REF ( QString , Type )
38  PROPERTYIMP_RO_REF( QVariantList, EnumItems )
39 
40  public:
41 
42  static inline void InitializeCustomTypes();
43 
44  Q_INVOKABLE explicit Enum(QObject *parent = nullptr)
45  : QObject( parent )
46  {
47  }
48 
49  void Copy( const Enum *src )
50  {
51  m_Type = src->m_Type;
52 
53  CopyListContents< EnumItem >( this, m_EnumItems, src->m_EnumItems );
54  }
55 
57  {
58  // We must make sure the object added to the QVariantList has
59  // a parent of 'this'
60 
61  auto *pObject = new EnumItem( this );
62  m_EnumItems.append( QVariant::fromValue<QObject *>( pObject ));
63 
64  return pObject;
65  }
66 
67  private:
68  Q_DISABLE_COPY(Enum);
69 };
70 
72 {
73  qRegisterMetaType< Enum* >();
74 
76 }
77 
78 } // namespace DTC
79 
80 #endif
DTC::EnumItem
Definition: enumItem.h:20
DTC::EnumItem::InitializeCustomTypes
static void InitializeCustomTypes()
Definition: enumItem.h:54
SERVICE_PUBLIC
#define SERVICE_PUBLIC
Definition: serviceexp.h:9
enumItem.h
PROPERTYIMP_RO_REF
#define PROPERTYIMP_RO_REF(type, name)
Definition: datacontracthelper.h:114
datacontracthelper.h
serviceexp.h
DTC::Enum::InitializeCustomTypes
static void InitializeCustomTypes()
Definition: enum.h:71
DTC::Enum
Definition: enum.h:23
DTC::Enum::Copy
void Copy(const Enum *src)
Definition: enum.h:49
DTC
Definition: datacontracthelper.h:123
PROPERTYIMP_REF
#define PROPERTYIMP_REF(type, name)
Definition: datacontracthelper.h:70
DTC::Enum::AddNewEnum
EnumItem * AddNewEnum()
Definition: enum.h:56