File indexing completed on 2024-05-12 04:35:04
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2016 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 "BoolProperty.h" 0021 0022 #include <QJsonObject> 0023 0024 namespace tikz { 0025 namespace core { 0026 0027 BoolProperty::BoolProperty(const QString & propertyName, PropertyInterface * interface) 0028 : Property(propertyName, interface) 0029 { 0030 } 0031 0032 BoolProperty::~BoolProperty() 0033 { 0034 } 0035 0036 const char * BoolProperty::propertyType() const 0037 { 0038 return "bool"; 0039 } 0040 0041 void BoolProperty::unset() 0042 { 0043 if (isSet()) { 0044 Transaction trans(this); 0045 m_enabled = false; 0046 Property::unset(); 0047 } 0048 } 0049 0050 void BoolProperty::setEnabled(bool enable) 0051 { 0052 if (! isSet() || m_enabled != enable) { 0053 Transaction trans(this); 0054 m_enabled = enable; 0055 } 0056 } 0057 0058 bool BoolProperty::enabled() const 0059 { 0060 if (isSet()) { 0061 return m_enabled; 0062 } 0063 0064 auto parent = parentProperty<BoolProperty>(); 0065 return parent ? parent->enabled() : false; 0066 } 0067 0068 void BoolProperty::loadData(const QJsonObject & json) 0069 { 0070 const QJsonValue v = json["value"]; 0071 if (v.isBool()) { 0072 m_enabled = v.toBool(); 0073 } 0074 } 0075 0076 void BoolProperty::saveData(QJsonObject & json) 0077 { 0078 json["value"] = m_enabled; 0079 } 0080 0081 } 0082 } 0083 0084 // kate: indent-width 4; replace-tabs on;