kexi
kexiactioncategories.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexiactioncategories.h"
00021
00022 #include <kstaticdeleter.h>
00023 #include <kdebug.h>
00024
00025 #include <qmap.h>
00026 #include <qasciidict.h>
00027
00028 namespace Kexi {
00029
00031 class ActionInternal
00032 {
00033 public:
00034 ActionInternal(int _categories)
00035 : categories(_categories)
00036 , supportedObjectTypes(0)
00037 , allObjectTypesAreSupported(false)
00038 {
00039 }
00040 ~ActionInternal() {
00041 delete supportedObjectTypes;
00042 }
00043 int categories;
00044 QMap<int, bool> *supportedObjectTypes;
00045 bool allObjectTypesAreSupported : 1;
00046 };
00047
00048 static KStaticDeleter<ActionCategories> Kexi_actionCategoriesDeleter;
00049 ActionCategories* Kexi_actionCategories = 0;
00050
00052 class ActionCategories::Private
00053 {
00054 public:
00055 Private()
00056 {
00057 actions.setAutoDelete(true);
00058 }
00059
00060 QAsciiDict<ActionInternal> actions;
00061 };
00062
00063 KEXICORE_EXPORT ActionCategories *actionCategories()
00064 {
00065 if (!Kexi_actionCategories)
00066 Kexi_actionCategoriesDeleter.setObject( Kexi_actionCategories, new ActionCategories() );
00067 return Kexi_actionCategories;
00068 }
00069
00070 }
00071
00072 using namespace Kexi;
00073
00074
00075
00076 ActionCategories::ActionCategories()
00077 : d( new Private() )
00078 {
00079 }
00080
00081 ActionCategories::~ActionCategories()
00082 {
00083 delete d;
00084 }
00085
00086 void ActionCategories::addAction(const char* name, int categories,
00087 KexiPart::ObjectTypes supportedObjectType1, KexiPart::ObjectTypes supportedObjectType2,
00088 KexiPart::ObjectTypes supportedObjectType3, KexiPart::ObjectTypes supportedObjectType4,
00089 KexiPart::ObjectTypes supportedObjectType5, KexiPart::ObjectTypes supportedObjectType6,
00090 KexiPart::ObjectTypes supportedObjectType7, KexiPart::ObjectTypes supportedObjectType8)
00091 {
00092 ActionInternal * a = d->actions.find( name );
00093 if (a) {
00094 a->categories |= categories;
00095 }
00096 else {
00097 a = new ActionInternal(categories);
00098 d->actions.insert(name, a);
00099 }
00100 if (supportedObjectType1) {
00101 if (!a->supportedObjectTypes)
00102 a->supportedObjectTypes = new QMap<int, bool>();
00103 a->supportedObjectTypes->insert(supportedObjectType1, true);
00104 if (supportedObjectType2) {
00105 a->supportedObjectTypes->insert(supportedObjectType2, true);
00106 if (supportedObjectType3) {
00107 a->supportedObjectTypes->insert(supportedObjectType3, true);
00108 if (supportedObjectType4) {
00109 a->supportedObjectTypes->insert(supportedObjectType4, true);
00110 if (supportedObjectType5) {
00111 a->supportedObjectTypes->insert(supportedObjectType5, true);
00112 if (supportedObjectType6) {
00113 a->supportedObjectTypes->insert(supportedObjectType6, true);
00114 if (supportedObjectType7) {
00115 a->supportedObjectTypes->insert(supportedObjectType7, true);
00116 if (supportedObjectType8) {
00117 a->supportedObjectTypes->insert(supportedObjectType8, true);
00118 }
00119 }
00120 }
00121 }
00122 }
00123 }
00124 }
00125 }
00126 }
00127
00128 void ActionCategories::setAllObjectTypesSupported(const char* name, bool set)
00129 {
00130 ActionInternal * a = d->actions.find( name );
00131 if (a)
00132 a->allObjectTypesAreSupported = set;
00133 else
00134 kexiwarn << "ActionCategories::setAllObjectTypesSupported(): no such action \"" << name << "\"" << endl;
00135 }
00136
00137 int ActionCategories::actionCategories(const char* name) const
00138 {
00139 const ActionInternal * a = d->actions.find( name );
00140 return a ? a->categories : 0;
00141 }
00142
00143 bool ActionCategories::actionSupportsObjectType(const char* name, KexiPart::ObjectTypes objectType) const
00144 {
00145 const ActionInternal * a = d->actions.find( name );
00146 if (a && a->allObjectTypesAreSupported)
00147 return true;
00148 return (a && a->supportedObjectTypes) ? a->supportedObjectTypes->contains(objectType) : false;
00149 }
|