From 9424e874f93d0d4e3a9ee98dee37ee495e88e391 Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Sat, 8 Oct 2005 15:28:22 +0000 Subject: [PATCH] add xml-creating svn path=/trunk/KDE/kdeedu/kalzium/src/spectrummanager/spectrumparser.cpp; revision=468560 --- .../src/spectrummanager/spectrumparser.cpp | 70 +++++++++++++++++++ kalzium/src/spectrummanager/spectrumparser.h | 20 +++++- 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 kalzium/src/spectrummanager/spectrumparser.cpp diff --git a/kalzium/src/spectrummanager/spectrumparser.cpp b/kalzium/src/spectrummanager/spectrumparser.cpp new file mode 100644 index 0000000..e4ef408 --- /dev/null +++ b/kalzium/src/spectrummanager/spectrumparser.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** +copyright : (C) 2005 by Carsten Niehaus +email : cniehaus@kde.org + ***************************************************************************/ +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ +#include "spectrumparser.h" +#include "../spectrum.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +SpectrumParser::SpectrumParser(const QString& filename) +{ +// m_file = QFile(filename); +} + +SpectrumParser::SpectrumParser(const QFile& file) +{ +// m_file = file; +} + +void SpectrumParser::saveSpectrum( Spectrum *spectrum ) +{ + if ( !spectrum ) return; + + QDomDocument doc( "SpectrumDocument" ); + + QFile docfile( "/home/carsten/test.xml" ); +// QTextStream stream( m_file ); + + QList blist = spectrum->bandlist(); + + QDomElement docelem = doc.createElement( "spectrum" ); + doc.appendChild( docelem ); + + foreach( Spectrum::band* band, blist ) + { + QDomElement bandelem = doc.createElement( "band" ); + bandelem.setAttribute( "wavelength", band->wavelength ); + bandelem.setAttribute( "intensity", band->intensity ); + bandelem.setAttribute( "aki", band->aki ); + bandelem.setAttribute( "energy1", band->energy1 ); + bandelem.setAttribute( "energy2", band->energy2 ); + bandelem.setAttribute( "term1", band->term1 ); + bandelem.setAttribute( "term2", band->term2 ); + bandelem.setAttribute( "electronconfig1", band->electronconfig1 ); + bandelem.setAttribute( "electronconfig2", band->electronconfig2 ); + bandelem.setAttribute( "J1", band->J1 ); + bandelem.setAttribute( "J2", band->J2 ); + docelem.appendChild( bandelem ); + } + + + + kdDebug() << "Text: " << doc.toString() << endl; +} diff --git a/kalzium/src/spectrummanager/spectrumparser.h b/kalzium/src/spectrummanager/spectrumparser.h index c558873..776c005 100644 --- a/kalzium/src/spectrummanager/spectrumparser.h +++ b/kalzium/src/spectrummanager/spectrumparser.h @@ -12,6 +12,11 @@ * (at your option) any later version. * * * ***************************************************************************/ + +#include + +class Spectrum; + /** * @author Carsten Niehaus */ @@ -20,9 +25,22 @@ class SpectrumParser public: /** * public contructor + * @param file The file which to read or write + */ + SpectrumParser(const QFile& file); + + /** + * public contructor + * @param filename the filename of the xml-file */ - SpectrumParser(); + SpectrumParser(const QString& filename); + + void saveSpectrum( Spectrum *spectrum ); + + Spectrum* loadSpectrum( QFile *file ); +// private: + QFile m_file; }; #endif // SPECTRUMPARSER_H -- 2.47.3