125 lines
5.4 KiB
C++
125 lines
5.4 KiB
C++
#ifndef PROJECTMODELDLG_H
|
||
#define PROJECTMODELDLG_H
|
||
|
||
#include <QDialog>
|
||
#include <QStandardItemModel>
|
||
#include <QItemSelection>
|
||
#include <QTableWidgetItem>
|
||
#include "tools.h"
|
||
#include "global.h"
|
||
|
||
QT_BEGIN_NAMESPACE
|
||
namespace Ui { class projectModelDlg; }
|
||
QT_END_NAMESPACE
|
||
|
||
enum projectState
|
||
{
|
||
Err = -1,
|
||
NotExist = 0,
|
||
Exist,
|
||
Changed
|
||
};
|
||
|
||
struct FormerName //曾用名,记录修改前名称
|
||
{
|
||
QString sName;
|
||
bool bChanged = false; //是否改变过
|
||
};
|
||
|
||
struct PropertyState //每个属性的状态
|
||
{
|
||
bool checkState = false;
|
||
QString dataType;
|
||
};
|
||
|
||
struct PropertyPage //属性信息
|
||
{
|
||
QMap<QString,PropertyState> mCheckState; //属性选择状态
|
||
};
|
||
|
||
typedef QMap<QString,PropertyPage> MapProperty; //属性组
|
||
struct PropertyModel //工程模
|
||
{
|
||
MapProperty mapProperty;
|
||
int nType = 0; //工程模类型,选择图标后确定
|
||
QStandardItemModel* pBase; //基础属性
|
||
QStandardItemModel* pSelect; //已选择属性
|
||
FormerName formerMeta; //曾用元模名
|
||
FormerName formerProject; //曾用工程模名
|
||
QMap<QString,projectManager> dataInfo; //存放数据库内容
|
||
};
|
||
typedef QMap<QString,PropertyModel> MapProject; //str为工程名,PropertyModel为工程属性
|
||
typedef QMap<QString,MapProject> MapMeta; //str为元模名,PropertyModel为工程模集
|
||
|
||
class projectModelDlg : public QDialog
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
projectModelDlg(QWidget *parent = nullptr);
|
||
~projectModelDlg();
|
||
|
||
void initial();
|
||
void initialModel();
|
||
void initialList();
|
||
MapProperty addNewProject(const QString& sMeta,const QString& sProject,PropertyModel&); //根据元模型、工程模名称生成工程模对象
|
||
//void update();
|
||
void generate(const QString&); //根据输入名称生成表
|
||
|
||
public slots:
|
||
void onSaveClicked();
|
||
void onCancelClicked();
|
||
void onApplyClicked();
|
||
void onRevokeClicked();
|
||
//void onBaseModelIndexChanged(const QString&);
|
||
//void onProjectIndexChanged(const QString&);
|
||
//void onPropertyIndexChanged(const QString&);
|
||
//void onIconClicked(const QModelIndex &index); //关联图元改变
|
||
//void onIndexClicked(const QModelIndex &index); //索引列表点击
|
||
void onIndexRbtnClicked(const QPoint &pos); //索引列表右键菜单
|
||
void onDeleteProjectClicked(); //删除选中工程模
|
||
|
||
void addPropertyGroup(); //添加tableWidget中的工程模
|
||
void onTableItemClicked(QTableWidgetItem *item); //模型item点击事件
|
||
void onDelegateFinishEdit(const QModelIndex &index, const QString &value); //lineEdit代理编辑完成事件
|
||
public:
|
||
QStringList getModelList() const; //获取元模型列表
|
||
QStringList getGroupList(const QString& model) const; //返回该元模下的属性组列表
|
||
QStringList getAttributeList(const QString& model,const QString& group) const; //根据元模名和组名返回属性列表
|
||
void setItemAttribute(const QString&,QStandardItem*); //设置item的属性(数据库表字段名)
|
||
QPair<QString,QString> combinePropertySql(const QStandardItem*); //根据item属性生成sql
|
||
QString getProjectName() const; //返回当前选择项目的名称
|
||
QString getMetaName() const; //返回当前元模型名
|
||
bool ifProjectEqual(QMap<QString,QJsonObject>); //根据每个属性组的勾选状态判断两个模型是否相同
|
||
QString modifyProjectModel(QMap<QString,QJsonObject>); //修改工程模
|
||
bool renameProjectModel(const QString& strCur,QMap<QString,projectManager> datas); //重命名工程模
|
||
void updateComponentModelName(const QString& strOld,const QString& strNew); //更新component中的工程模
|
||
private:
|
||
//void updateIconList(); //选择工程模后刷新关联图标
|
||
void removeProjectData(const QString&,const QString&,int role); //移除对应的project层级结构
|
||
QString getItemDataType(const QStandardItem* pItem); //返回数据类型
|
||
bool createPropertyTable(const QString& sProject,const QString& sGroup,QList<QStandardItem*> lstSelect,QList<QStandardItem*> lstBase,int nLinkType); //创建属性组表并插入记录到管理表(工程名,当前项迭代器,关联图元类型)
|
||
QJsonObject getSelectedState(QList<QStandardItem*> select,QList<QStandardItem*> base); //返回json格式的选中状态
|
||
QList<QStandardItem*> getGroupSub(QStandardItemModel*,const QString&); //返回指定组下的属性(如果存在)
|
||
|
||
void setupUI();
|
||
void initialTypeMap();
|
||
int getLevel(QStandardItem *item); //返回当前item所在层级,0为根
|
||
projectState couldSave();
|
||
|
||
void setTableItemState(int row,TableItemState state); //设置状态
|
||
int getModelEditState(); //返回工程模编辑状态(选择、编辑、新建)
|
||
private:
|
||
Ui::projectModelDlg *ui;
|
||
MapMeta m_mapTotal;
|
||
QString _curMeta; //当前元模型
|
||
QString _curProject; //当前工程模
|
||
QString _curType; //当前关联类型
|
||
PropertyModel _curModel; //新建的model
|
||
int _curRow; //当前操作行
|
||
|
||
BiDirectionalMap<QString,int> _mapType; //类型名映射表
|
||
};
|
||
|
||
#endif
|