QtPdCom  1.6.0
PdVariable.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2018 Wilhelm Hagemeister <hm@igh.de>
4  * Florian Pose <fp@igh.de>
5  * 2024 Bjarne von Horn <vh@igh.de>
6  *
7  * This file is part of the QtPdCom library.
8  *
9  * The QtPdCom library is free software: you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License as
11  * published by the Free Software Foundation, either version 3 of the License,
12  * or (at your option) any later version.
13  *
14  * The QtPdCom library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the QtPdCom Library. If not, see
21  * <http://www.gnu.org/licenses/>.
22  *
23  ****************************************************************************/
24 
25 #ifndef PD_PdVariable_H
26 #define PD_PdVariable_H
27 
28 #include <QtPdCom1/Process.h>
29 
30 #include "PdConnection.h"
31 
32 #include <QObject>
33 #include <QQmlEngine>
34 #include <QVariant>
35 
36 #include <chrono>
37 
38 namespace QtPdCom {
39 
40 /****************************************************************************/
41 
44 class Q_DECL_EXPORT PdVariable: public QObject
45 {
46  Q_OBJECT
47  QML_NAMED_ELEMENT(PdVariable)
48  QML_ADDED_IN_VERSION(1, 4)
49 
50 
69  Q_PROPERTY(QtPdCom::PdConnection connection READ getConnection WRITE
70  setConnection NOTIFY connectionChanged)
71 
72 
74  Q_PROPERTY(
75  bool connected READ getDataPresent NOTIFY dataPresentChanged)
76 
77 
79  Q_PROPERTY(QVariant value READ getValue WRITE setValue NOTIFY
80  valueChanged)
81 
82  Q_PROPERTY(QString as_string READ getString NOTIFY valueChanged)
83 
84 
86  Q_PROPERTY(QString text READ getValueAsString WRITE setValueAsString
87  NOTIFY valueChanged)
88 
89 
91  Q_PROPERTY(QVariant mtime READ getMTimeToDouble NOTIFY valueUpdated)
92 
93  public:
94  PdVariable(QObject * = Q_NULLPTR);
95  ~PdVariable();
96 
97  void clearVariable();
98  bool hasVariable() const;
99  void clearData();
100 
101  QVariant getValue() const;
102  Q_INVOKABLE void setValue(QVariant);
103  QString getValueAsString() const;
104  Q_INVOKABLE void setValueAsString(QString);
105  bool getDataPresent();
106 
107  std::chrono::nanoseconds getMTime() const;
108  double getMTimeToDouble() const;
109 
110  QString getString() { return getValue().toString(); }
111 
112  PdConnection getConnection();
113  void setConnection(PdConnection const &);
114  void updateConnection();
116  Q_INVOKABLE void inc();
117 
118  signals:
119  void valueChanged();
121  void valueUpdated(std::chrono::nanoseconds mtime);
127  void pathChanged(QString);
129  void dataPresentChanged(bool);
130 
131  private:
132  class Q_DECL_HIDDEN Impl;
133  std::unique_ptr<Impl> impl;
134 };
135 
136 /****************************************************************************/
137 
138 } // namespace QtPdCom
139 
140 #endif
Definition: PdConnection.h:38
Definition: PdVariable.cpp:267
Scalar/Vector/Matrix Variant to be used in QML applications.
Definition: PdVariable.h:45
QString getString()
Definition: PdVariable.h:110
void valueChanged()
Emitted, when the value changes, or the variable is disconnected.
void pathChanged(QString)
void dataPresentChanged(bool)
std::unique_ptr< Impl > impl
Definition: PdVariable.h:133
void valueUpdated(std::chrono::nanoseconds mtime)
Emitted also when value does not change but got an update from the msr process.
Definition: BroadcastModel.h:32