PdQmlWidgets  2.0.0
ScalarVariant.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2018-2021 Wilhelm Hagemeister<hm@igh.de>
4  * 2018-2022 Florian Pose <fp@igh.de>
5  *
6  * This file is part of the PdQmlWidgets library.
7  *
8  * The PdQmlWidgets library is free software: you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License as
10  * published by the Free Software Foundation, either version 3 of the License,
11  * or (at your option) any later version.
12  *
13  * The PdQmlWidgets library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with the PdQmlWidgets Library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  ****************************************************************************/
23 
24 #ifndef PD_SCALARVARIANT_H
25 #define PD_SCALARVARIANT_H
26 
27 #include <QtPdCom1/ScalarSubscriber.h>
28 #include <QtPdCom1/Process.h>
29 
30 #include <QScopedPointer>
31 #include <QObject>
32 #include <QVariant>
33 
34 
35 namespace PdQmlWidgets {
36 
37 class ScalarVariantPrivate;
38 
39 /****************************************************************************/
40 
45 class Q_DECL_EXPORT ScalarVariant:
46  public QObject, public QtPdCom::ScalarSubscriber
47 {
48  Q_OBJECT
49  Q_PROPERTY(QString path READ getPath WRITE setPath NOTIFY pathChanged)
59  Q_PROPERTY(QVariant connection READ getConnection WRITE setConnection NOTIFY connectionUpdated)
60 
61  /* indicates that the process is connected and data is transfered */
62  Q_PROPERTY(bool connected READ getDataPresent NOTIFY dataPresentChanged)
63 
64  Q_PROPERTY(QVariant value READ getValue WRITE setValue NOTIFY valueChanged)
65  Q_PROPERTY(double mtime READ getMTimeToDouble NOTIFY valueUpdated)
66  public:
67  ScalarVariant(QObject *parent = nullptr);
68  virtual ~ScalarVariant();
69 
70  QString getPath() const;
71  Q_INVOKABLE bool getDataPresent() const;
72  QVariant getConnection() const;
73 
74  void clearData(); // pure-virtual from ScalarSubscriber
75  Q_INVOKABLE bool hasData() const;
76  QtPdCom::Process *getProcess() const;
77 
78  void setPath(QString);
79  void setConnection(QVariant);
80 
81  void setProcess(QtPdCom::Process *);
82  QVariant getValue() const;
83  Q_INVOKABLE void setValue(QVariant);
84  std::chrono::nanoseconds getMTime() const;
85  double getMTimeToDouble() const;
86  Q_INVOKABLE void inc();
87 
88  private:
89  Q_DECLARE_PRIVATE(ScalarVariant);
90  QScopedPointer<ScalarVariantPrivate> const d_ptr;
91 
92  Q_DISABLE_COPY(ScalarVariant)
93 
94  // pure-virtual from ScalarSubscriber
95  void newValues(std::chrono::nanoseconds);
96 
97 
98 
99  private slots:
100  void processConnected();
101  void processDisconnected();
102  void processError();
103 
104  signals:
105  void valueChanged(QVariant);
107  void valueUpdated(double);
109  void pathChanged(QString &);
110  void dataPresentChanged(bool);
111  void connectionUpdated();
112 };
113 
114 /****************************************************************************/
115 
116 } // namespace
117 
118 
119 #endif
Scalar Variant to be used in QML applications which is aware of the process to detect connections/or ...
Definition: ScalarVariant.h:45
Definition: LiveSvg.h:18