#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(); } // ================================================================ // 构造与析构 // ================================================================ 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(); // 按长度降序排列wellCode,确保最长匹配优先 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; // 按wellCode排序遍历 QList listCodes = mapWellParas.keys(); qSort(listCodes); foreach (QString sCode, listCodes) { QStringList listParas = mapWellParas[sCode]; if (listParas.isEmpty()) { continue; } // 井前缀,如 "W001_" QString sPrefix = sCode + "_"; // 显示名称 QString sWellName = sCode; if (m_mapWellNames.contains(sCode)) { sWellName = m_mapWellNames[sCode]; } // 创建井分组(纯标题,不需要编辑器) 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); }