#pragma once #include #include "Defines.h" #include "ZxDynamic.h" #include "IxSerDes.h" #include "ZxSerializer.h" #include "iBase_global.h" #include "LlUtils_global.h" // 该类ZxDot是实现绘制点的工具类,主要提供了一种 // QVariant的自定义元数据的参照 class I_UTILSSHARED_EXPORT ZxDot : virtual public IxDynObj , virtual public IxSerDes { ZX_DECLARE_DYNAMIC public: ZxDot(); ZxDot(ZxDotType o, \ QColor clr = QColor(0, 0, 0), \ double r = 1.f, \ bool bFill = false); ~ZxDot(); #ifdef QT_DEBUG // 专门测试函数,元数据,自定义 void testMetaTypeUsage(); #endif public: // operator abouts ZxDot &operator = (const ZxDot &o); bool operator == (const ZxDot &o) const; bool operator != (const ZxDot &o) const { return !(operator == (o)); } operator QVariant() const { return QVariant::fromValue(*this); } public: // 序列化 virtual void onSerialize(ZxSerializer* ser); virtual void onDeserialize(ZxSerializer* ser); public: // 参数 set/get ZxDotType style() const; void setStyle(ZxDotType); QColor color() const; void setColor(const QColor &clr); double radius() const; void setRadius(const double& f); bool isFilling() const; void setFilling(const bool& b); protected: ZxDotType m_oType; //类型 QColor m_clr; //颜色 double m_fRadius; //半径 bool m_bFilling; //是否填充 }; Q_DECLARE_METATYPE(ZxDot) //宏定义 // QDebug << 重载 inline QDebug operator<< (QDebug debug, const ZxDot& o) { debug.nospace() << "ZxDot(" << (int)(o.style()) << "," << o.color() << "," << o.radius() << "," << o.isFilling() << ")"; return debug.space(); } // 序列化必须,DataStream inline QDataStream& operator<< (QDataStream& out, const ZxDot& o) { qRegisterMetaTypeStreamOperators("ZxDot"); out << (int)(o.style()); out << o.color(); out << o.radius(); out << o.isFilling(); return out; } // 序列化必须,DataStream inline QDataStream& operator>> (QDataStream& in, ZxDot& o) { qRegisterMetaTypeStreamOperators("ZxDot"); int n = 0; in >> n; o.setStyle((ZxDotType)n); QColor clr(0, 0, 0); in >> clr; o.setColor(clr); double r = 0.f; in >> r; o.setRadius(r); bool b = false; in >> b; o.setFilling(b); return in; }