Dokit
dev
v0.6.0
v0.5.8
v0.5.7
v0.5.6
v0.5.5
v0.5.4
v0.5.3
v0.5.2
v0.5.1
v0.5.0
v0.4.0
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
User docs
Internal
Coverage
Internal development documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
abstractcommand.h
1
// SPDX-FileCopyrightText: 2022-2026 Paul Colby <git@colby.id.au>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
4
#ifndef DOKIT_ABSTRACTCOMMAND_H
5
#define DOKIT_ABSTRACTCOMMAND_H
6
7
#include <
qtpokit/qtpokit_global.h
>
8
9
#include <QBluetoothDeviceInfo>
10
#include <QCommandLineParser>
11
#include <QLoggingCategory>
12
#include <QObject>
13
14
QTPOKIT_FORWARD_DECLARE_CLASS
(
PokitDiscoveryAgent
)
15
16
class
AbstractCommand
: public
QObject
17
{
18
Q_OBJECT
19
20
public
:
21
/// Supported output formats.
22
enum class
OutputFormat
{
23
Csv,
///< RFC 4180 compliant CSV text.
24
Json,
///< RFC 8259 compliant JSON text.
25
Text,
///< Plain unstructured text.
26
};
27
28
explicit
AbstractCommand
(
QObject
*
const
parent =
nullptr
);
29
30
virtual
QStringList
requiredOptions(
const
QCommandLineParser
&parser)
const
;
31
virtual
QStringList
supportedOptions(
const
QCommandLineParser
&parser)
const
;
32
33
static
QString
appendSiPrefix(
const
double
value,
int
precision = 6);
34
static
QString
escapeCsvField(
const
QString
&field);
35
36
template
<
typename
R,
typename
T = qu
int
32>
37
static
T parseNumber(
const
QString
&value,
const
QString
&unit,
const
T sensibleMinimum = 0);
38
39
public
slots:
40
virtual
QStringList
processOptions(
const
QCommandLineParser
&parser);
41
virtual
bool
start
() = 0;
42
43
protected
:
44
QString
deviceToScanFor
;
///< Device (if any) that were passed to processOptions().
45
PokitDiscoveryAgent
*
discoveryAgent
;
///< Agent for Pokit device discovery.
46
OutputFormat
format
{
OutputFormat::Text
};
///< Selected output format.
47
static
Q_LOGGING_CATEGORY
(lc,
"dokit.cli.command"
, QtInfoMsg);
///< Logging category for UI commands.
48
49
protected
slots:
50
virtual
void
deviceDiscovered
(
const
QBluetoothDeviceInfo
&info) = 0;
51
virtual
void
deviceDiscoveryFinished
() = 0;
52
53
QTPOKIT_BEFRIEND_TEST
(
AbstractCommand
)
54
};
55
56
#endif
// DOKIT_ABSTRACTCOMMAND_H
AbstractCommand::deviceToScanFor
QString deviceToScanFor
Device (if any) that were passed to processOptions().
Definition
abstractcommand.h:44
AbstractCommand::AbstractCommand
AbstractCommand(QObject *const parent=nullptr)
Constructs a new command with parent.
Definition
abstractcommand.cpp:28
AbstractCommand::deviceDiscovered
virtual void deviceDiscovered(const QBluetoothDeviceInfo &info)=0
Handles PokitDiscoveryAgent::pokitDeviceDiscovered signal.
AbstractCommand::discoveryAgent
PokitDiscoveryAgent * discoveryAgent
Agent for Pokit device discovery.
Definition
abstractcommand.h:45
AbstractCommand::format
OutputFormat format
Selected output format.
Definition
abstractcommand.h:46
AbstractCommand::OutputFormat
OutputFormat
Supported output formats.
Definition
abstractcommand.h:22
AbstractCommand::OutputFormat::Text
@ Text
Plain unstructured text.
Definition
abstractcommand.h:25
AbstractCommand::Q_LOGGING_CATEGORY
static Q_LOGGING_CATEGORY(lc, "dokit.cli.command", QtInfoMsg)
Logging category for UI commands.
AbstractCommand::start
virtual bool start()=0
Begins the functionality of this command, and returns true if begun successfully, false otherwise.
AbstractCommand::deviceDiscoveryFinished
virtual void deviceDiscoveryFinished()=0
Handles PokitDiscoveryAgent::deviceDiscoveryFinished signal.
PokitDiscoveryAgent
The PokitDiscoveryAgent class discovers nearby Pokit devices.
Definition
pokitdiscoveryagent.h:21
QBluetoothDeviceInfo
QCommandLineParser
QObject
QObject::QObject
QObject(QObject *parent)
QObject::Q_OBJECT
Q_OBJECTQ_OBJECT
QString
QStringList
qtpokit_global.h
Global QtPokit library macros.
QTPOKIT_FORWARD_DECLARE_CLASS
#define QTPOKIT_FORWARD_DECLARE_CLASS(name)
Macro for forward declaring classes in the QtPokit library's top-most namespace (if one is defined).
Definition
qtpokit_global.h:94
QTPOKIT_BEFRIEND_TEST
#define QTPOKIT_BEFRIEND_TEST(Class)
Macro for befriending a related unit test class, but only when QT_TESTLIB_LIB is defined.
Definition
qtpokit_global.h:118
dokit
dokit
src
cli
abstractcommand.h
Generated by
1.18.0