kexi
metaparameter.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "metaparameter.h"
00021 #include "exception.h"
00022 #include "variable.h"
00023
00024 #include <kdebug.h>
00025
00026 using namespace KoMacro;
00027
00028 namespace KoMacro {
00029
00034 class MetaParameter::Private
00035 {
00036 public:
00037
00043 QString signatureargument;
00044
00048 MetaParameter::Type type;
00049
00054 QVariant::Type varianttype;
00055
00056 };
00057
00058 }
00059
00060 MetaParameter::MetaParameter(const QString& signatureargument)
00061 : KShared()
00062 , d( new Private() )
00063 {
00064 d->type = TypeNone;
00065
00066 if(! signatureargument.isNull()) {
00067 setSignatureArgument( signatureargument );
00068 }
00069 }
00070
00071 MetaParameter::~MetaParameter()
00072 {
00073 delete d;
00074 }
00075
00076 MetaParameter::Type MetaParameter::type() const
00077 {
00078 return d->type;
00079 }
00080
00081 const QString MetaParameter::typeName() const
00082 {
00083 switch( d->type ) {
00084 case TypeNone:
00085 return "None";
00086 case TypeVariant:
00087 return "Variant";
00088 case TypeObject:
00089 return "Object";
00090 }
00091 return QString::null;
00092 }
00093
00094 void MetaParameter::setType(MetaParameter::Type type)
00095 {
00096 d->type = type;
00097 d->varianttype = QVariant::Invalid;
00098 }
00099
00100 QVariant::Type MetaParameter::variantType() const
00101 {
00102 return d->varianttype;
00103 }
00104
00105 void MetaParameter::setVariantType(QVariant::Type varianttype)
00106 {
00107 d->type = TypeVariant;
00108 d->varianttype = varianttype;
00109 }
00110
00111 void MetaParameter::setSignatureArgument(const QString& signatureargument)
00112 {
00113 d->signatureargument = signatureargument;
00114
00115 QString argument = signatureargument;
00116 if(argument.startsWith("const")) {
00117 argument = argument.mid(5).stripWhiteSpace();
00118 }
00119
00120 if(argument.endsWith("&")) {
00121 argument = argument.left( argument.length() - 1 ).stripWhiteSpace();
00122 }
00123
00124 if(argument.isEmpty()) {
00125 throw Exception(QString("Empty signature argument passed."));
00126 }
00127 if(argument == "QVariant") {
00128 setVariantType( QVariant::Invalid );
00129 }
00130
00131 QVariant::Type type = argument.isNull() ? QVariant::Invalid : QVariant::nameToType(argument.latin1());
00132 if (type != QVariant::Invalid) {
00133 setVariantType( type );
00134 }
00135 else {
00136 setType( TypeObject );
00137 }
00138 }
00139
00140 bool MetaParameter::validVariable(KSharedPtr<Variable> variable) const
00141 {
00142 if( type() != variable->type() ) {
00143 return false;
00144 }
00145 return true;
00146 }
|