Warning, file /office/calligra/libs/flake/KoResourceManager_p.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002    Copyright (c) 2006, 2011 Boudewijn Rempt (boud@valdyas.org)
0003    Copyright (C) 2007, 2010 Thomas Zander <zander@kde.org>
0004    Copyright (c) 2008 Carlos Licea <carlos.licea@kdemail.net>
0005    Copyright (c) 2011 Jan Hambrecht <jaham@gmx.net>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021  */
0022 #include "KoResourceManager_p.h"
0023 
0024 #include <QVariant>
0025 #include <FlakeDebug.h>
0026 
0027 #include "KoShape.h"
0028 
0029 void KoResourceManager::setResource(int key, const QVariant &value)
0030 {
0031     if (m_resources.contains(key)) {
0032         if (m_resources.value(key) == value)
0033             return;
0034         m_resources[key] = value;
0035     } else {
0036         m_resources.insert(key, value);
0037     }
0038 }
0039 
0040 QVariant KoResourceManager::resource(int key) const
0041 {
0042     if (!m_resources.contains(key)) {
0043         QVariant empty;
0044         return empty;
0045     } else
0046         return m_resources.value(key);
0047 }
0048 
0049 void KoResourceManager::setResource(int key, const KoColor &color)
0050 {
0051     QVariant v;
0052     v.setValue(color);
0053     setResource(key, v);
0054 }
0055 
0056 void KoResourceManager::setResource(int key, KoShape *shape)
0057 {
0058     QVariant v;
0059     v.setValue(shape);
0060     setResource(key, v);
0061 }
0062 
0063 void KoResourceManager::setResource(int key, const KoUnit &unit)
0064 {
0065     QVariant v;
0066     v.setValue(unit);
0067     setResource(key, v);
0068 }
0069 
0070 KoColor KoResourceManager::koColorResource(int key) const
0071 {
0072     if (! m_resources.contains(key)) {
0073         KoColor empty;
0074         return empty;
0075     }
0076     return resource(key).value<KoColor>();
0077 }
0078 
0079 KoShape *KoResourceManager::koShapeResource(int key) const
0080 {
0081     if (! m_resources.contains(key))
0082         return 0;
0083 
0084     return resource(key).value<KoShape *>();
0085 }
0086 
0087 
0088 KoUnit KoResourceManager::unitResource(int key) const
0089 {
0090     return resource(key).value<KoUnit>();
0091 }
0092 
0093 bool KoResourceManager::boolResource(int key) const
0094 {
0095     if (! m_resources.contains(key))
0096         return false;
0097     return m_resources[key].toBool();
0098 }
0099 
0100 int KoResourceManager::intResource(int key) const
0101 {
0102     if (! m_resources.contains(key))
0103         return 0;
0104     return m_resources[key].toInt();
0105 }
0106 
0107 QString KoResourceManager::stringResource(int key) const
0108 {
0109     if (! m_resources.contains(key)) {
0110         QString empty;
0111         return empty;
0112     }
0113     return qvariant_cast<QString>(resource(key));
0114 }
0115 
0116 QSizeF KoResourceManager::sizeResource(int key) const
0117 {
0118     if (! m_resources.contains(key)) {
0119         QSizeF empty;
0120         return empty;
0121     }
0122     return qvariant_cast<QSizeF>(resource(key));
0123 }
0124 
0125 bool KoResourceManager::hasResource(int key) const
0126 {
0127     return m_resources.contains(key);
0128 }
0129 
0130 void KoResourceManager::clearResource(int key)
0131 {
0132     if (! m_resources.contains(key))
0133         return;
0134     m_resources.remove(key);
0135 }