~ubuntu-branches/ubuntu/precise/kalzium/precise

« back to all changes in this revision

Viewing changes to libscience/psetables.h

  • Committer: Bazaar Package Importer
  • Author(s): Philip Muškovac
  • Date: 2011-07-03 12:28:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110703122858-q1yyxncs89e4w0hs
Tags: upstream-4.6.90+repack
Import upstream version 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************************
 
2
 *   Copyright (C) 2005, 2006  by Pino Toscano, toscano.pino@tiscali.it          *
 
3
 *   Copyright (C) 2007        by Carste Niehaus, cniehaus@kde.org               *
 
4
 *   copyright (C) 2010        by Etienne Rebetez, etienne.rebetez@oberwallis.ch *
 
5
 *                                                                               *
 
6
 *   This program is free software; you can redistribute it and/or modify       *
 
7
 *   it under the terms of the GNU General Public License as published by      *
 
8
 *   the Free Software Foundation; either version 2 of the License, or        *
 
9
 *   (at your option) any later version.                                     *
 
10
 *                                                                          *
 
11
 *   This program is distributed in the hope that it will be useful,       *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU General Public License for more details.                          *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU General Public License     *
 
17
 *   along with this program; if not, write to the                         *
 
18
 *   Free Software Foundation, Inc.,                                       *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 
20
 ***************************************************************************/
 
21
 
 
22
#ifndef PSETABLES_H
 
23
#define PSETABLES_H
 
24
 
 
25
#include "libkdeedu_science_export.h"
 
26
 
 
27
#include <QPoint>
 
28
#include <QList>
 
29
#include <QStringList>
 
30
 
 
31
/**
 
32
 * @class pseTables
 
33
 * Provides functions to easyli create pse tables with qGridLayouts or qGraphicsView.
 
34
 *
 
35
 * creating a table for the gridlayout
 
36
@code
 
37
  foreach (int elementIndex, pseTables::instance()->getTabletype( m_psTableType )->elements()) {
 
38
       int group = pseTables::instance()->getTabletype( m_psTableType )->elementCoords( elementIndex ).x();
 
39
       int period = pseTables::instance()->getTabletype( m_psTableType )->elementCoords( elementIndex ).y();
 
40
 
 
41
       ElementLabel *element = new ElementLabel( elementIndex );
 
42
 
 
43
       gridLayoutOfPeriodSystem->addItem (element, period, group );
 
44
  }
 
45
 
 
46
@endcode
 
47
 
 
48
 * position elements in a qGraphicsScene
 
49
@code
 
50
 
 
51
 
 
52
@endcode
 
53
 
 
54
 * getting the position of the Numerations for the periodic system of elements (j)
 
55
 @code
 
56
    for (int i = 0; i < pseTables::instance()->getTabletype( j )->tableSize().x() || i < numerationItems.count(); i++) {
 
57
        int itemAtPos = pseTables::instance()->getTabletype( j )->numerationAtPos( i );
 
58
    }
 
59
 @endcode
 
60
 * @short Provides shape and elements of diferent peridic tables of elements
 
61
 * @author Etienne Rebetez
 
62
 */
 
63
class pseTable;
 
64
 
 
65
/**
 
66
 * Holds all periodic system tables and make them accesible.
 
67
 */
 
68
class SCIENCE_EXPORT pseTables
 
69
{
 
70
public:
 
71
    static pseTables *instance();
 
72
 
 
73
    ~pseTables();
 
74
 
 
75
    /**
 
76
    * Returns the KalziumTableType with the @p id specified.
 
77
    * It will gives 0 if none found.
 
78
    */
 
79
    pseTable* getTabletype(const int tableType);
 
80
 
 
81
    /**
 
82
    * Returns the KalziumTableType whose name is the @p id
 
83
    * specified.
 
84
    * It will gives 0 if none found.
 
85
    */
 
86
    pseTable* getTabletype(const QString tableType);
 
87
 
 
88
    /**
 
89
     * Returns a list with the names of the table types we support.
 
90
     */
 
91
    QStringList tables() const;
 
92
 
 
93
private:
 
94
    pseTables();
 
95
    QList<pseTable*> m_tables;
 
96
    int m_currentTable;
 
97
};
 
