swift
namevariantpair.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_NAMEVARIANTPAIR_H
7 #define SWIFT_MISC_NAMEVARIANTPAIR_H
8 
9 #include <QMetaType>
10 #include <QString>
11 
12 #include "misc/metaclass.h"
13 #include "misc/propertyindexref.h"
14 #include "misc/swiftmiscexport.h"
15 #include "misc/valueobject.h"
16 #include "misc/variant.h"
17 
19 
20 namespace swift::misc
21 {
23  class SWIFT_MISC_EXPORT CNameVariantPair : public CValueObject<CNameVariantPair>
24  {
25  public:
28  {
29  IndexName = swift::misc::CPropertyIndexRef::GlobalIndexCNameVariantPair,
30  IndexVariant
31  };
32 
34  CNameVariantPair() = default;
35 
37  CNameVariantPair(const QString &name, const CVariant &variant, const CIcon &icon = CIcon());
38 
40  const QString &getName() const { return m_name; }
41 
43  CVariant getVariant() const { return m_variant; }
44 
46  void setName(const QString &name) { this->m_name = name; }
47 
49  bool hasName() const { return !this->m_name.isEmpty(); }
50 
52  void setVariant(const CVariant &variant) { m_variant = variant; }
53 
55  swift::misc::CIcons::IconIndex toIcon() const;
56 
58  bool hasIcon() const;
59 
61  QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const;
62 
64  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
65 
67  QString convertToQString(bool i18n = false) const;
68 
69  private:
70  QString m_name;
71  CVariant m_variant;
72  CIcon m_icon;
73 
76  SWIFT_METAMEMBER(name),
77  SWIFT_METAMEMBER(variant),
78  SWIFT_METAMEMBER(icon));
79  };
80 } // namespace swift::misc
81 
82 Q_DECLARE_METATYPE(swift::misc::CNameVariantPair)
83 
84 #endif // SWIFT_MISC_NAMEVARIANTPAIR_H
Value object for icons. An icon is stored in the global icon repository and identified by its index....
Definition: icon.h:39
IconIndex
Index for each icon, allows to send them via DBus, efficiently store them, etc.
Definition: icons.h:32
Value / variant pair.
void setVariant(const CVariant &variant)
Set variant.
CVariant getVariant() const
Get variant.
const QString & getName() const
Get name.
bool hasName() const
Name available?
void setName(const QString &name)
Set name.
CNameVariantPair()=default
Default constructor.
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition: metaclass.h:73
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition: metaclass.h:53
Free functions in swift::misc.
#define SWIFT_MISC_EXPORT
Export a class or function from the library.
#define SWIFT_DECLARE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template declaration of mixins for a CValueObject subclass to be placed near the top of the ...
Definition: valueobject.h:65