From 6b45c6e222a1a0a5800c9d1ff5c7762c14c755b5 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Sun, 27 Apr 2025 16:24:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=9E=E6=80=A7=E6=B7=BB=E5=8A=A0=E2=80=98?= =?UTF-8?q?=E5=8F=AF=E8=A7=81=E6=80=A7=E2=80=99=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/attributeSelector.h | 4 ---- include/global.h | 7 +++++-- source/attributeSelector.cpp | 8 -------- source/attributeTableDelegate.cpp | 7 +++++++ source/attributeTableModel.cpp | 16 +++++++++++++--- source/sqlQueryExecutor.cpp | 12 ++++++++---- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/include/attributeSelector.h b/include/attributeSelector.h index 5d002c8..6c6ef60 100644 --- a/include/attributeSelector.h +++ b/include/attributeSelector.h @@ -12,8 +12,6 @@ QT_END_NAMESPACE class MainWindow; class AttributeView; -class AttributeTableModel; -class AttributeTableDelegate; class AttributeSelector : public QWidget { @@ -33,8 +31,6 @@ private: Ui::AttributeSelector *ui; MainWindow* m_pMainWindow; AttributeView* m_attributeView; - AttributeTableModel* m_attributeTableModel; - AttributeTableDelegate* m_attributeTableDelegate; QString m_connection; }; diff --git a/include/global.h b/include/global.h index 23140a6..36cfe3f 100644 --- a/include/global.h +++ b/include/global.h @@ -92,6 +92,7 @@ struct Attribute int dataTypeID; int dataLength; //filed:length_precision QString defaultValue; + int isVisible; Attribute() { @@ -101,15 +102,17 @@ struct Attribute dataTypeID = -1; dataLength = -1; defaultValue = ""; + isVisible = 1; } - Attribute(int id, QString name, QString type, int dataTypeID, int dataLength, QString defaultVaule) + Attribute(int id, QString name, QString type, int dataTypeID, int dataLength, QString defaultVaule, int isVisible = 1) :id(id), name(std::move(name)), type(std::move(type)), dataTypeID(dataTypeID), dataLength(dataLength), - defaultValue(std::move(defaultVaule)){} + defaultValue(std::move(defaultVaule)), + isVisible(isVisible){} }; struct ModelAttributeGroup diff --git a/source/attributeSelector.cpp b/source/attributeSelector.cpp index 3e2d573..4afdb82 100644 --- a/source/attributeSelector.cpp +++ b/source/attributeSelector.cpp @@ -2,8 +2,6 @@ #include "ui_attributeSelector.h" #include "mainwindow.h" #include "attributeView.h" -#include "attributeTableModel.h" -#include "attributeTableDelegate.h" AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent) : QWidget(parent) @@ -21,12 +19,6 @@ AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent) m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection); ui->layoutTableView->addWidget(m_attributeView); - // m_attributeTableModel = new AttributeTableModel(attributeGroup, this, m_connection); - // m_tableView->setModel(m_attributeTableModel); - - // m_attributeTableDelegate = new AttributeTableDelegate(m_tableView, m_connection, m_tableView); - // m_tableView->setItemDelegate(m_attributeTableDelegate); - connect(ui->btnRefresh, &QPushButton::clicked, this, &AttributeSelector::onBtnClicked_refreshData); } diff --git a/source/attributeTableDelegate.cpp b/source/attributeTableDelegate.cpp index 90eb316..250a0db 100644 --- a/source/attributeTableDelegate.cpp +++ b/source/attributeTableDelegate.cpp @@ -230,6 +230,13 @@ QWidget* AttributeTableDelegate::createEditor(QWidget *parent, const QStyleOptio spinBox->setValue(0); return spinBox; } + else if(dataCol == 5) //可见性 + { + QComboBox* comboBox = new QComboBox(parent); + comboBox->addItem("1"); + comboBox->addItem("0"); + return comboBox; + } return QStyledItemDelegate::createEditor(parent, option, index); } diff --git a/source/attributeTableModel.cpp b/source/attributeTableModel.cpp index 08216c5..61d506c 100644 --- a/source/attributeTableModel.cpp +++ b/source/attributeTableModel.cpp @@ -227,7 +227,8 @@ void AttributeTableModel::updateRowThroughExisitingAttribute(int row, int attrib updateRow.values[2] = attribute.dataTypeID; updateRow.values[3] = attribute.dataLength; updateRow.values[4] = attribute.defaultValue; - updateRow.values[5] = attribute.id;//将id存入最后,不做显示,删除或者修改数据的时候会用到 + updateRow.values[5] = attribute.isVisible; + updateRow.values[6] = attribute.id;//将id存入最后,不做显示,删除或者修改数据的时候会用到 for(int i = 0; i < m_displayField.count(); i++) updateRow.cellModified[i] = true; //标记单元格 @@ -275,6 +276,12 @@ void AttributeTableModel::iniDisplayField() //field5.dataType = "character varying(64)"; m_displayField.append(field5); + FieldInfo field6; + field6.originalName = "is_visible"; + field6.displayName = QString::fromWCharArray(L"可见性"); + //field6.dataType = "smallint"; + m_displayField.append(field6); + QHash fieldType = SqlQueryExecutor::instance().getFiledType(m_connection, "attribute", "basic"); for(int i = 0; i < m_displayField.count(); i++) { @@ -381,6 +388,7 @@ void AttributeTableModel::loadPageData() data.values.append(attribute.dataTypeID); data.values.append(attribute.dataLength); data.values.append(attribute.defaultValue); + data.values.append(attribute.isVisible); data.values.append(attribute.id);//将id存入最后,不做显示,删除或者修改数据的时候会用到 m_currentPageData.append(data); } @@ -595,11 +603,12 @@ void AttributeTableModel::submitChanges() QString defaultValue = "null"; if(rowData.values.value(4).isValid()) defaultValue = rowData.values.value(4).toString(); + int isVisible = rowData.values.value(5).toInt(); int id = -1; if(rowData.values.size() == m_displayField.count() +1) id = rowData.values.value(m_displayField.count()).toInt(); - insertAttributes.emplace_back(id, name, type, dataTypeID, dataLength, defaultValue); + insertAttributes.emplace_back(id, name, type, dataTypeID, dataLength, defaultValue, isVisible); } insertCompleted = SqlQueryExecutor::instance().batchInsertAttributes(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID, insertAttributes); } @@ -635,8 +644,9 @@ void AttributeTableModel::submitChanges() QString defaultValue = "null"; if(rowData.values.value(4).isValid()) defaultValue = rowData.values.value(4).toString(); + int isVisible = rowData.values.value(5).toInt(); - updateAttributes.emplace_back(id, name, type, dataTypeID, dataLength, defaultValue); + updateAttributes.emplace_back(id, name, type, dataTypeID, dataLength, defaultValue, isVisible); } updateCompleted = SqlQueryExecutor::instance().batchUpdateAttributes(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID, updateAttributes); } diff --git a/source/sqlQueryExecutor.cpp b/source/sqlQueryExecutor.cpp index a1d8c20..fc016fe 100644 --- a/source/sqlQueryExecutor.cpp +++ b/source/sqlQueryExecutor.cpp @@ -610,6 +610,7 @@ bool SqlQueryExecutor::getAttributeInfo(const QString& connectionName, const QSt attribute.dataTypeID = query.value(2).toInt(); attribute.dataLength = query.value(3).toInt(); attribute.defaultValue = query.value(4).toString(); + attribute.isVisible = query.value(5).toInt(); } else return false; @@ -688,14 +689,15 @@ bool SqlQueryExecutor::batchInsertAttributes(const QString& connectionName, int qint64 attributeID = QDateTime::currentDateTime().toMSecsSinceEpoch(); //先向model_type中插入一条记录 - QString strSQL = "INSERT INTO basic.attribute (attribute, attribute_name, data_type_id, length_precision, default_value) VALUES " - "(:type, :name, :dataType, :dataLength, :defaultValue)"; + QString strSQL = "INSERT INTO basic.attribute (attribute, attribute_name, data_type_id, length_precision, default_value, is_visible) VALUES " + "(:type, :name, :dataType, :dataLength, :defaultValue, :isVisible)"; QVariantHash params; params.insert(":type", attribute.type); params.insert(":name", attribute.name); params.insert(":dataType", attribute.dataTypeID); params.insert(":dataLength", attribute.dataLength); params.insert(":defaultValue", attribute.defaultValue); + params.insert(":isVisible", attribute.isVisible); try { QSqlQuery query = executeSQL(connectionName, strSQL, params); @@ -842,7 +844,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int } QSqlQuery query(db); - QString strSQL = "UPDATE basic.attribute SET attribute = ?, attribute_name = ?, data_type_id = ?, length_precision = ?, default_value = ? WHERE id = ?"; + QString strSQL = "UPDATE basic.attribute SET attribute = ?, attribute_name = ?, data_type_id = ?, length_precision = ?, default_value = ?, is_visible = ? WHERE id = ?"; if(!query.prepare(strSQL)) { LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, query.lastError().databaseText())); @@ -852,7 +854,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int } return false; } - QVariantList types, names, dataTypes, lengths, defaults, ids; + QVariantList types, names, dataTypes, lengths, defaults, isVisibles, ids; for(const Attribute& attribute : attributes) { types << attribute.type; @@ -860,6 +862,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int dataTypes << attribute.dataTypeID; lengths << attribute.dataLength; defaults << attribute.defaultValue; + isVisibles << attribute.isVisible; ids << attribute.id; } query.addBindValue(types); @@ -867,6 +870,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int query.addBindValue(dataTypes); query.addBindValue(lengths); query.addBindValue(defaults); + query.addBindValue(isVisibles); query.addBindValue(ids); if( !query.execBatch() ) {