first commit
This commit is contained in:
84
procedure/functionregistry.h
Normal file
84
procedure/functionregistry.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef FUNCTIONREGISTRY_H
|
||||
#define FUNCTIONREGISTRY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QVariant>
|
||||
#include <QVariantMap>
|
||||
#include <QVariantList>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief 功能函數註冊表
|
||||
*
|
||||
* 管理測量和輸出功能的註冊和執行。
|
||||
* 每個功能函數接受參數映射,返回結果數組。
|
||||
*/
|
||||
class FunctionRegistry : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// 函數回調類型:接受 QVariantMap 參數,返回 QVariantList 結果
|
||||
using FunctionCallback = std::function<QVariantList(const QVariantMap &)>;
|
||||
|
||||
struct FunctionMetadata
|
||||
{
|
||||
QString functionType; // 函數類型標識
|
||||
QString displayName; // 顯示名稱
|
||||
QString description; // 功能描述
|
||||
QString category; // 類別 (measurement, output, etc.)
|
||||
QStringList parameterNames; // 參數名稱列表
|
||||
QVariantMap defaultParameters; // 默認參數值
|
||||
FunctionCallback callback; // 回調函數
|
||||
};
|
||||
|
||||
static FunctionRegistry *instance();
|
||||
|
||||
// 註冊功能函數
|
||||
bool registerFunction(const QString &functionType,
|
||||
const QStringList ¶meterNames,
|
||||
FunctionCallback callback,
|
||||
const QString &displayName = QString(),
|
||||
const QString &description = QString(),
|
||||
const QString &category = QString());
|
||||
|
||||
bool registerFunction(const FunctionMetadata &metadata);
|
||||
|
||||
// 註銷功能函數
|
||||
bool unregisterFunction(const QString &functionType);
|
||||
|
||||
// 執行功能函數
|
||||
QVariantList executeFunction(const QString &functionType,
|
||||
const QVariant ¶meters);
|
||||
|
||||
// 查詢
|
||||
bool hasFunction(const QString &functionType) const;
|
||||
FunctionMetadata getFunctionMetadata(const QString &functionType) const;
|
||||
QStringList getAllFunctionTypes() const;
|
||||
QStringList getFunctionsByCategory(const QString &category) const;
|
||||
|
||||
signals:
|
||||
void functionRegistered(const QString &functionType);
|
||||
void functionUnregistered(const QString &functionType);
|
||||
void functionExecuted(const QString &functionType, bool success);
|
||||
void functionProgress(const QString &functionType, int progress, const QString &message);
|
||||
|
||||
private:
|
||||
explicit FunctionRegistry(QObject *parent = nullptr);
|
||||
~FunctionRegistry();
|
||||
|
||||
QVariantMap normalizeParameters(const FunctionMetadata &metadata,
|
||||
const QVariant ¶meters);
|
||||
bool validateParameters(const FunctionMetadata &metadata,
|
||||
const QVariantMap ¶ms);
|
||||
|
||||
void registerBuiltinFunctions();
|
||||
|
||||
QMap<QString, FunctionMetadata> m_functions;
|
||||
static FunctionRegistry *m_instance;
|
||||
};
|
||||
|
||||
#endif // FUNCTIONREGISTRY_H
|
||||
Reference in New Issue
Block a user