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.

132 lines
3.7 KiB
C

/**
*
* @file FITKAbstractOperator.h
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*
*/
#ifndef _FITKABSTRACT_OPERATOR_H__
#define _FITKABSTRACT_OPERATOR_H__
#include "FITKCoreAPI.h"
#include "FITKAbstractObject.hpp"
#include <QObject>
#include <QHash>
namespace Core
{
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
class FITKCoreAPI FITKAbstractOperator : public QObject, public FITKAbstractObject
{
Q_OBJECT
public:
/**
* @brief Construct a new FITKAbstractOperator object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
explicit FITKAbstractOperator() = default;
/**
* @brief Destroy the FITKAbstractOperator object
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
virtual ~FITKAbstractOperator() = 0;
/**
* @brief
* @param[i] obj
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
virtual void setEmitter(QObject* obj);
/**
* @brief
* @param[i] argName
* @param[i] arg
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
void setArgs(const QString& argName, QVariant arg);
/**
* @brief
* @param[i] argName
* @return true
* @return false
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
bool hasArgs(const QString& argName);
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
virtual void clearArgs();
template < typename T >
/**
* @brief
* @param[i] name
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2023-04-18
*/
bool argValue(const QString& name, T& value)
{
if (!_operArgs.contains(name)) return false;
auto arg = _operArgs.value(name);
value = arg.value< T >();
return true;
}
template < typename T >
/**
* @brief
* @param[i] name
* @return T
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2023-04-18
*/
T* argValuePtr(const QString& name)
{
if (!_operArgs.contains(name)) return nullptr;
auto arg = _operArgs.value(name);
//先转成基类防止QVarient直接类型转换需要QObject宏
FITKAbstractObject* absObj = arg.value<FITKAbstractObject*>();
return dynamic_cast< T* >(absObj);
}
signals:
/**
* @brief
* @param[o] oper this
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
void operatorDestoryedSig(FITKAbstractOperator* oper);
protected:
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
QHash<QString, QVariant> _operArgs{};
/**
* @brief
* @author LiBaojun (libaojunqd@foxmail.com)
* @date 2024-03-04
*/
QObject* _emitter{};
};
}
#endif //