File indexing completed on 2024-05-19 04:36:23

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2018 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 #ifndef TIKZ_CORE_PROPERTY_MANAGER_H
0020 #define TIKZ_CORE_PROPERTY_MANAGER_H
0021 
0022 #include "tikz.h"
0023 #include "tikz_export.h"
0024 
0025 #include <QJsonDocument>
0026 #include <QJsonObject>
0027 #include <QDebug>
0028 
0029 namespace tikz {
0030 namespace core {
0031 
0032 class TIKZKITCORE_EXPORT PropertyInfo
0033 {
0034 public:
0035     /**
0036      * Constructor for property @p name based on the data @p json.
0037      */
0038     PropertyInfo(const QString & name, const QJsonObject & json);
0039 
0040     //! Check whether the property is valid.
0041     bool isValid() const;
0042 
0043     //! Returns the property type.
0044     QString type() const;
0045 
0046     //! Returns the property name.
0047     QString name() const;
0048 
0049     //! Returns a description / title of the property.
0050     QString title() const;
0051 
0052     //! Returns the minimum value. Not supported by all properties.
0053     QVariant minimum() const;
0054 
0055     //! Returns the maximum value. Not supported by all properties.
0056     QVariant maximum() const;
0057 
0058     //! Returns the single step used for e.g. spin boxes.
0059     //! Not supported by all properties.
0060     double singleStep() const;
0061 
0062     //! Returns a function to be called via QObject::invokeMethod() to check
0063     //! whether this property was set. Not supported by all properties.
0064     QString modifiedFunction() const;
0065 
0066     //! Returns true, if this property can be unset.
0067     bool isResettable() const;
0068 
0069     //! Returns true, if this property can be unset.
0070     QString resetFunction() const;
0071 
0072 private:
0073     QString m_name;
0074     QJsonObject m_json;
0075 };
0076 
0077 /**
0078  * The PropertyManager class provides meta information about properties.
0079  * The meta information is loaded from a json file.
0080  *
0081  * @see Entity
0082  */
0083 class TIKZKITCORE_EXPORT PropertyManager
0084 {
0085 public:
0086     /**
0087      * Default constructor. Creates an invalid PropertyManager.
0088      */
0089     PropertyManager();
0090 
0091     /**
0092      * Returns the meta information for property @p name.
0093      */
0094     PropertyInfo info(const QString & name) const;
0095 
0096 private:
0097     /**
0098      * Internal data structure for querying meta data about properties.
0099      */
0100     QJsonDocument m_json;
0101 };
0102 
0103 /**
0104  * Getter that returns the global instance.
0105  */
0106 TIKZKITCORE_EXPORT PropertyManager & propertyManager();
0107 
0108 }
0109 }
0110 
0111 #endif // TIKZ_CORE_PROPERTY_MANAGER_H
0112 
0113 // kate: indent-width 4; replace-tabs on;