2025-03-04 09:44:03 +08:00
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include <QJsonArray>
|
2025-03-07 19:24:19 +08:00
|
|
|
|
#include <QMenu>
|
2025-03-04 09:44:03 +08:00
|
|
|
|
#include "projectModelDlg.h"
|
|
|
|
|
|
#include "renameModel.h"
|
|
|
|
|
|
#include "dataBase.h"
|
|
|
|
|
|
#include "ui_projectModelDlg.h"
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
|
|
const QSet<QString> stringDataTypes = {"varchar", "char", "text", "date", "time", "timestamp"};
|
|
|
|
|
|
|
|
|
|
|
|
projectModelDlg::projectModelDlg(QWidget *parent)
|
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
|
, ui(new Ui::projectModelDlg)
|
|
|
|
|
|
,m_pRenameModel(nullptr)
|
|
|
|
|
|
,_viewModel(nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());
|
|
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
m_pRenameModel = new RenameModel(this);
|
|
|
|
|
|
if(m_pRenameModel)
|
|
|
|
|
|
m_pRenameModel->hide();
|
|
|
|
|
|
initial();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
projectModelDlg::~projectModelDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::initial()
|
|
|
|
|
|
{
|
2025-03-07 19:24:19 +08:00
|
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
connect(ui->btn_save,&QPushButton::clicked,this,&projectModelDlg::onSaveClicked);
|
|
|
|
|
|
connect(ui->btn_cancel,&QPushButton::clicked,this,&projectModelDlg::onCancelClicked);
|
|
|
|
|
|
connect(ui->btn_apply,&QPushButton::clicked,this,&projectModelDlg::onApplyClicked);
|
|
|
|
|
|
connect(ui->btn_revoke,&QPushButton::clicked,this,&projectModelDlg::onRevokeClicked);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui->cb_baseModel,&QComboBox::textActivated,this,&projectModelDlg::onBaseModelIndexChanged);
|
|
|
|
|
|
connect(ui->cb_projectModel,&QComboBox::textActivated,this,&projectModelDlg::onProjectIndexChanged);
|
|
|
|
|
|
connect(ui->cb_property,&QComboBox::textActivated,this,&projectModelDlg::onPropertyIndexChanged);
|
|
|
|
|
|
|
2025-03-07 19:24:19 +08:00
|
|
|
|
ui->treeView_model->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
connect(ui->treeView_model, &QTreeView::customContextMenuRequested, this, &projectModelDlg::onIndexRbtnClicked);
|
|
|
|
|
|
connect(ui->treeView_model, &QTreeView::clicked, this, &projectModelDlg::onIndexClicked);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
initialModel();
|
|
|
|
|
|
initialList();
|
|
|
|
|
|
update();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 17:18:25 +08:00
|
|
|
|
MapProperty projectModelDlg::addNewProject(const QString& sMeta,const QString& sProject)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
MapProperty mt;
|
|
|
|
|
|
QStringList lstProperty = getGroupList(sMeta);
|
|
|
|
|
|
//lstProperty<<QString("base")<<QString("seperation");
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,QJsonObject> mapCheckState = DataBase::GetInstance()->getCheckStateFromManager(sProject); //获取选择状态
|
2025-03-14 17:18:25 +08:00
|
|
|
|
for(auto &property:lstProperty)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-14 17:18:25 +08:00
|
|
|
|
PropertyPage struProperty;
|
|
|
|
|
|
struProperty.pBase = new QStandardItemModel(this);
|
|
|
|
|
|
struProperty.pSelect = new QStandardItemModel(this);
|
|
|
|
|
|
if(mapCheckState.contains(property)) //生成的模型中勾选了该属性组
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
QJsonObject obj = mapCheckState[property];
|
|
|
|
|
|
QJsonArray nodesJsonArray = obj["checkState"].toArray();
|
|
|
|
|
|
|
|
|
|
|
|
for (QJsonValueRef nodeJson : nodesJsonArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject node = nodeJson.toObject();
|
|
|
|
|
|
QString propertyName = node["name"].toString();
|
|
|
|
|
|
int nState = node["checked"].toInt();
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QString dataType = node["type"].toString();
|
2025-03-28 18:08:21 +08:00
|
|
|
|
QString defaultValue = node["defaultValue"].toString();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
|
|
|
|
|
|
QStandardItem* pItem = new QStandardItem(propertyName);
|
|
|
|
|
|
setItemAttribute(propertyName,pItem);
|
2025-03-14 17:18:25 +08:00
|
|
|
|
PropertyState sta;
|
|
|
|
|
|
sta.dataType = dataType;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
if(nState)
|
|
|
|
|
|
{
|
|
|
|
|
|
struProperty.pSelect->appendRow(pItem);
|
2025-03-14 17:18:25 +08:00
|
|
|
|
sta.checkState = true;
|
|
|
|
|
|
struProperty.mCheckState.insert(propertyName,sta);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
struProperty.pBase->appendRow(pItem);
|
2025-03-14 17:18:25 +08:00
|
|
|
|
sta.checkState = false;
|
|
|
|
|
|
struProperty.mCheckState.insert(propertyName,sta);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-14 17:18:25 +08:00
|
|
|
|
else //未勾选属性组或是新建
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList lstName = getAttributeList(sMeta,property);
|
|
|
|
|
|
for(auto &name:lstName)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItem* pItem = new QStandardItem(name);
|
|
|
|
|
|
setItemAttribute(name,pItem);
|
|
|
|
|
|
struProperty.pBase->appendRow(pItem);
|
|
|
|
|
|
QString dataType = getItemDataType(pItem);
|
|
|
|
|
|
PropertyState sta;
|
|
|
|
|
|
sta.dataType = dataType;
|
|
|
|
|
|
sta.checkState = false;
|
|
|
|
|
|
struProperty.mCheckState.insert(name,sta); //初始都是未选择状态
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
mt.insert(property,struProperty);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return mt;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::initialModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
_viewModel = new QStandardItemModel(this);
|
|
|
|
|
|
QStringList lstModel = getModelList();
|
|
|
|
|
|
//lstType<<QString("metaModel1")<<QString("metaModel2");
|
|
|
|
|
|
for(auto &model:lstModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject mp;
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QMap<QString,int> mapProject = DataBase::GetInstance()->getProjectFromManager(model);
|
|
|
|
|
|
mapProject.insert(QString::fromWCharArray(L"新建"),0); //每个类别都有未命名工程
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QStandardItem* modelItem = new QStandardItem(model); //总览view类型
|
|
|
|
|
|
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QMap<QString,int>::Iterator iter;
|
|
|
|
|
|
for(iter = mapProject.begin();iter != mapProject.end(); ++iter)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QStandardItem* propertyItem = new QStandardItem(iter.key());
|
2025-03-04 09:44:03 +08:00
|
|
|
|
modelItem->appendRow(propertyItem); //总览view名称
|
|
|
|
|
|
|
|
|
|
|
|
PropertyModel pm;
|
2025-03-14 17:18:25 +08:00
|
|
|
|
pm.mapProperty = addNewProject(model,iter.key());
|
|
|
|
|
|
pm.nType = iter.value();
|
|
|
|
|
|
mp.insert(iter.key(),pm);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
2025-03-14 17:18:25 +08:00
|
|
|
|
|
2025-03-04 09:44:03 +08:00
|
|
|
|
_viewModel->appendRow(modelItem);
|
|
|
|
|
|
//todo:读取存储,按分类遍历名称
|
|
|
|
|
|
m_mapTotal.insert(model,mp);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->treeView_model->setModel(_viewModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::initialList()
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItemModel *model = new QStandardItemModel(this);
|
|
|
|
|
|
ui->listView_icon->setModel(model);
|
|
|
|
|
|
|
|
|
|
|
|
QStandardItem* pNon = new QStandardItem(QString::fromWCharArray(L"未选择"));
|
|
|
|
|
|
QStandardItem* pMotor = new QStandardItem("motor");
|
|
|
|
|
|
QStandardItem* pBus = new QStandardItem("bus");
|
|
|
|
|
|
pNon->setData(0,Qt::UserRole);
|
|
|
|
|
|
pMotor->setData(1,Qt::UserRole);
|
|
|
|
|
|
pBus->setData(2,Qt::UserRole);
|
|
|
|
|
|
model->appendRow(pNon);
|
|
|
|
|
|
model->appendRow(pMotor);
|
|
|
|
|
|
model->appendRow(pBus);
|
|
|
|
|
|
|
|
|
|
|
|
connect(ui->listView_icon,&QListView::clicked,this,&projectModelDlg::onIconClicked);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::update()
|
|
|
|
|
|
{
|
|
|
|
|
|
for(MapMeta::Iterator iter = m_mapTotal.begin();iter != m_mapTotal.end();++iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->cb_baseModel->addItem(iter.key());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::generate(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(_curMeta); //获取元模下的工程
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject mp = iter.value();
|
|
|
|
|
|
MapProject::Iterator ite = mp.find(_curProject); //获取工程下的属性组
|
|
|
|
|
|
if(ite != mp.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProperty mapProperty = ite.value().mapProperty;
|
|
|
|
|
|
|
|
|
|
|
|
bool createRes = true; //动态表生成结果
|
|
|
|
|
|
for(MapProperty::Iterator it = mapProperty.begin();it != mapProperty.end();++it){ //每个属性组单独生成表
|
2025-03-14 17:18:25 +08:00
|
|
|
|
int nType = ite.value().nType;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QStandardItemModel* pSelectModel = it->pSelect;
|
|
|
|
|
|
QStandardItem *rootItem = pSelectModel->invisibleRootItem();
|
2025-03-14 17:18:25 +08:00
|
|
|
|
if(rootItem->rowCount() == 0) //修改逻辑,未勾选的属性组不生成表 by/20250311
|
|
|
|
|
|
continue;
|
|
|
|
|
|
bool res = createPropertyTable(str,it,nType);
|
|
|
|
|
|
createRes = createRes && res;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
if(createRes)
|
|
|
|
|
|
{
|
|
|
|
|
|
PropertyModel pm = m_mapTotal[_curMeta].take(_curProject); //取出要保存的对象,另存为新索引
|
|
|
|
|
|
m_mapTotal[_curMeta].insert(str,pm);
|
|
|
|
|
|
|
|
|
|
|
|
if(_curProject == QString::fromWCharArray(L"新建"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->cb_projectModel->addItem(str);
|
2025-03-14 17:18:25 +08:00
|
|
|
|
PropertyModel npm; //新建工程对象
|
|
|
|
|
|
npm.mapProperty = addNewProject(_curMeta,_curProject);
|
|
|
|
|
|
m_mapTotal[_curMeta].insert(_curProject,npm);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QList<QStandardItem*> lst = _viewModel->findItems(_curMeta);
|
|
|
|
|
|
if(lst.size() == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItem* item = lst[0];
|
|
|
|
|
|
item->appendRow(new QStandardItem(str));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
_curProject = str;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else //创建失败
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"创建表失败"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onSaveClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProject.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请选择操作的工程对象"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-14 17:18:25 +08:00
|
|
|
|
if(m_mapTotal[_curMeta][_curProject].nType == 0)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请选择工程模类型"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(m_pRenameModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pRenameModel->showCenter();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onCancelClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onApplyClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProperty.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请先选择属性"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(_curMeta);
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject project = iter.value();
|
|
|
|
|
|
MapProject::Iterator it= project.find(_curProject);
|
|
|
|
|
|
if(it != project.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProperty property = it.value().mapProperty;
|
|
|
|
|
|
QModelIndex selected = ui->treeView_base->currentIndex();
|
|
|
|
|
|
QStandardItem* item = property[_curProperty].pBase->takeItem(selected.row());
|
|
|
|
|
|
if(item)
|
|
|
|
|
|
{
|
|
|
|
|
|
property[_curProperty].pSelect->appendRow(item);
|
|
|
|
|
|
property[_curProperty].pBase->removeRow(selected.row());
|
2025-03-14 17:18:25 +08:00
|
|
|
|
m_mapTotal[_curMeta][_curProject].mapProperty[_curProperty].mCheckState[item->text()].checkState = true; //选择状态设为1
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onRevokeClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProperty.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请先选择属性"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(_curMeta);
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject project = iter.value();
|
|
|
|
|
|
MapProject::Iterator it= project.find(_curProject);
|
|
|
|
|
|
if(it != project.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProperty property = it.value().mapProperty;
|
|
|
|
|
|
QModelIndex selected = ui->treeView_sub->currentIndex();
|
|
|
|
|
|
QStandardItem* item = property[_curProperty].pSelect->takeItem(selected.row());
|
|
|
|
|
|
if(item)
|
|
|
|
|
|
{
|
|
|
|
|
|
property[_curProperty].pBase->appendRow(item);
|
|
|
|
|
|
property[_curProperty].pSelect->removeRow(selected.row());
|
2025-03-14 17:18:25 +08:00
|
|
|
|
m_mapTotal[_curMeta][_curProject].mapProperty[_curProperty].mCheckState[item->text()].checkState = false; //选择状态设为0
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onBaseModelIndexChanged(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curMeta == str) //选择未改变
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(ui->stackedWidget->currentIndex() !=1) //选择元模时隐藏iconlist
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->stackedWidget->setCurrentIndex(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->treeView_base->setModel(nullptr);
|
|
|
|
|
|
ui->treeView_sub->setModel(nullptr);
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(str);
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
//先清空已有
|
|
|
|
|
|
_curMeta = str;
|
|
|
|
|
|
_curProject = "";
|
|
|
|
|
|
_curProperty = "";
|
|
|
|
|
|
ui->cb_projectModel->clear();
|
|
|
|
|
|
ui->cb_property->clear();
|
|
|
|
|
|
MapProject project = iter.value();
|
|
|
|
|
|
for(MapProject::Iterator it = project.begin();it != project.end();++it)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->cb_projectModel->addItem(it.key());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onProjectIndexChanged(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curMeta.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请先选择元模型"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProject == str) //选择未改变
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->treeView_base->setModel(nullptr);
|
|
|
|
|
|
ui->treeView_sub->setModel(nullptr);
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(_curMeta);
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject project = iter.value();
|
|
|
|
|
|
MapProject::Iterator it= project.find(str);
|
|
|
|
|
|
if(it != project.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
_curProject = str;
|
|
|
|
|
|
_curProperty = "";
|
|
|
|
|
|
ui->cb_property->clear();
|
|
|
|
|
|
MapProperty property = it.value().mapProperty;
|
|
|
|
|
|
for(MapProperty::Iterator ite = property.begin();ite != property.end();++ite)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->cb_property->addItem(ite.key());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-14 17:18:25 +08:00
|
|
|
|
|
|
|
|
|
|
QString sFirst = ui->cb_property->itemText(0); //点选工程模后默认选中第一条属性
|
|
|
|
|
|
onPropertyIndexChanged(sFirst);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
2025-03-14 17:18:25 +08:00
|
|
|
|
updateIconList();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onPropertyIndexChanged(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProject.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"请先选择工程模型"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_curProperty == str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
ui->treeView_base->setModel(nullptr);
|
|
|
|
|
|
ui->treeView_sub->setModel(nullptr);
|
|
|
|
|
|
MapMeta::Iterator iter = m_mapTotal.find(_curMeta);
|
|
|
|
|
|
if(iter != m_mapTotal.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProject project = iter.value();
|
|
|
|
|
|
MapProject::Iterator it= project.find(_curProject);
|
|
|
|
|
|
if(it != project.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
MapProperty property = it.value().mapProperty;
|
|
|
|
|
|
MapProperty::Iterator ite = property.find(str);
|
|
|
|
|
|
if(ite != property.end())
|
|
|
|
|
|
{
|
|
|
|
|
|
_curProperty = str;
|
|
|
|
|
|
ui->treeView_base->setModel(nullptr);
|
|
|
|
|
|
ui->treeView_sub->setModel(nullptr);
|
|
|
|
|
|
QStandardItemModel* pBase = ite.value().pBase;
|
|
|
|
|
|
QStandardItemModel* pSelect = ite.value().pSelect;
|
|
|
|
|
|
ui->treeView_base->setModel(pBase);
|
|
|
|
|
|
ui->treeView_sub->setModel(pSelect);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onIconClicked(const QModelIndex &index)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItemModel *model = dynamic_cast<QStandardItemModel*>(ui->listView_icon->model());
|
|
|
|
|
|
if(model)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItem* pItem = model->itemFromIndex(index);
|
|
|
|
|
|
int id = pItem->data(Qt::UserRole).toInt();
|
2025-03-07 19:24:19 +08:00
|
|
|
|
m_mapTotal[_curMeta][_curProject].nType = id;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onIndexClicked(const QModelIndex &index)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取模型
|
|
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView_model->model());
|
|
|
|
|
|
if (!model) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为第二级节点
|
|
|
|
|
|
if (index.parent().isValid()) { // 父索引有效,说明是第二级节点
|
|
|
|
|
|
QString sMeta = model->data(index.parent(), Qt::DisplayRole).toString();
|
|
|
|
|
|
QString sProject = model->data(index, Qt::DisplayRole).toString();
|
|
|
|
|
|
|
|
|
|
|
|
ui->cb_baseModel->setCurrentText(sMeta); //无法编辑combobox的会跳转到该内容
|
2025-03-14 17:18:25 +08:00
|
|
|
|
onBaseModelIndexChanged(sMeta); //Base的改变会清空_project
|
2025-03-07 19:24:19 +08:00
|
|
|
|
|
|
|
|
|
|
ui->cb_projectModel->setCurrentText(sProject);
|
|
|
|
|
|
onProjectIndexChanged(sProject);
|
|
|
|
|
|
|
|
|
|
|
|
_curMeta = sMeta;
|
|
|
|
|
|
_curProject = sProject;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
QString sMeta = model->data(index, Qt::DisplayRole).toString();
|
|
|
|
|
|
ui->cb_baseModel->setCurrentText(sMeta); //无法编辑combobox的会跳转到该内容
|
|
|
|
|
|
onBaseModelIndexChanged(sMeta);
|
|
|
|
|
|
_curMeta = sMeta;
|
|
|
|
|
|
_curProject = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onIndexRbtnClicked(const QPoint &pos)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取当前点击的位置对应的索引
|
|
|
|
|
|
QModelIndex index = ui->treeView_model->indexAt(pos);
|
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
|
return; // 如果点击的是空白区域,直接返回
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为第一级节点
|
|
|
|
|
|
if (!index.parent().isValid()) {
|
|
|
|
|
|
return; // 如果是第一级节点,不显示菜单
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是第二级节点,创建右键菜单
|
|
|
|
|
|
QMenu menu;
|
|
|
|
|
|
QAction *deleteAction = new QAction("删除节点", this);
|
|
|
|
|
|
menu.addAction(deleteAction);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接删除菜单项的触发信号与槽函数
|
|
|
|
|
|
connect(deleteAction, &QAction::triggered, this, &projectModelDlg::onDeleteProjectClicked);
|
|
|
|
|
|
|
|
|
|
|
|
// 在点击位置显示菜单
|
|
|
|
|
|
menu.exec(ui->treeView_model->mapToGlobal(pos));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::onDeleteProjectClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取当前选中的索引
|
|
|
|
|
|
QModelIndexList selectedIndexes = ui->treeView_model->selectionModel()->selectedRows();
|
|
|
|
|
|
if (selectedIndexes.isEmpty()) {
|
|
|
|
|
|
return; // 没有选中任何行
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前选中的第一项索引
|
|
|
|
|
|
QModelIndex index = selectedIndexes.first();
|
|
|
|
|
|
|
|
|
|
|
|
// 确保索引有效
|
|
|
|
|
|
if (!index.isValid()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取模型
|
|
|
|
|
|
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->treeView_model->model());
|
|
|
|
|
|
if (!model) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为第二级节点
|
|
|
|
|
|
if (index.parent().isValid()) { // 父索引有效,说明是第二级节点
|
|
|
|
|
|
// 删除当前选中的项
|
|
|
|
|
|
QString meta = model->data(index.parent(), Qt::DisplayRole).toString();
|
|
|
|
|
|
QString text = model->data(index, Qt::DisplayRole).toString();
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QMessageBox msgBox;
|
|
|
|
|
|
msgBox.setText(QString::fromWCharArray(L"工程模将被删除"));
|
|
|
|
|
|
msgBox.setInformativeText(QString::fromWCharArray(L"删除后不可恢复,确定删除?"));
|
|
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
|
|
|
|
int ret = msgBox.exec();
|
|
|
|
|
|
switch (ret) {
|
|
|
|
|
|
case QMessageBox::Yes:
|
2025-03-07 19:24:19 +08:00
|
|
|
|
{
|
2025-03-14 17:18:25 +08:00
|
|
|
|
bool val = DataBase::GetInstance()->deleteProjectModel(text);
|
|
|
|
|
|
if(val)
|
|
|
|
|
|
{
|
|
|
|
|
|
removeProjectData(meta,text);
|
|
|
|
|
|
model->removeRow(index.row(), index.parent());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
QMessageBox::information(NULL, QString::fromWCharArray(L"提示"), QString::fromWCharArray(L"删除失败"));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case QMessageBox::Cancel:
|
|
|
|
|
|
// Cancel was clicked
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
// should never be reached
|
|
|
|
|
|
break;
|
2025-03-07 19:24:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果是第一级节点,不执行删除操作
|
|
|
|
|
|
return;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
QStringList projectModelDlg::getModelList() const
|
|
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelType> modelMap = DataBase::GetInstance()->ModelType();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
|
|
|
|
|
|
QSet<QString> modelSet;
|
|
|
|
|
|
for(auto &model:modelMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
modelSet.insert(model.modelType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return QStringList(modelSet.values());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList projectModelDlg::getGroupList(const QString& sM) const
|
|
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelType> modelType = DataBase::GetInstance()->ModelType();
|
|
|
|
|
|
QMap<int,modelGroup> modelGroupMap = DataBase::GetInstance()->ModelGroup();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QMap<int,attributeGroup> groupMap = DataBase::GetInstance()->AttributeGroup();
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
int metaId = 0;
|
|
|
|
|
|
for(auto &meta:modelType)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(sM == meta.modelType) //查找元模对应的id
|
|
|
|
|
|
{
|
|
|
|
|
|
metaId = meta.id;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QList<int> lstGroupId;
|
|
|
|
|
|
for(auto &group:modelGroupMap) //找到元模id对应的属性组id
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
if(group.modelTypeId == metaId)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
lstGroupId.push_back(group.attributeGroupId);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QStringList groupList;
|
|
|
|
|
|
for(auto &id:lstGroupId) //从属性组中找到id对应的组名
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
groupList.append(groupMap[id].groupType);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
2025-03-21 12:53:45 +08:00
|
|
|
|
|
2025-03-04 09:44:03 +08:00
|
|
|
|
return groupList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList projectModelDlg::getAttributeList(const QString& sM,const QString& sG) const
|
|
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelType> modelType = DataBase::GetInstance()->ModelType();
|
|
|
|
|
|
//QMap<int,modelGroup> modelGroupMap = DataBase::GetInstance()->ModelGroup();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QMap<int,attributeGroup> groupMap = DataBase::GetInstance()->AttributeGroup();
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,modelAttribute> modelAttMap = DataBase::GetInstance()->ModelAttribute();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
QMap<int,attribute> attMap = DataBase::GetInstance()->Attribute();
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
int metaId = -1;
|
|
|
|
|
|
for(auto &meta:modelType)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
if(sM == meta.modelType) //查找元模对应的id
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
metaId = meta.id;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
int groupId = -1;
|
|
|
|
|
|
for(auto &attGroup:groupMap)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
if(attGroup.groupType == sG) //返回参数属性组名对应的id
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
groupId = attGroup.id;
|
|
|
|
|
|
break;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
2025-03-21 12:53:45 +08:00
|
|
|
|
}
|
2025-03-04 09:44:03 +08:00
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QStringList lst;
|
|
|
|
|
|
for(auto &mt:modelAttMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(mt.modelTypeId == metaId && mt.attributeGroupId == groupId)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
lst.append(attMap[mt.attributeId].attribute);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 12:53:45 +08:00
|
|
|
|
return lst;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::setItemAttribute(const QString& name,QStandardItem* p)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<int,attribute> attMap = DataBase::GetInstance()->Attribute();
|
2025-03-07 19:24:19 +08:00
|
|
|
|
QMap<int,dataType> dt = DataBase::GetInstance()->DataType();
|
2025-03-04 09:44:03 +08:00
|
|
|
|
|
|
|
|
|
|
for(auto &att:attMap)
|
|
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QString sType = dt[att.dataTypeId].dataType; //获得属性id对应的属性名
|
2025-03-04 09:44:03 +08:00
|
|
|
|
if(name == att.attribute)
|
|
|
|
|
|
{
|
|
|
|
|
|
p->setData(att.id,Id);
|
|
|
|
|
|
p->setData(att.attribute,Attribute);
|
2025-03-21 12:53:45 +08:00
|
|
|
|
p->setData(att.attributeName,AttributeName);
|
|
|
|
|
|
p->setData(sType,DataType); //不直接使用id,拼接完成str
|
2025-03-04 09:44:03 +08:00
|
|
|
|
p->setData(att.lengthPrecision,LengthPrecision);
|
|
|
|
|
|
p->setData(att.scale,Scale);
|
2025-03-21 12:53:45 +08:00
|
|
|
|
p->setData(att.isNotNull,IsNotNull);
|
2025-03-04 09:44:03 +08:00
|
|
|
|
p->setData(att.defaultValue,DefaultValue);
|
|
|
|
|
|
p->setData(att.valueRange,ValueRange);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 17:18:25 +08:00
|
|
|
|
QPair<QString,QString> projectModelDlg::combinePropertySql(const QStandardItem* pItem)
|
2025-03-04 09:44:03 +08:00
|
|
|
|
{
|
2025-03-21 12:53:45 +08:00
|
|
|
|
QMap<int,dataType> dt = DataBase::GetInstance()->DataType();
|
|
|
|
|
|
|
2025-03-04 09:44:03 +08:00
|
|
|
|
int id = pItem->data(Id).toInt();
|
|
|
|
|
|
QString attribute = pItem->data(Attribute).toString();
|
|
|
|
|
|
QString dataType = pItem->data(DataType).toString();
|
|
|
|
|
|
int lengthPrecision = pItem->data(LengthPrecision).toInt();
|
|
|
|
|
|
int scale = pItem->data(Scale).toInt();
|
|
|
|
|
|
QString defaultValue = pItem->data(DefaultValue).toString();
|
|
|
|
|
|
QString valueRange = pItem->data(ValueRange).toString();
|
|
|
|
|
|
int isNotNull = pItem->data(IsNotNull).toInt();
|
|
|
|
|
|
|
|
|
|
|
|
bool needsQuotes = stringDataTypes.contains(dataType);
|
|
|
|
|
|
// 处理数据类型及其长度精度
|
|
|
|
|
|
QString dataTypePart = dataType;
|
|
|
|
|
|
if (lengthPrecision > 0) {
|
|
|
|
|
|
dataTypePart += QString("(%1").arg(lengthPrecision);
|
|
|
|
|
|
if (scale > 0) {
|
|
|
|
|
|
dataTypePart += QString(",%1").arg(scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
dataTypePart += ")";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 开始拼接SQL
|
|
|
|
|
|
QString sql = QString("%1 %2").arg(attribute, dataTypePart);
|
|
|
|
|
|
|
|
|
|
|
|
// 处理约束条件
|
|
|
|
|
|
if (isNotNull != 0) {
|
|
|
|
|
|
sql += " NOT NULL";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!defaultValue.isEmpty()) {
|
|
|
|
|
|
QString defValue = defaultValue;
|
|
|
|
|
|
if (needsQuotes) {
|
|
|
|
|
|
// 转义单引号并包裹
|
|
|
|
|
|
defValue.replace("'", "''");
|
|
|
|
|
|
defValue = QString("'%1'").arg(defValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
sql += QString(" DEFAULT %1").arg(defValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-07 19:24:19 +08:00
|
|
|
|
/*if (isPrimaryKey != 0) {
|
2025-03-04 09:44:03 +08:00
|
|
|
|
sql += " PRIMARY KEY";
|
2025-03-07 19:24:19 +08:00
|
|
|
|
}*/
|
2025-03-04 09:44:03 +08:00
|
|
|
|
|
2025-03-14 17:18:25 +08:00
|
|
|
|
return qMakePair(sql,dataTypePart);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString projectModelDlg::getProjectName() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return _curProject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString projectModelDlg::getMetaName() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return _curMeta;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool projectModelDlg::ifProjectEqual(QMap<QString,QJsonObject> map)
|
|
|
|
|
|
{
|
|
|
|
|
|
//todo:判断关联的模型类型
|
|
|
|
|
|
MapProperty curPro = m_mapTotal[_curMeta][_curProject].mapProperty;
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,PropertyPage>::Iterator iter;
|
|
|
|
|
|
for(iter = curPro.begin();iter != curPro.end();++iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!map.contains(iter.key())) //已存在的模型中不包含该属性组
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QString,PropertyState> curCheckState = iter.value().mCheckState;
|
|
|
|
|
|
for(auto &val:curCheckState)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(val.checkState) //该属性组不在模型中且被勾选
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
continue; //该属性组不在模型中且未被勾选,不做判断
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject dbCheckState = map[iter.key()]; //数据库中该属性组的勾选状态
|
|
|
|
|
|
QMap<QString,PropertyState> curCheckState = iter.value().mCheckState; //当前程序中的勾选状态
|
|
|
|
|
|
|
|
|
|
|
|
QJsonArray nodesJsonArray = dbCheckState["checkState"].toArray();
|
|
|
|
|
|
if(nodesJsonArray.size() != curCheckState.size()) //属性个数对不上,模型不同
|
|
|
|
|
|
return false;
|
|
|
|
|
|
for (QJsonValueRef nodeJson : nodesJsonArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject node = nodeJson.toObject();
|
|
|
|
|
|
QString propertyName = node["name"].toString();
|
|
|
|
|
|
int nState = node["checked"].toInt();
|
|
|
|
|
|
if(curCheckState[propertyName].checkState != nState) //相同属性选中状态不同
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString projectModelDlg::modifyProjectModel(QMap<QString,QJsonObject> mapOld)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString sRes;
|
|
|
|
|
|
MapProperty curPro = m_mapTotal[_curMeta][_curProject].mapProperty;
|
|
|
|
|
|
int nType = m_mapTotal[_curMeta][_curProject].nType;
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,PropertyPage>::Iterator iter;
|
|
|
|
|
|
for(iter = curPro.begin();iter != curPro.end();++iter) //遍历当前模型所有属性组
|
|
|
|
|
|
{
|
|
|
|
|
|
QMap<QString,PropertyState> curCheckState = iter.value().mCheckState; //当前程序中的属性勾选状态
|
|
|
|
|
|
bool isNull = true; //当前属性组是否未空
|
|
|
|
|
|
for(auto &val:curCheckState)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(val.checkState){
|
|
|
|
|
|
isNull = false; //当前程序模型有勾选,不为空
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isNull){
|
|
|
|
|
|
if(mapOld.contains(iter.key())){ //当前模型勾选为空且库模型中包含此属性组,移除库中该属性组表
|
|
|
|
|
|
QMap<QString,QString> map = DataBase::GetInstance()->getProjectTableName(_curProject);
|
|
|
|
|
|
bool res = DataBase::GetInstance()->deleteTable(map[iter.key()]);
|
|
|
|
|
|
if(res){
|
|
|
|
|
|
DataBase::GetInstance()->deleteRecordFromManager(_curProject,iter.key());
|
|
|
|
|
|
sRes = QString::fromWCharArray(L"修改模型成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else{
|
|
|
|
|
|
if(mapOld.contains(iter.key())){ //新旧模型中都存在,修改模型
|
|
|
|
|
|
QMap<QString,QString> oldSchema; //库中模型 属性名/数据类型
|
|
|
|
|
|
QMap<QString,QString> newSchema; //现有模型
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject obj = mapOld[iter.key()];
|
|
|
|
|
|
QJsonArray nodesJsonArray = obj["checkState"].toArray();
|
|
|
|
|
|
|
|
|
|
|
|
for (QJsonValueRef nodeJson : nodesJsonArray)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject node = nodeJson.toObject();
|
|
|
|
|
|
QString propertyName = node["name"].toString();
|
|
|
|
|
|
int nState = node["checked"].toInt();
|
|
|
|
|
|
QString dataType = node["type"].toString();
|
|
|
|
|
|
|
|
|
|
|
|
if(nState)
|
|
|
|
|
|
oldSchema.insert(propertyName,dataType);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,PropertyState>::Iterator it;
|
|
|
|
|
|
for(it = curCheckState.begin(); it != curCheckState.end();++it)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(it->checkState){
|
|
|
|
|
|
newSchema.insert(it.key(),it->dataType);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(oldSchema == newSchema)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString,QString> map = DataBase::GetInstance()->getProjectTableName(_curProject);
|
|
|
|
|
|
|
|
|
|
|
|
bool res = DataBase::GetInstance()->modifyProjectTable(map[iter.key()],oldSchema,newSchema);
|
|
|
|
|
|
QJsonObject objState = getSelectedState(iter);
|
|
|
|
|
|
DataBase::GetInstance()->updateCheckState(map[iter.key()],objState);
|
|
|
|
|
|
if(res)
|
|
|
|
|
|
{
|
|
|
|
|
|
sRes = QString::fromWCharArray(L"修改模型成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else{ //非空且库模型中不存在,新增
|
|
|
|
|
|
bool res = createPropertyTable(_curProject,iter,nType);
|
|
|
|
|
|
if(res)
|
|
|
|
|
|
{
|
|
|
|
|
|
sRes = QString::fromWCharArray(L"修改模型成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return sRes;
|
2025-03-04 09:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::updateIconList()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(ui->stackedWidget->currentIndex() !=0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->stackedWidget->setCurrentIndex(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
MapProject mp = m_mapTotal[_curMeta];
|
|
|
|
|
|
int nType = mp[_curProject].nType;
|
|
|
|
|
|
QStandardItemModel *model = dynamic_cast<QStandardItemModel*>(ui->listView_icon->model());
|
|
|
|
|
|
if(model)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int row = 0; row < model->rowCount(); ++row)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStandardItem* pItem = model->item(row);
|
|
|
|
|
|
int id = pItem->data(Qt::UserRole).toInt();
|
|
|
|
|
|
if(nType == id) //使用存储的序列号更新list
|
|
|
|
|
|
{
|
|
|
|
|
|
QModelIndex index = model->index(id,0);
|
|
|
|
|
|
ui->listView_icon->setCurrentIndex(index);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-07 19:24:19 +08:00
|
|
|
|
|
|
|
|
|
|
void projectModelDlg::removeProjectData(const QString& sMeta,const QString& sProject)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_mapTotal[sMeta].remove(sProject);
|
|
|
|
|
|
}
|
2025-03-14 17:18:25 +08:00
|
|
|
|
|
|
|
|
|
|
QString projectModelDlg::getItemDataType(const QStandardItem* pItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString dataType = pItem->data(DataType).toString();
|
|
|
|
|
|
int lengthPrecision = pItem->data(LengthPrecision).toInt();
|
|
|
|
|
|
int scale = pItem->data(Scale).toInt();
|
|
|
|
|
|
|
|
|
|
|
|
QString dataTypePart = dataType;
|
|
|
|
|
|
if (lengthPrecision > 0) {
|
|
|
|
|
|
dataTypePart += QString("(%1").arg(lengthPrecision);
|
|
|
|
|
|
if (scale > 0) {
|
|
|
|
|
|
dataTypePart += QString(",%1").arg(scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
dataTypePart += ")";
|
|
|
|
|
|
}
|
|
|
|
|
|
return dataTypePart;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool projectModelDlg::createPropertyTable(const QString& sProject,MapProperty::Iterator iter,int nLinkType)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString sName = _curMeta + QString("_") + sProject + QString("_")+iter.key();
|
|
|
|
|
|
|
|
|
|
|
|
QStringList fields;
|
|
|
|
|
|
fields.append("id SERIAL NOT NULL PRIMARY KEY");
|
|
|
|
|
|
fields.append("global_uuid uuid NOT NULL DEFAULT gen_random_uuid()");
|
|
|
|
|
|
fields.append("attribute_group VARCHAR(64) NOT NULL");
|
|
|
|
|
|
|
|
|
|
|
|
QStandardItemModel* pSelectModel = iter->pSelect;
|
|
|
|
|
|
QStandardItem *rootItem = pSelectModel->invisibleRootItem();
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < rootItem->rowCount(); ++row) { //遍历已选择列表
|
|
|
|
|
|
QStandardItem *childItem = rootItem->child(row);
|
|
|
|
|
|
if (childItem) {
|
|
|
|
|
|
QPair<QString,QString> pair = combinePropertySql(childItem); //拼接单句sql
|
|
|
|
|
|
fields.append(pair.first);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject objState = getSelectedState(iter);
|
|
|
|
|
|
|
|
|
|
|
|
if(!DataBase::GetInstance()->createDynamicTable(sName,fields))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
DataBase::GetInstance()->insertProjectManager(sName,sProject,_curMeta,iter.key(),nLinkType,objState);
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject projectModelDlg::getSelectedState(MapProperty::Iterator iter)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject objState;
|
|
|
|
|
|
QJsonArray arrState;
|
|
|
|
|
|
|
|
|
|
|
|
QStandardItemModel* pSelectModel = iter->pSelect;
|
|
|
|
|
|
QStandardItem *rootItem = pSelectModel->invisibleRootItem();
|
|
|
|
|
|
|
|
|
|
|
|
for (int row = 0; row < rootItem->rowCount(); ++row) { //遍历已选择列表
|
|
|
|
|
|
QStandardItem *childItem = rootItem->child(row);
|
|
|
|
|
|
if (childItem) {
|
|
|
|
|
|
|
|
|
|
|
|
QString dataType = childItem->data(DataType).toString();
|
|
|
|
|
|
int lengthPrecision = childItem->data(LengthPrecision).toInt();
|
|
|
|
|
|
int scale = childItem->data(Scale).toInt();
|
2025-03-28 18:08:21 +08:00
|
|
|
|
QString defaultValue = childItem->data(DefaultValue).toString();
|
2025-03-14 17:18:25 +08:00
|
|
|
|
|
|
|
|
|
|
QString dataTypePart = dataType; //拼接数据类型
|
|
|
|
|
|
if (lengthPrecision > 0) {
|
|
|
|
|
|
dataTypePart += QString("(%1").arg(lengthPrecision);
|
|
|
|
|
|
if (scale > 0) {
|
|
|
|
|
|
dataTypePart += QString(",%1").arg(scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
dataTypePart += ")";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject node; //保存已选择状态
|
|
|
|
|
|
node["name"] = childItem->text();
|
|
|
|
|
|
node["checked"] = 1;
|
|
|
|
|
|
node["type"] = dataTypePart;
|
2025-03-28 18:08:21 +08:00
|
|
|
|
node["defaultValue"] = defaultValue;
|
2025-03-14 17:18:25 +08:00
|
|
|
|
arrState.append(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
QStandardItemModel* pBaseModel = iter->pBase;
|
|
|
|
|
|
rootItem = pBaseModel->invisibleRootItem();
|
|
|
|
|
|
for (int row = 0; row < rootItem->rowCount(); ++row) { //遍历未选择列表
|
|
|
|
|
|
QStandardItem *childItem = rootItem->child(row);
|
|
|
|
|
|
if (childItem) {
|
|
|
|
|
|
QString dataType = childItem->data(DataType).toString();
|
|
|
|
|
|
int lengthPrecision = childItem->data(LengthPrecision).toInt();
|
|
|
|
|
|
int scale = childItem->data(Scale).toInt();
|
2025-03-28 18:08:21 +08:00
|
|
|
|
QString defaultValue = childItem->data(DefaultValue).toString();
|
2025-03-14 17:18:25 +08:00
|
|
|
|
|
|
|
|
|
|
QString dataTypePart = dataType; //拼接数据类型
|
|
|
|
|
|
if (lengthPrecision > 0) {
|
|
|
|
|
|
dataTypePart += QString("(%1").arg(lengthPrecision);
|
|
|
|
|
|
if (scale > 0) {
|
|
|
|
|
|
dataTypePart += QString(",%1").arg(scale);
|
|
|
|
|
|
}
|
|
|
|
|
|
dataTypePart += ")";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject node; //保存未选择状态
|
|
|
|
|
|
node["name"] = childItem->text();
|
|
|
|
|
|
node["checked"] = 0;
|
|
|
|
|
|
node["type"] = dataTypePart;
|
2025-03-28 18:08:21 +08:00
|
|
|
|
node["defaultValue"] = defaultValue;
|
2025-03-14 17:18:25 +08:00
|
|
|
|
arrState.append(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
objState["checkState"] = arrState;
|
|
|
|
|
|
return objState;
|
|
|
|
|
|
}
|