File indexing completed on 2024-05-12 04:35:06
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2015 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 0020 #include "PropertyManager.h" 0021 #include "Document.h" 0022 0023 #include <QFile> 0024 0025 namespace tikz { 0026 namespace core { 0027 0028 PropertyInfo::PropertyInfo(const QString & name, const QJsonObject & json) 0029 : m_name(name) 0030 , m_json(json) 0031 { 0032 } 0033 0034 bool PropertyInfo::isValid() const 0035 { 0036 return !m_json.isEmpty(); 0037 } 0038 0039 QString PropertyInfo::type() const 0040 { 0041 return m_json["type"].toString(); 0042 } 0043 0044 QString PropertyInfo::name() const 0045 { 0046 return m_name; 0047 } 0048 0049 QString PropertyInfo::title() const 0050 { 0051 return m_json["title"].toString(); 0052 } 0053 0054 QVariant PropertyInfo::minimum() const 0055 { 0056 return m_json["minimum"].toVariant(); 0057 } 0058 0059 QVariant PropertyInfo::maximum() const 0060 { 0061 return m_json["maximum"].toVariant(); 0062 } 0063 0064 double PropertyInfo::singleStep() const 0065 { 0066 return m_json["singleStep"].toDouble(1.0); 0067 } 0068 0069 QString PropertyInfo::modifiedFunction() const 0070 { 0071 return m_json["modified"].toString(); 0072 } 0073 0074 bool PropertyInfo::isResettable() const 0075 { 0076 return !m_json["reset"].toString().isEmpty(); 0077 } 0078 0079 QString PropertyInfo::resetFunction() const 0080 { 0081 return m_json["reset"].toString(); 0082 } 0083 0084 PropertyManager::PropertyManager() 0085 { 0086 QFile file("../data/properties.json"); 0087 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { 0088 qDebug() << "Could not read file properties.json"; 0089 return; 0090 } 0091 m_json = QJsonDocument::fromJson(file.readAll()); 0092 } 0093 0094 PropertyInfo PropertyManager::info(const QString & name) const 0095 { 0096 return PropertyInfo(name, m_json["properties"][name].toObject()); 0097 } 0098 0099 0100 PropertyManager & propertyManager() 0101 { 0102 static PropertyManager manager; 0103 return manager; 0104 } 0105 0106 } 0107 } 0108 0109 // kate: indent-width 4; replace-tabs on;