DAQ  1.0.0
Data Acquisition System (basic demo)
varsmodel.h
Go to the documentation of this file.
1 /*! @brief This file have the interface for VarsModel class.
2  @file varsmodel.h
3  @author Alvaro Denis <denisacostaq@gmail.com>
4  @date 7/27/2019
5 
6  @copyright
7  @attention <h1><center><strong>COPYRIGHT &copy; 2019 </strong>
8  [<strong>denisacostaq</strong>][denisacostaq-URL].
9  All rights reserved.</center></h1>
10  @attention This file is part of [<strong>DAQs</strong>][DAQs-URL].
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions
14  are met:
15  - 1. Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  - 2. Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  - 3. Neither the name of the University nor the names of its contributors
21  may be used to endorse or promote products derived from this software
22  without specific prior written permission.
23 
24  THIS PRODUCT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  THIS PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35  [denisacostaq-URL]: https://about.me/denisacostaq "Alvaro Denis Acosta"
36  [DAQs-URL]: https://github.com/denisacostaq/DAQs "DAQs"
37  */
38 #ifndef HMI_MODEL_VARSMODEL_H
39 #define HMI_MODEL_VARSMODEL_H
40 
41 class Client;
42 
43 #include <vector>
44 
45 #include <QtCore/QDebug>
46 #include <QtCore/QObject>
47 #include <QtQml/QQmlListProperty>
48 
49 #include "src/hmi/model/varmodel.h"
50 
51 class VarsModel : public QObject {
52  Q_OBJECT
53  public:
55  explicit VarsModel(Client *cl, QObject *parent = nullptr);
57 
58  signals:
59  void varsChanged();
60  public slots:
61  private:
67 
68  void clear() {
69  std::for_each(m_vars.begin(), m_vars.end(),
70  [](auto v) { v->deleteLater(); });
71  m_vars.clear();
72  emit varsChanged();
73  }
77  // FIXME(denisacostaq@gmail.com): Memory leak for VarModel*?
78  reinterpret_cast<VarsModel *>(property->data)->add_var(var);
79  }
80  auto var_at(int index) { return m_vars.at(index); }
81  static auto var_at(decltype(m_qml_vars) *property, int index) {
82  return reinterpret_cast<VarsModel *>(property->data)->var_at(index);
83  }
84  int vars_size() { return m_vars.size(); }
86  return reinterpret_cast<VarsModel *>(property->data)->vars_size();
87  }
88  static void clear_vars(decltype(m_qml_vars) *) {
89  qDebug() << "unsupported operation, so ignored";
90  }
91 };
92 
93 #endif // HMI_MODEL_VARSMODEL_H
static void clear_vars(decltype(m_qml_vars)*)
Definition: varsmodel.h:88
auto var_at(int index)
Definition: varsmodel.h:80
static int vars_size(decltype(m_qml_vars)*property)
Definition: varsmodel.h:85
void add_var(decltype(m_vars)::value_type var)
Client * m_cl
Definition: varsmodel.h:66
void do_request(const message::GetValues &gv)
Definition: client.cc:261
void clear()
Definition: varsmodel.h:68
int vars_size()
Definition: varsmodel.h:84