删除模型时同步关闭该模型所有被打开的属性组tab
This commit is contained in:
parent
a96d23a888
commit
5ab836da99
|
|
@ -2,6 +2,7 @@
|
|||
#define ATTRIBUTESELECTOR_H
|
||||
|
||||
#include "global.h"
|
||||
#include "messageDialog.h"
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
@ -23,11 +24,17 @@ public:
|
|||
|
||||
void setMainWindow(MainWindow*);
|
||||
|
||||
protected:
|
||||
virtual void showEvent(QShowEvent*);
|
||||
|
||||
private slots:
|
||||
void onBtnClicked_refreshData();
|
||||
void onSyncDataStatus(bool, const PaginationInfo&);
|
||||
void onShowMessage(MessageDialogType,const QString&,const QString&);
|
||||
|
||||
private:
|
||||
void iniData();
|
||||
|
||||
Ui::AttributeSelector *ui;
|
||||
MainWindow* m_pMainWindow;
|
||||
AttributeView* m_attributeView;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ public:
|
|||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
//ModelAttributeGroup getModelAttributeGroup() {return m_modelAttributeGroup;}
|
||||
void setModelAttributeGroup(const ModelAttributeGroup&);
|
||||
bool attributeTypeExistsInCurrentGroup(int, const QString&); //除数据库外,还有从内存存储的数据(当前页m_currentPageData)中进行查找判断,因为可能有编辑完但未提交至数据空的信息
|
||||
void updateRowThroughExisitingAttribute(int, int);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public:
|
|||
AttributeTableDelegate* delegate() const { return m_attributeTableDelegate; }
|
||||
|
||||
void active();
|
||||
void setEditable(bool);
|
||||
void syncChangeRecord();
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include "ui_attributeSelector.h"
|
||||
#include "mainwindow.h"
|
||||
#include "attributeView.h"
|
||||
#include "sqlQueryExecutor.h"
|
||||
|
||||
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
|
|
@ -17,7 +18,10 @@ AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
|||
|
||||
ModelAttributeGroup attributeGroup(-1, -1, "" ,"");
|
||||
m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection);
|
||||
m_attributeView->setEditable(false);//不可编辑
|
||||
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);
|
||||
}
|
||||
|
|
@ -27,6 +31,28 @@ AttributeSelector::~AttributeSelector()
|
|||
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)
|
||||
{
|
||||
m_pMainWindow = window;
|
||||
|
|
@ -34,16 +60,25 @@ void AttributeSelector::setMainWindow(MainWindow* window)
|
|||
|
||||
void AttributeSelector::onBtnClicked_refreshData()
|
||||
{
|
||||
|
||||
AttributeTableModel* model = m_attributeView->model();
|
||||
if(model)
|
||||
model->forceRefresh();
|
||||
}
|
||||
|
||||
void AttributeSelector::onSyncDataStatus(bool hasModifiedData, const PaginationInfo& paginationInfo)
|
||||
{
|
||||
ui->btnSave->setEnabled(!hasModifiedData);
|
||||
ui->btnCancle->setEnabled(!hasModifiedData);
|
||||
// ui->btnSave->setEnabled(!hasModifiedData);
|
||||
// ui->btnCancle->setEnabled(!hasModifiedData);
|
||||
|
||||
QString recordInfo = QString::fromWCharArray(L"共 %1 条记录").arg(paginationInfo.totalEntries);
|
||||
ui->recordInfo->setText(recordInfo);
|
||||
ui->lineEdit->setText(QString::number(paginationInfo.currentPage));
|
||||
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,10 +181,6 @@ int AttributeTableModel::columnCount(const QModelIndex &) const
|
|||
Qt::ItemFlags AttributeTableModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
|
||||
if(m_modelAttributeGroup.modelID < 0) //表示当前加载数据对象是所有属性,前端UI是属性选择器,选择器为非可编辑状态
|
||||
return flags;
|
||||
else
|
||||
{
|
||||
QModelIndex numberIndex = createIndex(index.row(), 0);
|
||||
QString text = numberIndex.data(Qt::DisplayRole).toString();
|
||||
|
||||
|
|
@ -192,6 +188,13 @@ Qt::ItemFlags AttributeTableModel::flags(const QModelIndex &index) const
|
|||
flags = flags | Qt::ItemIsEditable;
|
||||
return flags;
|
||||
}
|
||||
|
||||
void AttributeTableModel::setModelAttributeGroup(const ModelAttributeGroup& modelAttributeGroup)
|
||||
{
|
||||
m_modelAttributeGroup = modelAttributeGroup;
|
||||
//重新刷新
|
||||
m_paginationInfo.currentPage = 1;
|
||||
forceRefresh();
|
||||
}
|
||||
|
||||
bool AttributeTableModel::attributeTypeExistsInCurrentGroup(int id, const QString& type)
|
||||
|
|
@ -335,7 +338,7 @@ void AttributeTableModel::loadPageData()
|
|||
for(int i = 0; i < m_displayField.count(); i++)
|
||||
columns << m_displayField.at(i).originalName;
|
||||
|
||||
if(m_modelAttributeGroup.modelID < 0) //表示当前加载数据对象是所有属性
|
||||
if(m_modelAttributeGroup.modelID == -1) //表示当前加载数据对象是所有属性
|
||||
{
|
||||
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
||||
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_paginationInfo.entriesPerPage)
|
||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||
else
|
||||
strSQL = QString("SELECT attribute_id FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2 LIMIT %3 OFFSET %4")
|
||||
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 OR %2 = -1) LIMIT %3 OFFSET %4")
|
||||
.arg(m_modelAttributeGroup.modelID)
|
||||
.arg(m_modelAttributeGroup.groupID)
|
||||
.arg(m_paginationInfo.entriesPerPage)
|
||||
|
|
@ -474,7 +477,7 @@ void AttributeTableModel::updateTotalCount()
|
|||
return;
|
||||
}*/
|
||||
|
||||
if(m_modelAttributeGroup.modelID < 0)
|
||||
if(m_modelAttributeGroup.modelID == -1)
|
||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection);
|
||||
else
|
||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAttributeCount(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,14 @@ void AttributeView::active()
|
|||
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()
|
||||
{
|
||||
if(m_attributeGroup.isPublic)
|
||||
|
|
|
|||
|
|
@ -96,6 +96,21 @@ void DatabaseBrowser::addTab_attribute(const QString& connection, ModelAttribute
|
|||
}
|
||||
|
||||
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;
|
||||
int index = tabIndex(tabText);
|
||||
|
|
@ -104,6 +119,7 @@ void DatabaseBrowser::closeTab_attribute(ModelAttributeGroup& attributeGroup)
|
|||
|
||||
onTabCloseRequested(index);
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseBrowser::closeAllTab_attribute()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ void DBStructureView::openAttributeGroup(DBStructureNode* node)
|
|||
}
|
||||
|
||||
void DBStructureView::closeAttributeGroup(DBStructureNode* node)
|
||||
{
|
||||
if(node->type() == GroupNode)
|
||||
{
|
||||
DBStructureNode* parent = node->parentNode();
|
||||
if(parent && parent->type() == TableNode)
|
||||
|
|
@ -155,6 +157,14 @@ void DBStructureView::closeAttributeGroup(DBStructureNode* node)
|
|||
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()
|
||||
{
|
||||
|
|
@ -290,6 +300,8 @@ void DBStructureView::showContextMenu(const QPoint& pos)
|
|||
if(g_msgDlgBtn == btn_No)
|
||||
return;
|
||||
}
|
||||
//关闭tab(若打开)
|
||||
closeAttributeGroup(node);
|
||||
removeNode(node);
|
||||
});
|
||||
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 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
|
||||
{
|
||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||
|
|
|
|||
Loading…
Reference in New Issue