File indexing completed on 2024-05-19 04:36:36
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 0020 #include "UidPropertyManager.h" 0021 0022 namespace tikz { 0023 namespace ui { 0024 0025 class UidPropertyManagerPrivate 0026 { 0027 public: 0028 struct Data 0029 { 0030 tikz::core::Uid val; 0031 bool readOnly = false; 0032 }; 0033 0034 typedef QMap<const QtProperty *, Data> PropertyValueMap; 0035 PropertyValueMap m_values; 0036 }; 0037 0038 UidPropertyManager::UidPropertyManager(QObject *parent) 0039 : QtAbstractPropertyManager(parent) 0040 , d_ptr(new UidPropertyManagerPrivate()) 0041 { 0042 } 0043 0044 UidPropertyManager::~UidPropertyManager() 0045 { 0046 clear(); 0047 delete d_ptr; 0048 } 0049 0050 tikz::core::Uid UidPropertyManager::value(const QtProperty *property) const 0051 { 0052 const auto it = d_ptr->m_values.constFind(property); 0053 if (it == d_ptr->m_values.constEnd()) 0054 return tikz::core::Uid(); 0055 return it.value().val; 0056 } 0057 0058 bool UidPropertyManager::isReadOnly(const QtProperty *property) const 0059 { 0060 const auto it = d_ptr->m_values.constFind(property); 0061 if (it == d_ptr->m_values.constEnd()) 0062 return false; 0063 return it.value().readOnly; 0064 } 0065 0066 QString UidPropertyManager::valueText(const QtProperty *property) const 0067 { 0068 const auto it = d_ptr->m_values.constFind(property); 0069 if (it == d_ptr->m_values.constEnd()) 0070 return QString(); 0071 return it.value().val.toString(); 0072 } 0073 0074 void UidPropertyManager::setValue(QtProperty *property, const tikz::core::Uid & val) 0075 { 0076 const auto it = d_ptr->m_values.find(property); 0077 if (it == d_ptr->m_values.end()) 0078 return; 0079 0080 auto & data = it.value(); 0081 0082 if (data.val == val) 0083 return; 0084 0085 data.val = val; 0086 0087 Q_EMIT propertyChanged(property); 0088 Q_EMIT valueChanged(property, data.val); 0089 } 0090 0091 void UidPropertyManager::setReadOnly(QtProperty *property, bool readOnly) 0092 { 0093 const auto it = d_ptr->m_values.find(property); 0094 if (it == d_ptr->m_values.end()) 0095 return; 0096 0097 UidPropertyManagerPrivate::Data data = it.value(); 0098 0099 if (data.readOnly == readOnly) 0100 return; 0101 0102 data.readOnly = readOnly; 0103 it.value() = data; 0104 0105 Q_EMIT propertyChanged(property); 0106 Q_EMIT readOnlyChanged(property, data.readOnly); 0107 } 0108 0109 void UidPropertyManager::initializeProperty(QtProperty *property) 0110 { 0111 d_ptr->m_values[property] = UidPropertyManagerPrivate::Data(); 0112 } 0113 0114 0115 void UidPropertyManager::uninitializeProperty(QtProperty *property) 0116 { 0117 d_ptr->m_values.remove(property); 0118 } 0119 0120 } 0121 } 0122 0123 // kate: indent-width 4; replace-tabs on;