From: Etienne Rebetez Date: Wed, 14 Jul 2010 22:10:00 +0000 (+0000) Subject: adding previousOf, nextOf, first and lastElementfunction to pseTable class. X-Git-Tag: v4.5.80~11 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=7faa6c2fcfc8272e2827c904ee2dabe68fa9f772;p=libqmvoc.git adding previousOf, nextOf, first and lastElementfunction to pseTable class. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=1150039 --- diff --git a/libscience/psetables.cpp b/libscience/psetables.cpp index 580a5d9..c3c3a96 100644 --- a/libscience/psetables.cpp +++ b/libscience/psetables.cpp @@ -103,6 +103,28 @@ QList pseTable::elements() const return m_elementList; } +int pseTable::previousOf( int element ) const +{ + int index = m_elementList.indexOf( element ); + return index > 1 ? m_elementList.at( index - 1 ) : -1; +} + +int pseTable::nextOf( int element ) const +{ + int index = m_elementList.indexOf( element ); + return index != -1 && ( index < m_elementList.count() - 1 ) ? m_elementList.at( index + 1 ) : -1; +} + +int pseTable::firstElement() const +{ + return m_elementList.first(); +} + +int pseTable::lastElement() const +{ + return m_elementList.last(); +} + QPoint pseTable::elementCoords(const int element) { int elementIndex = m_elementList.indexOf( element ); diff --git a/libscience/psetables.h b/libscience/psetables.h index 7e49575..fdd2148 100644 --- a/libscience/psetables.h +++ b/libscience/psetables.h @@ -92,6 +92,34 @@ public: */ virtual QPoint elementCoords(int element); + /** + * Returns the element that comes right before the specified @p element. + * -1 means that @p element is the first in this table type. + * + * The default implementation returns element - 1 if @p element + * is not 1, else -1. + */ + int previousOf ( int element ) const; + + /** + * Returns the element that comes right after the specified @p element. + * -1 means that @p element is the last in this table type. + * + * The default implementation returns element + 1 if @p element + * is not the latest element, else -1. + */ + int nextOf ( int element ) const; + + /** + * Returns the first element of the table. + */ + int firstElement() const; + + /** + * Returns the last element of the table. + */ + int lastElement() const; + /** * Returns a list with all elements in the actual periodic table */