Eneboo - Documentación para desarrolladores
src/flbase/aqsobjects/AQSObject_p.h
Ir a la documentación de este archivo.
00001 /***************************************************************************
00002  AQSObject_p.h
00003  -------------------
00004  begin                : 29/01/2011
00005  copyright            : (C) 2003-2011 by InfoSiAL S.L.
00006  email                : mail@infosial.com
00007  ***************************************************************************/
00008 /***************************************************************************
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; version 2 of the License.               *
00012  ***************************************************************************/
00013 /***************************************************************************
00014  Este  programa es software libre. Puede redistribuirlo y/o modificarlo
00015  bajo  los  términos  de  la  Licencia  Pública General de GNU   en  su
00016  versión 2, publicada  por  la  Free  Software Foundation.
00017  ***************************************************************************/
00018 
00019 #ifndef AQSOBJECT_P_H_
00020 #define AQSOBJECT_P_H_
00021 
00022 #include "AQS_p.h"
00023 #include "AQSEvent_p.h"
00024 #include <qscrollview.h>
00025 #include <qbitarray.h>
00026 
00027 #define AQ_DECLARE_AQS_PREFIX_OBJECT(Prefix,Class,BaseClass) \
00028   protected: \
00029   void internalInit(Prefix##Class *o) { \
00030     o_ = o; \
00031     AQS##BaseClass::internalInit(o); \
00032   } \
00033   private: \
00034   Prefix##Class *o_; \
00035   void init(QObject *qo) { \
00036     o_ = ::qt_cast<Prefix##Class *>(qo); \
00037     if (!o_) { \
00038       AQS_IF_DEBUG(printf("%s\n", \
00039                       AQ_QUOTEME(BaseClass: AQS##Class must be initialized with a valid Prefix##Class) \
00040                          )); \
00041     } else { \
00042       QObject::setName(AQ_QUOTEME(Prefix##Class)); \
00043       AQS##BaseClass::internalInit(o_); \
00044       AQS_IF_DEBUG(printf("%s init %s %p\n", AQ_QUOTEME(AQS##Class), o_->QObject::name(), o_)); \
00045       specializedInternalInit(); \
00046     } \
00047   }\
00048   void finish() { \
00049     if (!finished_) { \
00050       AQS_IF_DEBUG(printf("%s finish %p\n", AQ_QUOTEME(AQS##Class), o_)); \
00051       finished_ = true; \
00052       specializedInternalFinish(); \
00053     } \
00054   }\
00055   public: \
00056   virtual const char *RTTI() const { return #Class; } \
00057   operator Prefix##Class *() { return o_; } \
00058   operator const Prefix##Class *() const { return o_; } \
00059   operator Prefix##Class &() { if (o_) return *o_; } \
00060   operator const Prefix##Class &() const { if (o_) return *o_; } \
00061   AQS##Class() : AQS##BaseClass (), o_(0) {} \
00062   AQS##Class(QObject *qo) : AQS##BaseClass () {init(qo);} \
00063   virtual ~AQS##Class() { \
00064     finish(); \
00065   } \
00066   AQ_STATIC_CONSTRUCTOR(Prefix,Class)
00067 
00068 #define AQ_DECLARE_AQS_OBJECT(Class,BaseClass) AQ_DECLARE_AQS_PREFIX_OBJECT(Q,Class,BaseClass)
00069 #define AQ_DECLARE_AQS_AQOBJECT(Class,BaseClass) AQ_DECLARE_AQS_PREFIX_OBJECT(AQ,Class,BaseClass)
00070 
00071 class AQSObject : public AQSBaseObject
00072 {
00073   Q_OBJECT
00074 
00075   Q_PROPERTY(QString eventFilterFunction READ eventFilterFunction WRITE setEventFilterFunction)
00076   Q_PROPERTY(QValueList allowedEvents READ allowedEvents WRITE setAllowedEvents)
00077 
00078   Q_OVERRIDE(QCString name READ objectName WRITE setObjectName)
00079 
00080   AQ_DECLARE_AQS(Object)
00081 
00082   AQ_STATIC_CONSTRUCTOR(Q, Object)
00083 
00084 public:
00085   AQSObject(QObject *qo) : AQSBaseObject() {
00086     init(qo);
00087   }
00088 
00089   virtual bool eventFilter(QObject *o, QEvent *e) {
00090     if (!filterArgs_ || e->type() > 99 || !bitAllowedEvents_.testBit(e->type()))
00091       return false;
00092     filterEvent_->setEvent(e);
00093     filterArgs_->first() = o;
00094     return globalAQSInterpreter->call(eventFilterFunction_, *filterArgs_, 0).variant().toBool();
00095   }
00096 
00097   void setEventFilterFunction(const QString &functionName) {
00098     if (filterArgs_ == 0) {
00099       filterEvent_ = new AQSEvent;
00100       filterArgs_ = new QSArgumentList;
00101       filterArgs_->append(QSArgument());
00102       filterArgs_->append(filterEvent_);
00103     }
00104     eventFilterFunction_ = functionName;
00105   }
00106 
00107   QString eventFilterFunction() const {
00108     return eventFilterFunction_;
00109   }
00110 
00111   void setAllowedEvents(const QValueList<QVariant> &allowed) {
00112     bitAllowedEvents_.fill(false, 100);
00113     for (QValueList<QVariant>::const_iterator it = allowed.begin();
00114          it != allowed.end(); ++it) {
00115       bitAllowedEvents_.setBit((*it).toInt());
00116     }
00117     allowedEvents_ = allowed;
00118   }
00119 
00120   QValueList<QVariant> allowedEvents() const {
00121     return allowedEvents_;
00122   }
00123 
00124   void setObjectName(const QCString &name) {
00125     AQ_CALL_VOID(QObject::setName(name));
00126   }
00127 
00128   QCString objectName() const {
00129     AQ_CALL_RET(QObject::name());
00130   }
00131 
00132 public slots :
00133   bool isEqual(QObject *other) const {
00134     return (o_ ? o_ == other : false);
00135   }
00136 
00137   bool isEqual(AQSBaseObject *other) const {
00138     return ((o_ && other) ? o_ == other->o() : false);
00139   }
00140 
00141   QObject *parent() const {
00142     AQ_CALL_RET(parent());
00143   }
00144 
00145   QObject *child(const QString &objName,
00146                  const QString &inheritsClass = QString::null,
00147                  bool recursiveSearch = true) {
00148     AQ_CALL_RET(child(objName.latin1(), inheritsClass.latin1(),
00149                       recursiveSearch));
00150   }
00151 
00152   void installEventFilter(QObject *filterObj) {
00153     AQSBaseObject *aqo = globalAQS->findAQSObject(filterObj);
00154     AQ_CALL_VOID(installEventFilter(aqo));
00155 
00156     QScrollView *sco = ::qt_cast<QScrollView *>(o_);
00157     if (sco) {
00158       QWidget *v = sco->viewport();
00159       v->QObject::setName(o_->QObject::name());
00160       v->installEventFilter(aqo);
00161     }
00162   }
00163 
00164   void removeEventFilter(QObject *obj) {
00165     AQ_CALL_VOID(removeEventFilter(globalAQS->findAQSObject(obj)));
00166   }
00167 
00168   bool isWidgetType() const {
00169     AQ_CALL_RET_V(isWidgetType(), bool);
00170   }
00171 
00172   bool isA(const QString &clname) const {
00173     AQ_CALL_RET_V(isA(clname), bool);
00174   }
00175 
00176   bool inherits(const QString &clname) const {
00177     AQ_CALL_RET_V(inherits(clname), bool);
00178   }
00179 
00180   int startInternalTimer(int interval) {
00181     AQ_CALL_RET_V(startTimer(interval), int);
00182   }
00183 
00184   void killInternalTimer(int id) {
00185     AQ_CALL_VOID(killTimer(id));
00186   }
00187 
00188   virtual QCString className() {
00189     AQ_CALL_RET(className());
00190   }
00191 
00192   virtual QCString rtti() {
00193     return RTTI();
00194   }
00195 
00196   virtual void insertChild(QObject *obj) {
00197     AQ_CALL_VOID(insertChild(obj));
00198   }
00199 
00200   virtual void removeChild(QObject *obj) {
00201     AQ_CALL_VOID(removeChild(obj));
00202   }
00203 
00204   virtual QDomNode *toXml(bool includeComplexTypes = false) {
00205     xml_.clear();
00206     QDomElement e(xml_.createElement("object"));
00207 
00208     e.setAttribute("class", RTTI());
00209     xml_.appendChild(e);
00210 
00211     if (!o_)
00212       return &xml_;
00213 
00214     QMap<QString, bool> propMap;
00215     QMap<QCString, bool> override;
00216     const QMetaObject *m = o_->metaObject();
00217     int num = m->numProperties(true);
00218 
00219     for (int j = 0; j < num; ++j) {
00220       const QMetaProperty *mp = m->property(j, true);
00221       if (mp->testFlags(QMetaProperty::Override))
00222         override[mp->name()] = true;
00223       else if (override.contains(mp->name()))
00224         continue;
00225 
00226       if (propMap.find(mp->name()) != propMap.end())
00227         continue;
00228       propMap.replace(mp->name(), false);
00229 
00230       QVariant val(o_->property(mp->name()));
00231       if (val.isNull() || !val.isValid())
00232         continue;
00233 
00234       if (!val.canCast(QVariant::String)) {
00235         if (!includeComplexTypes)
00236           continue;
00237         QByteArray ba;
00238         QDataStream ds(ba, IO_WriteOnly);
00239         val.save(ds);
00240         val = QVariant(byteArrayToBase64(&ba));
00241       }
00242 
00243       QString valStr(val.toString());
00244       if (!valStr.isEmpty())
00245         e.setAttribute(mp->name(), valStr);
00246     }
00247 
00248     return &xml_;
00249   }
00250 
00251 protected:
00252   void internalInit(void *o) {
00253     o_ = 0;
00254     AQSBaseObject::internalInit(o);
00255   }
00256 
00257   void internalInit(QObject *o) {
00258     o_ = o;
00259     AQSBaseObject::internalInit(o);
00260   }
00261 
00262   static void *construct(const QSArgumentList &args) {
00263     QMap<int, QStringList> candidates;
00264     candidates[0].append(QString::null);
00265     candidates[1].append(QString::fromLatin1("QObject*"));
00266     candidates[1].append(QString::fromLatin1("QString"));
00267     candidates[2].append(QString::fromLatin1("QObject*,QString"));
00268     QString sgt(castArgsSignature(args, candidates));
00269     if (sgt.isEmpty())
00270       return new QObject;
00271     if (sgt == QString::fromLatin1("QObject*"))
00272       return new QObject(argValue<QObject *>(args[0]));
00273     if (sgt == QString::fromLatin1("QString"))
00274       return new QObject(0, *(argValue<QString *>(args[0])));
00275     if (sgt == QString::fromLatin1("QObject*,QString"))
00276       return new QObject(argValue<QObject *>(args[0]),
00277                          *(argValue<QString *>(args[1])));
00278     return 0;
00279   }
00280 
00281 public:
00282   static QMap<int, QStringList> candidateConstructors() {
00283     QMap<int, QStringList> candidates;
00284     candidates[0].append(QString::null);
00285     candidates[1].append(QString::fromLatin1("QObject*"));
00286     candidates[1].append(QString::fromLatin1("QString"));
00287     candidates[2].append(QString::fromLatin1("QObject*,QString"));
00288     return candidates;
00289   }
00290 
00291 private:
00292   QObject *o_;
00293   QString eventFilterFunction_;
00294   QVariantList allowedEvents_;
00295   QBitArray bitAllowedEvents_;
00296   static AQSEvent *filterEvent_;
00297   static QSArgumentList *filterArgs_;
00298 };
00299 
00300 #endif /* AQSOBJECT_P_H_ */
00301 // @AQSOBJECT@
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'