属性添加‘可见性’字段
This commit is contained in:
parent
bbae749216
commit
6b45c6e222
|
|
@ -12,8 +12,6 @@ QT_END_NAMESPACE
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class AttributeView;
|
class AttributeView;
|
||||||
class AttributeTableModel;
|
|
||||||
class AttributeTableDelegate;
|
|
||||||
|
|
||||||
class AttributeSelector : public QWidget
|
class AttributeSelector : public QWidget
|
||||||
{
|
{
|
||||||
|
|
@ -33,8 +31,6 @@ private:
|
||||||
Ui::AttributeSelector *ui;
|
Ui::AttributeSelector *ui;
|
||||||
MainWindow* m_pMainWindow;
|
MainWindow* m_pMainWindow;
|
||||||
AttributeView* m_attributeView;
|
AttributeView* m_attributeView;
|
||||||
AttributeTableModel* m_attributeTableModel;
|
|
||||||
AttributeTableDelegate* m_attributeTableDelegate;
|
|
||||||
QString m_connection;
|
QString m_connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ struct Attribute
|
||||||
int dataTypeID;
|
int dataTypeID;
|
||||||
int dataLength; //filed:length_precision
|
int dataLength; //filed:length_precision
|
||||||
QString defaultValue;
|
QString defaultValue;
|
||||||
|
int isVisible;
|
||||||
|
|
||||||
Attribute()
|
Attribute()
|
||||||
{
|
{
|
||||||
|
|
@ -101,15 +102,17 @@ struct Attribute
|
||||||
dataTypeID = -1;
|
dataTypeID = -1;
|
||||||
dataLength = -1;
|
dataLength = -1;
|
||||||
defaultValue = "";
|
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),
|
:id(id),
|
||||||
name(std::move(name)),
|
name(std::move(name)),
|
||||||
type(std::move(type)),
|
type(std::move(type)),
|
||||||
dataTypeID(dataTypeID),
|
dataTypeID(dataTypeID),
|
||||||
dataLength(dataLength),
|
dataLength(dataLength),
|
||||||
defaultValue(std::move(defaultVaule)){}
|
defaultValue(std::move(defaultVaule)),
|
||||||
|
isVisible(isVisible){}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ModelAttributeGroup
|
struct ModelAttributeGroup
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
#include "ui_attributeSelector.h"
|
#include "ui_attributeSelector.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "attributeView.h"
|
#include "attributeView.h"
|
||||||
#include "attributeTableModel.h"
|
|
||||||
#include "attributeTableDelegate.h"
|
|
||||||
|
|
||||||
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
|
@ -21,12 +19,6 @@ AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
||||||
m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection);
|
m_attributeView = new AttributeView(attributeGroup, ui->attributeViewContainer, connection);
|
||||||
ui->layoutTableView->addWidget(m_attributeView);
|
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);
|
connect(ui->btnRefresh, &QPushButton::clicked, this, &AttributeSelector::onBtnClicked_refreshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,13 @@ QWidget* AttributeTableDelegate::createEditor(QWidget *parent, const QStyleOptio
|
||||||
spinBox->setValue(0);
|
spinBox->setValue(0);
|
||||||
return spinBox;
|
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);
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,8 @@ void AttributeTableModel::updateRowThroughExisitingAttribute(int row, int attrib
|
||||||
updateRow.values[2] = attribute.dataTypeID;
|
updateRow.values[2] = attribute.dataTypeID;
|
||||||
updateRow.values[3] = attribute.dataLength;
|
updateRow.values[3] = attribute.dataLength;
|
||||||
updateRow.values[4] = attribute.defaultValue;
|
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++)
|
for(int i = 0; i < m_displayField.count(); i++)
|
||||||
updateRow.cellModified[i] = true; //标记单元格
|
updateRow.cellModified[i] = true; //标记单元格
|
||||||
|
|
@ -275,6 +276,12 @@ void AttributeTableModel::iniDisplayField()
|
||||||
//field5.dataType = "character varying(64)";
|
//field5.dataType = "character varying(64)";
|
||||||
m_displayField.append(field5);
|
m_displayField.append(field5);
|
||||||
|
|
||||||
|
FieldInfo field6;
|
||||||
|
field6.originalName = "is_visible";
|
||||||
|
field6.displayName = QString::fromWCharArray(L"可见性");
|
||||||
|
//field6.dataType = "smallint";
|
||||||
|
m_displayField.append(field6);
|
||||||
|
|
||||||
QHash<QString, QString> fieldType = SqlQueryExecutor::instance().getFiledType(m_connection, "attribute", "basic");
|
QHash<QString, QString> fieldType = SqlQueryExecutor::instance().getFiledType(m_connection, "attribute", "basic");
|
||||||
for(int i = 0; i < m_displayField.count(); i++)
|
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.dataTypeID);
|
||||||
data.values.append(attribute.dataLength);
|
data.values.append(attribute.dataLength);
|
||||||
data.values.append(attribute.defaultValue);
|
data.values.append(attribute.defaultValue);
|
||||||
|
data.values.append(attribute.isVisible);
|
||||||
data.values.append(attribute.id);//将id存入最后,不做显示,删除或者修改数据的时候会用到
|
data.values.append(attribute.id);//将id存入最后,不做显示,删除或者修改数据的时候会用到
|
||||||
m_currentPageData.append(data);
|
m_currentPageData.append(data);
|
||||||
}
|
}
|
||||||
|
|
@ -595,11 +603,12 @@ void AttributeTableModel::submitChanges()
|
||||||
QString defaultValue = "null";
|
QString defaultValue = "null";
|
||||||
if(rowData.values.value(4).isValid())
|
if(rowData.values.value(4).isValid())
|
||||||
defaultValue = rowData.values.value(4).toString();
|
defaultValue = rowData.values.value(4).toString();
|
||||||
|
int isVisible = rowData.values.value(5).toInt();
|
||||||
|
|
||||||
int id = -1;
|
int id = -1;
|
||||||
if(rowData.values.size() == m_displayField.count() +1)
|
if(rowData.values.size() == m_displayField.count() +1)
|
||||||
id = rowData.values.value(m_displayField.count()).toInt();
|
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);
|
insertCompleted = SqlQueryExecutor::instance().batchInsertAttributes(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID, insertAttributes);
|
||||||
}
|
}
|
||||||
|
|
@ -635,8 +644,9 @@ void AttributeTableModel::submitChanges()
|
||||||
QString defaultValue = "null";
|
QString defaultValue = "null";
|
||||||
if(rowData.values.value(4).isValid())
|
if(rowData.values.value(4).isValid())
|
||||||
defaultValue = rowData.values.value(4).toString();
|
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);
|
updateCompleted = SqlQueryExecutor::instance().batchUpdateAttributes(m_connection, m_modelAttributeGroup.modelID, m_modelAttributeGroup.groupID, updateAttributes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -610,6 +610,7 @@ bool SqlQueryExecutor::getAttributeInfo(const QString& connectionName, const QSt
|
||||||
attribute.dataTypeID = query.value(2).toInt();
|
attribute.dataTypeID = query.value(2).toInt();
|
||||||
attribute.dataLength = query.value(3).toInt();
|
attribute.dataLength = query.value(3).toInt();
|
||||||
attribute.defaultValue = query.value(4).toString();
|
attribute.defaultValue = query.value(4).toString();
|
||||||
|
attribute.isVisible = query.value(5).toInt();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -688,14 +689,15 @@ bool SqlQueryExecutor::batchInsertAttributes(const QString& connectionName, int
|
||||||
|
|
||||||
qint64 attributeID = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
qint64 attributeID = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
||||||
//先向model_type中插入一条记录
|
//先向model_type中插入一条记录
|
||||||
QString strSQL = "INSERT INTO basic.attribute (attribute, attribute_name, data_type_id, length_precision, default_value) VALUES "
|
QString strSQL = "INSERT INTO basic.attribute (attribute, attribute_name, data_type_id, length_precision, default_value, is_visible) VALUES "
|
||||||
"(:type, :name, :dataType, :dataLength, :defaultValue)";
|
"(:type, :name, :dataType, :dataLength, :defaultValue, :isVisible)";
|
||||||
QVariantHash params;
|
QVariantHash params;
|
||||||
params.insert(":type", attribute.type);
|
params.insert(":type", attribute.type);
|
||||||
params.insert(":name", attribute.name);
|
params.insert(":name", attribute.name);
|
||||||
params.insert(":dataType", attribute.dataTypeID);
|
params.insert(":dataType", attribute.dataTypeID);
|
||||||
params.insert(":dataLength", attribute.dataLength);
|
params.insert(":dataLength", attribute.dataLength);
|
||||||
params.insert(":defaultValue", attribute.defaultValue);
|
params.insert(":defaultValue", attribute.defaultValue);
|
||||||
|
params.insert(":isVisible", attribute.isVisible);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QSqlQuery query = executeSQL(connectionName, strSQL, params);
|
QSqlQuery query = executeSQL(connectionName, strSQL, params);
|
||||||
|
|
@ -842,7 +844,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlQuery query(db);
|
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))
|
if(!query.prepare(strSQL))
|
||||||
{
|
{
|
||||||
LOG_ERROR("SQL", QString("SQL '%1' prepare fialed. error: %2").arg(strSQL, query.lastError().databaseText()));
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
QVariantList types, names, dataTypes, lengths, defaults, ids;
|
QVariantList types, names, dataTypes, lengths, defaults, isVisibles, ids;
|
||||||
for(const Attribute& attribute : attributes)
|
for(const Attribute& attribute : attributes)
|
||||||
{
|
{
|
||||||
types << attribute.type;
|
types << attribute.type;
|
||||||
|
|
@ -860,6 +862,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int
|
||||||
dataTypes << attribute.dataTypeID;
|
dataTypes << attribute.dataTypeID;
|
||||||
lengths << attribute.dataLength;
|
lengths << attribute.dataLength;
|
||||||
defaults << attribute.defaultValue;
|
defaults << attribute.defaultValue;
|
||||||
|
isVisibles << attribute.isVisible;
|
||||||
ids << attribute.id;
|
ids << attribute.id;
|
||||||
}
|
}
|
||||||
query.addBindValue(types);
|
query.addBindValue(types);
|
||||||
|
|
@ -867,6 +870,7 @@ bool SqlQueryExecutor::batchUpdateAttributes(const QString& connectionName, int
|
||||||
query.addBindValue(dataTypes);
|
query.addBindValue(dataTypes);
|
||||||
query.addBindValue(lengths);
|
query.addBindValue(lengths);
|
||||||
query.addBindValue(defaults);
|
query.addBindValue(defaults);
|
||||||
|
query.addBindValue(isVisibles);
|
||||||
query.addBindValue(ids);
|
query.addBindValue(ids);
|
||||||
if( !query.execBatch() )
|
if( !query.execBatch() )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue