|
|
|
|
@ -1,136 +1,148 @@
|
|
|
|
|
#include "nmWxChangeAnal.h"
|
|
|
|
|
|
|
|
|
|
#include "iSubWndFitting.h"
|
|
|
|
|
#include "nmDataAnalyzeManager.h"
|
|
|
|
|
#include "nmSubWxsAnalyzeContext.h"
|
|
|
|
|
#include "nmSubWxsAnalyzeContextProvider.h"
|
|
|
|
|
|
|
|
|
|
// 构造函数实现
|
|
|
|
|
nmWxChangeAnal::nmWxChangeAnal(QWidget *parent, ZxMainWindow* pMainWindow)
|
|
|
|
|
: iDlgBase(parent) // 初始化基类
|
|
|
|
|
, m_pMainWindow(pMainWindow) // 初始化主窗口指针
|
|
|
|
|
, m_pAnalysisLabel(nullptr) // 初始化标签指针
|
|
|
|
|
, m_pAnalysisComboBox(nullptr) // 初始化下拉框指针
|
|
|
|
|
, m_pConfirmButton(nullptr) // 初始化确认按钮指针
|
|
|
|
|
, m_pCancelButton(nullptr) // 初始化取消按钮指针
|
|
|
|
|
#include "ZxBaseUtil.h"
|
|
|
|
|
#include "ZxMainWindow.h"
|
|
|
|
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QVariant>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
nmWxChangeAnal::nmWxChangeAnal(QWidget* parent, ZxMainWindow* pMainWindow)
|
|
|
|
|
: iDlgBase(parent),
|
|
|
|
|
m_pMainWindow(pMainWindow),
|
|
|
|
|
m_pAnalysisComboBox(nullptr)
|
|
|
|
|
{
|
|
|
|
|
// 设置对话框标题
|
|
|
|
|
this->setWindowTitle(tr("Switch analysis"));
|
|
|
|
|
|
|
|
|
|
// 设置窗口大小
|
|
|
|
|
this->setFixedSize(400, 200);
|
|
|
|
|
|
|
|
|
|
// 初始化UI界面
|
|
|
|
|
this->setupUI();
|
|
|
|
|
|
|
|
|
|
// 连接信号槽:
|
|
|
|
|
// 当下拉框选项改变时,触发analysisChanged信号
|
|
|
|
|
connect(m_pAnalysisComboBox, SIGNAL(currentTextChanged(QString)),
|
|
|
|
|
this, SIGNAL(analysisChanged(QString)));
|
|
|
|
|
setWindowTitle(tr("Switch analysis"));
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
|
|
// 连接按钮点击信号到对应的槽函数
|
|
|
|
|
connect(m_pConfirmButton, SIGNAL(clicked()), this, SLOT(onConfirmButtonClicked()));
|
|
|
|
|
connect(m_pCancelButton, SIGNAL(clicked()), this, SLOT(onCancelButtonClicked()));
|
|
|
|
|
// 布局创建与列表填充分开,初始大小由字体、主题和最终内容共同决定。
|
|
|
|
|
setupUI();
|
|
|
|
|
fillAnalysisList();
|
|
|
|
|
adjustSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化UI界面
|
|
|
|
|
void nmWxChangeAnal::setupUI()
|
|
|
|
|
{
|
|
|
|
|
// 1. 创建UI控件
|
|
|
|
|
m_pAnalysisLabel = new QLabel(tr("Analysis"), this); // 创建分析标签
|
|
|
|
|
m_pAnalysisComboBox = new QComboBox(this); // 创建下拉选择框
|
|
|
|
|
|
|
|
|
|
// 遍历主窗口下的所有的流动段分析名称
|
|
|
|
|
ZxMainWindow* pMainWnd1 = const_cast<ZxMainWindow*>(m_pMainWindow);
|
|
|
|
|
if (nullptr != pMainWnd1)
|
|
|
|
|
{
|
|
|
|
|
ZxTabWidget* pTabWx = pMainWnd1->getCurTabWx();
|
|
|
|
|
QVector<iSubWnd*> vecSubWnds = pMainWnd1->getAllSubWndsOf(pTabWx);
|
|
|
|
|
foreach (iSubWnd* pSub, vecSubWnds)
|
|
|
|
|
{
|
|
|
|
|
iSubWndFitting* pSubWndF = dynamic_cast<iSubWndFitting*>(pSub);
|
|
|
|
|
// 分析窗口存在,并且有对应的数据中心已经初始化了边界、井等相关信息
|
|
|
|
|
if (nullptr != pSubWndF && nmDataAnalyzeManager::findManagerByFitting(pSubWndF) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
// 添加项并绑定指针
|
|
|
|
|
int index = m_pAnalysisComboBox->count();
|
|
|
|
|
m_pAnalysisComboBox->addItem(pSubWndF->windowTitle());
|
|
|
|
|
m_pAnalysisComboBox->setItemData(index, QVariant::fromValue<void*>(pSubWndF));
|
|
|
|
|
|
|
|
|
|
// 如果是当前分析项,设为选中
|
|
|
|
|
if (pSubWndF == nmDataAnalyzeManager::getCurrentFitting())
|
|
|
|
|
{
|
|
|
|
|
m_pAnalysisComboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_pConfirmButton = new QPushButton(tr("OK"), this);
|
|
|
|
|
m_pCancelButton = new QPushButton(tr("Cancel"), this);
|
|
|
|
|
|
|
|
|
|
// 2. 布局设置 - 修改后的布局
|
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
// 中心部件布局 - 使用网格布局实现居中效果
|
|
|
|
|
QGridLayout *centerLayout = new QGridLayout();
|
|
|
|
|
centerLayout->setColumnStretch(0, 1); // 第一列伸缩
|
|
|
|
|
centerLayout->addWidget(m_pAnalysisLabel, 0, 1, Qt::AlignRight); // 标签右对齐
|
|
|
|
|
centerLayout->addWidget(m_pAnalysisComboBox, 0, 2); // 下拉框
|
|
|
|
|
centerLayout->setColumnStretch(3, 1); // 最后一列伸缩
|
|
|
|
|
|
|
|
|
|
// 设置下拉框的最小宽度
|
|
|
|
|
m_pAnalysisComboBox->setMinimumWidth(200);
|
|
|
|
|
|
|
|
|
|
// 按钮布局
|
|
|
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
|
|
|
buttonLayout->addStretch(); // 左侧伸缩
|
|
|
|
|
buttonLayout->addWidget(m_pConfirmButton);
|
|
|
|
|
buttonLayout->addWidget(m_pCancelButton);
|
|
|
|
|
|
|
|
|
|
// 将布局添加到主布局
|
|
|
|
|
mainLayout->addStretch(1); // 顶部伸缩
|
|
|
|
|
mainLayout->addLayout(centerLayout);
|
|
|
|
|
mainLayout->addStretch(1); // 中间伸缩
|
|
|
|
|
mainLayout->addLayout(buttonLayout);
|
|
|
|
|
QVBoxLayout* pMainLayout = new QVBoxLayout(this);
|
|
|
|
|
pMainLayout->setContentsMargins(12, 10, 12, 0);
|
|
|
|
|
pMainLayout->setSpacing(10);
|
|
|
|
|
|
|
|
|
|
// 表单随窗口横向伸展,控件高度使用字体和主题推荐值。
|
|
|
|
|
QWidget* pForm = new QWidget(this);
|
|
|
|
|
pForm->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
QHBoxLayout* pFormLayout = new QHBoxLayout(pForm);
|
|
|
|
|
pFormLayout->setContentsMargins(0, 5, 0, 5);
|
|
|
|
|
pFormLayout->setSpacing(6);
|
|
|
|
|
QLabel* pAnalysisLabel = new QLabel(tr("Analysis"), pForm);
|
|
|
|
|
pAnalysisLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
pAnalysisLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
|
m_pAnalysisComboBox = new QComboBox(pForm);
|
|
|
|
|
// 用字符数确定推荐宽度,避免固定像素宽度在不同字体和缩放下过窄。
|
|
|
|
|
m_pAnalysisComboBox->setMinimumContentsLength(24);
|
|
|
|
|
m_pAnalysisComboBox->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
|
|
|
|
|
m_pAnalysisComboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
|
pFormLayout->addWidget(pAnalysisLabel);
|
|
|
|
|
pFormLayout->addWidget(m_pAnalysisComboBox, 1);
|
|
|
|
|
pMainLayout->addWidget(pForm);
|
|
|
|
|
// 纵向余量由表单与按钮区之间的空白吸收,不拉高下拉框。
|
|
|
|
|
pMainLayout->addStretch(1);
|
|
|
|
|
|
|
|
|
|
// 标签和按钮仅在此处使用,由 Qt 父子关系管理,不保留为成员变量。
|
|
|
|
|
QWidget* pFooter = new QWidget(this);
|
|
|
|
|
pFooter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
|
|
|
QHBoxLayout* pFooterLayout = new QHBoxLayout(pFooter);
|
|
|
|
|
pFooterLayout->setContentsMargins(4, 5, 4, 5);
|
|
|
|
|
pFooterLayout->setSpacing(8);
|
|
|
|
|
pFooterLayout->addStretch();
|
|
|
|
|
QDialogButtonBox* pButtons = new QDialogButtonBox(
|
|
|
|
|
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, pFooter);
|
|
|
|
|
QPushButton* pConfirmButton = pButtons->button(QDialogButtonBox::Ok);
|
|
|
|
|
pConfirmButton->setText(tr("OK"));
|
|
|
|
|
pConfirmButton->setIcon(zxLoadIcon("OK"));
|
|
|
|
|
QPushButton* pCancelButton = pButtons->button(QDialogButtonBox::Cancel);
|
|
|
|
|
pCancelButton->setText(tr("Cancel"));
|
|
|
|
|
pCancelButton->setIcon(zxLoadIcon("Cancel"));
|
|
|
|
|
pFooterLayout->addWidget(pButtons);
|
|
|
|
|
pMainLayout->addWidget(pFooter);
|
|
|
|
|
|
|
|
|
|
// 仅按钮触发原有确认、取消流程,下拉框改选不执行切换。
|
|
|
|
|
connect(pConfirmButton, SIGNAL(clicked()), this, SLOT(onConfirmButtonClicked()));
|
|
|
|
|
connect(pCancelButton, SIGNAL(clicked()), this, SLOT(onCancelButtonClicked()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
|
|
void nmWxChangeAnal::fillAnalysisList()
|
|
|
|
|
{
|
|
|
|
|
// 沿用原候选范围:列出当前成果中已初始化数值数据的分析。
|
|
|
|
|
ZxMainWindow* pMainWnd1 = m_pMainWindow;
|
|
|
|
|
if (nullptr != pMainWnd1)
|
|
|
|
|
{
|
|
|
|
|
ZxTabWidget* pTabWx = pMainWnd1->getCurTabWx();
|
|
|
|
|
QVector<iSubWnd*> vecSubWnds = pMainWnd1->getAllSubWndsOf(pTabWx);
|
|
|
|
|
foreach (iSubWnd* pSub, vecSubWnds)
|
|
|
|
|
{
|
|
|
|
|
iSubWndFitting* pSubWndF = dynamic_cast<iSubWndFitting*>(pSub);
|
|
|
|
|
// 分析窗口存在,并且有对应的数据中心已经初始化了边界、井等相关信息
|
|
|
|
|
if (nullptr != pSubWndF && nmDataAnalyzeManager::findManagerByFitting(pSubWndF) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
// 添加项并绑定指针
|
|
|
|
|
int index = m_pAnalysisComboBox->count();
|
|
|
|
|
m_pAnalysisComboBox->addItem(pSubWndF->windowTitle());
|
|
|
|
|
m_pAnalysisComboBox->setItemData(index, QVariant::fromValue<void*>(pSubWndF));
|
|
|
|
|
|
|
|
|
|
// 如果是当前分析项,设为选中
|
|
|
|
|
if (pSubWndF == nmDataAnalyzeManager::getCurrentFitting())
|
|
|
|
|
{
|
|
|
|
|
m_pAnalysisComboBox->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 确认按钮点击处理
|
|
|
|
|
void nmWxChangeAnal::onConfirmButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
// 获取当前选中项的索引
|
|
|
|
|
int index = m_pAnalysisComboBox->currentIndex();
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
{
|
|
|
|
|
// 通过索引获取关联的指针
|
|
|
|
|
QVariant data = m_pAnalysisComboBox->itemData(index);
|
|
|
|
|
if (data.isValid() && data.canConvert<void*>())
|
|
|
|
|
{
|
|
|
|
|
iSubWndFitting* pCurSubWndF = static_cast<iSubWndFitting*>(data.value<void*>());
|
|
|
|
|
|
|
|
|
|
// 切换了分析,则处理
|
|
|
|
|
if (pCurSubWndF != nmDataAnalyzeManager::getCurrentFitting())
|
|
|
|
|
{
|
|
|
|
|
// 创建/获取数据中心类
|
|
|
|
|
nmDataAnalyzeManager::getInstanceByFitting(pCurSubWndF);
|
|
|
|
|
// 设置当前操作的分析
|
|
|
|
|
nmDataAnalyzeManager::setCurrentFitting(pCurSubWndF);
|
|
|
|
|
|
|
|
|
|
//// 遍历主窗口下的所有的流动段分析名称
|
|
|
|
|
ZxMainWindow* pMainWnd1 = const_cast<ZxMainWindow*>(m_pMainWindow);
|
|
|
|
|
nmSubWxsAnalyzeContextProvider* pProvider = nmSubWxsAnalyzeContext::provider();
|
|
|
|
|
if (nullptr != pProvider) {
|
|
|
|
|
pProvider->updateWindowsForCurrentAnalyze(pMainWnd1, pCurSubWndF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->accept(); // 接受对话框
|
|
|
|
|
// 获取当前选中项的索引
|
|
|
|
|
int index = m_pAnalysisComboBox->currentIndex();
|
|
|
|
|
if (index >= 0)
|
|
|
|
|
{
|
|
|
|
|
// 通过索引获取关联的指针
|
|
|
|
|
QVariant data = m_pAnalysisComboBox->itemData(index);
|
|
|
|
|
if (data.isValid() && data.canConvert<void*>())
|
|
|
|
|
{
|
|
|
|
|
iSubWndFitting* pCurSubWndF = static_cast<iSubWndFitting*>(data.value<void*>());
|
|
|
|
|
|
|
|
|
|
// 切换了分析,则处理
|
|
|
|
|
if (pCurSubWndF != nmDataAnalyzeManager::getCurrentFitting())
|
|
|
|
|
{
|
|
|
|
|
// 创建/获取数据中心类
|
|
|
|
|
nmDataAnalyzeManager::getInstanceByFitting(pCurSubWndF);
|
|
|
|
|
// 设置当前操作的分析
|
|
|
|
|
nmDataAnalyzeManager::setCurrentFitting(pCurSubWndF);
|
|
|
|
|
|
|
|
|
|
//// 遍历主窗口下的所有的流动段分析名称
|
|
|
|
|
ZxMainWindow* pMainWnd1 = const_cast<ZxMainWindow*>(m_pMainWindow);
|
|
|
|
|
nmSubWxsAnalyzeContextProvider* pProvider = nmSubWxsAnalyzeContext::provider();
|
|
|
|
|
if (nullptr != pProvider) {
|
|
|
|
|
pProvider->updateWindowsForCurrentAnalyze(pMainWnd1, pCurSubWndF);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->accept(); // 接受对话框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取消按钮点击处理
|
|
|
|
|
void nmWxChangeAnal::onCancelButtonClicked()
|
|
|
|
|
{
|
|
|
|
|
this->reject(); // 拒绝对话框
|
|
|
|
|
this->reject(); // 拒绝对话框
|
|
|
|
|
}
|
|
|
|
|
|