|
|
#include "nmWxChangeAnal.h"
|
|
|
#include "iSubWndFitting.h"
|
|
|
#include "nmDataAnalyzeManager.h"
|
|
|
#include "nmSubWxsAnalyzeContext.h"
|
|
|
#include "nmSubWxsAnalyzeContextProvider.h"
|
|
|
|
|
|
// 构造函数实现
|
|
|
nmWxChangeAnal::nmWxChangeAnal(QWidget *parent, ZxMainWindow* pMainWindow)
|
|
|
: QDialog(parent) // 初始化基类
|
|
|
, m_pMainWindow(pMainWindow) // 初始化主窗口指针
|
|
|
, m_pAnalysisLabel(nullptr) // 初始化标签指针
|
|
|
, m_pAnalysisComboBox(nullptr) // 初始化下拉框指针
|
|
|
, m_pConfirmButton(nullptr) // 初始化确认按钮指针
|
|
|
, m_pCancelButton(nullptr) // 初始化取消按钮指针
|
|
|
{
|
|
|
// 设置对话框标题
|
|
|
this->setWindowTitle(tr("AnalChange"));
|
|
|
|
|
|
// 设置窗口大小
|
|
|
this->setFixedSize(400, 200);
|
|
|
|
|
|
// 初始化UI界面
|
|
|
this->setupUI();
|
|
|
|
|
|
// 连接信号槽:
|
|
|
// 当下拉框选项改变时,触发analysisChanged信号
|
|
|
connect(m_pAnalysisComboBox, SIGNAL(currentTextChanged(QString)),
|
|
|
this, SIGNAL(analysisChanged(QString)));
|
|
|
|
|
|
// 连接按钮点击信号到对应的槽函数
|
|
|
connect(m_pConfirmButton, SIGNAL(clicked()), this, SLOT(onConfirmButtonClicked()));
|
|
|
connect(m_pCancelButton, SIGNAL(clicked()), this, SLOT(onCancelButtonClicked()));
|
|
|
}
|
|
|
|
|
|
// 初始化UI界面
|
|
|
void nmWxChangeAnal::setupUI()
|
|
|
{
|
|
|
// 1. 创建UI控件
|
|
|
m_pAnalysisLabel = new QLabel("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);
|
|
|
|
|
|
setLayout(mainLayout);
|
|
|
}
|
|
|
|
|
|
// 确认按钮点击处理
|
|
|
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(); // 接受对话框
|
|
|
}
|
|
|
|
|
|
// 取消按钮点击处理
|
|
|
void nmWxChangeAnal::onCancelButtonClicked()
|
|
|
{
|
|
|
this->reject(); // 拒绝对话框
|
|
|
}
|