aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qiviabstractfeature/qivifeaturetester.h
blob: b8b78b960fac00e232f6c434e9d87aca9a16d893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/****************************************************************************
**
** Copyright (C) 2019 Luxoft Sweden AB
** Copyright (C) 2018 Pelagicore AG
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtIvi module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$
** Commercial License Usage
** Licensees holding valid commercial Qt Automotive Suite licenses may use
** this file in accordance with the commercial license agreement provided
** with the Software or, alternatively, in accordance with the terms
** contained in a written agreement between you and The Qt Company.  For
** licensing terms and conditions see https://www.qt.io/terms-conditions.
** For further information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#ifndef QIVIFEATURETESTER_H
#define QIVIFEATURETESTER_H

#include <QIviAbstractFeature>
#include <QIviAbstractFeatureListModel>

QT_BEGIN_NAMESPACE

class QIviFeatureTester : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QIviAbstractFeature::DiscoveryMode discoveryMode READ discoveryMode WRITE setDiscoveryMode NOTIFY discoveryModeChanged)
    Q_PROPERTY(QIviAbstractFeature::DiscoveryResult discoveryResult READ discoveryResult NOTIFY discoveryResultChanged)
    Q_PROPERTY(QIviServiceObject *serviceObject READ serviceObject WRITE setServiceObject NOTIFY serviceObjectChanged)
    Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
    Q_PROPERTY(bool isInitialized READ isInitialized NOTIFY isInitializedChanged)
    Q_PROPERTY(QString error READ errorMessage NOTIFY errorChanged)

public:
    explicit QIviFeatureTester(QIviAbstractFeature *feature, QObject *parent = nullptr)
        : QObject(parent)
        , m_feature(feature)
        , m_featureListModel(nullptr)
    {
        connect(m_feature, &QIviAbstractFeature::discoveryModeChanged, this, &QIviFeatureTester::discoveryModeChanged);
        connect(m_feature, &QIviAbstractFeature::discoveryResultChanged, this, &QIviFeatureTester::discoveryResultChanged);
        connect(m_feature, &QIviAbstractFeature::serviceObjectChanged, this, &QIviFeatureTester::serviceObjectChanged);
        connect(m_feature, &QIviAbstractFeature::isValidChanged, this, &QIviFeatureTester::isValidChanged);
        connect(m_feature, &QIviAbstractFeature::isInitializedChanged, this, &QIviFeatureTester::isInitializedChanged);
        connect(m_feature, &QIviAbstractFeature::errorChanged, this, &QIviFeatureTester::errorChanged);
    }

    explicit QIviFeatureTester(QIviAbstractFeatureListModel *featureModel, QObject *parent = nullptr)
        : QObject(parent)
        , m_feature(nullptr)
        , m_featureListModel(featureModel)
    {
        connect(m_featureListModel, &QIviAbstractFeatureListModel::discoveryModeChanged, this, &QIviFeatureTester::discoveryModeChanged);
        connect(m_featureListModel, &QIviAbstractFeatureListModel::discoveryResultChanged, this, &QIviFeatureTester::discoveryResultChanged);
        connect(m_featureListModel, &QIviAbstractFeatureListModel::serviceObjectChanged, this, &QIviFeatureTester::serviceObjectChanged);
        connect(m_featureListModel, &QIviAbstractFeatureListModel::isValidChanged, this, &QIviFeatureTester::isValidChanged);
        connect(m_featureListModel, &QIviAbstractFeatureListModel::isInitializedChanged, this, &QIviFeatureTester::isInitializedChanged);
        connect(m_featureListModel, &QIviAbstractFeatureListModel::errorChanged, this, &QIviFeatureTester::errorChanged);
    }

    QIviServiceObject *serviceObject() const
    {
        return m_feature ? m_feature->serviceObject() : m_featureListModel->serviceObject();
    }

    QIviAbstractFeature::DiscoveryMode discoveryMode() const
    {
        return m_feature ? m_feature->discoveryMode() : m_featureListModel->discoveryMode();
    }

    QIviAbstractFeature::DiscoveryResult discoveryResult() const
    {
        return m_feature ? m_feature->discoveryResult() : m_featureListModel->discoveryResult();
    }

    bool isValid() const
    {
        return m_feature ? m_feature->isValid() : m_featureListModel->isValid();
    }

    bool isInitialized() const
    {
        return m_feature ? m_feature->isInitialized() : m_featureListModel->isInitialized();
    }

    QIviAbstractFeature::Error error() const
    {
        return m_feature ? m_feature->error() : m_featureListModel->error();
    }

    QString errorMessage() const
    {
        return m_feature ? m_feature->errorMessage() : m_featureListModel->errorMessage();
    }

    QString errorText() const
    {
        return m_feature ? m_feature->errorText() : m_featureListModel->errorText();
    }

public Q_SLOTS:
    bool setServiceObject(QIviServiceObject *so)
    {
        return m_feature ? m_feature->setServiceObject(so) : m_featureListModel->setServiceObject(so);
    }
    void setDiscoveryMode(QIviAbstractFeature::DiscoveryMode discoveryMode)
    {
        return m_feature ? m_feature->setDiscoveryMode(discoveryMode) : m_featureListModel->setDiscoveryMode(discoveryMode);
    }
    QIviAbstractFeature::DiscoveryResult startAutoDiscovery()
    {
        return m_feature ? m_feature->startAutoDiscovery() : m_featureListModel->startAutoDiscovery();
    }

Q_SIGNALS:
    void serviceObjectChanged();
    void discoveryModeChanged(QIviAbstractFeature::DiscoveryMode discoveryMode);
    void discoveryResultChanged(QIviAbstractFeature::DiscoveryResult discoveryResult);
    void isValidChanged(bool arg);
    void isInitializedChanged(bool isInitialized);
    void errorChanged(QIviAbstractFeature::Error error, const QString &message);

private:
    QIviAbstractFeature *m_feature;
    QIviAbstractFeatureListModel *m_featureListModel;
};

QT_END_NAMESPACE

#endif // QIVIFEATURETESTER_H