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.
AppFlow/FITK_Kernel/FITKCore/FITKAbstractDataObject.h

263 lines
7.4 KiB
C

/**
*
* @file FITKAbstractDataObject.h
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*
*/
#ifndef _FITKABSTRACTDATAOBJECT_H__
#define _FITKABSTRACTDATAOBJECT_H__
#include "FITKCoreAPI.h"
#include "FITKCoreMacros.h"
#include "FITKAbstractObject.hpp"
#include <QObject>
#include <QHash>
#include <QVariant>
namespace Core
{
class FITKDataRepo;
class FITKAbstractDataIDAlter;
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
enum FITKUserData
{
FITKUserRole = 1,
FITKUserRoleEnd = 1000000,
};
class FITKCoreAPI FITKAbstractDataObject : public QObject , public FITKAbstractObject
{
friend FITKAbstractDataIDAlter;
friend FITKDataRepo;
Q_OBJECT;
//FITKSafeDownCastA(FITKAbstractDataObject, FITKAbstractObject)
public:
/**
* @brief Construct a new FITKAbstractDataObject object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
explicit FITKAbstractDataObject(const int parentDataID = -1 );
/**
* @brief Destroy the FITKAbstractDataObject object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
virtual ~FITKAbstractDataObject() = 0;
/**
* @brief ID
* @return int ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
int getDataObjectID() const;
/**
* @brief id
* @param[i] id
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
virtual void setParentDataID(const int id);
/**
* @brief id
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
int getParentDataID() const;
/**
* @brief
* @param[i] userData
* @return QVariant
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
QVariant getUserData(int userData);
/**
* @brief ud
* @param[i] ud
* @param[i] va
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
virtual void setUserData(int ud, QVariant va);
/**
* @brief
* @return QList<int>
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
QList<int> getUserDataKeys();
template <typename T>
/**
* @brief
* @param[i] ud
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
T getUserDataT(int ud)
{
QVariant v = this->getUserData(ud);
return v.value<T>();
}
/**
* @brief ,id
* @param[i] obj
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-27
*/
virtual bool copy(FITKAbstractDataObject* obj);
/**
* @brief
* @return FITKAbstractDataObject*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-14
*/
FITKAbstractDataObject* getParentObject();
template <typename T>
/***
* @brief
* @return T*
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-14
*/
T* getParentObjectT()
{
FITKAbstractDataObject* tempObj = this;
while (tempObj)
{
//类型转换成功,返回数据对象
T* obj = dynamic_cast<T*>(tempObj);
if (obj) return obj;
tempObj = tempObj->getParentObject();
}
return nullptr;
}
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
QString objectName() = delete;
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
void setObjectName(const QString &name) = delete;
private:
/**
* @brief ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-18
*/
static void ResetMaxID(const int maxid =0);
/**
* @brief ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-18
*/
static int GetMaxID();
signals:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
void dataObjectDestoried(FITKAbstractDataObject*);
protected:
/***
* @brief ID使
* @param ID id
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-05-14
*/
virtual void setAbsDataID(const int id);
private:
/**
* @brief ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-22
*/
int _absDataID{ 0 };
/**
* @brief ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
int _parentDataID{ -1 };
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-07
*/
QHash<int, QVariant> _userData{};
};
/**
* @brief ID
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-03
*/
class FITKCoreAPI FITKAbstractDataIDAlter
{
public:
/**
* @brief Construct a new FITKAbstractDataIDAlter object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-03
*/
explicit FITKAbstractDataIDAlter() = default;
/**
* @brief Destroy the FITKAbstractDataIDAlter object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-03
*/
virtual ~FITKAbstractDataIDAlter() = default;
/**
* @brief ID
* @param[i] d
* @param[i] id ID
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-03
*/
bool modifyDataID(FITKAbstractDataObject* d, const int id);
/**
* @brief IDID
* @return int
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-06-03
*/
static int GetAValidDataID();
};
}
#endif