完成属性编辑时‘取消修改’和属性页面的刷新操作逻辑
This commit is contained in:
parent
25249b97b6
commit
8455d6522c
|
|
@ -63,6 +63,7 @@ public:
|
||||||
void insertRecord(int);
|
void insertRecord(int);
|
||||||
void removeRecord(int);
|
void removeRecord(int);
|
||||||
void submitChanges(); //提交更改(增、删、改)
|
void submitChanges(); //提交更改(增、删、改)
|
||||||
|
void cancleChanges(); //取消修改
|
||||||
|
|
||||||
//展示列控制
|
//展示列控制
|
||||||
//void setVisibleColumns(const QStringList& columns);
|
//void setVisibleColumns(const QStringList& columns);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,8 @@ private slots:
|
||||||
void onBtnClicked_addRecord();
|
void onBtnClicked_addRecord();
|
||||||
void onBtnClicked_removeRecord();
|
void onBtnClicked_removeRecord();
|
||||||
void onBtnClicked_submitChanges();
|
void onBtnClicked_submitChanges();
|
||||||
|
void onBtnClicked_cancleChanges();
|
||||||
|
void onBtnClicked_refreshData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int tabIndex(const QString&);
|
int tabIndex(const QString&);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ enum NodeStatus //节点状态(主要是ConnectionNode)
|
||||||
|
|
||||||
enum NodeDataRole
|
enum NodeDataRole
|
||||||
{
|
{
|
||||||
ID = 1
|
ID = 1,
|
||||||
|
Type
|
||||||
};
|
};
|
||||||
|
|
||||||
class DBStructureNode
|
class DBStructureNode
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,15 @@ struct AttributeGroup
|
||||||
QString remark;
|
QString remark;
|
||||||
bool isPublic;
|
bool isPublic;
|
||||||
|
|
||||||
|
AttributeGroup()
|
||||||
|
{
|
||||||
|
id = -1;
|
||||||
|
name = "";
|
||||||
|
type = "";
|
||||||
|
remark = "";
|
||||||
|
isPublic = false;
|
||||||
|
}
|
||||||
|
|
||||||
//利用移动语义优化的构造函数(不定义也可以,QString实际上实现了隐式共享)
|
//利用移动语义优化的构造函数(不定义也可以,QString实际上实现了隐式共享)
|
||||||
AttributeGroup(int id, QString name, QString type, QString remark, bool isPublic)
|
AttributeGroup(int id, QString name, QString type, QString remark, bool isPublic)
|
||||||
: id(id),
|
: id(id),
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ public:
|
||||||
//基于具体业务的查询接口-对外调用
|
//基于具体业务的查询接口-对外调用
|
||||||
//属性组相关
|
//属性组相关
|
||||||
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
||||||
const QString getArributeGropuName(const QString&, int);
|
const QString getAttributeGroupName(const QString&, int);
|
||||||
|
const AttributeGroup getAttributeGroupData(const QString&, int);
|
||||||
//模型相关
|
//模型相关
|
||||||
const QVector<Model> getModels(const QString&);
|
const QVector<Model> getModels(const QString&);
|
||||||
bool addModel(const QString&, Model&);
|
bool addModel(const QString&, Model&);
|
||||||
|
|
|
||||||
|
|
@ -363,16 +363,12 @@ void AttributeTableModel::refresh()
|
||||||
if(!m_modifiedRows.isEmpty())
|
if(!m_modifiedRows.isEmpty())
|
||||||
{
|
{
|
||||||
emit showMessage(type_question, QString::fromWCharArray(L"提示"),
|
emit showMessage(type_question, QString::fromWCharArray(L"提示"),
|
||||||
QString::fromWCharArray(L"当前有编辑或修改数据未提交,是否进行提交?"));
|
QString::fromWCharArray(L"有编辑数据还未提交,确认刷新放弃提交吗?"));
|
||||||
if(g_msgDlgBtn == btn_Yes)
|
if(g_msgDlgBtn == btn_No)
|
||||||
{
|
return;
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_modifiedRows.clear();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_modifiedRows.clear();
|
||||||
loadPageData();
|
loadPageData();
|
||||||
updateTotalCount();
|
updateTotalCount();
|
||||||
emit syncDataStatus(m_modifiedRows.isEmpty(), m_paginationInfo);
|
emit syncDataStatus(m_modifiedRows.isEmpty(), m_paginationInfo);
|
||||||
|
|
@ -508,6 +504,17 @@ void AttributeTableModel::submitChanges()
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttributeTableModel::cancleChanges()
|
||||||
|
{
|
||||||
|
if(m_modifiedRows.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_modifiedRows.clear();
|
||||||
|
loadPageData();
|
||||||
|
updateTotalCount();
|
||||||
|
emit syncDataStatus(m_modifiedRows.isEmpty(), m_paginationInfo);
|
||||||
|
}
|
||||||
|
|
||||||
void AttributeTableModel::triggerSyncSignal()
|
void AttributeTableModel::triggerSyncSignal()
|
||||||
{
|
{
|
||||||
emit syncDataStatus(m_modifiedRows.isEmpty(), m_paginationInfo);
|
emit syncDataStatus(m_modifiedRows.isEmpty(), m_paginationInfo);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ DatabaseBrowser::DatabaseBrowser(QWidget *parent)
|
||||||
connect(ui->btnAdd, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_addRecord);
|
connect(ui->btnAdd, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_addRecord);
|
||||||
connect(ui->btnRemove, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_removeRecord);
|
connect(ui->btnRemove, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_removeRecord);
|
||||||
connect(ui->btnSave, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_submitChanges);
|
connect(ui->btnSave, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_submitChanges);
|
||||||
|
connect(ui->btnCancle, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_cancleChanges);
|
||||||
|
connect(ui->btnRefresh, &QPushButton::clicked, this, &DatabaseBrowser::onBtnClicked_refreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseBrowser::~DatabaseBrowser()
|
DatabaseBrowser::~DatabaseBrowser()
|
||||||
|
|
@ -174,6 +176,32 @@ void DatabaseBrowser::onBtnClicked_submitChanges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseBrowser::onBtnClicked_cancleChanges()
|
||||||
|
{
|
||||||
|
QWidget* widget = ui->tabWidget->currentWidget();
|
||||||
|
AttributeView* attributeView = qobject_cast<AttributeView*>(widget);
|
||||||
|
if(attributeView)
|
||||||
|
{
|
||||||
|
QTableView* view = attributeView->view();
|
||||||
|
AttributeTableModel* model = attributeView->model();
|
||||||
|
if(view && model)
|
||||||
|
model->cancleChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatabaseBrowser::onBtnClicked_refreshData()
|
||||||
|
{
|
||||||
|
QWidget* widget = ui->tabWidget->currentWidget();
|
||||||
|
AttributeView* attributeView = qobject_cast<AttributeView*>(widget);
|
||||||
|
if(attributeView)
|
||||||
|
{
|
||||||
|
QTableView* view = attributeView->view();
|
||||||
|
AttributeTableModel* model = attributeView->model();
|
||||||
|
if(view && model)
|
||||||
|
model->refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseBrowser::onSyncDataStatus(bool hasModifiedData, const PaginationInfo& paginationInfo)
|
void DatabaseBrowser::onSyncDataStatus(bool hasModifiedData, const PaginationInfo& paginationInfo)
|
||||||
{
|
{
|
||||||
ui->btnSave->setEnabled(!hasModifiedData);
|
ui->btnSave->setEnabled(!hasModifiedData);
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,13 @@ void DBStructureModel::addDataModel(const QString& connection, Model& model)
|
||||||
modelNode->setData(Qt::UserRole + NodeDataRole::ID, model.id);
|
modelNode->setData(Qt::UserRole + NodeDataRole::ID, model.id);
|
||||||
for(int groupID : model.groups)
|
for(int groupID : model.groups)
|
||||||
{
|
{
|
||||||
QString groupName = SqlQueryExecutor::instance().getArributeGropuName(connection, groupID);
|
//QString groupName = SqlQueryExecutor::instance().getAttributeGroupName(connection, groupID);
|
||||||
DBStructureNode* groupNode = new DBStructureNode(GroupNode, groupName, modelNode);
|
AttributeGroup group = SqlQueryExecutor::instance().getAttributeGroupData(connection, groupID);
|
||||||
|
if(group.name.isEmpty())
|
||||||
|
continue;
|
||||||
|
DBStructureNode* groupNode = new DBStructureNode(GroupNode, group.name, modelNode);
|
||||||
groupNode->setData(Qt::UserRole + NodeDataRole::ID, groupID);
|
groupNode->setData(Qt::UserRole + NodeDataRole::ID, groupID);
|
||||||
|
groupNode->setData(Qt::UserRole + NodeDataRole::Type, group.isPublic);
|
||||||
modelNode->appendChild(groupNode);
|
modelNode->appendChild(groupNode);
|
||||||
}
|
}
|
||||||
connNode->appendChild(modelNode);
|
connNode->appendChild(modelNode);
|
||||||
|
|
@ -246,9 +250,13 @@ void DBStructureModel::refreshStructure_Connection(const QString& connection)
|
||||||
modelNode->setData(Qt::UserRole + NodeDataRole::ID, model.id);
|
modelNode->setData(Qt::UserRole + NodeDataRole::ID, model.id);
|
||||||
for(int groupID : model.groups)
|
for(int groupID : model.groups)
|
||||||
{
|
{
|
||||||
QString groupName = SqlQueryExecutor::instance().getArributeGropuName(connection, groupID);
|
//QString groupName = SqlQueryExecutor::instance().getAttributeGroupName(connection, groupID);
|
||||||
DBStructureNode* groupNode = new DBStructureNode(GroupNode, groupName, modelNode);
|
AttributeGroup group = SqlQueryExecutor::instance().getAttributeGroupData(connection, groupID);
|
||||||
|
if(group.name.isEmpty())
|
||||||
|
continue;
|
||||||
|
DBStructureNode* groupNode = new DBStructureNode(GroupNode, group.name, modelNode);
|
||||||
groupNode->setData(Qt::UserRole + NodeDataRole::ID, groupID);
|
groupNode->setData(Qt::UserRole + NodeDataRole::ID, groupID);
|
||||||
|
groupNode->setData(Qt::UserRole + NodeDataRole::Type, group.isPublic);
|
||||||
modelNode->appendChild(groupNode);
|
modelNode->appendChild(groupNode);
|
||||||
}
|
}
|
||||||
connNode->appendChild(modelNode);
|
connNode->appendChild(modelNode);
|
||||||
|
|
|
||||||
|
|
@ -382,9 +382,9 @@ const QVector<AttributeGroup> SqlQueryExecutor::getAttributeGroup(const QString&
|
||||||
return groupList;
|
return groupList;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString SqlQueryExecutor::getArributeGropuName(const QString& connectionName, int groupID)
|
const QString SqlQueryExecutor::getAttributeGroupName(const QString& connectionName, int groupID)
|
||||||
{
|
{
|
||||||
QString name;
|
QString name = "";
|
||||||
QString strSQL = "SELECT group_name FROM basic.attribute_group WHERE id = :id";
|
QString strSQL = "SELECT group_name FROM basic.attribute_group WHERE id = :id";
|
||||||
QVariantHash params;
|
QVariantHash params;
|
||||||
params.insert(":id", groupID);
|
params.insert(":id", groupID);
|
||||||
|
|
@ -397,12 +397,37 @@ const QString SqlQueryExecutor::getArributeGropuName(const QString& connectionNa
|
||||||
catch (const DatabaseException& e)
|
catch (const DatabaseException& e)
|
||||||
{
|
{
|
||||||
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性组名称失败,id:%1").arg(QString::number(groupID)));
|
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性组名称失败,id:%1").arg(QString::number(groupID)));
|
||||||
name = "groupID-" + QString::number(groupID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const AttributeGroup SqlQueryExecutor::getAttributeGroupData(const QString& connectionName, int groupID)
|
||||||
|
{
|
||||||
|
AttributeGroup group;
|
||||||
|
QString strSQL = "SELECT group_type, group_name, remark, is_public FROM basic.attribute_group WHERE id = :id";
|
||||||
|
QVariantHash params;
|
||||||
|
params.insert(":id", groupID);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QSqlQuery query = executeSQL(connectionName, strSQL, params);
|
||||||
|
if(query.next())
|
||||||
|
{
|
||||||
|
QString type = query.value(0).toString();
|
||||||
|
QString name = query.value(1).toString();
|
||||||
|
QString remark = query.value(2).toString();
|
||||||
|
bool isPublic = query.value(3).toBool();
|
||||||
|
return AttributeGroup(groupID,name,type,remark,isPublic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const DatabaseException& e)
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性组信息失败,id:%1").arg(QString::number(groupID)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID)
|
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
@ -416,7 +441,6 @@ int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int model
|
||||||
catch (const DatabaseException& e)
|
catch (const DatabaseException& e)
|
||||||
{
|
{
|
||||||
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性数量失败"));
|
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性数量失败"));
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue