完成‘属性选择器’的开发

This commit is contained in:
duanshengchao 2025-05-08 09:30:47 +08:00
parent 122ac57e3d
commit 0339082a45
7 changed files with 40 additions and 13 deletions

View File

@ -54,6 +54,9 @@ private:
QString m_fliterChars_type;
QString m_curModelName;
QString m_curGroupName;
signals:
void completeSelection(QVector<QVector<QVariant>>);
};
#endif //ATTRIBUTESELECTOR_H

View File

@ -86,12 +86,12 @@ public:
void refresh();
void forceRefresh(); //强制刷新(不会出现询问提示,数据同步时会用到)
void insertRecord(int);
void addRecords(QList<RowData>);
void addRecords(QVector<QVector<QVariant>>);
void removeRecord();
bool removeRecord(int);
void submitChanges(); //提交更改(增、删、改)
void cancleChanges(); //取消修改
QList<RowData> getSelectedRowData();
QVector<QVector<QVariant>> getSelectedRowData();
//展示列控制
//void setVisibleColumns(const QStringList& columns);

View File

@ -45,6 +45,9 @@ private slots:
void onBtnClicked_lastPage();
void onEditingFinished_page();
public slots:
void processAttributeSelectedData(QVector<QVector<QVariant>>);
private:
int tabIndex(const QString&);

View File

@ -212,7 +212,10 @@ void AttributeSelector::onBtnClicked_refreshData()
void AttributeSelector::onBtnClicked_submitSelect()
{
QVector<QVector<QVariant>> selectedResult = m_attributeView->model()->getSelectedRowData();
emit completeSelection(selectedResult);
close();
}
void AttributeSelector::onBtnClicked_cancleSelect()

View File

@ -568,14 +568,14 @@ void AttributeTableModel::insertRecord(int row)
endInsertRows();
}
void AttributeTableModel::addRecords(QList<RowData> records)
void AttributeTableModel::addRecords(QVector<QVector<QVariant>> records)
{
QList<RowData> validRecords;
QVector<QVector<QVariant>> validRecords;
//首先过滤掉已经存在记录
for(const RowData& record : records)
for(const QVector<QVariant>& record : records)
{
int id = record.values.last().toInt(); //目前该函数的数据源都来‘属性选择器’(都是已创建好的属性)
QString type = record.values.value(0).toString();
int id = record.last().toInt(); //目前该函数的数据源都来‘属性选择器’(都是已创建好的属性)
QString type = record.value(0).toString();
bool existed = attributeTypeExistsInCurrentGroup(id, type);
if(!existed)
validRecords.append(record);
@ -583,14 +583,14 @@ void AttributeTableModel::addRecords(QList<RowData> records)
if(validRecords.count() == 0)
return;
beginInsertRows(QModelIndex(), rowCount(), rowCount() + records.count() - 1);
beginInsertRows(QModelIndex(), rowCount(), rowCount() + validRecords.count() - 1);
int row = m_currentPageData.count();
for(const RowData& record : records)
for(const QVector<QVariant>& record : validRecords)
{
RowData newRow;
newRow.state = New;
newRow.values = record.values;
newRow.values = record;
int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage + row;
m_modifiedRows[globalRow] = newRow;
@ -746,14 +746,14 @@ void AttributeTableModel::cancleChanges()
emit syncDataStatus(dataHasbeenModified(), m_paginationInfo);
}
QList<AttributeTableModel::RowData> AttributeTableModel::getSelectedRowData()
QVector<QVector<QVariant>> AttributeTableModel::getSelectedRowData()
{
QList<RowData> result;
QVector<QVector<QVariant>> result;
for(int row = 0; row < rowCount(); row++)
{
QModelIndex numberIndex = createIndex(row, 0);
if(m_selectionModel && m_selectionModel->isSelected(numberIndex))
result.append(m_currentPageData.at(row));
result.append(m_currentPageData.at(row).values);
}
return result;
}

View File

@ -370,3 +370,20 @@ void DatabaseBrowser::onShowMessage(MessageDialogType type,const QString& strTit
if(m_pMainWindow)
m_pMainWindow->showMessageDialog(type, strTitle, strContent);
}
void DatabaseBrowser::processAttributeSelectedData(QVector<QVector<QVariant>> datas)
{
QWidget* widget = ui->tabWidget->currentWidget();
AttributeView* attributeView = qobject_cast<AttributeView*>(widget);
if(attributeView)
{
QTableView* view = attributeView->view();
AttributeTableModel* model = attributeView->model();
if(view && model)
{
model->addRecords(datas);
ui->btnSave->setEnabled(true);
ui->btnCancle->setEnabled(true);
}
}
}

View File

@ -338,6 +338,7 @@ void MainWindow::onSIG_openAttributeSelector()
m_pAttributeSelector->setMainWindow(this);
m_pAttributeSelector->installEventFilter(this);
connect(m_pAttributeSelector, &AttributeSelector::finished, this, [=]{ MaskManager::instance()->hideMask(m_pAttributeSelector); });
connect(m_pAttributeSelector, &AttributeSelector::completeSelection, m_dbBrowser, &DatabaseBrowser::processAttributeSelectedData);
}
int nX = (this->width() - m_pAttributeSelector->width()) * 0.5;