55 lines
1.3 KiB
C
55 lines
1.3 KiB
C
|
|
#ifndef TOOLBARCONFIG_H
|
||
|
|
#define TOOLBARCONFIG_H
|
||
|
|
|
||
|
|
/********************toolbar配置类*******************/
|
||
|
|
#include <QObject>
|
||
|
|
#include <QMap>
|
||
|
|
#include <QString>
|
||
|
|
#include <QJsonObject>
|
||
|
|
#include <QIcon>
|
||
|
|
|
||
|
|
struct ToolInfo
|
||
|
|
{
|
||
|
|
QString type; // 工具类型标识符
|
||
|
|
QString name; // 显示名称
|
||
|
|
QString iconPath; // 图标路径
|
||
|
|
QVariantMap properties; // 自定义属性
|
||
|
|
|
||
|
|
ToolInfo() = default;
|
||
|
|
ToolInfo(const QString &type, const QString &name,
|
||
|
|
const QString &iconPath = QString())
|
||
|
|
: type(type), name(name), iconPath(iconPath) {}
|
||
|
|
QIcon getIcon() const;
|
||
|
|
};
|
||
|
|
|
||
|
|
class ToolBarConfig : public QObject
|
||
|
|
{
|
||
|
|
Q_OBJECT
|
||
|
|
|
||
|
|
public:
|
||
|
|
explicit ToolBarConfig(QObject *parent = nullptr);
|
||
|
|
|
||
|
|
// 加载配置
|
||
|
|
bool loadFromFile(const QString &filePath);
|
||
|
|
bool loadFromJson(const QByteArray &jsonData);
|
||
|
|
|
||
|
|
// 获取工具
|
||
|
|
ToolInfo getTool(const QString &type) const;
|
||
|
|
QList<ToolInfo> getAllTools() const;
|
||
|
|
QStringList getToolTypes() const;
|
||
|
|
|
||
|
|
// 工具数量
|
||
|
|
int count() const { return m_tools.size(); }
|
||
|
|
|
||
|
|
// 检查工具是否存在
|
||
|
|
bool contains(const QString &type) const;
|
||
|
|
|
||
|
|
private:
|
||
|
|
QMap<QString, ToolInfo> m_tools;
|
||
|
|
|
||
|
|
void addDefaultTools();
|
||
|
|
ToolInfo parseTool(const QJsonObject &json);
|
||
|
|
};
|
||
|
|
|
||
|
|
#endif
|