删除模型时同步关闭该模型所有被打开的属性组tab
This commit is contained in:
parent
a96d23a888
commit
5ab836da99
|
|
@ -2,6 +2,7 @@
|
||||||
#define ATTRIBUTESELECTOR_H
|
#define ATTRIBUTESELECTOR_H
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
#include "messageDialog.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
@ -23,11 +24,17 @@ public:
|
||||||
|
|
||||||
void setMainWindow(MainWindow*);
|
void setMainWindow(MainWindow*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void showEvent(QShowEvent*);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onBtnClicked_refreshData();
|
void onBtnClicked_refreshData();
|
||||||
void onSyncDataStatus(bool, const PaginationInfo&);
|
void onSyncDataStatus(bool, const PaginationInfo&);
|
||||||
|
void onShowMessage(MessageDialogType,const QString&,const QString&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void iniData();
|
||||||
|
|
||||||
Ui::AttributeSelector *ui;
|
Ui::AttributeSelector *ui;
|
||||||
MainWindow* m_pMainWindow;
|
MainWindow* m_pMainWindow;
|
||||||
AttributeView* m_attributeView;
|
AttributeView* m_attributeView;
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
//ModelAttributeGroup getModelAttributeGroup() {return m_modelAttributeGroup;}
|
//ModelAttributeGroup getModelAttributeGroup() {return m_modelAttributeGroup;}
|
||||||
|
void setModelAttributeGroup(const ModelAttributeGroup&);
|
||||||
bool attributeTypeExistsInCurrentGroup(int, const QString&); //除数据库外,还有从内存存储的数据(当前页m_currentPageData)中进行查找判断,因为可能有编辑完但未提交至数据空的信息
|
bool attributeTypeExistsInCurrentGroup(int, const QString&); //除数据库外,还有从内存存储的数据(当前页m_currentPageData)中进行查找判断,因为可能有编辑完但未提交至数据空的信息
|
||||||
void updateRowThroughExisitingAttribute(int, int);
|
void updateRowThroughExisitingAttribute(int, int);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ public:
|
||||||
AttributeTableDelegate* delegate() const { return m_attributeTableDelegate; }
|
AttributeTableDelegate* delegate() const { return m_attributeTableDelegate; }
|
||||||
|
|
||||||
void active();
|
void active();
|
||||||
|
void setEditable(bool);
|
||||||
void syncChangeRecord();
|
void syncChangeRecord();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ui_attributeSelector.h"
|
#include "ui_attributeSelector.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "attributeView.h"
|
#include "attributeView.h"
|
||||||
|
#include "sqlQueryExecutor.h"
|
||||||
|
|
||||||
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
|
@ -17,7 +18,10 @@ AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
||||||
|
|
||||||
ModelAttributeGroup attributeGroup(-1, -1, "" ,"");
|
ModelAttributeGroup attributeGroup(-1, -1, "" ,"");
|
||||||
m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection);
|
m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection);
|
||||||
|
m_attributeView->setEditable(false);//不可编辑
|
||||||
ui->layoutTableView->addWidget(m_attributeView);
|
ui->layoutTableView->addWidget(m_attributeView);
|
||||||
|
connect(m_attributeView->model(), &AttributeTableModel::showMessage, this, &AttributeSelector::onShowMessage);
|
||||||
|
connect(m_attributeView->model(), &AttributeTableModel::syncDataStatus, this, &AttributeSelector::onSyncDataStatus);
|
||||||
|
|
||||||
connect(ui->btnRefresh, &QPushButton::clicked, this, &AttributeSelector::onBtnClicked_refreshData);
|
connect(ui->btnRefresh, &QPushButton::clicked, this, &AttributeSelector::onBtnClicked_refreshData);
|
||||||
}
|
}
|
||||||
|
|
@ -27,6 +31,28 @@ AttributeSelector::~AttributeSelector()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttributeSelector::iniData()
|
||||||
|
{
|
||||||
|
ui->lineEdit_attributeType->setText("");
|
||||||
|
|
||||||
|
ui->comboBox_model->clear();
|
||||||
|
ui->comboBox_model->addItem(QString::fromWCharArray(L"所有模型"), -1);
|
||||||
|
const QVector<Model> models = SqlQueryExecutor::instance().getModels(m_connection);
|
||||||
|
for(const Model& model : models)
|
||||||
|
ui->comboBox_model->addItem(model.name, model.id);
|
||||||
|
|
||||||
|
ui->comboBox_group->clear();
|
||||||
|
ui->comboBox_group->addItem(QString::fromWCharArray(L"所有属性组"), -1);
|
||||||
|
const QVector<AttributeGroup> groups = SqlQueryExecutor::instance().getAttributeGroup(m_connection);
|
||||||
|
for(const AttributeGroup& group : groups)
|
||||||
|
ui->comboBox_group->addItem(group.name, group.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AttributeSelector::showEvent(QShowEvent* e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void AttributeSelector::setMainWindow(MainWindow* window)
|
void AttributeSelector::setMainWindow(MainWindow* window)
|
||||||
{
|
{
|
||||||
m_pMainWindow = window;
|
m_pMainWindow = window;
|
||||||
|
|
@ -34,16 +60,25 @@ void AttributeSelector::setMainWindow(MainWindow* window)
|
||||||
|
|
||||||
void AttributeSelector::onBtnClicked_refreshData()
|
void AttributeSelector::onBtnClicked_refreshData()
|
||||||
{
|
{
|
||||||
|
AttributeTableModel* model = m_attributeView->model();
|
||||||
|
if(model)
|
||||||
|
model->forceRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttributeSelector::onSyncDataStatus(bool hasModifiedData, const PaginationInfo& paginationInfo)
|
void AttributeSelector::onSyncDataStatus(bool hasModifiedData, const PaginationInfo& paginationInfo)
|
||||||
{
|
{
|
||||||
ui->btnSave->setEnabled(!hasModifiedData);
|
// ui->btnSave->setEnabled(!hasModifiedData);
|
||||||
ui->btnCancle->setEnabled(!hasModifiedData);
|
// ui->btnCancle->setEnabled(!hasModifiedData);
|
||||||
|
|
||||||
QString recordInfo = QString::fromWCharArray(L"共 %1 条记录").arg(paginationInfo.totalEntries);
|
QString recordInfo = QString::fromWCharArray(L"共 %1 条记录").arg(paginationInfo.totalEntries);
|
||||||
ui->recordInfo->setText(recordInfo);
|
ui->recordInfo->setText(recordInfo);
|
||||||
ui->lineEdit->setText(QString::number(paginationInfo.currentPage));
|
ui->lineEdit->setText(QString::number(paginationInfo.currentPage));
|
||||||
ui->lineEdit->setEnabled(true);
|
ui->lineEdit->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttributeSelector::onShowMessage(MessageDialogType type,const QString& strTitle,const QString& strContent)
|
||||||
|
{
|
||||||
|
if(m_pMainWindow)
|
||||||
|
m_pMainWindow->showMessageDialog(type, strTitle, strContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -181,17 +181,20 @@ int AttributeTableModel::columnCount(const QModelIndex &) const
|
||||||
Qt::ItemFlags AttributeTableModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags AttributeTableModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
||||||
if(m_modelAttributeGroup.modelID < 0) //表示当前加载数据对象是所有属性,前端UI是属性选择器,选择器为非可编辑状态
|
|
||||||
return flags;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QModelIndex numberIndex = createIndex(index.row(), 0);
|
QModelIndex numberIndex = createIndex(index.row(), 0);
|
||||||
QString text = numberIndex.data(Qt::DisplayRole).toString();
|
QString text = numberIndex.data(Qt::DisplayRole).toString();
|
||||||
|
|
||||||
if (index.column() != 0 && !text.contains("-")) //行号列和处于删除状态的item不能编辑
|
if (index.column() != 0 && !text.contains("-")) //行号列和处于删除状态的item不能编辑
|
||||||
flags = flags | Qt::ItemIsEditable;
|
flags = flags | Qt::ItemIsEditable;
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttributeTableModel::setModelAttributeGroup(const ModelAttributeGroup& modelAttributeGroup)
|
||||||
|
{
|
||||||
|
m_modelAttributeGroup = modelAttributeGroup;
|
||||||
|
//重新刷新
|
||||||
|
m_paginationInfo.currentPage = 1;
|
||||||
|
forceRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AttributeTableModel::attributeTypeExistsInCurrentGroup(int id, const QString& type)
|
bool AttributeTableModel::attributeTypeExistsInCurrentGroup(int id, const QString& type)
|
||||||
|
|
@ -335,7 +338,7 @@ void AttributeTableModel::loadPageData()
|
||||||
for(int i = 0; i < m_displayField.count(); i++)
|
for(int i = 0; i < m_displayField.count(); i++)
|
||||||
columns << m_displayField.at(i).originalName;
|
columns << m_displayField.at(i).originalName;
|
||||||
|
|
||||||
if(m_modelAttributeGroup.modelID < 0) //表示当前加载数据对象是所有属性
|
if(m_modelAttributeGroup.modelID == -1) //表示当前加载数据对象是所有属性
|
||||||
{
|
{
|
||||||
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
||||||
QString strSQL = QString("SELECT %1 FROM basic.attribute LIMIT %2 OFFSET %3")
|
QString strSQL = QString("SELECT %1 FROM basic.attribute LIMIT %2 OFFSET %3")
|
||||||
|
|
@ -367,8 +370,8 @@ void AttributeTableModel::loadPageData()
|
||||||
.arg(m_modelAttributeGroup.groupID)
|
.arg(m_modelAttributeGroup.groupID)
|
||||||
.arg(m_paginationInfo.entriesPerPage)
|
.arg(m_paginationInfo.entriesPerPage)
|
||||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||||
else
|
else //利用短路机制,当attribute_group_id!=-1时,括号整体为false,需要进行内部条件判断,=-1时,整体为true,忽略整体,也就忽略了attribute_group_id的条件判断
|
||||||
strSQL = QString("SELECT attribute_id FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2 LIMIT %3 OFFSET %4")
|
strSQL = QString("SELECT attribute_id FROM basic.model_attribute WHERE model_type_id = %1 AND (attribute_group_id = %2 OR %2 = -1) LIMIT %3 OFFSET %4")
|
||||||
.arg(m_modelAttributeGroup.modelID)
|
.arg(m_modelAttributeGroup.modelID)
|
||||||
.arg(m_modelAttributeGroup.groupID)
|
.arg(m_modelAttributeGroup.groupID)
|
||||||
.arg(m_paginationInfo.entriesPerPage)
|
.arg(m_paginationInfo.entriesPerPage)
|
||||||
|
|
@ -474,7 +477,7 @@ void AttributeTableModel::updateTotalCount()
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if(m_modelAttributeGroup.modelID < 0)
|
if(m_modelAttributeGroup.modelID == -1)
|
||||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection);
|
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection);
|
||||||
else
|
else
|
||||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAttributeCount(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID);
|
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAttributeCount(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID);
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,14 @@ void AttributeView::active()
|
||||||
m_attributeTableModel->triggerSyncSignal();
|
m_attributeTableModel->triggerSyncSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttributeView::setEditable(bool editable)
|
||||||
|
{
|
||||||
|
if(editable)
|
||||||
|
m_tableView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
||||||
|
else
|
||||||
|
m_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
}
|
||||||
|
|
||||||
void AttributeView::syncChangeRecord()
|
void AttributeView::syncChangeRecord()
|
||||||
{
|
{
|
||||||
if(m_attributeGroup.isPublic)
|
if(m_attributeGroup.isPublic)
|
||||||
|
|
|
||||||
|
|
@ -97,12 +97,28 @@ void DatabaseBrowser::addTab_attribute(const QString& connection, ModelAttribute
|
||||||
|
|
||||||
void DatabaseBrowser::closeTab_attribute(ModelAttributeGroup& attributeGroup)
|
void DatabaseBrowser::closeTab_attribute(ModelAttributeGroup& attributeGroup)
|
||||||
{
|
{
|
||||||
|
if(attributeGroup.groupID == -1) //关闭该模型下所有打开的tab
|
||||||
|
{
|
||||||
|
//int tabCount = ui->tabWidget->count();
|
||||||
|
for(int i = 0; i < ui->tabWidget->count(); i++)
|
||||||
|
{
|
||||||
|
if(ui->tabWidget->tabText(i).contains(attributeGroup.strModelName + "/"))
|
||||||
|
{
|
||||||
|
onTabCloseRequested(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else //关闭具体的tab
|
||||||
|
{
|
||||||
QString tabText = attributeGroup.strModelName + "/" + attributeGroup.strGroupName;
|
QString tabText = attributeGroup.strModelName + "/" + attributeGroup.strGroupName;
|
||||||
int index = tabIndex(tabText);
|
int index = tabIndex(tabText);
|
||||||
if(index == -1)
|
if(index == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
onTabCloseRequested(index);
|
onTabCloseRequested(index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseBrowser::closeAllTab_attribute()
|
void DatabaseBrowser::closeAllTab_attribute()
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,8 @@ void DBStructureView::openAttributeGroup(DBStructureNode* node)
|
||||||
|
|
||||||
void DBStructureView::closeAttributeGroup(DBStructureNode* node)
|
void DBStructureView::closeAttributeGroup(DBStructureNode* node)
|
||||||
{
|
{
|
||||||
|
if(node->type() == GroupNode)
|
||||||
|
{
|
||||||
DBStructureNode* parent = node->parentNode();
|
DBStructureNode* parent = node->parentNode();
|
||||||
if(parent && parent->type() == TableNode)
|
if(parent && parent->type() == TableNode)
|
||||||
{
|
{
|
||||||
|
|
@ -154,6 +156,14 @@ void DBStructureView::closeAttributeGroup(DBStructureNode* node)
|
||||||
ModelAttributeGroup attributeGroup(modelID, groupID, modelName, groupName);
|
ModelAttributeGroup attributeGroup(modelID, groupID, modelName, groupName);
|
||||||
emit closeAttributeInfo(attributeGroup);
|
emit closeAttributeInfo(attributeGroup);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if(node->type() == TableNode)
|
||||||
|
{
|
||||||
|
int modelID = node->data(Qt::UserRole + NodeDataRole::ID).toInt();
|
||||||
|
QString modelName = node->name();
|
||||||
|
ModelAttributeGroup attributeGroup(modelID, -1, modelName, "");
|
||||||
|
emit closeAttributeInfo(attributeGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBStructureView::disconnectCurConnection()
|
void DBStructureView::disconnectCurConnection()
|
||||||
|
|
@ -290,6 +300,8 @@ void DBStructureView::showContextMenu(const QPoint& pos)
|
||||||
if(g_msgDlgBtn == btn_No)
|
if(g_msgDlgBtn == btn_No)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//关闭tab(若打开)
|
||||||
|
closeAttributeGroup(node);
|
||||||
removeNode(node);
|
removeNode(node);
|
||||||
});
|
});
|
||||||
menu.addAction(QString::fromWCharArray(L"刷新"), []{});
|
menu.addAction(QString::fromWCharArray(L"刷新"), []{});
|
||||||
|
|
|
||||||
|
|
@ -564,7 +564,8 @@ bool SqlQueryExecutor::removeAttributeGroup(const QString& connectionName, int m
|
||||||
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;
|
||||||
QString strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2").arg(modelID).arg(groupID);
|
//利用短路机制,当attribute_group_id!=-1时,括号整体为false,需要进行内部条件判断,=-1时,整体为true,忽略整体,也就忽略了attribute_group_id的条件判断
|
||||||
|
QString strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute WHERE model_type_id = %1 AND (attribute_group_id = %2 OR %2 = -1)").arg(modelID).arg(groupID);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue