swift
joystickbutton.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 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_INPUT_JOYSTICKBUTTON_H
7 #define SWIFT_MISC_INPUT_JOYSTICKBUTTON_H
8 
9 #include <QMetaType>
10 #include <QString>
11 #include <QtGlobal>
12 
13 #include "misc/metaclass.h"
14 #include "misc/propertyindexref.h"
15 #include "misc/swiftmiscexport.h"
16 #include "misc/valueobject.h"
17 
18 SWIFT_DECLARE_VALUEOBJECT_MIXINS(swift::misc::input, CJoystickButton)
19 
20 namespace swift::misc::input
21 {
23  class SWIFT_MISC_EXPORT CJoystickButton : public CValueObject<CJoystickButton>
24  {
25  public:
28  {
29  IndexDeviceName = CPropertyIndexRef::GlobalIndexCJoystickButton,
30  IndexButton,
31  IndexButtonAsString,
32  IndexButtonObject, // just for updates
33  };
34 
36  CJoystickButton() = default;
37 
39  CJoystickButton(const QString &deviceName, int index);
40 
42  QString getDeviceName() const { return m_deviceName; }
43 
45  int getButtonIndex() const { return m_buttonIndex; }
46 
48  QString getButtonAsString() const { return buttonIndexToString(m_buttonIndex); }
49 
51  QString getButtonAsStringWithDeviceName() const;
52 
54  void setDeviceName(const QString &deviceName) { m_deviceName = deviceName; }
55 
57  void setButtonIndex(int buttonIndex);
58 
60  bool isValid() const;
61 
63  void setButtonObject(CJoystickButton button);
64 
66  void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant);
67 
69  QVariant propertyByIndex(CPropertyIndexRef index) const;
70 
72  static QString buttonIndexToString(qint32 buttonIndex);
73 
75  static int buttonIndexFromString(const QString &button);
76 
78  static int getInvalidIndex() { return InvalidButtonIndex; }
79 
81  QString convertToQString(bool i18n = false) const;
82 
83  private:
84  static const QString &buttonIndentifier()
85  {
86  static const QString bn("Button");
87  return bn;
88  }
89  static constexpr int InvalidButtonIndex = -1;
90 
91  QString m_deviceName;
92  int m_buttonIndex = InvalidButtonIndex;
93 
95  CJoystickButton,
96  SWIFT_METAMEMBER(deviceName),
97  SWIFT_METAMEMBER(buttonIndex));
98  };
99 } // namespace swift::misc::input
100 
101 Q_DECLARE_METATYPE(swift::misc::input::CJoystickButton)
102 
103 #endif // SWIFT_MISC_INPUT_JOYSTICKBUTTON_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Mix of the most commonly used mixin classes.
Definition: valueobject.h:114
Value object representing a joystick button.
CJoystickButton()=default
Default constructor.
void setDeviceName(const QString &deviceName)
Set owning device name.
int getButtonIndex() const
Get button index.
static int getInvalidIndex()
Invalid button index.
QString getButtonAsString() const
Get button as String.
QString getDeviceName() const
Get device name.
#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
#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