226 lines
5.2 KiB
C
226 lines
5.2 KiB
C
|
//解析各模块计算数据 到内存中
|
||
|
|
||
|
#ifndef DATABLOCK_H
|
||
|
#define DATABLOCK_H
|
||
|
#include "DataManagerGlobal.h"
|
||
|
#include <QString>
|
||
|
#include <QMap>
|
||
|
#include "pugixml.hpp"
|
||
|
#include <QObject>
|
||
|
#include <QMetaProperty>
|
||
|
#include <QDebug>
|
||
|
|
||
|
struct DataRowInf : public QObject
|
||
|
{
|
||
|
Q_OBJECT
|
||
|
Q_PROPERTY(QString ID READ ID WRITE setID)
|
||
|
Q_PROPERTY(QString Caption READ Caption WRITE setCaption)
|
||
|
Q_PROPERTY(QString Remark READ Remark WRITE setRemark)
|
||
|
Q_PROPERTY(QString Value READ Value WRITE setValue)
|
||
|
|
||
|
public:
|
||
|
explicit DataRowInf(QObject *parent = nullptr) : QObject(parent) {}
|
||
|
|
||
|
QString ID() const { return m_ID; }
|
||
|
QString Caption() const { return m_Caption; }
|
||
|
QString Remark() const { return m_Remark; }
|
||
|
QString Value() const { return m_Value; }
|
||
|
|
||
|
void setID(const QString &id)
|
||
|
{
|
||
|
if (m_ID != id)
|
||
|
{
|
||
|
m_ID = id;
|
||
|
}
|
||
|
}
|
||
|
void setCaption(const QString &caption)
|
||
|
{
|
||
|
if (m_Caption != caption)
|
||
|
{
|
||
|
m_Caption = caption;
|
||
|
}
|
||
|
}
|
||
|
void setRemark(const QString &remark)
|
||
|
{
|
||
|
if (m_Remark != remark)
|
||
|
{
|
||
|
m_Remark = remark;
|
||
|
}
|
||
|
}
|
||
|
void setValue(const QString &value)
|
||
|
{
|
||
|
if (m_Value != value)
|
||
|
{
|
||
|
m_Value = value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
QString m_ID;
|
||
|
QString m_Caption;
|
||
|
QString m_Remark;
|
||
|
QString m_Value;
|
||
|
};
|
||
|
|
||
|
class DataBlock
|
||
|
{
|
||
|
public:
|
||
|
DataBlock(/* args */)
|
||
|
{
|
||
|
}
|
||
|
virtual ~DataBlock()
|
||
|
{
|
||
|
clear();
|
||
|
}
|
||
|
|
||
|
virtual QString DataBlockName() { return "DataBlockName"; };
|
||
|
|
||
|
|
||
|
|
||
|
virtual void clear()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
virtual void toXml(pugi::xml_node xRoot)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
virtual void fromXml(const pugi::xml_node xml)
|
||
|
{
|
||
|
if (xml.empty())
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
void serializeObjDic(const QMap<QString, DataRowInf *> &dic, pugi::xml_node xDic)
|
||
|
{
|
||
|
if (dic.isEmpty())
|
||
|
return;
|
||
|
|
||
|
for (auto it = dic.constBegin(); it != dic.constEnd(); ++it)
|
||
|
{
|
||
|
const QString &key = it.key();
|
||
|
DataRowInf *o = it.value();
|
||
|
|
||
|
pugi::xml_node xo = xDic.append_child(o->ID().toStdString().c_str());
|
||
|
serializeToXml(xo, o);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void serializeToXml(pugi::xml_node xElement, DataRowInf *obj)
|
||
|
{
|
||
|
xElement.append_attribute("Type").set_value("CS.Infrastructure.Data.DataRowInf");
|
||
|
const QMetaObject *metaObj = obj->metaObject();
|
||
|
for (int i = 0; i < metaObj->propertyCount(); ++i)
|
||
|
{
|
||
|
QMetaProperty property = metaObj->property(i);
|
||
|
|
||
|
pugi::xml_node fieldNode = xElement.append_child("Field");
|
||
|
|
||
|
fieldNode.append_attribute("Name").set_value(property.name());
|
||
|
fieldNode.append_attribute("Type").set_value("System.String");
|
||
|
fieldNode.append_attribute("Value").set_value(property.read(obj).toString().toUtf8().constData());
|
||
|
|
||
|
qDebug() << "Property name:" << property.name();
|
||
|
qDebug() << "Property value:" << property.read(obj);
|
||
|
qDebug() << "Property type:" << property.typeName();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void deserializeObjDics(QMap<QString, DataRowInf *> &dic, pugi::xml_node xDic, std::vector<std::string> &namesList)
|
||
|
{
|
||
|
dic.clear();
|
||
|
if (xDic.empty())
|
||
|
return;
|
||
|
for (const auto &e : xDic.children())
|
||
|
{
|
||
|
DataRowInf *o = deserializeFromXml(e);
|
||
|
// DataRowInf* oo = qobject_cast<DataRowInf *>(o);
|
||
|
dic.insert(o->ID(), o);
|
||
|
namesList.push_back(o->ID().toStdString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DataRowInf *deserializeFromXml(const pugi::xml_node xObj)
|
||
|
{
|
||
|
if (xObj.empty())
|
||
|
return nullptr;
|
||
|
try
|
||
|
{
|
||
|
DataRowInf *o = new DataRowInf();
|
||
|
for (const auto &xe : xObj.children())
|
||
|
{
|
||
|
QString name = xe.attribute("Name").value();
|
||
|
QString value = xe.attribute("Value").value();
|
||
|
|
||
|
bool ret = o->setProperty(name.toUtf8().constData(), value);
|
||
|
}
|
||
|
return o;
|
||
|
}
|
||
|
catch (const std::exception &e)
|
||
|
{
|
||
|
// std::cerr << e.what() << '\n';
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class StabilityCalDataBlock : public DataBlock
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
StabilityCalDataBlock()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
~StabilityCalDataBlock()
|
||
|
{
|
||
|
clear();
|
||
|
}
|
||
|
|
||
|
|
||
|
QString DataBlockName() override { return "StabilityCal"; }
|
||
|
|
||
|
|
||
|
|
||
|
void clear()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
void toXml(pugi::xml_node xRoot, QMap<QString, DataRowInf*>& _DataRows, QMap<QString, DataRowInf*>& _childModules)
|
||
|
{
|
||
|
pugi::xml_node xDicDataRows = xRoot.append_child("DataRows");
|
||
|
serializeObjDic(_DataRows, xDicDataRows);
|
||
|
|
||
|
pugi::xml_node xDic = xRoot.append_child("ChildModulus");
|
||
|
serializeObjDic(_childModules, xDic);
|
||
|
}
|
||
|
|
||
|
void fromXmlEx(const pugi::xml_node xml, QMap<QString, DataRowInf*>& _childModules, std::vector<std::string>& _childModuleNames, QMap<QString, DataRowInf*>& _DataRows, std::vector<std::string>& _DataRowsNames) ;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
private:
|
||
|
//QMap<QString, DataRowInf*> m_childModules;
|
||
|
//std::vector<std::string> m_childModuleNames;
|
||
|
};
|
||
|
|
||
|
class StructureCalDataBlock: public DataBlock
|
||
|
{
|
||
|
};
|
||
|
|
||
|
class CertifyCalDataBlock: public DataBlock
|
||
|
{
|
||
|
};
|
||
|
#endif
|