File: PropertyObject.h

package info (click to toggle)
camitk 6.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 389,496 kB
  • sloc: cpp: 103,476; sh: 2,448; python: 1,618; xml: 984; makefile: 128; perl: 84; sed: 20
file content (165 lines) | stat: -rw-r--r-- 5,665 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*****************************************************************************
 * $CAMITK_LICENCE_BEGIN$
 *
 * CamiTK - Computer Assisted Medical Intervention ToolKit
 * (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
 *
 * Visit http://camitk.imag.fr for more information
 *
 * This file is part of CamiTK.
 *
 * CamiTK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * CamiTK 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 Lesser General Public License version 3 for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with CamiTK.  If not, see <http://www.gnu.org/licenses/>.
 *
 * $CAMITK_LICENCE_END$
 ****************************************************************************/

#ifndef PROPERTYOBJECT_H
#define PROPERTYOBJECT_H

// Qt includes
#include <QObject>

// CamiTK includes
#include "CamiTKAPI.h"
#include "Property.h"
#include "InterfacePersistence.h"

namespace camitk {

/**
 *  @ingroup group_sdk_libraries_core_utils
 *
 *  @brief
 *  This class describes a property object.
 *
 *  A property object is simply a QObject tagged with some CamiTK Properties
 *  The idea is to have an object which implements all the necessary methods to take advantages of the
 *  CamiTK Properties within the ObjectController
 *
 *  PropertyObject can be saved/loaded from settings.
 *  A typical use in this case is to
    \code
        PropertyObject = new PropertyObject(...);

        // set default value
        propertyObject->addProperty(...);
        propertyObject->addProperty(...);
        propertyObject->addProperty(...);

        // load values from settings
        loadFromSettings("mySection");

        ...

        /// at any time values can be saved to settings
        saveToSettings("mySection")
    \endcode

    See the Application class for an example of a property object load/save to settings.

 *  @see ObjectController, Property
 */
class CAMITK_API PropertyObject : public QObject, public InterfacePersistence {

    Q_OBJECT

public:
    /**
     * Default constructor
     * @param name The name of the PropertyObject instance. This one would be displayed in any SettingsDialog entries.
     */
    PropertyObject(QString name);

    /// Destructor
    ~PropertyObject() override;

    /**
     * Tag a new CamiTK property to this object.
     * If the property already exist, it will just change its value.
     *
     * \note
     * The object takes ownership of the Property instance.
     *
     * @return false if the Qt Meta Object property was added by this method
     * (otherwise the property was already defined and true is returned if it was successfully updated)
     */
    virtual bool addProperty(Property*);

    /**
     *  Get a Property given its name
     *  @param name the property name
     *  @return nullptr if the name does not match any property name
     *
     *  @note
     *  This method is required so that the ObjectController can take advantage of the camitk properties.
     *
     *  @see Property, ObjectController
     */
    Q_INVOKABLE virtual const camitk::Property* getProperty(QString name) const;
    Q_INVOKABLE virtual camitk::Property* getProperty(QString name);

    /**
     *  Remove a CamiTK property of this object
     */
    virtual void removeProperty(Property*);

    /// get the current number of property
    virtual unsigned int getNumberOfProperties() const;

    /// get the name of the property at the given index, null string if index is out of bounds (i.e., isNull() == true)
    virtual QString getPropertyName(unsigned int index) const;

    /// get the value of the property at the given index, a non valid QVariant if the index is out of bounds (i.e., isValid() == false)
    virtual QVariant getPropertyValue(unsigned int index);

    /// convenient method to get the value of a given property, returns a non valid QVariant if no property with that name exists
    virtual QVariant getPropertyValue(const QString name) const;

    /// initializes all property values from setting values found in the given group name
    void loadFromSettings(const QString& settingGroupName);

    /// save setting in the given group name using all the property values
    void saveToSettings(const QString& settingGroupName);

    /// utility method to transform property name to camel case. Quite useful to make sure all settings are stored as lowerCamelCase
    static QString toCamelCase(const QString&);

    /**
     * * @name InterfacePersistence
     * Customized InterfacePersistence methods to support geometry data (e.g. color)
     */
    ///@{
    /// Convert all data from the object to a QVariant (usually a QVariantMap)
    virtual QVariant toVariant() const override;

    /// Load data from a QVariant to initialize the current object
    virtual void fromVariant(const QVariant&) override;

    /// Get the unique ID of the propertyObject (usually the uuid of the containing object)
    virtual QUuid getUuid() const override;

    /// Set the unique ID of the propertyObject (usually the uuid of the containing object)
    virtual bool setUuid(QUuid) override;
    ///@}

private:
    /// @name Property management
    ///@{
    /// list of CamiTK properties decorating the object
    QMap<QString, Property*> propertiesMap;
    ///@}
};

}

#endif // PROPERTYOBJECT_H