JS8Call-Improved master
Loading...
Searching...
No Matches
Modes.h
1#ifndef MODES_HPP__
2#define MODES_HPP__
3
4#include "qt_helpers.h"
5
6#include <QAbstractListModel>
7
8class QString;
9class QVariant;
10class QModelIndex;
11
12//
13// Class Modes - Qt model that implements a list of data modes
14//
15//
16// Responsibilities
17//
18// Provides a single column list model that contains the human
19// readable string version of the data mode in the display role. Also
20// provided is a translatable column header string and tool tip
21// string.
22//
23//
24// Collaborations
25//
26// Implements a concrete sub-class of the QAbstractListModel class.
27//
28class Modes final : public QAbstractListModel {
29 Q_OBJECT
30 Q_ENUMS(Mode)
31
32 public:
33 //
34 // This enumeration contains the supported modes, to complement this
35 // an array of human readable strings in the implementation
36 // (Modes.cpp) must be maintained in parallel.
37 //
38 enum Mode {
39 ALL, // matches with all modes
40 JS8,
41 MODES_END_SENTINAL_AND_COUNT // this must be last
42 };
43 Q_ENUM(Mode)
44
45 explicit Modes(QObject *parent = nullptr);
46
47 // translate between enumeration and human readable strings
48 static char const *name(Mode);
49 static Mode value(QString const &);
50
51 // Implement the QAbstractListModel interface
52 int rowCount(QModelIndex const &parent = QModelIndex{}) const override {
53 return parent.isValid()
54 ? 0
55 : MODES_END_SENTINAL_AND_COUNT; // Number of modes in Mode
56 // enumeration class
57 }
58 QVariant data(QModelIndex const &,
59 int role = Qt::DisplayRole) const override;
60 QVariant headerData(int section, Qt::Orientation,
61 int = Qt::DisplayRole) const override;
62};
63
64// Qt boilerplate to make the Modes::Mode enumeration a type that can
65// be streamed and queued as a signal argument as well as showing the
66// human readable string when output to debug streams.
67#if QT_VERSION < 0x050500
68// Qt 5.5 introduces the Q_ENUM macro which automatically registers
69// the meta-type
70Q_DECLARE_METATYPE(Modes::Mode);
71#endif
72
73#if !defined(QT_NO_DEBUG_STREAM)
74ENUM_QDEBUG_OPS_DECL(Modes, Mode);
75#endif
76
77ENUM_QDATASTREAM_OPS_DECL(Modes, Mode);
78ENUM_CONVERSION_OPS_DECL(Modes, Mode);
79
80#endif
Definition Modes.h:28