#include "nmGridRowUtils.h" #include "iGridRowGroup.h" #include "iParameter.h" #include "iSysParaHelper.h" // 井编码可能互为前缀,拆分参数时必须优先匹配更长的编码。 static bool longerStringFirst(const QString& a, const QString& b) { return a.length() > b.length(); } namespace { // 参考多对象 UI 中的 tGridRowGroupLayer:对象分组只负责标题和折叠, // 不创建普通参数编辑器,但仍完成基类要求的其余初始化。 class nmWellGridRowGroup : public iGridRowGroup { public: explicit nmWellGridRowGroup(iGridRowItem* pParent = nullptr) : iGridRowGroup(pParent) { } virtual void initEditor() { } virtual void configEditor() { } }; } // ================================================================ // 构造与析构 // ================================================================ 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; } void nmGridRowUtils::setItemsReadonly(bool bReadonly) { foreach (iGridRowItem* pItem, m_vecAllItems) { if (pItem != nullptr) { pItem->setReadonly(bReadonly); } } } bool nmGridRowUtils::buildRowUtils(QStringList listParas, bool bDnMode, QWidget* pWxDlg) { // 分离储层参数和带对象编码前缀的参数。 QStringList listRes; QMap mapWellParas; splitWellParas(listParas, listRes, mapWellParas); // 构建普通参数(基类处理)。结果面板只有对象分组时,空列表不应阻断后续构建。 const bool bBaseBuilt = iGridRowUtils::buildRowUtils(listRes, bDnMode, pWxDlg); if (!listRes.isEmpty() && !bBaseBuilt) { 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); } QString nmGridRowUtils::stripWellPrefix(QString sPara) const { QList listCodes = m_mapWellNames.keys(); qSort(listCodes.begin(), listCodes.end(), longerStringFirst); foreach (const QString& sCode, listCodes) { QString sPrefix = sCode + "_"; if (sPara.startsWith(sPrefix)) { return sPara.mid(sPrefix.length()); } } return QString(); } QString nmGridRowUtils::getUpperLayerTagOf(iGridRowItem* pItem) { iGridRowItem* pCurrent = pItem; while (pCurrent != nullptr) { const QString sTagLayer = pCurrent->getTagLayer(); foreach (const QString& sCode, m_mapWellNames.keys()) { if (sTagLayer == sCode + "_") { return sTagLayer; } } pCurrent = pCurrent->getParent(); } return QString(); } 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) { QString sNameInner; if (pParent != nullptr && p != nullptr) { const QString sTagLayer = getUpperLayerTagOf(pParent); if (!sTagLayer.isEmpty()) { 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); } void nmGridRowUtils::bindItems() { iGridRowUtils::bindItems(); } // ================================================================ // 多对象分组实现(沿用多井接口) // ================================================================ void nmGridRowUtils::splitWellParas(QStringList listParas, QStringList& listRes, QMap& mapWellParas) { listRes.clear(); mapWellParas.clear(); QList listCodes = m_mapWellNames.keys(); qSort(listCodes.begin(), listCodes.end(), longerStringFirst); foreach (QString sPara, listParas) { bool bMatched = false; foreach (QString sCode, listCodes) { QString sPrefix = sCode + "_"; if (sPara.startsWith(sPrefix)) { QString sBaseName = sPara.mid(sPrefix.length()); mapWellParas[sCode] << sBaseName; bMatched = true; break; } } if (!bMatched) { listRes << sPara; } } } void nmGridRowUtils::buildWellGroups(QMap& mapWellParas, bool bDnMode) { bool bProperOrder = true; // 沿用多井分组机制,按对象编码排序遍历。 QList listCodes = mapWellParas.keys(); qSort(listCodes); // 多边形边界先建立外层分组,各顶点作为其子分组。 nmWellGridRowGroup* pPolygonGroup = nullptr; foreach (const QString& sCode, listCodes) { if (sCode.startsWith("BVERT")) { pPolygonGroup = new nmWellGridRowGroup(nullptr); Q_ASSERT(nullptr != pPolygonGroup); pPolygonGroup->setParaSrcTag(m_sParaSrcTag); pPolygonGroup->setTagInner(m_mapWellNames.value("BOUNDARY", tr("PolygonOutline"))); connectSignalsOf(pPolygonGroup); pPolygonGroup->setDlgBase(this); pPolygonGroup->initEditor(); pPolygonGroup->configEditor(); pPolygonGroup->setSplitPos(m_dSplitPos); pPolygonGroup->initOtherEditors(); m_vecGridItems.append(pPolygonGroup); break; } } foreach (QString sCode, listCodes) { QStringList listParas = mapWellParas[sCode]; if (listParas.isEmpty()) { continue; } // 对象编码前缀,如 "W001_"、"FRAC0001_"。 QString sPrefix = sCode + "_"; // 显示名称 QString sWellName = sCode; if (m_mapWellNames.contains(sCode) && !m_mapWellNames.value(sCode).isEmpty()) { sWellName = m_mapWellNames[sCode]; } // 用父节点的 tagLayer 标记对象作用域。 iGridRowItem* pParent = sCode.startsWith("BVERT") ? pPolygonGroup : nullptr; nmWellGridRowGroup* pGroup = new nmWellGridRowGroup(pParent); Q_ASSERT(nullptr != pGroup); if (pParent != nullptr) { pParent->appendChild(pGroup); } pGroup->setParaSrcTag(m_sParaSrcTag); pGroup->setTagInner(sWellName); // Group 标题 pGroup->setTagLayer(sPrefix); // 对象编码前缀 connectSignalsOf(pGroup); pGroup->setDlgBase(this); pGroup->initEditor(); pGroup->configEditor(); pGroup->setSplitPos(m_dSplitPos); pGroup->initOtherEditors(); if (pParent == nullptr) { m_vecGridItems.append(pGroup); } // 多边形顶点直接显示 X/Y,避免每个 Point 下重复一层参数组。 if (pParent != nullptr) { foreach (const QString& sPara, listParas) { iParameter* p = _paraHelper->getPara(sPara, m_sParaSrcTag); if (p != nullptr) { createAndAddItem(pGroup, p, sPara); } } } else { // 在该分组下构建参数项 _buildRowUtils(listParas, pGroup, bDnMode, bProperOrder); } } } void nmGridRowUtils::slotGetValueOf(QString sPara, QVariant& o, bool& bOk) { iGridRowUtils::slotGetValueOf(sPara, o, bOk); }