You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWATI/Include/iData/iDataPool/ZxDataObject.h

204 lines
6.8 KiB
C

#pragma once
#include <QIcon>
#include "Defines.h"
#include "IxSerDes.h"
#include "IxDynObj.h"
#include "iDataPool_global.h"
class iXmlTable;
// 数据模型对象类的抽象基类
class I_DATAPOOL_EXPORT ZxDataObject
: public QObject
, virtual public IxDynObj
, virtual public IxSerDes
{
Q_OBJECT
public:
ZxDataObject(ZxDataObject* pParent);
ZxDataObject(const ZxDataObject& other);
virtual ~ZxDataObject();
// 接口,子类必须实现
virtual ZxDataObject* clone() = 0;
virtual QString type() const = 0;
// 操作符
virtual ZxDataObject& operator = (const ZxDataObject& other);
virtual bool operator == (const ZxDataObject& other) const;
virtual bool operator != (const ZxDataObject& other) const;
public:
// 加载保存
virtual bool load();
virtual void ensureLoaded() const;
virtual bool save();
// 该函数是加载子类对象仅仅加载code之类的关键信息
// 比如在建立树时,创建该节点。
virtual bool createChildren();
// 序列化
virtual void onSerialize(ZxSerializer* ser);
virtual void onDeserialize(ZxSerializer* ser);
// Icon
virtual QIcon getIcon(bool expanded = false) const;
// 获取新建的默认ID
virtual QString getDefaultCode(ZxDataObject* pParent/* = NULL*/);
// 由于原先函数总是出这样那样的问题,故增加一种新的方式
// 直接读取表格中Key字段进行判断
virtual QString getDefaultCodeEx();
virtual bool getCurObjTags(QStringList& list);
//检查名字不能重复(名字字段)
virtual bool checkUniqueObjName(QString sFiledName, QString sName);
// TODO 20231231 Old
virtual bool isParentType(const QString &type) const;
virtual bool isChildType(const QString &type) const;
virtual bool isAncestorType(const QString &type) const;
virtual bool isDescendantType(const QString &type) const;
virtual QStringList getParameterNames(void) const;
virtual VecInt getDataTypes(void) const;
public:
// 对象编码
virtual void setCode(const QString& sCode);
virtual QString getCode(void) const;
// 名称
virtual void setName(const QString& sName);
virtual QString getName(void) const;
// 是否load
virtual void setLoaded(bool b);
virtual bool isLoaded(void) const;
// 修改状态
virtual void setModified(bool bModified = true);
virtual bool isModified(void) const;
// 可见
virtual void setVisible(bool b);
virtual bool isVisible(void) const;
public:
//父对象
virtual void setParent(ZxDataObject* pParent);
virtual ZxDataObject* getParent(void) const;
virtual ZxDataObject* getRoot(void) const; //顶级祖先
// 子对象相关操作
virtual qint32 getChildrenCount(const QString& type = "") const;
virtual qint32 indexOfChild(ZxDataObject* pObject) const;
virtual ZxDataObject* getChild(QString sType, QString sCode);
virtual ZxDataObject* getChild(qint32 index) const;
virtual qint32 appendChildren(const ZxDataObjectList &lstGmObjects);
virtual bool appendChild(ZxDataObject* pObject);
virtual bool insertChild(ZxDataObject* pObject, int nPos);
virtual void removeChild(qint32 index, bool bDeleteLater = false);
virtual void removeChild(ZxDataObject* pObject, bool bDeleteLater = false);
virtual void clearChildren(const QString& type = "",
bool bDeleteLater = true);
virtual void removeChildren(const ZxDataObjectList &lstGmObjects, \
bool bDeleteLater = true);
virtual ZxDataObject* findChild(QString type, const QString& code);
// 查找相关子对象
ZxDataObject* getPreviousChild(ZxDataObject* pObject) const;
ZxDataObject* getNextChild(ZxDataObject* pObject) const;
// 子对象批量操作
virtual ZxDataObjectList getChildren(QString sType = "", \
QStringList listCodes = QStringList()) const;
// 子对象可见
virtual void setHasVisibleChildren(bool b);
virtual bool hasVisibleChildren(void) const;
virtual ZxDataObjectList getVisibleChildren() const;
// 把父子层级关系全部放入数据,以方便应用
static ZxDataObjectList parseObjsToVec(ZxDataObjectList& vecOlds);
public:
// 数据库相关
virtual void checkXmlTable(); // 根据type选定XmlTable结构体
virtual QString getTableName(); // 表名
virtual QString getTableNameBy(QString sType);
QStringList getKeyFields(); //主键
virtual QString getSqlR(); //Load时的SQL
virtual QString getSqlW();
virtual QStringList getKeyValues(); //筛选时获得主键的值。
// 名称重命名,存入数据库
virtual bool renameInDb(QString sNewName, QString sOldName);
// 删除该Code的数据库内容
virtual bool deleteInDb();
// 对附属关联的数据大字段ID的统一微调
virtual void adjustDataID(QString& sDataID);
// 加载数据
virtual bool loadData(VVecVariant& vvec, \
QString &sLog, \
bool bTopOneOnly = true);
virtual bool loadData(QString& sSql, \
VVecVariant& vvec, \
QString &sLog, \
bool bTopOneOnly = true);
// 保存
virtual bool saveData(VVecVariant& vvec, QString& sLog);
protected:
// 加载数据
/// @brief 加载数据的实现函数
/// @param bWellDbPreferred 是否优先从单井db文件里面获取20220616目前只被pvt中间过程数据调用
bool _load(QString& sSql, VVecVariant& vvec, \
QString& sLog, bool bTopOneOnly = true, \
bool bWellDbPreferred = false); //加载数据
public:
// 解析与组织
virtual bool parseData(VecVariant vec);
virtual bool sumUpData(VecVariant& vec);
// 暂时保留
// 确定对象是否有效
virtual bool isValid() const;
// m_bUnableSP
virtual bool isUnableSP();
virtual void setUnableSP(bool b);
QStringList getTableFieldNames(bool bEn);
protected:
QString m_sCode; //对象标识\序号\编号\编码
QString m_sName; //对象名称, 包括分组\分类\名称
bool m_bModified; //对象数据修改标记
bool m_bLoaded; //数据及索引是否已经加载
bool m_bHasVisibleChildren; //在m_bLoaded为FALSE时, 标记是否有子节点
bool m_bVisible; //是否在数据树上显示
ZxDataObject* m_pParent; //对象的父对象指针
ZxDataObjectList m_vecChildren; //对象的子对象列表
iXmlTable* m_pTableDefine; //xml中的配置
bool m_bUnableSP; //临时变量不参与序列化
QString m_sCth; //临时变量不参与序列化
};