98
 
 
99
 
 
100
/**
 
101
 * defines a Periodic Table.
 
102
 * Holds the position (x,y) and all the displaed elements
 
103
 */
 
104
class pseTable
 
105
 
 
106
{
 
107
public:
 
108
    static pseTable *init();
 
109
 
 
110
    virtual ~pseTable();
 
111
 
 
112
    /**
 
113
     * Returns the ID of this table type.
 
114
     */
 
115
    virtual QString name() const;
 
116
 
 
117
    /**
 
118
     * Returns a short description of the periodic table in use
 
119
     */
 
120
    virtual QString description() const;
 
121
 
 
122
    /**
 
123
     * Returns the coordinates of an element  @p element in
 
124
     * the periodic system.
 
125
     * If the element is not in the periodic system QPoint(-1,-1) is returned.
 
126
     */
 
127
    virtual QPoint elementCoords(int element) const;
 
128
 
 
129
    /**
 
130
     * Returns a list with all elements in the actual periodic table
 
131
     */
 
132
    virtual QList<int> elements() const;
 
133
 
 
134
    /**
 
135
 
 
136
     * Returns the element that comes right before the specified @p element.
 
137
     * -1 means that @p element is the first in this table type.
 
138
     *
 
139
     * The default implementation returns <tt>element - 1</tt> if @p element
 
140
     * is not 1, else -1.
 
141
     */
 
142
    virtual int previousOf ( int element ) const;
 
143
 
 
144
    /**
 
145
     * Returns the element that comes right after the specified @p element.
 
146
     * -1 means that @p element is the last in this table type.
 
147
     *
 
148
     * The default implementation returns <tt>element + 1</tt> if @p element
 
149
     * is not the latest element, else -1.
 
150
     */
 
151
    virtual int nextOf ( int element ) const;
 
152
 
 
153
    /**
 
154
     * Returns the first element of the table.
 
155
     */
 
156
    virtual int firstElement() const;
 
157
 
 
158
    /**
 
159
     * Returns the last element of the table.
 
160
     */
 
161
    virtual int lastElement() const;
 
162
 
 
163
    /**
 
164
     * Returns the maximal size of the periodic table.
 
165
     */
 
166
    virtual QPoint tableSize() const;
 
167
 
 
168
     /**
 
169
     * Returns the Numeration for the current Table according to the position in the Table.
 
170
     * Coordinatates beginning wiht 0. Returns -1 if none is found.
 
171
     */
 
172
     virtual int numerationAtPos( int xPos ) const;
 
173
 
 
174
protected:
 
175
    pseTable();
 
176
 
 
177
    QString m_name;
 
178
    QString m_description;
 
179
 
 
180
    QList<int> m_posX;
 
181
    QList<int> m_posY;
 
182
    QList<int> m_xCoordsNumeration;
 
183
    QList<int> m_elementList;
 
184
};
 
185
 
 
186
 
 
187
 
 
188
class pseRegularTable : public pseTable
 
189
{
 
190
public:
 
191
    static pseRegularTable *init();
 
192
 
 
193
private:
 
194
    pseRegularTable();
 
195
};
 
196
 
 
197
class pseLongTable : public pseTable
 
198
{
 
199
public:
 
200
    static pseLongTable *init();
 
201
 
 
202
private:
 
203
    pseLongTable();
 
204
};
 
205
 
 
206
class pseShortTable : public pseTable
 
207
{
 
208
public:
 
209
    static pseShortTable *init();
 
210
 
 
211
private:
 
212
    pseShortTable();
 
213
};
 
214
 
 
215
class pseDTable : public pseTable
 
216
{
 
217
public:
 
218
    static pseDTable *init();
 
219
 
 
220
private:
 
221
    pseDTable();
 
222
};
 
223
 
 
224
class pseDZTable : public pseTable
 
225
{
 
226
public:
 
227
    static pseDZTable *init();
 
228
 
 
229
private:
 
230
    pseDZTable();
 
231
};
 
232
#endif // PSTABLES_H