You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Src/nmNum/nmGUI/nmGridRowUtils.cpp

353 lines
9.5 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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<QString, QString> map)
{
m_mapWellNames = map;
}
bool nmGridRowUtils::buildRowUtils(QStringList listParas,
bool bDnMode,
QWidget* pWxDlg)
{
// 分离储层参数和井参数
QStringList listRes;
QMap<QString, QStringList> 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);
}
QString nmGridRowUtils::stripWellPrefix(QString sPara) const
{
QList<QString> 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<QString, QVariant>& map,
bool bOnlyFitted,
bool bClearMap)
{
return iGridRowUtils::getAllParaValues(map, bOnlyFitted, bClearMap);
}
bool nmGridRowUtils::getAllParaUnits(QMap<QString, QString>& 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<iResultInfo>& 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<QString, QStringList>& mapWellParas)
{
listRes.clear();
mapWellParas.clear();
QList<QString> 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<QString, QStringList>& mapWellParas,
bool bDnMode)
{
bool bProperOrder = true;
// 按wellCode排序遍历
QList<QString> 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) &&
!m_mapWellNames.value(sCode).isEmpty())
{
sWellName = m_mapWellNames[sCode];
}
// 参考多对象 UI 的 Layer 分组:用父节点的 tagLayer 标记对象作用域。
nmWellGridRowGroup* pGroup = new nmWellGridRowGroup(nullptr);
Q_ASSERT(nullptr != 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();
m_vecGridItems.append(pGroup);
// 在该分组下构建参数项
_buildRowUtils(listParas, pGroup, bDnMode, bProperOrder);
}
}
void nmGridRowUtils::slotGetValueOf(QString sPara, QVariant& o, bool& bOk)
{
iGridRowUtils::slotGetValueOf(sPara, o, bOk);
}