#include "nmGridRowUtils.h" #include "iGridRowGroup.h" #include "iParameter.h" #include "iSysParaHelper.h" // ================================================================ // 构造与析构 // ================================================================ nmGridRowUtils::nmGridRowUtils(bool bSimple, QWidget* parent) : iGridRowUtils(bSimple, parent) { } nmGridRowUtils::~nmGridRowUtils() { } // ================================================================ // 初始化与构建 // ================================================================ void nmGridRowUtils::initUI() { // 当前直接转发至基类,后续可在此添加NM模块特有的初始化逻辑 iGridRowUtils::initUI(); } void nmGridRowUtils::setWellNames(QMap map) { m_mapWellNames = map; } bool nmGridRowUtils::buildRowUtils(QStringList listParas, bool bDnMode, QWidget* pWxDlg) { // 分离储层参数和井参数 QStringList listRes; QMap mapWellParas; splitWellParas(listParas, listRes, mapWellParas); // 构建储层参数(基类处理) if (!iGridRowUtils::buildRowUtils(listRes, bDnMode, pWxDlg)) { return false; } // 构建井分组 if (!mapWellParas.isEmpty()) { buildWellGroups(mapWellParas, bDnMode); // 井分组追加完成后,重新备份、绑定、计算布局 bkAllItems(); bindItems(); double h = getUtilHeight(); QRectF rt = QRectF(0, 0, 300, h); setBounds(rt); setMinimumHeight(h); } return true; } // ================================================================ // 参数读写 // ================================================================ bool nmGridRowUtils::setParaValue(QString sPara, QVariant o) { return iGridRowUtils::setParaValue(sPara, o); } bool nmGridRowUtils::getParaValue(QString sPara, QVariant& o) { return iGridRowUtils::getParaValue(sPara, o); } bool nmGridRowUtils::getAllParaValues(QMap& map, bool bOnlyFitted, bool bClearMap) { return iGridRowUtils::getAllParaValues(map, bOnlyFitted, bClearMap); } bool nmGridRowUtils::getAllParaUnits(QMap& map, bool bOnlyFitted, bool bClearMap) { return iGridRowUtils::getAllParaUnits(map, bOnlyFitted, bClearMap); } // ================================================================ // 参数项查找 // ================================================================ iGridRowItem* nmGridRowUtils::getItemByPara(QString sPara) { return iGridRowUtils::getItemByPara(sPara); } QVariant nmGridRowUtils::getItemValueByPara(QString sPara) { return iGridRowUtils::getItemValueByPara(sPara); } // ================================================================ // 参数来源标识 // ================================================================ void nmGridRowUtils::setParaSrcTag(QString s) { // 基类已有实现,直接转发 iGridRowUtils::setParaSrcTag(s); } // ================================================================ // 序列化 // ================================================================ void nmGridRowUtils::onSerialize(ZxSerializer* ser) { iGridRowUtils::onSerialize(ser); } void nmGridRowUtils::onDeserialize(ZxSerializer* ser) { iGridRowUtils::onDeserialize(ser); } // ================================================================ // 结果组织 // ================================================================ bool nmGridRowUtils::organizeResults(QVector& vec, QString sType, bool bMultiPhase) { return iGridRowUtils::organizeResults(vec, sType, bMultiPhase); } // ================================================================ // 内部构建(protected) // ================================================================ bool nmGridRowUtils::_buildRowUtils(QStringList listParas, iGridRowItem* pItemParent, bool bDnMode, bool bProperOrder) { return iGridRowUtils::_buildRowUtils(listParas, pItemParent, bDnMode, bProperOrder); } bool nmGridRowUtils::createAndAddItem(iGridRowItem* pParent, iParameter* p, QString sPara) { // 检查父级是否为井分组,若是则设置 nameInner(含井前缀) QString sNameInner; if (nullptr != pParent) { QString sTagLayer = pParent->getTagLayer(); if (!sTagLayer.isEmpty() && nullptr != p) { sNameInner = sTagLayer + p->m_sName; } } int nOldCount = (nullptr != pParent ? pParent->getChildCount() : 0); if (!iGridRowUtils::createAndAddItem(pParent, p, sPara)) { return false; } // 设置 nameInner if (!sNameInner.isEmpty() && nullptr != pParent) { if (pParent->getChildCount() == nOldCount + 1) { iGridRowItem* pItem = pParent->getChildAt(nOldCount); if (nullptr != pItem) { pItem->setNameInner(sNameInner); } } } return true; } void nmGridRowUtils::connectSignalsOf(iGridRowItem* p) { iGridRowUtils::connectSignalsOf(p); // 连接 sigValueChanged,值改变立即同步到数据层 connect(p, SIGNAL(sigValueChanged(QString, QVariant)), this, SLOT(slotItemValueChanged(QString, QVariant))); } void nmGridRowUtils::bindItems() { iGridRowUtils::bindItems(); } // ================================================================ // 多井分组实现 // ================================================================ void nmGridRowUtils::splitWellParas(QStringList listParas, QStringList& listRes, QMap& mapWellParas) { listRes.clear(); mapWellParas.clear(); foreach (QString sPara, listParas) { // 检查是否匹配 "WN_" 格式(N为井永久ID) if (sPara.length() >= 2 && sPara.at(0).toUpper() == 'W' && sPara.at(1).isDigit()) { // 提取井ID int i = 1; while (i < sPara.length() && sPara.at(i).isDigit()) { i++; } if (i < sPara.length() && sPara.at(i) == '_') { int nWellId = sPara.mid(1, i - 1).toInt(); QString sBaseName = sPara.mid(i + 1); // 剥掉 "WN_" 前缀 mapWellParas[nWellId] << sBaseName; continue; } } // 非井参数,归入储层 listRes << sPara; } } void nmGridRowUtils::buildWellGroups(QMap& mapWellParas, bool bDnMode) { bool bProperOrder = true; // 按井ID排序遍历 QList listIds = mapWellParas.keys(); qSort(listIds); foreach (int nWellId, listIds) { QStringList listParas = mapWellParas[nWellId]; if (listParas.isEmpty()) { continue; } // 井前缀,如 "W0_" QString sPrefix = QString("W%1_").arg(nWellId); // 显示名称 QString sWellName = tr("Well #%1").arg(nWellId); if (m_mapWellNames.contains(nWellId)) { sWellName = m_mapWellNames[nWellId]; } // 创建井分组(纯标题,不需要编辑器) iGridRowGroup* pGroup = new iGridRowGroup(nullptr); Q_ASSERT(nullptr != pGroup); pGroup->setParaSrcTag(m_sParaSrcTag); pGroup->setTagInner(sWellName); // Group 标题 pGroup->setTagLayer(sPrefix); // 井前缀标识 connectSignalsOf(pGroup); pGroup->setDlgBase(this); m_vecGridItems.append(pGroup); // 在该分组下构建参数项 _buildRowUtils(listParas, pGroup, bDnMode, bProperOrder); } } // ================================================================ // 槽函数 // ================================================================ void nmGridRowUtils::slotItemValueChanged(QString sPara, QVariant o) { emit sigParaChanged(sPara, o); } void nmGridRowUtils::slotGetValueOf(QString sPara, QVariant& o, bool& bOk) { iGridRowUtils::slotGetValueOf(sPara, o, bOk); }