PowerModeler/include/global.h

147 lines
3.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef GLOBAL_H
#define GLOBAL_H
#include <QString>
#include <QSqlError>
#include <QVector>
enum DialogState
{
DS_New,
DS_Edit
};
struct DatabaseConfig
{
QString strID; //存储在配置文件时用作唯一标识
QString strConnectionName;
QString strDBType; //"QPSQL","QMYSQL"...
QString strHost;
int nPort;
QString strDBName;
QString strUserName;
QString strPassword;
bool bSavePS;
QString strComment;
DatabaseConfig()
{
strConnectionName = "";
strDBType = "QPSQL";
strHost = "";
nPort = 5432;
strDBName = "postgres";
strUserName = "";
strPassword = "";
bSavePS = true;
strComment = "";
}
};
struct AttributeGroup
{
int id;
QString name; //中文展示名称
QString type; //英文标识名称
QString remark;
bool isPublic;
AttributeGroup()
{
id = -1;
name = "";
type = "";
remark = "";
isPublic = false;
}
//利用移动语义优化的构造函数(不定义也可以QString实际上实现了隐式共享)
AttributeGroup(int id, QString name, QString type, QString remark, bool isPublic)
: id(id),
name(std::move(name)),
type(std::move(type)),
remark(std::move(remark)),
isPublic(isPublic){}
};
struct Model
{
int id;
QString name; //中文展示名称
QString type; //英文标识名称
QString remark;
QVector<int> groups;
Model(int id, QString name, QString type, QString remark, QVector<int> groups)
: id(id),
name(std::move(name)),
type(std::move(type)),
remark(std::move(remark)),
groups(std::move(groups)){}
};
struct Attribute
{
int id;
QString name; //中文展示名称(filed:attribute_name)
QString type; //英文表示名称(filed:attribute),不可重名
int dataTypeID;
int dataLength; //filed:length_precision
QString defaultValue;
Attribute()
{
id = -1;
name = "";
type = "";
dataTypeID = -1;
dataLength = -1;
defaultValue = "";
}
Attribute(int id, QString name, QString type, int dataTypeID, int dataLength, QString defaultVaule)
:id(id),
name(std::move(name)),
type(std::move(type)),
dataTypeID(dataTypeID),
dataLength(dataLength),
defaultValue(std::move(defaultVaule)){}
};
struct ModelAttributeGroup
{
int modelID;
int groupID;
QString strModelName;
QString strGroupName;
ModelAttributeGroup(int modelID, int groupID, QString strModelName, QString strGroupName)
: modelID(modelID),
groupID(groupID),
strModelName(std::move(strModelName)),
strGroupName(std::move(strGroupName)){}
};
struct PaginationInfo
{
int totalEntries; //数据条目总数量
int entriesPerPage; //每页条目数量
int totalPages; //总页数
int currentPage; //当前页数
};
class DatabaseException : public std::runtime_error
{
public:
explicit DatabaseException(const QSqlError& error)
: std::runtime_error(error.text().toStdString()), m_error(error) {}
QSqlError error() const { return m_error; }
private:
QSqlError m_error;
};
#endif