|
|
|
|
@ -25,10 +25,14 @@
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QPointer>
|
|
|
|
|
#include "iGuiPlot.h"
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxObjCurve.h"
|
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
#include <QAbstractScrollArea>
|
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QWheelEvent>
|
|
|
|
|
@ -175,19 +179,30 @@ bool validSamplingValue(const QString& name, double& value)
|
|
|
|
|
class SensitivityResultsModel : public QAbstractTableModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit SensitivityResultsModel(QObject* parent) : QAbstractTableModel(parent) {}
|
|
|
|
|
SensitivityResultsModel(const QSharedPointer<nmDataSensitive::BatchResult>& results,
|
|
|
|
|
iGuiPlot* plot, QObject* parent)
|
|
|
|
|
: QAbstractTableModel(parent), m_results(results), m_plot(plot) {}
|
|
|
|
|
|
|
|
|
|
void setResults(const QSharedPointer<nmDataSensitive::BatchResult>& results)
|
|
|
|
|
QList<ZxObjCurve*> runCurves(int row) const
|
|
|
|
|
{
|
|
|
|
|
// 同一批次同步已应用的选择,并保留本窗口尚未应用的勾选。
|
|
|
|
|
if(m_results == results) {
|
|
|
|
|
if(rowCount() > 0) emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_results = results;
|
|
|
|
|
m_pendingVisibility.clear();
|
|
|
|
|
endResetModel();
|
|
|
|
|
// 双对数图的一组包含压力与导数,历史压力图只包含压力。
|
|
|
|
|
QList<ZxObjCurve*> curves;
|
|
|
|
|
if(m_plot.isNull()) return curves;
|
|
|
|
|
const quint64 number = m_results->m_runs[row].m_nRunIndex + 1;
|
|
|
|
|
ZxObjCurve* pressure = m_plot->getCurve(nmWxSensitive::tr("Run %1 - Pressure").arg(number));
|
|
|
|
|
ZxObjCurve* derivative = m_plot->getCurve(nmWxSensitive::tr("Run %1 - Derivative").arg(number));
|
|
|
|
|
if(pressure) curves.append(pressure);
|
|
|
|
|
if(derivative) curves.append(derivative);
|
|
|
|
|
return curves;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isRunVisible(int row) const
|
|
|
|
|
{
|
|
|
|
|
// 从所属图读取已应用状态,两个 Show 表格互不共享勾选结果。
|
|
|
|
|
const QList<ZxObjCurve*> curves = runCurves(row);
|
|
|
|
|
for(int i = 0; i < curves.size(); ++i)
|
|
|
|
|
if(curves[i]->isVisible()) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override
|
|
|
|
|
@ -217,7 +232,7 @@ public:
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(role == Qt::CheckStateRole && index.column() == 0)
|
|
|
|
|
return run.m_bSucceeded && !run.m_bCancelled &&
|
|
|
|
|
m_pendingVisibility.value(index.row(), run.m_bVisible) ? Qt::Checked : Qt::Unchecked;
|
|
|
|
|
m_pendingVisibility.value(index.row(), isRunVisible(index.row())) ? Qt::Checked : Qt::Unchecked;
|
|
|
|
|
if(role == Qt::TextAlignmentRole && index.column() == 1)
|
|
|
|
|
return int(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
if(role == Qt::ToolTipRole && !run.m_sFailureReason.isEmpty()) return run.m_sFailureReason;
|
|
|
|
|
@ -243,19 +258,19 @@ public:
|
|
|
|
|
if(!index.isValid()) return Qt::NoItemFlags;
|
|
|
|
|
Qt::ItemFlags result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(index.column() == 0 && run.m_bSucceeded && !run.m_bCancelled)
|
|
|
|
|
if(index.column() == 0 && run.m_bSucceeded && !run.m_bCancelled && !runCurves(index.row()).isEmpty())
|
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role) override
|
|
|
|
|
{
|
|
|
|
|
// 勾选只记在本窗口,点击 Apply 或 OK 后才写入绘图使用的结果。
|
|
|
|
|
// 勾选只记在本窗口,点击 Apply 或 OK 后才改变所属图的显示。
|
|
|
|
|
if(!index.isValid() || index.column() != 0 || role != Qt::CheckStateRole) return false;
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled) return false;
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled || runCurves(index.row()).isEmpty()) return false;
|
|
|
|
|
const bool visible = value.toInt() == Qt::Checked;
|
|
|
|
|
if(visible == run.m_bVisible) m_pendingVisibility.remove(index.row());
|
|
|
|
|
if(visible == isRunVisible(index.row())) m_pendingVisibility.remove(index.row());
|
|
|
|
|
else m_pendingVisibility.insert(index.row(), visible);
|
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
return true;
|
|
|
|
|
@ -267,34 +282,105 @@ public:
|
|
|
|
|
if(m_results.isNull() || m_results->m_runs.empty()) return;
|
|
|
|
|
for(int i = 0; i < rowCount(); ++i) {
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[i];
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled) continue;
|
|
|
|
|
if(visible == run.m_bVisible) m_pendingVisibility.remove(i);
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled || runCurves(i).isEmpty()) continue;
|
|
|
|
|
if(visible == isRunVisible(i)) m_pendingVisibility.remove(i);
|
|
|
|
|
else m_pendingVisibility.insert(i, visible);
|
|
|
|
|
}
|
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool applyVisibility()
|
|
|
|
|
void applyVisibility()
|
|
|
|
|
{
|
|
|
|
|
// 只提交本窗口改过的组,其他结果列表已应用的选择保持不变。
|
|
|
|
|
bool changed = false;
|
|
|
|
|
// Apply 仅更新所属图的采样曲线,保留实测、基准和流量参考线。
|
|
|
|
|
QMap<int, bool>::const_iterator it = m_pendingVisibility.constBegin();
|
|
|
|
|
for(; it != m_pendingVisibility.constEnd(); ++it) {
|
|
|
|
|
nmDataSensitive::RunResult& run = m_results->m_runs[it.key()];
|
|
|
|
|
if(run.m_bVisible != it.value()) {
|
|
|
|
|
run.m_bVisible = it.value();
|
|
|
|
|
changed = true;
|
|
|
|
|
}
|
|
|
|
|
const QList<ZxObjCurve*> curves = runCurves(it.key());
|
|
|
|
|
for(int i = 0; i < curves.size(); ++i) curves[i]->setVisible(it.value());
|
|
|
|
|
}
|
|
|
|
|
m_pendingVisibility.clear();
|
|
|
|
|
return changed;
|
|
|
|
|
if(!m_plot.isNull()) {
|
|
|
|
|
m_plot->clearUndoStack();
|
|
|
|
|
m_plot->m_pPlot->update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> m_results;
|
|
|
|
|
QMap<int, bool> m_pendingVisibility;
|
|
|
|
|
QPointer<iGuiPlot> m_plot;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nmWxSensitivityShow::nmWxSensitivityShow(
|
|
|
|
|
const QSharedPointer<nmDataSensitive::BatchResult>& results, iGuiPlot* plot, QWidget* parent)
|
|
|
|
|
: iDlgBase(parent)
|
|
|
|
|
{
|
|
|
|
|
// 沿用原 Results 的白色表格及按钮布局,勾选在 Apply 或 OK 后生效。
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
setObjectName("nmSensitivityShowDialog");
|
|
|
|
|
resize(700, 380);
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
|
QTableView* table = new QTableView(this);
|
|
|
|
|
table->setStyleSheet("QTableView { background-color: white; }");
|
|
|
|
|
m_model = new SensitivityResultsModel(results, plot, this);
|
|
|
|
|
table->setModel(m_model);
|
|
|
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
table->setWordWrap(false);
|
|
|
|
|
table->verticalHeader()->setVisible(false);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
|
|
|
|
|
layout->addWidget(table);
|
|
|
|
|
QHBoxLayout* buttons = new QHBoxLayout();
|
|
|
|
|
QPushButton* showAll = new QPushButton(tr("Show all"), this);
|
|
|
|
|
QPushButton* hideAll = new QPushButton(tr("Hide all"), this);
|
|
|
|
|
// 明确按钮顺序,避免系统的标准按钮布局把 Apply 排到最后。
|
|
|
|
|
QPushButton* apply = new QPushButton(tr("Apply"), this);
|
|
|
|
|
QPushButton* ok = new QPushButton(tr("OK"), this);
|
|
|
|
|
QPushButton* cancel = new QPushButton(tr("Cancel"), this);
|
|
|
|
|
apply->setAutoDefault(false);
|
|
|
|
|
cancel->setAutoDefault(false);
|
|
|
|
|
ok->setDefault(true);
|
|
|
|
|
buttons->addWidget(showAll);
|
|
|
|
|
buttons->addWidget(hideAll);
|
|
|
|
|
buttons->addStretch();
|
|
|
|
|
buttons->addWidget(apply);
|
|
|
|
|
buttons->addWidget(ok);
|
|
|
|
|
buttons->addWidget(cancel);
|
|
|
|
|
layout->addLayout(buttons);
|
|
|
|
|
connect(showAll, SIGNAL(clicked()), this, SLOT(onShowAll()));
|
|
|
|
|
connect(hideAll, SIGNAL(clicked()), this, SLOT(onHideAll()));
|
|
|
|
|
connect(apply, SIGNAL(clicked()), this, SLOT(onApply()));
|
|
|
|
|
connect(ok, SIGNAL(clicked()), this, SLOT(onAccept()));
|
|
|
|
|
connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityShow::onApply()
|
|
|
|
|
{
|
|
|
|
|
// 应用选择,保留窗口以便继续调整。
|
|
|
|
|
m_model->applyVisibility();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityShow::onAccept()
|
|
|
|
|
{
|
|
|
|
|
// 确认时提交勾选,取消则直接丢弃未应用的选择。
|
|
|
|
|
onApply();
|
|
|
|
|
accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityShow::onShowAll()
|
|
|
|
|
{
|
|
|
|
|
// 只修改待应用的采样组选择。
|
|
|
|
|
m_model->setAllVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityShow::onHideAll()
|
|
|
|
|
{
|
|
|
|
|
// 参考曲线不属于采样组,保持原来的显示方式。
|
|
|
|
|
m_model->setAllVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SensitivityDistributionPlot : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
@ -1993,107 +2079,21 @@ void nmWxSensitive::onSensitivityFinished()
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onResultsClicked()
|
|
|
|
|
{
|
|
|
|
|
// 绘图窗口仍由主界面创建;本窗口只提供运行列表与显示选择。
|
|
|
|
|
// Results 只打开或恢复结果图,曲线显示由各图自己的 Show 控制。
|
|
|
|
|
onResultsChanged();
|
|
|
|
|
if(!resultsButton->isEnabled()) return;
|
|
|
|
|
emit sigSensitiveResultsRequested();
|
|
|
|
|
if(m_resultsDialog.isNull()) {
|
|
|
|
|
// 与参数窗口共用框架对话框样式,避免普通 QDialog 使用默认灰色背景。
|
|
|
|
|
m_resultsDialog = new iDlgBase(this);
|
|
|
|
|
m_resultsDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
m_resultsDialog->setWindowTitle(tr("Sensitivity Results"));
|
|
|
|
|
m_resultsDialog->resize(700, 380);
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(m_resultsDialog.data());
|
|
|
|
|
QTableView* table = new QTableView(m_resultsDialog.data());
|
|
|
|
|
table->setStyleSheet("QTableView { background-color: white; }");
|
|
|
|
|
m_resultsModel = new SensitivityResultsModel(m_resultsDialog.data());
|
|
|
|
|
m_resultsModel->setResults(m_pDataManager->getSensitiveData()->getResults());
|
|
|
|
|
table->setModel(m_resultsModel.data());
|
|
|
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
table->setWordWrap(false);
|
|
|
|
|
table->verticalHeader()->setVisible(false);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
|
|
|
|
|
layout->addWidget(table);
|
|
|
|
|
QHBoxLayout* buttons = new QHBoxLayout();
|
|
|
|
|
QPushButton* showAll = new QPushButton(tr("Show all"), m_resultsDialog.data());
|
|
|
|
|
QPushButton* hideAll = new QPushButton(tr("Hide all"), m_resultsDialog.data());
|
|
|
|
|
// 明确按钮顺序,避免系统的标准按钮布局把 Apply 排到最后。
|
|
|
|
|
QPushButton* apply = new QPushButton(tr("Apply"), m_resultsDialog.data());
|
|
|
|
|
QPushButton* ok = new QPushButton(tr("OK"), m_resultsDialog.data());
|
|
|
|
|
QPushButton* cancel = new QPushButton(tr("Cancel"), m_resultsDialog.data());
|
|
|
|
|
apply->setAutoDefault(false);
|
|
|
|
|
cancel->setAutoDefault(false);
|
|
|
|
|
ok->setDefault(true);
|
|
|
|
|
buttons->addWidget(showAll);
|
|
|
|
|
buttons->addWidget(hideAll);
|
|
|
|
|
buttons->addStretch();
|
|
|
|
|
buttons->addWidget(apply);
|
|
|
|
|
buttons->addWidget(ok);
|
|
|
|
|
buttons->addWidget(cancel);
|
|
|
|
|
layout->addLayout(buttons);
|
|
|
|
|
connect(showAll, SIGNAL(clicked()), this, SLOT(onShowAllResults()));
|
|
|
|
|
connect(hideAll, SIGNAL(clicked()), this, SLOT(onHideAllResults()));
|
|
|
|
|
connect(apply, SIGNAL(clicked()), this, SLOT(onApplyResults()));
|
|
|
|
|
connect(ok, SIGNAL(clicked()), this, SLOT(onAcceptResults()));
|
|
|
|
|
connect(cancel, SIGNAL(clicked()), m_resultsDialog.data(), SLOT(reject()));
|
|
|
|
|
}
|
|
|
|
|
onResultsChanged();
|
|
|
|
|
hide();
|
|
|
|
|
m_resultsDialog->show();
|
|
|
|
|
m_resultsDialog->raise();
|
|
|
|
|
m_resultsDialog->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onResultsChanged()
|
|
|
|
|
{
|
|
|
|
|
// 新结果替换旧批次时,已经打开的列表也切到同一份结果。
|
|
|
|
|
// 新模型清除旧批次后同步禁用结果入口。
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> results;
|
|
|
|
|
if(m_pDataManager && m_pDataManager->getSensitiveData())
|
|
|
|
|
results = m_pDataManager->getSensitiveData()->getResults();
|
|
|
|
|
resultsButton->setEnabled(!results.isNull());
|
|
|
|
|
m_sensitiveData.setResults(results);
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setResults(results);
|
|
|
|
|
// 新模型清除旧批次后关闭结果列表,不能继续操作上一模型的运行记录。
|
|
|
|
|
if(results.isNull()) {
|
|
|
|
|
if(!m_resultsDialog.isNull()) m_resultsDialog->close();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(!m_resultsDialog.isNull()) {
|
|
|
|
|
const QString status = results.isNull() ? QString() : results->m_bStopped ? tr("Stopped")
|
|
|
|
|
: results->m_bCompleted ? tr("Completed") : tr("Failed");
|
|
|
|
|
m_resultsDialog->setWindowTitle(tr("Sensitivity Results")
|
|
|
|
|
+ (status.isEmpty() ? QString() : " - " + status));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onApplyResults()
|
|
|
|
|
{
|
|
|
|
|
// 应用选择后通知主界面刷新,结果选择窗口保持打开。
|
|
|
|
|
if(m_pDataManager && !m_resultsModel.isNull() && m_resultsModel->applyVisibility())
|
|
|
|
|
m_pDataManager->publishSensitiveResults(m_pDataManager->getSensitiveDataCopy());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onAcceptResults()
|
|
|
|
|
{
|
|
|
|
|
// OK 与 Apply 提交相同的选择,随后关闭窗口。
|
|
|
|
|
onApplyResults();
|
|
|
|
|
if(!m_resultsDialog.isNull()) m_resultsDialog->accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onShowAllResults()
|
|
|
|
|
{
|
|
|
|
|
// 勾选所有成功组,等待 Apply 或 OK 更新曲线。
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setAllVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onHideAllResults()
|
|
|
|
|
{
|
|
|
|
|
// 取消所有采样组的勾选,测量曲线和原模型数值解仍作为参考。
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setAllVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onCalculationTypeChanged(int index)
|
|
|
|
|
|