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 "PosProperty.h"
0021 
0022 #include <QJsonObject>
0023 
0024 namespace tikz {
0025 namespace core {
0026 
0027 PosProperty::PosProperty(const QString & propertyName, PropertyInterface * interface)
0028     : Property(propertyName, interface)
0029     , m_pos()
0030 {
0031 }
0032 
0033 PosProperty::~PosProperty()
0034 {
0035 }
0036 
0037 const char * PosProperty::propertyType() const
0038 {
0039     return "pos";
0040 }
0041 
0042 void PosProperty::unset()
0043 {
0044     if (isSet()) {
0045         Transaction trans(this);
0046         m_pos = Pos();
0047         Property::unset();
0048     }
0049 }
0050 
0051 void PosProperty::setPos(const Pos & pos)
0052 {
0053     if (! isSet() || m_pos != pos) {
0054         Transaction trans(this);
0055         m_pos = pos;
0056     }
0057 }
0058 
0059 Pos PosProperty::pos () const
0060 {
0061     if (isSet()) {
0062         return m_pos;
0063     }
0064 
0065     auto parent = parentProperty<PosProperty>();
0066     return parent ? parent->pos() : Pos();
0067 }
0068 
0069 void PosProperty::loadData(const QJsonObject & json)
0070 {
0071     const QJsonValue v = json["pos"];
0072     if (v.isString()) {
0073         const QString pos = v.toString();
0074         m_pos = Pos::fromString(pos);
0075     }
0076 }
0077 
0078 void PosProperty::saveData(QJsonObject & json)
0079 {
0080     json["pos"] = m_pos.toString();
0081 }
0082 
0083 }
0084 }
0085 
0086 // kate: indent-width 4; replace-tabs on;