完善测量分析记录实现
This commit is contained in:
parent
c039e9bf61
commit
aaf6883f4d
|
|
@ -1,17 +1,27 @@
|
||||||
#include "MeasureAnalysisHistoryForm.h"
|
#include "MeasureAnalysisHistoryForm.h"
|
||||||
#include "MeasureAnalysisProjectModel.h"
|
#include "MeasureAnalysisProjectModel.h"
|
||||||
#include "ui_MeasureAnalysisHistoryForm.h"
|
#include "ui_MeasureAnalysisHistoryForm.h"
|
||||||
#include <QDebug>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
MeasureAnalysisHistoryForm::MeasureAnalysisHistoryForm(QWidget* parent)
|
MeasureAnalysisHistoryForm::MeasureAnalysisHistoryForm(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, ui(new Ui::MeasureAnalysisHistoryForm)
|
, ui(new Ui::MeasureAnalysisHistoryForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
connect(ui->btn_query, &QPushButton::clicked, [this]() {
|
|
||||||
queryHistory();
|
ui->tablew_history->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
});
|
ui->tablew_history->horizontalHeader()->setSectionResizeMode(
|
||||||
|
ui->tablew_history->columnCount() - 1, QHeaderView::Stretch);
|
||||||
|
ui->tablew_history->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
|
|
||||||
|
connect(ui->btn_query, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onQueryHistory);
|
||||||
|
connect(ui->btn_remove, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onRemoveSelectedProject);
|
||||||
|
connect(ui->btn_select_all, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onAllSelect);
|
||||||
|
connect(ui->btn_reverse, &QPushButton::clicked, this, &MeasureAnalysisHistoryForm::onReverseSelect);
|
||||||
|
connect(ui->tablew_history, &QTableWidget::cellDoubleClicked, this, &MeasureAnalysisHistoryForm::onTableCellDoubleClicked);
|
||||||
|
|
||||||
loadHistoryInfo();
|
loadHistoryInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,57 +34,130 @@ void MeasureAnalysisHistoryForm::loadHistoryInfo()
|
||||||
{
|
{
|
||||||
auto row_count = ui->tablew_history->rowCount();
|
auto row_count = ui->tablew_history->rowCount();
|
||||||
for (int row = row_count - 1; row >= 0; --row) {
|
for (int row = row_count - 1; row >= 0; --row) {
|
||||||
QPushButton* btn_remove_row = dynamic_cast<QPushButton*>(ui->tablew_history->cellWidget(row, 8));
|
ui->tablew_history->removeRow(row);
|
||||||
if (btn_remove_row) {
|
|
||||||
ui->tablew_history->removeRow(row);
|
|
||||||
btn_remove_row->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 遍历可执行文件目录下Projects目录下的所有文件夹,找出所有项目文件夹下的.msproject文件
|
// 遍历可执行文件目录下Projects目录下的所有文件夹,找出所有项目文件夹下的.msproject文件
|
||||||
QDir projects_dir(QDir(qApp->applicationDirPath()).filePath("Projects"));
|
QDir projects_dir(QDir(qApp->applicationDirPath()).filePath("Projects"));
|
||||||
if (!projects_dir.exists()) {
|
if (!projects_dir.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QList<QString> project_dirs = projects_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QList<QString> project_dirs = projects_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time);
|
||||||
for (const QString& project_dir : project_dirs) {
|
for (const QString& project_dir : project_dirs) {
|
||||||
QDir project_dir_path(projects_dir.path() + "/" + project_dir);
|
QDir project_dir_path(projects_dir.filePath(project_dir));
|
||||||
if (project_dir_path.exists()) {
|
if (project_dir_path.exists()) {
|
||||||
QList<QString> msproject_files = project_dir_path.entryList(QStringList({ "*.msproject" }));
|
QList<QString> msproject_files = project_dir_path.entryList(QStringList({ "*.msproject" }));
|
||||||
if (msproject_files.isEmpty()) {
|
if (msproject_files.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const QString& project_filename = project_dir_path.filePath(msproject_files.first());
|
const QString& project_filename = project_dir_path.filePath(msproject_files.first());
|
||||||
qDebug() << project_filename;
|
|
||||||
MeasureAnalysisProjectModel project_model;
|
MeasureAnalysisProjectModel project_model;
|
||||||
project_model.LoadProjectModel(project_filename);
|
project_model.LoadProjectModel(project_filename);
|
||||||
|
int row = ui->tablew_history->rowCount();
|
||||||
// int row = ui->tablew_history->rowCount();
|
ui->tablew_history->insertRow(row);
|
||||||
// ui->tablew_history->insertRow(row);
|
ui->tablew_history->setItem(row, 0, new QTableWidgetItem(project_model.GetProjectName()));
|
||||||
// ui->tablew_history->setItem(row, 0, new QTableWidgetItem(channel_name));
|
ui->tablew_history->item(row, 0)->setCheckState(Qt::Unchecked);
|
||||||
// ui->tablew_history->item(row, 0)->setCheckState(Qt::Unchecked);
|
ui->tablew_history->item(row, 0)->setData(Qt::UserRole, project_filename);
|
||||||
// ui->tablew_history->setItem(row, 1, new QTableWidgetItem(QString::number(fit_data_item[0])));
|
const QString& is_measure_complete = project_model.GetIsMeasureComplete() ? QStringLiteral(u"是") : QStringLiteral(u"否");
|
||||||
// ui->tablew_history->setItem(row, 2, new QTableWidgetItem(QString::number(fit_data_item[1])));
|
ui->tablew_history->setItem(row, 1, new QTableWidgetItem(is_measure_complete));
|
||||||
// ui->tablew_history->setItem(row, 3, new QTableWidgetItem(QString::number(fit_data_item[2])));
|
QStringList spectrum_type_names { QStringLiteral(u"未知"), QStringLiteral(u"样品谱"), QStringLiteral(u"本底谱") };
|
||||||
// ui->tablew_history->setItem(row, 4, new QTableWidgetItem(QString::number(fit_data_item[3])));
|
const QString& spectrum_type_name = spectrum_type_names.value(project_model.GetSpectrumType(), QStringLiteral(u"未知"));
|
||||||
// ui->tablew_history->setItem(row, 5, new QTableWidgetItem(QString::number(fit_data_item[4])));
|
ui->tablew_history->setItem(row, 2, new QTableWidgetItem(spectrum_type_name));
|
||||||
// ui->tablew_history->setItem(row, 6, new QTableWidgetItem(QString::number(fit_data_item[5])));
|
const QString& is_std_source = project_model.GetIsStdSource() ? QStringLiteral(u"是") : QStringLiteral(u"否");
|
||||||
// ui->tablew_history->setItem(row, 7, new QTableWidgetItem(QString::number(fit_data_item[6])));
|
ui->tablew_history->setItem(row, 3, new QTableWidgetItem(is_std_source));
|
||||||
// QTableWidgetItem* item = new QTableWidgetItem;
|
ui->tablew_history->setItem(row, 7, new QTableWidgetItem(project_model.GetDescriptionInfo()));
|
||||||
// ui->tablew_history->setItem(row, 8, item);
|
|
||||||
// QPushButton* btn_remove_row = new QPushButton(QStringLiteral(u"删除"));
|
|
||||||
// btn_remove_row->setMaximumWidth(35);
|
|
||||||
// connect(btn_remove_row, &QPushButton::clicked, [this, channel_name, item, btn_remove_row]() {
|
|
||||||
// item->setCheckState(Qt::Unchecked);
|
|
||||||
// int remove_row = item->row();
|
|
||||||
// ui->tablew_history->removeRow(remove_row);
|
|
||||||
// btn_remove_row->deleteLater();
|
|
||||||
// });
|
|
||||||
// ui->tablew_history->setCellWidget(row, 8, btn_remove_row);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeasureAnalysisHistoryForm::queryHistory()
|
void MeasureAnalysisHistoryForm::onQueryHistory()
|
||||||
{
|
{
|
||||||
const QString& query_text = ui->linedit_query->text();
|
const QString& query_text = ui->linedit_query->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MeasureAnalysisHistoryForm::onAllSelect()
|
||||||
|
{
|
||||||
|
ui->tablew_history->setCurrentItem(nullptr);
|
||||||
|
auto row_count = ui->tablew_history->rowCount();
|
||||||
|
for (int i = 0; i < row_count; ++i) {
|
||||||
|
if (ui->tablew_history->isRowHidden(i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto item = ui->tablew_history->item(i, 0);
|
||||||
|
if (item) {
|
||||||
|
if (item->flags() & Qt::ItemIsUserCheckable) {
|
||||||
|
item->setCheckState(Qt::Checked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureAnalysisHistoryForm::onReverseSelect()
|
||||||
|
{
|
||||||
|
ui->tablew_history->setCurrentItem(nullptr);
|
||||||
|
auto row_count = ui->tablew_history->rowCount();
|
||||||
|
for (int i = 0; i < row_count - 1; i++) {
|
||||||
|
if (ui->tablew_history->isRowHidden(i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto item = ui->tablew_history->item(i, 0);
|
||||||
|
if (item) {
|
||||||
|
if (item->flags() & Qt::ItemIsUserCheckable) {
|
||||||
|
Qt::CheckState check_state = (item->checkState() == Qt::Checked) ? Qt::Unchecked : Qt::Checked;
|
||||||
|
item->setCheckState(check_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureAnalysisHistoryForm::onRemoveSelectedProject()
|
||||||
|
{
|
||||||
|
auto row_count = ui->tablew_history->rowCount();
|
||||||
|
for (int row = row_count - 1; row >= 0; --row) {
|
||||||
|
if (Qt::Checked == ui->tablew_history->item(row, 0)->checkState()) {
|
||||||
|
const QString& project_filename = ui->tablew_history->item(row, 0)->data(Qt::UserRole).toString();
|
||||||
|
QFileInfo project_file_info(project_filename);
|
||||||
|
const QString& project_dir_path = project_file_info.absoluteDir().absolutePath();
|
||||||
|
QDir(project_dir_path).removeRecursively();
|
||||||
|
ui->tablew_history->removeRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureAnalysisHistoryForm::onTableCellDoubleClicked(int row, int column)
|
||||||
|
{
|
||||||
|
Q_UNUSED(column);
|
||||||
|
QTableWidgetItem* item = ui->tablew_history->item(row, 0);
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString& project_name = item->text();
|
||||||
|
MeasureAnalysisProjectModel* model = ProjectList::Instance()->GetProjectModel(project_name);
|
||||||
|
if (model) {
|
||||||
|
QMessageBox::information(this, QStringLiteral(u"提示"), QStringLiteral(u"测量分析项目\"%1\"已经打开.").arg(project_name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (QMessageBox::No == QMessageBox::question(this, QStringLiteral(u"确认"), QStringLiteral(u"是否打开测量分析项目\"%1\"").arg(project_name))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString& project_filename = item->data(Qt::UserRole).toString();
|
||||||
|
if (!project_filename.isEmpty()) {
|
||||||
|
QFileInfo project_file_info(project_filename);
|
||||||
|
if (project_file_info.exists()) {
|
||||||
|
if (project_file_info.size() == 0) {
|
||||||
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"测量分析项目文件异常,打开失败,此记录将被清除!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel;
|
||||||
|
if (model->LoadProjectModel(project_filename)) {
|
||||||
|
bool loaded = ProjectList::Instance()->AddProjectModel(model);
|
||||||
|
if (loaded) {
|
||||||
|
item->setCheckState(Qt::Unchecked);
|
||||||
|
item->setFlags(item->flags() & ~Qt::ItemIsUserCheckable);
|
||||||
|
} else {
|
||||||
|
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit openProject(project_filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,15 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void loadHistoryInfo();
|
void loadHistoryInfo();
|
||||||
void queryHistory();
|
private slots:
|
||||||
|
void onQueryHistory();
|
||||||
|
void onAllSelect();
|
||||||
|
void onReverseSelect();
|
||||||
|
void onRemoveSelectedProject();
|
||||||
|
void onTableCellDoubleClicked(int row, int column);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void openProject(const QString& project_filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MeasureAnalysisHistoryForm *ui;
|
Ui::MeasureAnalysisHistoryForm *ui;
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,27 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_select_all">
|
||||||
|
<property name="text">
|
||||||
|
<string>全选</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_reverse">
|
||||||
|
<property name="text">
|
||||||
|
<string>反选</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_remove">
|
||||||
|
<property name="text">
|
||||||
|
<string>删除</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
@ -84,7 +105,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::SingleSelection</enum>
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user