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/FITKAbstractParam.hpp

261 lines
6.6 KiB
C++


/**
*
* @file FITKAbstractParam.hpp
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*
*/
#ifndef __FITKABSTRACTPARAM_HPP__
#define __FITKABSTRACTPARAM_HPP__
#include "FITKAbstractNDataObject.h"
#include <QMetaEnum>
namespace Core
{
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
class FITKAbstractParamObj : public Core::FITKAbstractNDataObject
{
public:
explicit FITKAbstractParamObj() = default;
#ifdef Q_OS_WIN
virtual ~FITKAbstractParamObj() = 0 {};
#else
virtual ~FITKAbstractParamObj() = 0;
#endif
/**
* @brief
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-13
*/
virtual bool isDefault() { return false; }
/**
* @brief
* @return QString
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-04-13
*/
virtual QString value2String() { return QString(); }
};
template<typename T>
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
class FITKAbstractParamEmum : public Core::FITKAbstractParamObj
{
public:
/**
* @brief Destroy the FITKAbstractParam object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
explicit FITKAbstractParamEmum() { _metaEnum =QMetaEnum::fromType<T>(); }
/**
* @brief Destroy the FITKAbstractParam object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual ~FITKAbstractParamEmum() = default;
/**
* @brief
* @param[i] v
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
void setValue(const T v)
{
_value = v;
}
/**
* @brief
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T getValue() const
{
return _value;
}
/**
* @brief
* @param[i] dv
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual void setDefault(const T dv)
{
_defaultValue = dv;
}
/**
* @brief
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T getDefault() const
{
return _defaultValue;
}
/**
* @brief
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual bool isDefault() override
{
return _value == _defaultValue;
}
/**
* @brief
* @return QString
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual QString value2String() override
{
if (_metaEnum.isValid())
return _metaEnum.valueToKey(_value);
else return QString();
}
protected:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T _value{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T _defaultValue{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
QMetaEnum _metaEnum;
};
template<typename T>
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
class FITKAbstractParamValue : public Core::FITKAbstractParamObj
{
public:
/**
* @brief Destroy the FITKAbstractParam object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
explicit FITKAbstractParamValue() = default;
/**
* @brief Destroy the FITKAbstractParam object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual ~FITKAbstractParamValue() = default;
/**
* @brief
* @param[i] v
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
void setValue(const T v)
{
_value = v;
}
/**
* @brief
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T getValue() const
{
return _value;
}
/**
* @brief
* @param[i] dv
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual void setDefault(const T dv)
{
_defaultValue = dv;
}
/**
* @brief
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T getDefault() const
{
return _defaultValue;
}
/**
* @brief
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual bool isDefault() override
{
return _defaultValue == _value;
}
/**
* @brief
* @return QString
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
virtual QString value2String() override
{
return QString("%1").arg(_value);
}
protected:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T _value{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-02-29
*/
T _defaultValue{};
};
}
#endif