[go: up one dir, main page]

Menu

[88fba7]: / src / CLog.cpp  Maximize  Restore  History

Download this file

102 lines (88 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
/***************************************************************************
* Copyright (C) 2007 by Massimiliano Fago *
* massimiliano.fago@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/*! \file
* \brief Salvataggio log valori in formato xml
*
* Consente il salvataggio di un log delle variabili lette dal robot
* e visualizzate nella lista di openshowvar.
* Lo step di archiviazione e' pari all'intervallo di visualizzazione.
*
*/
#include "CLog.h"
/*! \brief Costruttore
*
* Inizializza la classe xml
*
*/
CLog::CLog(const QString filename){
logfile=filename;
}
CLog::~CLog(){
}
/*! \brief Scrittura lista variabili
*
* Scrive su file la lista delle variabili e i relativi ip di provenienza nel seguente
* formato:
* <LOG DATA="sab mar 22 10:49:08 2008" >
* <VAR NAME="$OV_PRO">
* <VALORE>50</VALORE>
* <TEMPOLETTURA>10 [ms]</TEMPOLETTURA>
* <IPROBOT>192.168.0.1</IPROBOT>
* </VARNAME>
* </LOG>
*
* \param tree Lista delle variabili
*/
void CLog::writeList(TreeModel *model){
QDomDocument doc;
QDateTime tempolettura;
QDomElement variablelist = doc.createElement("LOG");
variablelist.setAttribute("DATA", tempolettura.currentDateTime().toString());
doc.appendChild(variablelist);
QModelIndex robotipindex=model->index(0,0,QModelIndex());
for(int row=0;row<model->rowCount(robotipindex);row++){
QModelIndex varindex = model->index(row,TreeModel::VARNAME,robotipindex);
QModelIndex timeindex = model->index(row,TreeModel::TIME,robotipindex);
QModelIndex valueindex = model->index(row,TreeModel::VARVALUE,robotipindex);
for(int var=0;var<model->rowCount();var++){
QDomElement variable = doc.createElement("VAR");
variable.setAttribute("NAME",model->data(varindex,Qt::DisplayRole).toString());
QDomElement varvalue = doc.createElement("VALUE");
QDomElement readtime = doc.createElement("READTIME");
QDomElement robotip = doc.createElement("ROBOT");
QDomText var = doc.createTextNode(model->data(valueindex,Qt::DisplayRole).toString());
QDomText time = doc.createTextNode(model->data(timeindex,Qt::DisplayRole).toString());
QDomText ip = doc.createTextNode(model->data(robotipindex,Qt::DisplayRole).toString());
variablelist.appendChild(variable);
variable.appendChild(varvalue);
variable.appendChild(readtime);
variable.appendChild(robotip);
varvalue.appendChild(var);
readtime.appendChild(time);
robotip.appendChild(ip);
}
}
QFile file(logfile);
QTextStream out(&file);
file.open(QIODevice::Append);
const int Indent=4;
doc.save(out, Indent);
file.close();
}