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.
75 lines
1.8 KiB
C++
75 lines
1.8 KiB
C++
#ifndef COMMON_H
|
|
#define COMMON_H
|
|
|
|
#include <QObject>
|
|
#include "utils/Singleton.h"
|
|
#include <QString>
|
|
#include <QMap>
|
|
#include "nlohmann/json.hpp"
|
|
#include "EasySpdLog.h"
|
|
enum Mode
|
|
{
|
|
GLOBAL,
|
|
LOCAL,
|
|
};
|
|
|
|
struct ModeConfig
|
|
{
|
|
int index;
|
|
QString name;
|
|
QString workPath;
|
|
QString reworkPath;
|
|
};
|
|
|
|
struct ProductConfig
|
|
{
|
|
int productId;
|
|
Mode workMode;
|
|
bool selected;
|
|
QString productFormat;
|
|
};
|
|
|
|
class Common : public QObject, public Singleton<Common>
|
|
{
|
|
Q_OBJECT
|
|
friend class Singleton<Common>;
|
|
public:
|
|
bool loadConfig(const QString& filePath);
|
|
bool saveConfig(const QMap<int, ProductConfig>& productsCfg, const QMap<int, ModeConfig>& workmodeCfg);
|
|
|
|
QString getHostAddress() const;
|
|
int getSrcPort() const;
|
|
int getDstPort() const;
|
|
|
|
QMap<int, ProductConfig> getProductConfigs();
|
|
void setProductConfig(const QMap<int, ProductConfig>& productsCfg);
|
|
QMap<int, ModeConfig> getWorkModeConfigs();
|
|
void setWorkModeConfigs(const QMap<int, ModeConfig>& workmodeCfg);
|
|
|
|
const QMap<QString, Mode>& getSelectedProducts() const;
|
|
|
|
int getCurrentWorkMode() const;
|
|
void setCurrentWorkMode(const int workMode);
|
|
|
|
signals:
|
|
|
|
private:
|
|
Common();
|
|
bool saveConfig();
|
|
void FilterSelectedProducts();
|
|
|
|
private:
|
|
QString m_configFilePath{};
|
|
nlohmann::json m_configJson{};
|
|
QString m_currentWorkPath{}; // 当前工作路径
|
|
std::atomic<int> m_currentMode{ -1 }; // 当前正在进行的工作模式
|
|
QString m_ipAddr{};
|
|
int m_dstPort{};
|
|
int m_srcPort{};
|
|
QMap<int, ModeConfig> m_modeConfigs{}; // 模式配置
|
|
QMap<int, ProductConfig> m_productConfigs{}; // 产品配置
|
|
QMap<QString, Mode> m_selectedProduct{}; // 选择的产品
|
|
};
|
|
|
|
#endif // COMMON_H
|