更新属性按关键词搜索时获取结果数量逻辑
This commit is contained in:
parent
399ee6340d
commit
2dd33f2280
|
|
@ -23,7 +23,9 @@ public:
|
||||||
AttributeSelector(const QString& connection = "", QWidget *parent = nullptr);
|
AttributeSelector(const QString& connection = "", QWidget *parent = nullptr);
|
||||||
~AttributeSelector();
|
~AttributeSelector();
|
||||||
|
|
||||||
void setMainWindow(MainWindow*);
|
void setMainWindow(MainWindow* window) {m_pMainWindow = window;}
|
||||||
|
// const QString& connection() {return m_connection;}
|
||||||
|
// void setConnection(const QString& conn) {m_connection = conn;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void showEvent(QShowEvent*) override;
|
void showEvent(QShowEvent*) override;
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ public:
|
||||||
bool addModleGrpus(const QString&, int, QVector<int>);
|
bool addModleGrpus(const QString&, int, QVector<int>);
|
||||||
QVector<int> getModelGroups(const QString&, int);
|
QVector<int> getModelGroups(const QString&, int);
|
||||||
//属性相关
|
//属性相关
|
||||||
int getAttributeCount(const QString&, int, int);
|
int getAttributeCount(const QString&, int, int, const QString& filterChars = "");
|
||||||
int getAllAttributeCount(const QString&);
|
int getAllAttributeCount(const QString&, const QString& filterChars = "");
|
||||||
bool getAttributeInfo(const QString&, const QString&, Attribute&);
|
bool getAttributeInfo(const QString&, const QString&, Attribute&);
|
||||||
int getAttributeID(const QString&, const QString&);
|
int getAttributeID(const QString&, const QString&);
|
||||||
bool attributeTypeUseByModelGroup(const QString&, int, int, int);
|
bool attributeTypeUseByModelGroup(const QString&, int, int, int);
|
||||||
|
|
|
||||||
|
|
@ -178,11 +178,6 @@ bool AttributeSelector::eventFilter(QObject* obj, QEvent* event)
|
||||||
return QDialog::eventFilter(obj, event);
|
return QDialog::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttributeSelector::setMainWindow(MainWindow* window)
|
|
||||||
{
|
|
||||||
m_pMainWindow = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AttributeSelector::onBtnClicked_search()
|
void AttributeSelector::onBtnClicked_search()
|
||||||
{
|
{
|
||||||
if(m_fliterChars_type != ui->lineEdit_attributeType->text() || m_curModelName != ui->comboBox_model->currentText()
|
if(m_fliterChars_type != ui->lineEdit_attributeType->text() || m_curModelName != ui->comboBox_model->currentText()
|
||||||
|
|
|
||||||
|
|
@ -355,8 +355,9 @@ void AttributeTableModel::loadPageData()
|
||||||
if(m_modelAttributeGroup.modelID == -1) //表示当前加载数据对象是所有属性
|
if(m_modelAttributeGroup.modelID == -1) //表示当前加载数据对象是所有属性
|
||||||
{
|
{
|
||||||
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
columns.append("id"); //将id放到最后,和按照具体模型、具体属性组读取数据方式时逻辑统一,具体见下面分支逻辑
|
||||||
QString strSQL = QString("SELECT %1 FROM basic.attribute ORDER BY id ASC LIMIT %2 OFFSET %3")
|
QString strSQL = QString("SELECT %1 FROM basic.attribute WHERE attribute LIKE '%%2%' ORDER BY id ASC LIMIT %3 OFFSET %4")
|
||||||
.arg(columns.join(", "))
|
.arg(columns.join(", "))
|
||||||
|
.arg(m_filterChars_attributeType)
|
||||||
.arg(m_paginationInfo.entriesPerPage)
|
.arg(m_paginationInfo.entriesPerPage)
|
||||||
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
.arg((m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage);
|
||||||
try
|
try
|
||||||
|
|
@ -364,9 +365,9 @@ void AttributeTableModel::loadPageData()
|
||||||
QSqlQuery query = SqlQueryExecutor::instance().executeSQL(m_connection, strSQL);
|
QSqlQuery query = SqlQueryExecutor::instance().executeSQL(m_connection, strSQL);
|
||||||
while(query.next())
|
while(query.next())
|
||||||
{
|
{
|
||||||
QString type = query.value(0).toString();
|
// QString type = query.value(0).toString();
|
||||||
if(!m_filterChars_attributeType.isEmpty() && !type.contains(m_filterChars_attributeType))
|
// if(!m_filterChars_attributeType.isEmpty() && !type.contains(m_filterChars_attributeType))
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
RowData data;
|
RowData data;
|
||||||
for(int i = 0; i < columns.count(); i++)
|
for(int i = 0; i < columns.count(); i++)
|
||||||
|
|
@ -501,7 +502,7 @@ void AttributeTableModel::updateTotalCount()
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if(m_modelAttributeGroup.modelID == -1)
|
if(m_modelAttributeGroup.modelID == -1)
|
||||||
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection);
|
m_paginationInfo.totalEntries = SqlQueryExecutor::instance().getAllAttributeCount(m_connection, m_filterChars_attributeType);
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -578,15 +578,27 @@ bool SqlQueryExecutor::removeAttributeGroup(const QString& connectionName, int m
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID)
|
int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int modelID, int groupID, const QString& filterChars)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
QString strSQL = "";
|
QString strSQL = "";
|
||||||
bool isPublicGroup = isPublicAttributeGroup(connectionName, groupID);
|
bool isPublicGroup = isPublicAttributeGroup(connectionName, groupID);
|
||||||
if(isPublicGroup)
|
if(isPublicGroup)
|
||||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute_public WHERE attribute_group_id = %1").arg(groupID);
|
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute_public AS map "
|
||||||
|
"INNER JOIN basic.attribute AS a ON map.attribute_id = a.id "
|
||||||
|
"WHERE attribute_group_id = %1 "
|
||||||
|
"AND a.attribute LIKE '%%2%'")
|
||||||
|
.arg(groupID)
|
||||||
|
.arg(filterChars);
|
||||||
else
|
else
|
||||||
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute WHERE model_type_id = %1 AND attribute_group_id = %2").arg(modelID).arg(groupID);
|
strSQL = QString("SELECT COUNT(*) FROM basic.model_attribute AS map "
|
||||||
|
"INNER JOIN basic.attribute AS a ON map.attribute_id = a.id "
|
||||||
|
"WHERE model_type_id = %1 "
|
||||||
|
"AND attribute_group_id = %2 "
|
||||||
|
"AND a.attribute LIKE '%%3%'")
|
||||||
|
.arg(modelID)
|
||||||
|
.arg(groupID)
|
||||||
|
.arg(filterChars);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||||
|
|
@ -601,15 +613,17 @@ int SqlQueryExecutor::getAttributeCount(const QString& connectionName, int model
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SqlQueryExecutor::getAllAttributeCount(const QString& connectionName)
|
int SqlQueryExecutor::getAllAttributeCount(const QString& connectionName, const QString& filterChars)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
QString strSQL = QString("SELECT COUNT(*) FROM basic.attribute");
|
QString strSQL = QString("SELECT COUNT(*) FROM basic.attribute WHERE attribute LIKE '%") + filterChars + "%'";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QSqlQuery query = executeSQL(connectionName, strSQL);
|
QSqlQuery query = executeSQL(connectionName, strSQL);
|
||||||
if(query.next())
|
if(query.next())
|
||||||
|
{
|
||||||
count = query.value(0).toInt();
|
count = query.value(0).toInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const DatabaseException& e)
|
catch (const DatabaseException& e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue