File indexing completed on 2024-04-14 03:40:14
0001 /* 0002 SPDX-FileCopyrightText: 2005, 2006 Pino Toscano <toscano.pino@tiscali.it> 0003 SPDX-FileCopyrightText: 2007 Carste Niehaus <cniehaus@kde.org> 0004 SPDX-FileCopyrightText: 2010 Etienne Rebetez <etienne.rebetez@oberwallis.ch> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef PSETABLES_H 0010 #define PSETABLES_H 0011 0012 #include "science_export.h" 0013 0014 #include <QList> 0015 #include <QPoint> 0016 #include <QStringList> 0017 0018 /** 0019 * @class pseTables 0020 * Provides functions to easily create pse tables with qGridLayouts or qGraphicsView. 0021 * 0022 * creating a table for the gridlayout 0023 @code 0024 foreach (int elementIndex, pseTables::instance()->getTabletype(m_psTableType)->elements()) { 0025 int group = pseTables::instance()->getTabletype(m_psTableType)->elementCoords(elementIndex).x(); 0026 int period = pseTables::instance()->getTabletype(m_psTableType)->elementCoords(elementIndex).y(); 0027 0028 ElementLabel *element = new ElementLabel(elementIndex); 0029 0030 gridLayoutOfPeriodSystem->addItem(element, period, group); 0031 } 0032 0033 @endcode 0034 0035 * position elements in a qGraphicsScene 0036 @code 0037 0038 0039 @endcode 0040 0041 * getting the position of the Numerations for the periodic system of elements(j) 0042 @code 0043 for (int i = 0; i < pseTables::instance()->getTabletype(j)->tableSize().x() || i < numerationItems.count(); ++i) { 0044 int itemAtPos = pseTables::instance()->getTabletype(j)->numerationAtPos(i); 0045 } 0046 @endcode 0047 * @short Provides shape and elements of different periodic tables of elements 0048 * @author Etienne Rebetez 0049 */ 0050 class pseTable; 0051 0052 /** 0053 * Holds all periodic system tables and make them accessible. 0054 */ 0055 class SCIENCE_EXPORT pseTables 0056 { 0057 public: 0058 static pseTables *instance(); 0059 0060 ~pseTables(); 0061 0062 /** 0063 * Returns the KalziumTableType with the @p id specified. 0064 * It will gives 0 if none found. 0065 */ 0066 pseTable *getTabletype(const int tableType); 0067 0068 /** 0069 * Returns the KalziumTableType whose name is the @p id 0070 * specified. 0071 * It will gives 0 if none found. 0072 */ 0073 pseTable *getTabletype(const QString &tableType); 0074 0075 /** 0076 * Returns a list with the names of the table types we support. 0077 */ 0078 QStringList tables() const; 0079 0080 private: 0081 pseTables(); 0082 QList<pseTable *> m_tables; 0083 // int m_currentTable; 0084 }; 0085 0086 /** 0087 * defines a Periodic Table. 0088 * Holds the position (x,y) and all the displayed elements 0089 */ 0090 class pseTable 0091 0092 { 0093 public: 0094 static pseTable *init(); 0095 0096 virtual ~pseTable(); 0097 0098 /** 0099 * Returns the ID of this table type. 0100 */ 0101 virtual QString name() const; 0102 0103 /** 0104 * Returns a short description of the periodic table in use 0105 */ 0106 virtual QString description() const; 0107 0108 /** 0109 * Returns the coordinates of an element @p element in 0110 * the periodic system. 0111 * If the element is not in the periodic system QPoint(-1,-1) is returned. 0112 */ 0113 virtual QPoint elementCoords(int element) const; 0114 0115 /** 0116 * Returns a list with all elements in the actual periodic table 0117 */ 0118 virtual QList<int> elements() const; 0119 0120 /** 0121 0122 * Returns the element that comes right before the specified @p element. 0123 * -1 means that @p element is the first in this table type. 0124 * 0125 * The default implementation returns <tt>element - 1</tt> if @p element 0126 * is not 1, else -1. 0127 */ 0128 virtual int previousOf(int element) const; 0129 0130 /** 0131 * Returns the element that comes right after the specified @p element. 0132 * -1 means that @p element is the last in this table type. 0133 * 0134 * The default implementation returns <tt>element + 1</tt> if @p element 0135 * is not the latest element, else -1. 0136 */ 0137 virtual int nextOf(int element) const; 0138 0139 /** 0140 * Returns the first element of the table. 0141 */ 0142 virtual int firstElement() const; 0143 0144 /** 0145 * Returns the last element of the table. 0146 */ 0147 virtual int lastElement() const; 0148 0149 /** 0150 * Returns the maximal size of the periodic table. 0151 */ 0152 virtual QPoint tableSize() const; 0153 0154 /** 0155 * Returns the Numeration for the current Table according to the position in the Table. 0156 * Coordinates beginning with 0. Returns -1 if none is found. 0157 */ 0158 virtual int numerationAtPos(int xPos) const; 0159 0160 protected: 0161 pseTable(); 0162 0163 QString m_name; 0164 QString m_description; 0165 0166 QList<int> m_posX; 0167 QList<int> m_posY; 0168 QList<int> m_xCoordsNumeration; 0169 QList<int> m_elementList; 0170 }; 0171 0172 class pseRegularTable : public pseTable 0173 { 0174 public: 0175 static pseRegularTable *init(); 0176 0177 private: 0178 pseRegularTable(); 0179 }; 0180 0181 class pseLongTable : public pseTable 0182 { 0183 public: 0184 static pseLongTable *init(); 0185 0186 private: 0187 pseLongTable(); 0188 }; 0189 0190 class pseShortTable : public pseTable 0191 { 0192 public: 0193 static pseShortTable *init(); 0194 0195 private: 0196 pseShortTable(); 0197 }; 0198 0199 class pseDTable : public pseTable 0200 { 0201 public: 0202 static pseDTable *init(); 0203 0204 private: 0205 pseDTable(); 0206 }; 0207 0208 class pseDZTable : public pseTable 0209 { 0210 public: 0211 static pseDZTable *init(); 0212 0213 private: 0214 pseDZTable(); 0215 }; 0216 0217 #endif // PSTABLES_H