generate project model completed
This commit is contained in:
parent
b8c7a191a7
commit
2660140626
|
|
@ -49,7 +49,6 @@ set(H_HEADER_FILES
|
|||
include/renameModel.h
|
||||
|
||||
common/include/global.h
|
||||
common/include/dataBase.h
|
||||
common/include/httpInterface.h
|
||||
common/include/compiler.hpp
|
||||
common/include/export.hpp
|
||||
|
|
@ -70,7 +69,6 @@ set(CPP_SOURCE_FILES
|
|||
source/projectModelDlg.cpp
|
||||
source/renameModel.cpp
|
||||
|
||||
common/source/dataBase.cpp
|
||||
common/source/httpInterface.cpp
|
||||
)
|
||||
set(UI_FILES
|
||||
|
|
@ -136,7 +134,8 @@ set_target_properties(DiagramDesigner PROPERTIES
|
|||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${dd_PlatformDir}/bin"
|
||||
)
|
||||
|
||||
target_link_libraries(DiagramDesigner PRIVATE diagramCavas)
|
||||
target_link_libraries(DiagramDesigner PRIVATE diagramCavas diagramUtils)
|
||||
add_subdirectory(diagramCavas)
|
||||
add_subdirectory(diagramUtils)
|
||||
|
||||
file(COPY setting.xml DESTINATION "${CMAKE_BINARY_DIR}/${dd_PlatformDir}/bin")
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <QtCore/QMetaObject>
|
||||
#include <QtSwap>
|
||||
#include <QHash>
|
||||
#include <QUuid>
|
||||
#include <QJsonObject>
|
||||
|
||||
const double g_dGriaphicsScene_Width = 800;
|
||||
const double g_dGriaphicsScene_Height = 600;
|
||||
|
|
@ -25,6 +27,11 @@ enum GraphicsItemType
|
|||
GIT_link= QGraphicsItem::UserType + 53
|
||||
};
|
||||
|
||||
enum AbstractItemType //工程模关联的对象类型
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
enum DiagramMode //组态图模式
|
||||
{
|
||||
DM_edit = 0,
|
||||
|
|
@ -35,14 +42,120 @@ enum Attribute //元模属性字段对照
|
|||
{
|
||||
Id = Qt::UserRole + 1,
|
||||
Attribute = Qt::UserRole + 2,
|
||||
DataType = Qt::UserRole + 3,
|
||||
LengthPrecision = Qt::UserRole + 4,
|
||||
Scale = Qt::UserRole + 5,
|
||||
DefaultValue = Qt::UserRole + 6,
|
||||
ValueRange = Qt::UserRole + 7,
|
||||
AttributeGroup = Qt::UserRole + 8,
|
||||
IsNotNull = Qt::UserRole + 9,
|
||||
IsIndex = Qt::UserRole + 10
|
||||
AttributeName = Qt::UserRole + 3,
|
||||
DataType = Qt::UserRole + 4,
|
||||
LengthPrecision = Qt::UserRole + 5,
|
||||
Scale = Qt::UserRole + 6,
|
||||
IsNotNull = Qt::UserRole + 7,
|
||||
DefaultValue = Qt::UserRole + 8,
|
||||
ValueRange = Qt::UserRole + 9,
|
||||
};
|
||||
|
||||
struct attributeGroup //属性组(元模)
|
||||
{
|
||||
int id = 0;
|
||||
QString groupType;
|
||||
QString groupName;
|
||||
int isPublic = -1;
|
||||
QString remark;
|
||||
};
|
||||
|
||||
struct dataType //数据类型(元模)
|
||||
{
|
||||
int id = 0;
|
||||
QString dataType;
|
||||
QString databaseType;
|
||||
};
|
||||
|
||||
struct modelType //模型类型
|
||||
{
|
||||
int id = 0;
|
||||
QString modelType;
|
||||
QString modelName;
|
||||
QString remark;
|
||||
};
|
||||
|
||||
struct modelGroup
|
||||
{
|
||||
int id = 0;
|
||||
qint64 modelTypeId = 0;
|
||||
qint64 attributeGroupId = 0;
|
||||
};
|
||||
|
||||
struct attribute //属性表(元模属性字段)
|
||||
{
|
||||
int id = 0;
|
||||
QString attribute; //属性名
|
||||
QString attributeName; //别名(中文名)
|
||||
qint64 dataTypeId = 0; //数据类型id
|
||||
int lengthPrecision=0; //长度限制(varchar)
|
||||
int scale=0; //小数点位数
|
||||
int isNotNull=0; //是否非空
|
||||
QString defaultValue; //默认值
|
||||
QString valueRange; //数值范围
|
||||
};
|
||||
|
||||
struct modelAttribute //模型属性表(所有模型属性的索引)
|
||||
{
|
||||
int id = 0;
|
||||
qint64 modelTypeId = 0;
|
||||
qint64 attributeGroupId = 0;
|
||||
qint64 attributeId = 0;
|
||||
};
|
||||
|
||||
struct modelConnectivity //模型连接性表(元模是否可以连接)
|
||||
{
|
||||
int id = 0;
|
||||
QString fromModel; //属性名
|
||||
QString toModel;
|
||||
int connectivity=0; //是否可连
|
||||
};
|
||||
|
||||
//=====================================
|
||||
struct projectManager //工程模管理类
|
||||
{
|
||||
int id = 0;
|
||||
QString name; //工程模表名
|
||||
QString tag; //工程模名称
|
||||
QString metaModel; //元模名
|
||||
QString groupName; //属性组名
|
||||
int linkType; //图元链接类型
|
||||
QJsonObject checkState; //属性选择状态
|
||||
};
|
||||
|
||||
//==================================================
|
||||
|
||||
struct componentInfo
|
||||
{
|
||||
int id = 0;
|
||||
QUuid uuid;
|
||||
QString nspath;
|
||||
QString tag;
|
||||
QString name;
|
||||
QString description;
|
||||
QString grid;
|
||||
QString zone;
|
||||
QString station;
|
||||
int type = 0;
|
||||
bool inService = true;
|
||||
int state = 0;
|
||||
QJsonObject connected_bus;
|
||||
QJsonObject label;
|
||||
QJsonObject context;
|
||||
int page_id = 0;
|
||||
int op = 0;
|
||||
};
|
||||
|
||||
struct busStability
|
||||
{
|
||||
int componentId = 0;
|
||||
double resistance = 0;
|
||||
bool anchor_v = false;
|
||||
double uv_alarm = 0;
|
||||
double ov_alarm = 0;
|
||||
bool anchor_i = false;
|
||||
double ui_alarm = 0;
|
||||
double oi_alarm = 0;
|
||||
};
|
||||
//Q_ENUM_NS(GraphicsItemType)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ set(DIAGRAMCAVAS_HEADER_FILES
|
|||
include/util/scalingSelector.h
|
||||
include/util/selectorManager.h
|
||||
include/util/subMovingSelector.h
|
||||
../common/include/dataBase.h
|
||||
../common/include/httpInterface.h
|
||||
../common/include/global.h
|
||||
../common/include/compiler.hpp
|
||||
|
|
@ -76,7 +75,6 @@ set(DIAGRAMCAVAS_SOURCE_FILES
|
|||
source/util/scalingSelector.cpp
|
||||
source/util/selectorManager.cpp
|
||||
source/util/subMovingSelector.cpp
|
||||
../common/source/dataBase.cpp
|
||||
../common/source/httpInterface.cpp
|
||||
)
|
||||
|
||||
|
|
@ -116,6 +114,8 @@ option(BUILD_SHARED_LIBS "Build as shared library" ON)
|
|||
|
||||
target_include_directories(diagramCavas PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
target_link_libraries(diagramCavas PRIVATE diagramUtils)
|
||||
|
||||
target_compile_definitions(diagramCavas
|
||||
PUBLIC
|
||||
DIAGRAM_DESIGNER_SHARED
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
project(diagramUtils)
|
||||
|
||||
set(DIAGRAMUTILS_HEADER_FILES
|
||||
include/logger.h
|
||||
../common/include/global.h
|
||||
../common/include/compiler.hpp
|
||||
../common/include/export.hpp
|
||||
../common/include/operatingSystem.hpp
|
||||
)
|
||||
|
||||
set(DIAGRAMUTILS_SOURCE_FILES
|
||||
source/logger.cpp
|
||||
source/dataBase.cpp
|
||||
)
|
||||
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_library(diagramUtils SHARED
|
||||
MANUAL_FINALIZATION
|
||||
${DIAGRAMUTILS_HEADER_FILES}
|
||||
${DIAGRAMUTILS_SOURCE_FILES}
|
||||
)
|
||||
else()
|
||||
add_library(diagramUtils SHARED
|
||||
${DIAGRAMUTILS_HEADER_FILES}
|
||||
${DIAGRAMUTILS_SOURCE_FILES}
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(diagramUtils PUBLIC Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::Gui
|
||||
Qt${QT_VERSION_MAJOR}::Widgets)
|
||||
|
||||
target_link_libraries(diagramUtils PRIVATE Qt6::Xml)
|
||||
target_link_libraries(diagramUtils PRIVATE Qt6::Network)
|
||||
target_link_libraries(diagramUtils PRIVATE Qt6::Sql ${POSTGRESQL_LIBRARIES})
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build as shared library" ON)
|
||||
|
||||
|
||||
|
||||
target_include_directories(diagramUtils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
|
||||
target_compile_definitions(diagramUtils
|
||||
PUBLIC
|
||||
DIAGRAM_DESIGNER_SHARED
|
||||
PRIVATE
|
||||
DIAGRAM_DESIGNER_EXPORTS
|
||||
#QT_NO_KEYWORDS
|
||||
)
|
||||
|
|
@ -5,142 +5,27 @@
|
|||
#include <QObject>
|
||||
#include <QUuid>
|
||||
#include <QJsonObject>
|
||||
#include "global.h"
|
||||
#include "export.hpp"
|
||||
|
||||
struct attributeGroup //属性组(元模)
|
||||
{
|
||||
int id = 0;
|
||||
QString group;
|
||||
QString groupName;
|
||||
};
|
||||
|
||||
struct dataType //数据类型(元模)
|
||||
{
|
||||
int id = 0;
|
||||
QString dataType;
|
||||
QString databaseType;
|
||||
};
|
||||
|
||||
struct attribute //属性表(元模属性字段)
|
||||
{
|
||||
int id = 0;
|
||||
QString attribute; //属性名
|
||||
int dataType; //数据类型
|
||||
int lengthPrecision=0; //长度限制(varchar)
|
||||
int scale=0; //小数点位数
|
||||
QString defaultValue; //默认值
|
||||
QString valueRange; //数值范围
|
||||
int attributeGroup=0; //属性组
|
||||
int isNotNull=0; //是否非空
|
||||
int isIndex=0; //是否index
|
||||
};
|
||||
|
||||
struct modelAttribute //模型-属性对应表(元模在此表查找)
|
||||
{
|
||||
int id = 0;
|
||||
QString modelType; //元模名
|
||||
int attributeId; //属性id
|
||||
};
|
||||
|
||||
struct modelConnectivity //模型连接性表(元模是否可以连接)
|
||||
{
|
||||
int id = 0;
|
||||
QString fromModel; //属性名
|
||||
QString toModel;
|
||||
int connectivity=0; //是否可连
|
||||
};
|
||||
|
||||
//==================================================
|
||||
struct availableID //可用id
|
||||
{
|
||||
int componentId = -1;
|
||||
int pageId = -1;
|
||||
int stationId = -1;
|
||||
int gridId = -1;
|
||||
int zoneId = -1;
|
||||
int topoId = -1;
|
||||
};
|
||||
|
||||
struct componentInfo
|
||||
{
|
||||
int id = 0;
|
||||
QUuid uuid;
|
||||
QString nspath;
|
||||
QString tag;
|
||||
QString name;
|
||||
QString description;
|
||||
QString grid;
|
||||
QString zone;
|
||||
QString station;
|
||||
int type = 0;
|
||||
bool inService = true;
|
||||
int state = 0;
|
||||
QJsonObject connected_bus;
|
||||
QJsonObject label;
|
||||
QJsonObject context;
|
||||
int page_id = 0;
|
||||
int op = 0;
|
||||
componentInfo& operator=(const componentInfo& obj)
|
||||
{
|
||||
if(this == &obj)
|
||||
return *this;
|
||||
id = obj.id;
|
||||
uuid = obj.uuid;
|
||||
nspath = obj.nspath;
|
||||
tag = obj.tag;
|
||||
name = obj.name;
|
||||
description = obj.description;
|
||||
grid = obj.grid;
|
||||
zone = obj.zone;
|
||||
station = obj.station;
|
||||
type = obj.type;
|
||||
inService = obj.inService;
|
||||
state = obj.state;
|
||||
connected_bus = obj.connected_bus;
|
||||
label = obj.label;
|
||||
context = obj.context;
|
||||
page_id = obj.page_id;
|
||||
op = obj.op;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
struct busStability
|
||||
{
|
||||
int componentId = 0;
|
||||
double resistance = 0;
|
||||
bool anchor_v = false;
|
||||
double uv_alarm = 0;
|
||||
double ov_alarm = 0;
|
||||
bool anchor_i = false;
|
||||
double ui_alarm = 0;
|
||||
double oi_alarm = 0;
|
||||
busStability& operator=(const busStability& obj)
|
||||
{
|
||||
if(this == &obj)
|
||||
return *this;
|
||||
componentId = obj.componentId;
|
||||
resistance = obj.resistance;
|
||||
anchor_v = obj.anchor_v;
|
||||
uv_alarm = obj.uv_alarm;
|
||||
ov_alarm = obj.ov_alarm;
|
||||
anchor_i = obj.anchor_i;
|
||||
ui_alarm = obj.ui_alarm;
|
||||
oi_alarm = obj.oi_alarm;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class DataBase
|
||||
class DIAGRAM_DESIGNER_PUBLIC DataBase
|
||||
{
|
||||
//Q_OBJECT
|
||||
public:
|
||||
DataBase();
|
||||
~DataBase();
|
||||
QSqlQuery executeSQL(const QString& strSQL, bool createOrDrop = false,const QVariantList& params = {}, bool useTranscation = false);
|
||||
/**
|
||||
* @brief 多条批量SQL语句执行接口
|
||||
* @param sqlStatements SQL语句列表
|
||||
* @param paramsList 参数列表(要与SQL语句一一对应)
|
||||
*/
|
||||
QSqlQuery executeBatchSQL(const QStringList& sqlStatements, bool createOrDrop = false,
|
||||
const QList<QVariantList>& paramsList = QList<QVariantList>(), bool useTranscation = false);
|
||||
static DataBase* GetInstance();
|
||||
|
||||
public:
|
||||
availableID structID;
|
||||
public:
|
||||
void updateId();
|
||||
bool insertPage(QString tag,QString name,int status,QJsonObject label,QJsonObject context,QString description,int op);
|
||||
bool insertStation(int zoneId,QString name,QString description,bool isLocal,int op);
|
||||
bool insertGrid(QString name,QString description,int op);
|
||||
|
|
@ -173,14 +58,18 @@ public:
|
|||
//***********元模
|
||||
bool getAttributeGroup(); //获取属性组信息
|
||||
bool getDataType(); //获取数据类型信息
|
||||
bool getModelType(); //获取模型类型
|
||||
bool getModelGroup(); //获取模型组
|
||||
bool getAttribute(); //获取属性
|
||||
bool getModelAttribute(); //获取元模
|
||||
bool getModelAttribute(); //获取模型-属性对照组
|
||||
bool getModelConnectivity(); //获取连接性
|
||||
|
||||
QMap<int,attributeGroup> AttributeGroup() const {return _attributeGroup;}
|
||||
QMap<int,dataType> DataType() const {return _dataType;}
|
||||
QMap<int,modelType> ModelType() const {return _modelType;}
|
||||
QMap<int,modelGroup> ModelGroup() const {return _modelGroup;}
|
||||
QMap<int,attribute> Attribute() const {return _attribute;}
|
||||
QMap<int,modelAttribute> ModelAttribute() const {return _modelAttribute;}
|
||||
QMap<int,modelAttribute> ModelAttribute() const {return _modelAttribute;}
|
||||
QMap<int,modelConnectivity> ModelConnectivity() const {return _modelConnectivity;}
|
||||
//***********工程模
|
||||
bool createProjectManager(); //生成记录表,包含工程模名称,属性组名,启用和关闭的属性字段(json类型)[一个属性组建一个表]
|
||||
|
|
@ -194,18 +83,23 @@ public:
|
|||
bool deleteTable(const QString&); //删除表
|
||||
bool deleteRecordFromManager(const QString& sProject,const QString& sGroup); //删除某个模型下的组
|
||||
bool modifyProjectTable(QString sTable,QMap<QString,QString> mOld,QMap<QString,QString> mNew);
|
||||
//**********使用工程模
|
||||
QMap<QString,int> getAllProjectModel(); //获取所有工程模<名称,图元类型>
|
||||
QMap<QString,projectManager> getProjectModelGroupInfo(const QString&); //获取指定工程模所有属性组信息<属性组名,属性信息>
|
||||
private:
|
||||
QMap<int,attributeGroup> _attributeGroup; //属性组的组
|
||||
QMap<int,dataType> _dataType; //数据类型组
|
||||
QMap<int,modelType> _modelType; //模型类型
|
||||
QMap<int,modelGroup> _modelGroup; //模型组
|
||||
QMap<int,attribute> _attribute; //属性组
|
||||
QMap<int,modelAttribute> _modelAttribute; //元模组
|
||||
QMap<int,modelAttribute> _modelAttribute; //模型-属性对照组
|
||||
QMap<int,modelConnectivity> _modelConnectivity; //连接性组
|
||||
private:
|
||||
void initial();
|
||||
//bool createProjectDB();
|
||||
//void initialProjectDB();
|
||||
void readXML();
|
||||
static DataBase* instance;
|
||||
static DataBase* dbInstance;
|
||||
static int _id;
|
||||
QSqlDatabase db;
|
||||
//QSqlDatabase prodb;
|
||||
|
|
@ -217,6 +111,5 @@ private:
|
|||
int _Port;
|
||||
QString _UserName;
|
||||
QString _PassWord;
|
||||
|
||||
};
|
||||
#endif // DATABASE_H
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <QDateTime>
|
||||
|
||||
// 日志宏定义
|
||||
#define LOG(level, module, message) Logger::instance().log(Logger::level, module, message)
|
||||
#define LOG_DEBUG(module, message) LOG(DEBUG, module, message)
|
||||
#define LOG_INFO(module, message) LOG(INFO, module, message)
|
||||
#define LOG_WARN(module, message) LOG(WARNING, module, message)
|
||||
#define LOG_ERROR(module, message) LOG(ERROR, module, message)
|
||||
#define LOG_FATAL(module, message) LOG(FATAL, module, message)
|
||||
|
||||
class Logger : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum LogLevel
|
||||
{
|
||||
FATAL = 0,
|
||||
ERROR,
|
||||
WARNING,
|
||||
INFO,
|
||||
DEBUG
|
||||
};
|
||||
|
||||
//获取单例实例
|
||||
static Logger& instance();
|
||||
void log(LogLevel, const QString&, const QString&);
|
||||
|
||||
private:
|
||||
explicit Logger();
|
||||
~Logger();
|
||||
//禁止拷贝
|
||||
Logger(const Logger&) = delete; //delete关键字表示该函数不可用,包括编译器自动生成的函数
|
||||
Logger& operator=(const Logger&) = delete;
|
||||
|
||||
void initialize();
|
||||
void loadConfig(/*const QString&*/); //本系统是通过Settings类进行配置文件信息读取
|
||||
void setLogFile(const QString&);
|
||||
void shutdown();
|
||||
|
||||
void writeToFile(const QString&);
|
||||
void rollLogFiles(); //当文件大小超过设置上线时会触发'滚动'
|
||||
QString formatLogMessage(LogLevel, const QString&, const QString&);
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
QDateTime time;
|
||||
LogLevel level;
|
||||
QString module;
|
||||
QString message;
|
||||
Qt::HANDLE threadId;
|
||||
};
|
||||
|
||||
//配置参数
|
||||
LogLevel m_logLevel;
|
||||
QString m_logFilePath;
|
||||
QFile m_logFile;
|
||||
qint64 m_maxFileSize;
|
||||
int m_maxBackupFiles;
|
||||
bool m_outputToConsole;
|
||||
bool m_outputOtFile;
|
||||
};
|
||||
|
||||
#endif //LOGGER_H
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,155 @@
|
|||
#include "logger.h"
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QTextStream>
|
||||
#include <QApplication>
|
||||
|
||||
Logger& Logger::instance()
|
||||
{
|
||||
//采用静态局部变量的方式,静态局部变量的初始化是在第一次访问时,以后的调用不会多次初始化,并且生命周期和程序一致
|
||||
static Logger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
Logger::Logger()
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
shutdown();
|
||||
}
|
||||
|
||||
void Logger::initialize()
|
||||
{
|
||||
//默认配置
|
||||
m_logFilePath = "";
|
||||
m_logLevel = INFO;
|
||||
m_maxFileSize = 1024 *1024 * 10; //10MB
|
||||
m_maxBackupFiles = 5;
|
||||
m_outputToConsole = true;
|
||||
m_outputOtFile = true;
|
||||
//从配置文件中加载配置
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
void Logger::loadConfig(/*const QString& configFilePath*/)
|
||||
{
|
||||
//QString filePath = Settings::instance().value("Log", "logFile").toString();
|
||||
QString filePath = QApplication::applicationDirPath();
|
||||
setLogFile(filePath);
|
||||
|
||||
/*QString strLevel = Settings::instance().value("Log", "level").toString().toUpper();
|
||||
if(strLevel == "DEBUG")
|
||||
m_logLevel = DEBUG;
|
||||
else if(strLevel == "INFO")
|
||||
m_logLevel = INFO;
|
||||
else if(strLevel == "WARNING")
|
||||
m_logLevel = WARNING;
|
||||
else if(strLevel == "ERROR")
|
||||
m_logLevel = ERROR;
|
||||
else if(strLevel == "FATAL")
|
||||
m_logLevel = FATAL;
|
||||
|
||||
m_maxFileSize = Settings::instance().value("Log", "maxSize").toLongLong();
|
||||
m_maxBackupFiles = Settings::instance().value("Log", "backups").toInt();
|
||||
QString strOutputToConsole = Settings::instance().value("Log", "consoleOutput").toString();
|
||||
if(strOutputToConsole == "true")
|
||||
m_outputToConsole = true;
|
||||
else
|
||||
m_outputToConsole = false;
|
||||
QString strOutputToFile = Settings::instance().value("Log", "fileOutput").toString();
|
||||
if(strOutputToFile == "true")
|
||||
m_outputOtFile = true;
|
||||
else
|
||||
m_outputOtFile = false;*/
|
||||
}
|
||||
|
||||
void Logger::setLogFile(const QString& filePath)
|
||||
{
|
||||
//检查目录文件所在目录,如果不存在则创建目录
|
||||
QFileInfo fileInfo(filePath);
|
||||
QDir logDir = fileInfo.dir();
|
||||
if(!logDir.exists())
|
||||
logDir.mkpath(".");
|
||||
|
||||
//更新log文件前要先关闭当前已打开的文件
|
||||
if(m_logFile.isOpen())
|
||||
m_logFile.close();
|
||||
|
||||
m_logFilePath = filePath;
|
||||
m_logFile.setFileName(filePath);
|
||||
}
|
||||
|
||||
void Logger::shutdown()
|
||||
{
|
||||
if(m_logFile.isOpen())
|
||||
m_logFile.close();
|
||||
}
|
||||
|
||||
void Logger::writeToFile(const QString& message)
|
||||
{
|
||||
if(m_logFilePath.isEmpty())
|
||||
return;
|
||||
|
||||
if(!m_logFile.isOpen())
|
||||
{
|
||||
if (!m_logFile.open(QIODevice::Append | QIODevice::Text))
|
||||
{
|
||||
qWarning() << "Failed to open log file:" << m_logFile.errorString();
|
||||
return;
|
||||
}
|
||||
//打开文件时先键入一个换行符
|
||||
QTextStream stream(&m_logFile);
|
||||
stream << Qt::endl;
|
||||
stream.flush(); //刷新输出缓冲区,确保数据立即写入文件
|
||||
}
|
||||
|
||||
QTextStream stream(&m_logFile);
|
||||
stream << message << Qt::endl;
|
||||
stream.flush(); //刷新输出缓冲区,确保数据立即写入文件
|
||||
|
||||
if(m_logFile.size() > m_maxFileSize)
|
||||
rollLogFiles();
|
||||
}
|
||||
|
||||
void Logger::rollLogFiles()
|
||||
{
|
||||
if(m_logFile.isOpen())
|
||||
m_logFile.close();
|
||||
|
||||
//删除最旧的备份文件(备份文件以‘日志文件.数字’的格式命名,数字越大表示文件越旧)
|
||||
QFile::remove(QString("%1.%2").arg(m_logFilePath).arg(m_maxBackupFiles));
|
||||
//剩余文件依次更改名称
|
||||
for(int i = m_maxBackupFiles - 1; i > 0; i--)
|
||||
QFile::rename(QString("%1.%2").arg(m_logFilePath).arg(i), QString("%1.%2").arg(m_logFilePath).arg(i + 1));
|
||||
//将当前日志文件更改为'最新'的备份文件(编号为1)
|
||||
QFile::rename(m_logFilePath, QString("%1.1").arg(m_logFilePath));
|
||||
//更新当前配置文件(重新打开)
|
||||
m_logFile.setFileName(m_logFilePath);
|
||||
if (!m_logFile.open(QIODevice::Append | QIODevice::Text))
|
||||
qWarning() << "Failed to open new log file after rolling:" << m_logFile.errorString();
|
||||
}
|
||||
|
||||
QString Logger::formatLogMessage(LogLevel level, const QString& context, const QString& message)
|
||||
{
|
||||
static const char* levelStrings[] = {"FATAL", "ERROR", "WARNING", "INFO", "DEBUG"};
|
||||
return QString("[%1] [%2] [%3] %4")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
.arg(levelStrings[level])
|
||||
.arg(context)
|
||||
.arg(message);
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, const QString& context, const QString& message)
|
||||
{
|
||||
if(level > m_logLevel)
|
||||
return;
|
||||
|
||||
QString formatMessage = formatLogMessage(level, context, message);
|
||||
if(m_outputToConsole)
|
||||
QTextStream(stderr) << formatMessage << Qt::endl;
|
||||
if(m_outputOtFile)
|
||||
writeToFile(formatMessage);
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ public:
|
|||
public:
|
||||
void initial();
|
||||
ToolBox* getToolBox() const;
|
||||
void updateProjectModelItemList(); //更新工程模对象列表
|
||||
signals:
|
||||
void addEletricItem(GraphicsItemType&);
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#include <QVBoxLayout>
|
||||
|
||||
#include "electricElementsPanel.h"
|
||||
#include "electricElementsBox.h"
|
||||
#include "toolBox.h"
|
||||
#include "util/baseSelector.h"
|
||||
#include "dataBase.h"
|
||||
|
||||
ElectricElementsBox::ElectricElementsBox(QObject *parent)
|
||||
: QObject(parent),
|
||||
|
|
@ -46,6 +46,11 @@ ToolBox* ElectricElementsBox::getToolBox() const
|
|||
return m_pToolBox;
|
||||
}
|
||||
|
||||
void ElectricElementsBox::updateProjectModelItemList()
|
||||
{
|
||||
QMap<QString,int> model = DataBase::GetInstance()->getAllProjectModel();
|
||||
}
|
||||
|
||||
void ElectricElementsBox::onSignal_addEletricItem(GraphicsItemType& type)
|
||||
{
|
||||
emit addEletricItem(type);
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ void projectModelDlg::onDeleteProjectClicked()
|
|||
//=============================================================================
|
||||
QStringList projectModelDlg::getModelList() const
|
||||
{
|
||||
QMap<int,modelAttribute> modelMap = DataBase::GetInstance()->ModelAttribute();
|
||||
QMap<int,modelType> modelMap = DataBase::GetInstance()->ModelType();
|
||||
|
||||
QSet<QString> modelSet;
|
||||
for(auto &model:modelMap)
|
||||
|
|
@ -550,68 +550,76 @@ QStringList projectModelDlg::getModelList() const
|
|||
|
||||
QStringList projectModelDlg::getGroupList(const QString& sM) const
|
||||
{
|
||||
QMap<int,modelType> modelType = DataBase::GetInstance()->ModelType();
|
||||
QMap<int,modelGroup> modelGroupMap = DataBase::GetInstance()->ModelGroup();
|
||||
QMap<int,attributeGroup> groupMap = DataBase::GetInstance()->AttributeGroup();
|
||||
QMap<int,modelAttribute> modelMap = DataBase::GetInstance()->ModelAttribute();
|
||||
QMap<int,attribute> attMap = DataBase::GetInstance()->Attribute();
|
||||
|
||||
QSet<int> groupSet;
|
||||
QStringList groupList;
|
||||
for(auto &model:modelMap) //遍历获取属性组id
|
||||
int metaId = 0;
|
||||
for(auto &meta:modelType)
|
||||
{
|
||||
if(model.modelType == sM)
|
||||
if(sM == meta.modelType) //查找元模对应的id
|
||||
{
|
||||
int attId = model.attributeId;
|
||||
groupSet.insert(attMap[attId].attributeGroup);
|
||||
metaId = meta.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &id:groupSet) //取得id对应的组名
|
||||
QList<int> lstGroupId;
|
||||
for(auto &group:modelGroupMap) //找到元模id对应的属性组id
|
||||
{
|
||||
groupList.append(groupMap[id].group);
|
||||
if(group.modelTypeId == metaId)
|
||||
{
|
||||
lstGroupId.push_back(group.attributeGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList groupList;
|
||||
for(auto &id:lstGroupId) //从属性组中找到id对应的组名
|
||||
{
|
||||
groupList.append(groupMap[id].groupType);
|
||||
}
|
||||
|
||||
return groupList;
|
||||
}
|
||||
|
||||
QStringList projectModelDlg::getAttributeList(const QString& sM,const QString& sG) const
|
||||
{
|
||||
QMap<int,modelType> modelType = DataBase::GetInstance()->ModelType();
|
||||
//QMap<int,modelGroup> modelGroupMap = DataBase::GetInstance()->ModelGroup();
|
||||
QMap<int,attributeGroup> groupMap = DataBase::GetInstance()->AttributeGroup();
|
||||
QMap<int,modelAttribute> modelMap = DataBase::GetInstance()->ModelAttribute();
|
||||
QMap<int,modelAttribute> modelAttMap = DataBase::GetInstance()->ModelAttribute();
|
||||
QMap<int,attribute> attMap = DataBase::GetInstance()->Attribute();
|
||||
|
||||
int groupId = -1;
|
||||
for(auto &group:groupMap)
|
||||
int metaId = -1;
|
||||
for(auto &meta:modelType)
|
||||
{
|
||||
if(group.group == sG) //根据group获取对应Id
|
||||
if(sM == meta.modelType) //查找元模对应的id
|
||||
{
|
||||
groupId = group.id;
|
||||
metaId = meta.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QSet<int> attSet;
|
||||
QStringList attList;
|
||||
if(groupId != -1)
|
||||
int groupId = -1;
|
||||
for(auto &attGroup:groupMap)
|
||||
{
|
||||
for(auto &model:modelMap) //获取当前模型,当前属性组下的属性
|
||||
if(attGroup.groupType == sG) //返回参数属性组名对应的id
|
||||
{
|
||||
if(model.modelType == sM)
|
||||
{
|
||||
int attId = model.attributeId;
|
||||
if(attMap[attId].attributeGroup == groupId) //当前属性的属性组id等于选定的属性组id
|
||||
{
|
||||
attSet.insert(model.attributeId);
|
||||
}
|
||||
}
|
||||
groupId = attGroup.id;
|
||||
break;
|
||||
}
|
||||
|
||||
for(auto &id:attSet) //取得id对应的组名
|
||||
{
|
||||
attList.append(attMap[id].attribute);
|
||||
}
|
||||
return attList;
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
QStringList lst;
|
||||
for(auto &mt:modelAttMap)
|
||||
{
|
||||
if(mt.modelTypeId == metaId && mt.attributeGroupId == groupId)
|
||||
{
|
||||
lst.append(attMap[mt.attributeId].attribute);
|
||||
}
|
||||
}
|
||||
|
||||
return lst;
|
||||
}
|
||||
|
||||
void projectModelDlg::setItemAttribute(const QString& name,QStandardItem* p)
|
||||
|
|
@ -621,19 +629,18 @@ void projectModelDlg::setItemAttribute(const QString& name,QStandardItem* p)
|
|||
|
||||
for(auto &att:attMap)
|
||||
{
|
||||
QString sType = dt[att.dataType].dataType; //获得属性id对应的属性名
|
||||
QString sType = dt[att.dataTypeId].dataType; //获得属性id对应的属性名
|
||||
if(name == att.attribute)
|
||||
{
|
||||
p->setData(att.id,Id);
|
||||
p->setData(att.attribute,Attribute);
|
||||
p->setData(sType,DataType);
|
||||
p->setData(att.attributeName,AttributeName);
|
||||
p->setData(sType,DataType); //不直接使用id,拼接完成str
|
||||
p->setData(att.lengthPrecision,LengthPrecision);
|
||||
p->setData(att.scale,Scale);
|
||||
p->setData(att.isNotNull,IsNotNull);
|
||||
p->setData(att.defaultValue,DefaultValue);
|
||||
p->setData(att.valueRange,ValueRange);
|
||||
p->setData(att.attributeGroup,AttributeGroup);
|
||||
p->setData(att.isNotNull,IsNotNull);
|
||||
p->setData(att.isIndex,IsIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -641,6 +648,8 @@ void projectModelDlg::setItemAttribute(const QString& name,QStandardItem* p)
|
|||
|
||||
QPair<QString,QString> projectModelDlg::combinePropertySql(const QStandardItem* pItem)
|
||||
{
|
||||
QMap<int,dataType> dt = DataBase::GetInstance()->DataType();
|
||||
|
||||
int id = pItem->data(Id).toInt();
|
||||
QString attribute = pItem->data(Attribute).toString();
|
||||
QString dataType = pItem->data(DataType).toString();
|
||||
|
|
@ -648,9 +657,7 @@ QPair<QString,QString> projectModelDlg::combinePropertySql(const QStandardItem*
|
|||
int scale = pItem->data(Scale).toInt();
|
||||
QString defaultValue = pItem->data(DefaultValue).toString();
|
||||
QString valueRange = pItem->data(ValueRange).toString();
|
||||
int attributeGroup = pItem->data(AttributeGroup).toInt();
|
||||
int isNotNull = pItem->data(IsNotNull).toInt();
|
||||
int isIndex = pItem->data(IsIndex).toInt();
|
||||
|
||||
bool needsQuotes = stringDataTypes.contains(dataType);
|
||||
// 处理数据类型及其长度精度
|
||||
|
|
|
|||
Loading…
Reference in New Issue