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.
nmWATI/Src/nmNum/nmData/nmDataUtils.cpp

103 lines
2.9 KiB
C++

#include "zxLogInstance.h"
#include "ZxDataProject.h"
#include "ZxDataWell.h"
#include "nmDataDemo.h"
#include "nmDataUtils.h"
nmDataUtils::nmDataUtils()
{
}
nmDataUtils::~nmDataUtils()
{
}
bool nmDataUtils::extendChildrenOfProj(ZxDataProject* pDataProj)
{
Q_ASSERT (NULL != pDataProj);
/* 如下代码只是参照,请根据具体需求咨询框架负责人员后进行处理
pDataObj->clearChildren(iDataModelType::sTypePvtInfo);
// load Job PVTs
QString sSql = "Select PvtID, PvtName, JobID from V_PVT_INFO";
sSql += QString(" order by PvtID");
VVecVariant vvec;
QString sLog = "";
if (_load(sSql, vvec, sLog, false, true))
{
for (int i = 0; i < vvec.count(); i++)
{
ZxDataPvtInfo* p = new ZxDataPvtInfo();
Q_ASSERT (NULL != p);
p->setCode(vvec.at(i).at(0).toString());
p->setName(vvec.at(i).at(1).toString());
p->setJobID(vvec.at(i).at(2).toString());
p->createChildren();
appendChild(p);
p->setLoaded(false);
}
}
else if (!sLog.isEmpty())
{
zxLogRunW(QObject::tr("Failed to load PVTInfo with \r\n '%1'").arg(sLog));
return false;
}//*/
return true;
}
bool nmDataUtils::extendChildrenOfWell(ZxDataWell* pDataWell)
{
Q_ASSERT (NULL != pDataWell);
// 此处仅仅以获取样表举例 Alias="n数值样例数据表" Name="N_DATA_DEMO"
QString sWellCode = pDataWell->getCode();
QString sSql = "Select distinct ID from N_DATA_DEMO";
sSql += QString(" where WellCode = '%1'").arg(sWellCode);
sSql += QString(" order by ID");
VVecVariant vvec;
QString sLog = "";
if (pDataWell->loadData(sSql, vvec, sLog, false)) {
for (int i = 0; i < vvec.count(); i++) {
nmDataDemo* p = new nmDataDemo();
Q_ASSERT (NULL != p);
p->setCode(vvec.at(i).at(0).toString());
p->setWellCode(sWellCode);
pDataWell->appendChild(p);
}
} else if (!sLog.isEmpty()) {
zxLogRunW(QObject::tr("Failed to load nmDataDemo with \r\n '%1'").arg(sLog));
return false;
}
return true;
}
bool nmDataUtils::convertVP2Ba(QVector<QPointF> &points, QByteArray& byteArray)
{
// 创建一个 QDataStream用于将数据写入 QByteArray
QDataStream stream(&byteArray, QIODevice::WriteOnly);
// 写入 QVector 的大小
stream << points.size();
// 将 QVector 的每个 QPointF 写入到 QDataStream
for (int i = 0; i < points.size(); i++) {
stream << points[i];
}
return true;
}
bool nmDataUtils::convertBa2VP(QByteArray &byteArray, QVector<QPointF>& points)
{
QDataStream stream(&byteArray, QIODevice::ReadOnly);
int size;
stream >> size;
for (int i = 0; i < size; ++i) {
QPointF point;
stream >> point;
points.append(point);
}
// 现在 points 包含了反序列化的数据
return true;
}