]> Git trees. - libqmvoc.git/commitdiff
adding previousOf, nextOf, first and lastElementfunction to pseTable class.
authorEtienne Rebetez <etienne.rebetez@oberwallis.ch>
Wed, 14 Jul 2010 22:10:00 +0000 (22:10 +0000)
committerEtienne Rebetez <etienne.rebetez@oberwallis.ch>
Wed, 14 Jul 2010 22:10:00 +0000 (22:10 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=1150039

libscience/psetables.cpp
libscience/psetables.h

index 580a5d914cd33bb0bcd237107f773209d1939466..c3c3a96842ebcbd8a59f6f01260c0686fabe0569 100644 (file)
@@ -103,6 +103,28 @@ QList<int> 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 );
index 7e49575334e412d3337e8e53b96d5f4253bc64e7..fdd2148794ce3cb984272372bb6ee6f8baa6604a 100644 (file)
@@ -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 <tt>element - 1</tt> 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 <tt>element + 1</tt> 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
      */