FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
qobject_wrap.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include <QtCore/QObject>
19 
20 namespace qtcore {
21 
30 template<typename T>
31 class QObjectWrap : public QObject
32 {
33 public:
34  QObjectWrap(const T& value, QObject* parent = nullptr);
35  QObjectWrap(T&& value, QObject* parent = nullptr);
36 
37  const T& value() const;
38  void setValue(const T& val);
39  void setValue(T&& val);
40 
41 private:
42  T m_value;
43 };
44 
51 template<typename T>
52 QObjectWrap<T>* wrapAsQObject(const T& value, QObject* parent = nullptr);
53 
54 
55 // --
56 // -- Implementation
57 // --
58 
59 template<typename T>
60 QObjectWrap<T>::QObjectWrap(const T& value, QObject* parent)
61  : QObject(parent),
62  m_value(value)
63 { }
64 
65 template<typename T>
66 QObjectWrap<T>::QObjectWrap(T&& value, QObject* parent)
67  : QObject(parent),
68  m_value(value)
69 { }
70 
71 template<typename T>
72 const T& QObjectWrap<T>::value() const
73 { return m_value; }
74 
75 template<typename T>
76 void QObjectWrap<T>::setValue(const T& val)
77 { m_value = val; }
78 
79 template<typename T>
81 { m_value = val; }
82 
83 template<typename T>
84 QObjectWrap<T>* wrapAsQObject(const T& value, QObject* parent)
85 {
86  return new QObjectWrap<T>(value, parent);
87 }
88 
89 } // namespace qtcore
QObjectWrap(const T &value, QObject *parent=nullptr)
Definition: qobject_wrap.h:60
const T & value() const
Definition: qobject_wrap.h:72
Definition: grid_numbering.cpp:19
Definition: qobject_wrap.h:31
QObjectWrap< T > * wrapAsQObject(const T &value, QObject *parent)
Definition: qobject_wrap.h:84
void setValue(const T &val)
Definition: qobject_wrap.h:76