From 1e3ad32bfa52c56c65feaaf39e9ffa89c93b3edd Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Wed, 7 Jan 2015 21:57:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8QTextStream=E6=9D=A5=E8=BE=93=E5=87=BA?= =?UTF-8?q?Container=E7=9A=84=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/elementhashtable.cpp | 27 ++++++++++-- testHasttable/elementhashtable.h | 3 ++ testHasttable/topologyrecorder.cpp | 69 ++++++++++++++++-------------- testHasttable/topologyrecorder.h | 2 + 4 files changed, 66 insertions(+), 35 deletions(-) diff --git a/testHasttable/elementhashtable.cpp b/testHasttable/elementhashtable.cpp index b92b134..cd8897c 100644 --- a/testHasttable/elementhashtable.cpp +++ b/testHasttable/elementhashtable.cpp @@ -1,7 +1,7 @@ #include "elementhashtable.h" #include ElementHashtable::ElementHashtable(QObject *parent) : - QObject(parent),currentHT(NULL) + QObject(parent),currentHT(NULL),tpRecorder(NULL) { } @@ -96,9 +96,14 @@ bool ElementHashtable::GoPath() continue;//有些Terminal是没有Node的 } std::cout<eleHT,this->FDSet); - tpRecorder.startWithNode(node); - tpRecorder.exportTo(""); + if(this->tpRecorder!=NULL) + { + delete this->tpRecorder; + this->tpRecorder=NULL; + } + this->tpRecorder=new TopologyRecorder(this->eleHT,this->FDSet); + this->tpRecorder->startWithNode(node); + this->tpRecorder->exportTo(""); break; } } @@ -155,6 +160,8 @@ bool ElementHashtable::Parse(const QString& xmlPWPath,const QString& xmlZWPath){ return true; } + + void ElementHashtable::SetACLineID(const QString &id)//寻找的线路ID { this->lineID=id; @@ -163,3 +170,15 @@ void ElementHashtable::SetFDSet(const QVector &FDSet)//FeeDer集合 { this->FDSet=FDSet; } + +void ElementHashtable::ShowContainerInfo(const QString& fileName) +{ + QString relPath="./../output/"; + QFile file(relPath+fileName+".txt"); + if(file.open(QFile::ReadOnly)) + { + QTextStream stream(&file); + this->tpRecorder->showContainerInfo(stream); + file.close(); + } +} diff --git a/testHasttable/elementhashtable.h b/testHasttable/elementhashtable.h index a27d217..17a98ea 100644 --- a/testHasttable/elementhashtable.h +++ b/testHasttable/elementhashtable.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include "BasicElementInfo.h" @@ -28,6 +29,7 @@ public: bool GoPath(); void SetACLineID(const QString &id);//寻找的线路ID void SetFDSet(const QVector &FDSet);//FeeDer集合 + void ShowContainerInfo(const QString& fileName); private: bool child(QXmlStreamReader &reader); bool setCurrentHashTable(QHash *t); @@ -38,6 +40,7 @@ private: QHash *currentHT; QString lineID; QVector FDSet; + TopologyRecorder *tpRecorder; signals: public slots: diff --git a/testHasttable/topologyrecorder.cpp b/testHasttable/topologyrecorder.cpp index 5c7afb2..3f9a40f 100644 --- a/testHasttable/topologyrecorder.cpp +++ b/testHasttable/topologyrecorder.cpp @@ -7,37 +7,7 @@ TopologyRecorder::TopologyRecorder(const QHash& elem TopologyRecorder::~TopologyRecorder() { - const QHash &ht=this->eleHT; - std::cout<<"total tf"<tfs.length()< > s; - for(QVector::iterator ite=this->tfs.begin(); - ite!=this->tfs.end(); - ite++) - { - PowerTransformer *pf=static_cast(ht[*ite]); - QString container; - container=pf->getEquipmentMemberOf_EquipmentContainer(); - s[container].push_back(*ite); - } - std::cout<<"container "< keys=s.keys(); - for(QList::iterator ite=keys.begin(); - ite!=keys.end(); - ite++) - { - QString k=*ite; - std::cout<(ht[k]); - std::cout<<", "<getNamingDescription().toStdString(); - QVector v=s[k]; - foreach (QString n, v) { - std::cout<<", "<(ht[n]); - std::cout<<"("<getNamingDescription().toStdString()<<")"; - } - std::cout<cimExporter.exportTo(path); } +void TopologyRecorder::showContainerInfo(QTextStream &stream) +{ + + const QHash &ht=this->eleHT; + stream<<"total tf"<tfs.length()<<"\n"; + //统计一下每个Container下有多少个变压器 + QHash > s; + for(QVector::iterator ite=this->tfs.begin(); + ite!=this->tfs.end(); + ite++) + { + PowerTransformer *pf=static_cast(ht[*ite]); + QString container; + container=pf->getEquipmentMemberOf_EquipmentContainer(); + s[container].push_back(*ite); + } + std::cout<<"container "< keys=s.keys(); + for(QList::iterator ite=keys.begin(); + ite!=keys.end(); + ite++) + { + QString k=*ite; + stream<(ht[k]); + stream<<"("<getNamingDescription()<<")"; + QVector v=s[k]; + foreach (QString n, v) { + std::cout<<", "<(ht[n]); + stream<<"("<getNamingDescription()<<")"; + } + stream<<"\n"; + } + +} + bool TopologyRecorder::startWithNode(const QString& node) { if(node=="") diff --git a/testHasttable/topologyrecorder.h b/testHasttable/topologyrecorder.h index 13913b2..3ca8c28 100644 --- a/testHasttable/topologyrecorder.h +++ b/testHasttable/topologyrecorder.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "BasicElementInfo.h" #include "breaker.h" #include "aclinesegment.h" @@ -31,6 +32,7 @@ class TopologyRecorder:public QObject public: TopologyRecorder(const QHash& elementHT,const QVector &FDSet,QObject *parent=0); ~TopologyRecorder(); + void showContainerInfo(QTextStream &stream); bool startWithNode(const QString& node); void exportTo(const QString& path); private: