• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalzium/libscience

  • sources
  • kde-4.12
  • kdeedu
  • kalzium
  • libscience
spectrumparser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 copyright : (C) 2005, 2008 by Carsten Niehaus
3 email : cniehaus@kde.org
4  ***************************************************************************/
5 /***************************************************************************
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  ***************************************************************************/
13 #include "spectrumparser.h"
14 #include "spectrum.h"
15 
16 #include <qdom.h>
17 #include <QList>
18 #include <QFile>
19 #include <QDebug>
20 
21 class SpectrumParser::Private
22 {
23 public:
24  Private()
25  : currentSpectrum(0),
26  inMetadata_(false),
27  inSpectrum_(false),
28  inSpectrumList_(false),
29  inPeakList_(false),
30  inPeak_(false)
31  {}
32 
33  ~Private()
34  {
35  delete currentSpectrum;
36  delete currentPeak;
37  }
38 
39  Spectrum * currentSpectrum;
40  Spectrum::peak * currentPeak;
41 
42  bool inMetadata_;
43  bool inSpectrum_;
44  bool inSpectrumList_;
45  bool inPeakList_;
46  bool inPeak_;
47 
48  double wavelength;
49  int intensity;
50 
51  QList<Spectrum*> spectra;
52 };
53 
54 SpectrumParser::SpectrumParser()
55  : QXmlDefaultHandler(), d( new Private )
56 {
57 }
58 
59 SpectrumParser::~SpectrumParser()
60 {
61  delete d;
62 }
63 
64 bool SpectrumParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs)
65 {
66  if (localName == "spectrum"){
67 
68  d->currentSpectrum = new Spectrum();
69  d->inSpectrum_ = true;
70 
71  //now save the element of the current spectrum
72  for (int i = 0; i < attrs.length(); ++i)
73  if ( attrs.localName( i ) == "id" )
74  currentElementID = attrs.value( i );
75 
76  } else if (d->inSpectrum_ && localName == "peakList") {
77  d->inPeakList_ = true;
78  }
79  else if (d->inSpectrum_ && d->inPeakList_ && localName == "peak") {
80  d->inPeak_ = true;
81  for (int i = 0; i < attrs.length(); ++i){
82  if (attrs.localName(i) == "xValue") {
83  d->intensity = attrs.value(i).toInt();
84  }
85  else if (attrs.localName(i) == "yValue") {
86  d->wavelength = attrs.value(i).toDouble();
87  }
88  }
89  d->currentPeak = new Spectrum::peak(d->wavelength, d->intensity);
90  }
91  return true;
92 }
93 
94 bool SpectrumParser::endElement( const QString&, const QString& localName, const QString& )
95 {
96  if ( localName == "spectrum" )
97  {
98  int num = currentElementID.mid(1).toInt();
99  d->currentSpectrum->setParentElementNumber( num );
100 
101  d->spectra.append( d->currentSpectrum );
102 
103  d->currentSpectrum = 0;
104  d->inSpectrum_ = false;
105  }
106  else if ( localName == "peakList" ) {
107  d->inSpectrumList_ = false;
108  }
109  else if ( localName == "peak" ) {
110 //X qDebug() << "in 'peak'" << " with this data: " << d->currentPeak->intensity << " (intesity)" ;
111  d->currentSpectrum->addPeak(d->currentPeak);
112  d->currentPeak = 0;
113  d->inPeak_ = false;
114  }
115  return true;
116 }
117 
118 bool SpectrumParser::characters(const QString &ch)
119 {
120  Q_UNUSED(ch)
121  return true;
122 }
123 
124 QList<Spectrum*> SpectrumParser::getSpectrums()
125 {
126  return d->spectra;
127 }
SpectrumParser::startElement
bool startElement(const QString &, const QString &localName, const QString &, const QXmlAttributes &attrs)
Definition: spectrumparser.cpp:64
Spectrum
Definition: spectrum.h:35
SpectrumParser::endElement
bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Definition: spectrumparser.cpp:94
SpectrumParser::~SpectrumParser
~SpectrumParser()
Definition: spectrumparser.cpp:59
spectrum.h
QXmlDefaultHandler
SpectrumParser::SpectrumParser
SpectrumParser()
Constructor.
Definition: spectrumparser.cpp:54
Spectrum::peak
a peak is one line in the spectrum of an element
Definition: spectrum.h:51
SpectrumParser::getSpectrums
QList< Spectrum * > getSpectrums()
Definition: spectrumparser.cpp:124
SpectrumParser::characters
bool characters(const QString &ch)
Definition: spectrumparser.cpp:118
spectrumparser.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:31 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalzium/libscience

Skip menu "kalzium/libscience"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal