From 4f1ef2a95f9e95c47f01bf3ce088cf95c52ff92f Mon Sep 17 00:00:00 2001 From: Carsten Niehaus Date: Sun, 17 Jul 2005 15:15:53 +0000 Subject: [PATCH] * s/Spektrum/Spectrum * move the class into spectrum.cpp/h * add some more API svn path=/trunk/KDE/kdeedu/kalzium/src/spectrum.h; revision=435591 --- kalzium/src/element.cpp | 7 ++-- kalzium/src/element.h | 41 ++---------------------- kalzium/src/spectrum.cpp | 36 ++++++++++++++++++--- kalzium/src/spectrum.h | 69 +++++++++++++++++++++++++++++++++++----- 4 files changed, 99 insertions(+), 54 deletions(-) diff --git a/kalzium/src/element.cpp b/kalzium/src/element.cpp index 83b42cb..5c1993c 100644 --- a/kalzium/src/element.cpp +++ b/kalzium/src/element.cpp @@ -20,6 +20,7 @@ #include "element.h" #include "prefs.h" +#include "spectrum.h" #include #include @@ -625,10 +626,10 @@ EList KalziumDataObject::readData( QDomDocument &dataDocument ) QDomNodeList spectrumList = domElement.namedItem( "spectra" ).toElement().elementsByTagName( "spectrum" ); - Spektrum *spectrum = new Spektrum(); + Spectrum *spectrum = new Spectrum(); for( uint i = 0; i < spectrumList.length(); i++ ) { - Spektrum::band b; + Spectrum::band b; QDomElement spec = spectrumList.item( i ).toElement(); b.intensity = spec.attributeNode( "intensity" ).value().toInt(); @@ -647,7 +648,7 @@ EList KalziumDataObject::readData( QDomDocument &dataDocument ) } Element *e = new Element(); - e->setSpektrum( spectrum ); + e->setSpectrum( spectrum ); e->setDate(date); e->setBiologicalMeaning(bio); e->setNumber( number ); diff --git a/kalzium/src/element.h b/kalzium/src/element.h index 21bd86b..60e68f5 100644 --- a/kalzium/src/element.h +++ b/kalzium/src/element.h @@ -29,6 +29,7 @@ class Element; class QDomDocument; class QPainter; class QPoint; +class Spectrum; struct coordinate; @@ -36,42 +37,6 @@ typedef QValueList EList; typedef QValueList CList; typedef QValueList doubleList; -/** - * @author Carsten Niehaus - * - * This class represents an spectrum with all its properties - */ -class Spektrum -{ - public: - Spektrum(){}; - ~Spektrum(){}; - - /** - * a band is one line in the spektrum of an element - */ - struct band - { - double wavelength; - double aki; - double energy1; - double energy2; - int intensity; - QString electronconfig1; - QString electronconfig2; - QString term1; - QString term2; - QString J1; - QString J2; - }; - - void addBand( band b ){ - m_bandlist.append( b ); - } - - QValueList m_bandlist; -}; - /** * @author Carsten Niehaus * @author Jörg Buchwald @@ -322,7 +287,7 @@ class Element{ m_isotopeList = list; } - void setSpektrum( Spektrum *spec ){ + void setSpectrum( Spectrum *spec ){ m_spectrum = spec; } @@ -562,7 +527,7 @@ class Element{ */ int m_ElementNumber; - Spektrum *m_spectrum; + Spectrum *m_spectrum; QValueList m_isotopeList; diff --git a/kalzium/src/spectrum.cpp b/kalzium/src/spectrum.cpp index 6b04dcb..53564d3 100644 --- a/kalzium/src/spectrum.cpp +++ b/kalzium/src/spectrum.cpp @@ -28,6 +28,32 @@ #include +double Spectrum::minBand() +{ + double value = ( *m_bandlist.begin() ).wavelength; + QValueList::Iterator it = m_bandlist.begin(); + const QValueList::Iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + if ( value > ( *it ).wavelength ) + value = ( *it ).wavelength; + } + return value; +} + +double Spectrum::maxBand() +{ + double value = ( *m_bandlist.begin() ).wavelength; + QValueList::Iterator it = m_bandlist.begin(); + const QValueList::Iterator itEnd = m_bandlist.end(); + for (;it!=itEnd;++it) + { + if ( value < ( *it ).wavelength ) + value = ( *it ).wavelength; + } + return value; +} + SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name ) : QWidget( parent,name ) { @@ -263,8 +289,8 @@ SpectrumView::SpectrumView( QWidget *parent, const char* name ) : QWidget( parent, name ) { QVBoxLayout *spectrumLayout = new QVBoxLayout( this ); - m_spectrum = new SpectrumWidget( this, "spectrum" ); - spectrumLayout->addWidget( m_spectrum ); + m_spectrumWidget = new SpectrumWidget( this, "spectrum" ); + spectrumLayout->addWidget( m_spectrumWidget ); QHBoxLayout *hbox = new QHBoxLayout( this ); m_spinbox_left = new QSpinBox( 380, 779, 1, this ); @@ -272,13 +298,13 @@ SpectrumView::SpectrumView( QWidget *parent, const char* name ) m_spinbox_right->setValue( 700 ); m_spinbox_left->setValue( 400 ); - connect( m_spinbox_right, SIGNAL( valueChanged( int ) ), m_spectrum, SLOT( setRightBorder( int ) ) ); - connect( m_spinbox_left, SIGNAL( valueChanged( int ) ), m_spectrum, SLOT( setLeftBorder( int ) ) ); + connect( m_spinbox_right, SIGNAL( valueChanged( int ) ), m_spectrumWidget, SLOT( setRightBorder( int ) ) ); + connect( m_spinbox_left, SIGNAL( valueChanged( int ) ), m_spectrumWidget, SLOT( setLeftBorder( int ) ) ); m_spectrumbox = new KComboBox( this, "combobox" ); m_spectrumbox->insertItem( "Emission Spectrum" ); m_spectrumbox->insertItem( "Absorption Spectrum" ); - connect( m_spectrumbox, SIGNAL( activated( int ) ), m_spectrum, SLOT( slotActivateSpectrum( int ) ) ); + connect( m_spectrumbox, SIGNAL( activated( int ) ), m_spectrumWidget, SLOT( slotActivateSpectrum( int ) ) ); hbox->addWidget( new QLabel( i18n( "Minimumvalue" ), this ) ); diff --git a/kalzium/src/spectrum.h b/kalzium/src/spectrum.h index 7bee4ab..34fc980 100644 --- a/kalzium/src/spectrum.h +++ b/kalzium/src/spectrum.h @@ -35,6 +35,58 @@ #include "element.h" +/** + * @author Carsten Niehaus + * + * This class represents an spectrum with all its properties + */ +class Spectrum +{ + public: + Spectrum(){ + m_min = minBand(); + m_max = maxBand(); + }; + ~Spectrum(){}; + + /** + * a band is one line in the spectrum of an element + */ + struct band + { + double wavelength; + double aki; + double energy1; + double energy2; + int intensity; + QString electronconfig1; + QString electronconfig2; + QString term1; + QString term2; + QString J1; + QString J2; + }; + + void addBand( band b ){ + m_bandlist.append( b ); + } + + private: + /** + * @return the smallest wavelength + */ + double minBand(); + + /** + * @return the biggest wavelength + */ + double maxBand(); + + QValueList m_bandlist; + + double m_max, m_min; +}; + /** * @author Carsten Niehaus */ @@ -46,8 +98,8 @@ class SpectrumWidget : public QWidget SpectrumWidget( QWidget *parent, const char* name = 0 ); ~SpectrumWidget(); - void setSpektrum( Spektrum* spec ){ - m_spektrum = spec; + void setSpectrum( Spectrum* spec ){ + m_spectrum = spec; } /** @@ -106,7 +158,7 @@ class SpectrumWidget : public QWidget */ int Adjust( double color, double factor ); - Spektrum *m_spektrum; + Spectrum *m_spectrum; /** * @param the position on a 0 to 1-scale in the widget. 0.5 mean @@ -210,13 +262,14 @@ class SpectrumView : public QWidget public: SpectrumView( QWidget* parent, const char* name ); -//X void setSpectra( QValueList l ){ -//X m_spectrum->setSpektrum( l ); -//X update(); -//X } + void setSpectra( Spectrum* spec ){ + m_spectrum = spec; + } private: - SpectrumWidget *m_spectrum; + SpectrumWidget *m_spectrumWidget; + + Spectrum* m_spectrum; QSpinBox *m_spinbox_left, *m_spinbox_right; -- 2.47.3