85 lines
2.8 KiB
C++
85 lines
2.8 KiB
C++
#include "attributeSelector.h"
|
|
#include "ui_attributeSelector.h"
|
|
#include "mainwindow.h"
|
|
#include "attributeView.h"
|
|
#include "sqlQueryExecutor.h"
|
|
|
|
AttributeSelector::AttributeSelector(const QString& connection, QWidget *parent)
|
|
: QWidget(parent)
|
|
, ui(new Ui::AttributeSelector)
|
|
, m_connection(connection)
|
|
{
|
|
ui->setupUi(this);
|
|
//隐藏一些功能按钮
|
|
ui->btnAdd->setVisible(false);
|
|
ui->btnRemove->setVisible(false);
|
|
ui->btnSave->setVisible(false);
|
|
ui->btnCancle->setVisible(false);
|
|
|
|
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);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
|