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
31 public:
32 //
33 // This enumeration contains the supported modes, to complement this
34 // an array of human readable strings in the implementation
35 // (Modes.cpp) must be maintained in parallel.
36 //
37 enum Mode {
38 ALL, // matches with all modes
39 JS8,
40 MODES_END_SENTINAL_AND_COUNT // this must be last
41 };
42 Q_ENUM(Mode)
43
44 explicit Modes(QObject *parent = nullptr);
45
46 // translate between enumeration and human readable strings
47 static char const *name(Mode);
48 static Mode value(QString const &);
49
50 // Implement the QAbstractListModel interface
51 int rowCount(QModelIndex const &parent = QModelIndex{}) const override {
52 return parent.isValid()
53 ? 0
54 : MODES_END_SENTINAL_AND_COUNT; // Number of modes in Mode
55 // enumeration class
56 }
57 QVariant data(QModelIndex const &,
58 int role = Qt::DisplayRole) const override;
59 QVariant headerData(int section, Qt::Orientation,
60 int = Qt::DisplayRole) const override;
61};
62
63// Qt boilerplate to make the Modes::Mode enumeration a type that can
64// be streamed and queued as a signal argument as well as showing the
65// human readable string when output to debug streams.
66#if !defined(QT_NO_DEBUG_STREAM)
67ENUM_QDEBUG_OPS_DECL(Modes, Mode);
68#endif
69
70ENUM_QDATASTREAM_OPS_DECL(Modes, Mode);
71ENUM_CONVERSION_OPS_DECL(Modes, Mode);
72
73#endif
Definition Modes.h:28