Fact.h 3.98 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
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
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

/// @file
///     @author Don Gagne <don@thegagnes.com>

#ifndef Fact_H
#define Fact_H

#include "FactMetaData.h"

#include <QObject>
#include <QString>
#include <QVariant>
35
#include <QDebug>
Don Gagne's avatar
Don Gagne committed
36 37 38 39 40 41 42 43 44 45

/// @brief A Fact is used to hold a single value within the system.
///
/// Along with the value property is a set of meta data which further describes the Fact. This information is
/// exposed through QObject Properties such that you can bind to it from QML as well as use it within C++ code.
/// Since the meta data is common to all instances of the same Fact, it is acually stored once in a seperate object.
class Fact : public QObject
{
    Q_OBJECT
    
Don Gagne's avatar
Don Gagne committed
46
    Q_PROPERTY(QString name READ name CONSTANT)
Don Gagne's avatar
Don Gagne committed
47
    Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true)
48
    Q_PROPERTY(QVariant valueString READ valueString NOTIFY valueChanged)
Don Gagne's avatar
Don Gagne committed
49 50 51 52 53 54 55 56 57 58 59
    Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT)
    Q_PROPERTY(FactMetaData::ValueType_t type READ type CONSTANT)
    Q_PROPERTY(QString shortDescription READ shortDescription CONSTANT)
    Q_PROPERTY(QString longDescription READ longDescription CONSTANT)
    Q_PROPERTY(QString units READ units CONSTANT)
    Q_PROPERTY(QVariant min READ min CONSTANT)
    Q_PROPERTY(QVariant max READ max CONSTANT)
    
    Q_ENUMS(FactMetaData::ValueType_t)
    
public:
Don Gagne's avatar
Don Gagne committed
60
    Fact(QString name = "", QObject* parent = NULL);
Don Gagne's avatar
Don Gagne committed
61 62 63
    
    // Property system methods
    
Don Gagne's avatar
Don Gagne committed
64
    /// Read accessor or name property
65
    QString name(void) const;
Don Gagne's avatar
Don Gagne committed
66
    
Don Gagne's avatar
Don Gagne committed
67
    /// Read accessor for value property
68 69 70 71
    QVariant value(void) const;
    
    /// Read accessor for valueString property
    QString valueString(void) const;
Don Gagne's avatar
Don Gagne committed
72 73
    
    /// Write accessor for value property
74
    void setValue(const QVariant& value);
Don Gagne's avatar
Don Gagne committed
75 76
    
    /// Read accesor for defaultValue property
77
    QVariant defaultValue(void);
Don Gagne's avatar
Don Gagne committed
78 79
    
    /// Read accesor for type property
80
    FactMetaData::ValueType_t type(void);
Don Gagne's avatar
Don Gagne committed
81 82
    
    /// Read accesor for shortDescription property
83
    QString shortDescription(void);
Don Gagne's avatar
Don Gagne committed
84 85
    
    /// Read accesor for longDescription property
86
    QString longDescription(void);
Don Gagne's avatar
Don Gagne committed
87 88
    
    /// Read accesor for units property
89
    QString units(void);
Don Gagne's avatar
Don Gagne committed
90 91
    
    /// Read accesor for min property
92
    QVariant min(void);
Don Gagne's avatar
Don Gagne committed
93 94

    /// Read accesor for max property
95
    QVariant max(void);
Don Gagne's avatar
Don Gagne committed
96 97
    
    /// Sets the meta data associated with the Fact.
98
    void setMetaData(FactMetaData* metaData);
Don Gagne's avatar
Don Gagne committed
99
    
100 101
    void _containerSetValue(const QVariant& value);
    
Don Gagne's avatar
Don Gagne committed
102 103 104 105
signals:
    /// QObject Property System signal for value property changes
    ///
    /// This signal is only meant for use by the QT property system. It should not be connected to by client code.
106
    void valueChanged(QVariant value);
Don Gagne's avatar
Don Gagne committed
107 108 109
    
    /// Signalled when property has been changed by a call to the property write accessor
    ///
110 111
    /// This signal is meant for use by Fact container implementations.
    void _containerValueChanged(QVariant& value);
Don Gagne's avatar
Don Gagne committed
112 113
    
private:
Don Gagne's avatar
Don Gagne committed
114
    QString         _name;      ///< Fact name
Don Gagne's avatar
Don Gagne committed
115 116 117 118 119
    QVariant        _value;     ///< Fact value
    FactMetaData*   _metaData;  ///< FactMetaData object for Fact
};

#endif