File indexing completed on 2024-05-12 16:39:35
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006 Jarosław Staniek <staniek@kde.org> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this program; see the file COPYING. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "kexiactioncategories.h" 0021 0022 #include <QDebug> 0023 #include <QMap> 0024 0025 #include <kexi_global.h> 0026 0027 namespace Kexi 0028 { 0029 0030 //! @internal 0031 class ActionInternal 0032 { 0033 public: 0034 explicit ActionInternal(int _categories) 0035 : categories(_categories) 0036 , supportedObjectTypes(0) 0037 , allObjectTypesAreSupported(false) { 0038 } 0039 ~ActionInternal() { 0040 delete supportedObjectTypes; 0041 } 0042 int categories; 0043 QSet<int> *supportedObjectTypes; 0044 bool allObjectTypesAreSupported; 0045 }; 0046 0047 Q_GLOBAL_STATIC(ActionCategories, Kexi_actionCategories) 0048 0049 //! @internal 0050 class Q_DECL_HIDDEN ActionCategories::Private 0051 { 0052 public: 0053 Private() { 0054 } 0055 ~Private() { 0056 qDeleteAll(actions); 0057 actions.clear(); 0058 } 0059 0060 QMap<QByteArray, ActionInternal*> actions; 0061 }; 0062 0063 KEXICORE_EXPORT ActionCategories *actionCategories() 0064 { 0065 return Kexi_actionCategories; 0066 } 0067 0068 } // Kexi 0069 0070 using namespace Kexi; 0071 0072 //---------------------------------- 0073 0074 ActionCategories::ActionCategories() 0075 : d(new Private()) 0076 { 0077 } 0078 0079 ActionCategories::~ActionCategories() 0080 { 0081 delete d; 0082 } 0083 0084 void ActionCategories::addAction(const char* name, int categories, 0085 KexiPart::ObjectType supportedObjectType1, KexiPart::ObjectType supportedObjectType2, 0086 KexiPart::ObjectType supportedObjectType3, KexiPart::ObjectType supportedObjectType4, 0087 KexiPart::ObjectType supportedObjectType5, KexiPart::ObjectType supportedObjectType6, 0088 KexiPart::ObjectType supportedObjectType7, KexiPart::ObjectType supportedObjectType8) 0089 { 0090 ActionInternal * a = d->actions.value(name); 0091 if (a) { 0092 a->categories |= categories; 0093 } else { 0094 a = new ActionInternal(categories); 0095 d->actions.insert(name, a); 0096 } 0097 if (supportedObjectType1 > 0) { 0098 if (!a->supportedObjectTypes) 0099 a->supportedObjectTypes = new QSet<int>(); 0100 a->supportedObjectTypes->insert(supportedObjectType1); 0101 if (supportedObjectType2 > 0) { 0102 a->supportedObjectTypes->insert(supportedObjectType2); 0103 if (supportedObjectType3 > 0) { 0104 a->supportedObjectTypes->insert(supportedObjectType3); 0105 if (supportedObjectType4 > 0) { 0106 a->supportedObjectTypes->insert(supportedObjectType4); 0107 if (supportedObjectType5 > 0) { 0108 a->supportedObjectTypes->insert(supportedObjectType5); 0109 if (supportedObjectType6 > 0) { 0110 a->supportedObjectTypes->insert(supportedObjectType6); 0111 if (supportedObjectType7 > 0) { 0112 a->supportedObjectTypes->insert(supportedObjectType7); 0113 if (supportedObjectType8 > 0) { 0114 a->supportedObjectTypes->insert(supportedObjectType8); 0115 } 0116 } 0117 } 0118 } 0119 } 0120 } 0121 } 0122 } 0123 } 0124 0125 void ActionCategories::setAllObjectTypesSupported(const char* name, bool set) 0126 { 0127 ActionInternal * a = d->actions.value(name); 0128 if (a) 0129 a->allObjectTypesAreSupported = set; 0130 else 0131 qWarning() << "no such action:" << name; 0132 } 0133 0134 int ActionCategories::actionCategories(const char* name) const 0135 { 0136 const ActionInternal * a = d->actions.value(name); 0137 return a ? a->categories : 0; 0138 } 0139 0140 bool ActionCategories::actionSupportsObjectType(const char* name, KexiPart::ObjectType objectType) const 0141 { 0142 const ActionInternal * a = d->actions.value(name); 0143 if (a && a->allObjectTypesAreSupported) 0144 return true; 0145 return (a && a->supportedObjectTypes) ? a->supportedObjectTypes->contains(objectType) : false; 0146 }