File indexing completed on 2022-10-04 13:46:48

0001 /*
0002     SPDX-FileCopyrightText: 2005, 2006 Pino Toscano <toscano.pino@tiscali.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "kalziumnumerationtype.h"
0008 
0009 #include "kalziumdataobject.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 KalziumNumerationTypeFactory::KalziumNumerationTypeFactory()
0014 {
0015     m_numerations << KalziumNoneNumerationType::instance();
0016     m_numerations << KalziumIUPACNumerationType::instance();
0017     m_numerations << KalziumCASNumerationType::instance();
0018     m_numerations << KalziumOldIUPACNumerationType::instance();
0019 }
0020 
0021 KalziumNumerationTypeFactory *KalziumNumerationTypeFactory::instance()
0022 {
0023     static KalziumNumerationTypeFactory kntf;
0024     return &kntf;
0025 }
0026 
0027 KalziumNumerationType *KalziumNumerationTypeFactory::build(int id) const
0028 {
0029     if ((id < 0) || (id >= m_numerations.count())) {
0030         return nullptr;
0031     }
0032 
0033     return m_numerations.at(id);
0034 }
0035 
0036 KalziumNumerationType *KalziumNumerationTypeFactory::build(const QByteArray &id) const
0037 {
0038     for (int i = 0; i < m_numerations.count(); ++i) {
0039         if (m_numerations.at(i)->name() == id) {
0040             return m_numerations.at(i);
0041         }
0042     }
0043 
0044     // not found
0045     return nullptr;
0046 }
0047 
0048 QStringList KalziumNumerationTypeFactory::numerations() const
0049 {
0050     QStringList l;
0051     for (int i = 0; i < m_numerations.count(); ++i) {
0052         l << m_numerations.at(i)->description();
0053     }
0054     return l;
0055 }
0056 
0057 KalziumNumerationType *KalziumNumerationType::instance()
0058 {
0059     return nullptr;
0060 }
0061 
0062 KalziumNumerationType::KalziumNumerationType() = default;
0063 
0064 KalziumNumerationType::~KalziumNumerationType() = default;
0065 
0066 QString KalziumNumerationType::item(const int num) const
0067 {
0068     if ((num < 0) || (num >= m_items.count())) {
0069         return {};
0070     }
0071 
0072     return m_items.at(num);
0073 }
0074 
0075 QStringList KalziumNumerationType::items() const
0076 {
0077     return m_items;
0078 }
0079 
0080 KalziumNoneNumerationType *KalziumNoneNumerationType::instance()
0081 {
0082     static KalziumNoneNumerationType knnt;
0083     return &knnt;
0084 }
0085 
0086 KalziumNoneNumerationType::KalziumNoneNumerationType()
0087     : KalziumNumerationType()
0088 {
0089 }
0090 
0091 QByteArray KalziumNoneNumerationType::name() const
0092 {
0093     return "None";
0094 }
0095 
0096 QString KalziumNoneNumerationType::description() const
0097 {
0098     return i18n("No Numeration");
0099 }
0100 
0101 QString KalziumNoneNumerationType::item(const int num) const
0102 {
0103     Q_UNUSED(num);
0104     return {};
0105 }
0106 
0107 QStringList KalziumNoneNumerationType::items() const
0108 {
0109     return {};
0110 }
0111 
0112 KalziumIUPACNumerationType *KalziumIUPACNumerationType::instance()
0113 {
0114     static KalziumIUPACNumerationType kint;
0115     return &kint;
0116 }
0117 
0118 KalziumIUPACNumerationType::KalziumIUPACNumerationType()
0119     : KalziumNumerationType()
0120 {
0121     // cache them
0122     m_items << QStringLiteral("1");
0123     m_items << QStringLiteral("2");
0124     m_items << QStringLiteral("3");
0125     m_items << QStringLiteral("4");
0126     m_items << QStringLiteral("5");
0127     m_items << QStringLiteral("6");
0128     m_items << QStringLiteral("7");
0129     m_items << QStringLiteral("8");
0130     m_items << QStringLiteral("9");
0131     m_items << QStringLiteral("10");
0132     m_items << QStringLiteral("11");
0133     m_items << QStringLiteral("12");
0134     m_items << QStringLiteral("13");
0135     m_items << QStringLiteral("14");
0136     m_items << QStringLiteral("15");
0137     m_items << QStringLiteral("16");
0138     m_items << QStringLiteral("17");
0139     m_items << QStringLiteral("18");
0140 }
0141 
0142 QByteArray KalziumIUPACNumerationType::name() const
0143 {
0144     return "IUPAC";
0145 }
0146 
0147 QString KalziumIUPACNumerationType::description() const
0148 {
0149     return i18n("IUPAC");
0150 }
0151 
0152 KalziumCASNumerationType *KalziumCASNumerationType::instance()
0153 {
0154     static KalziumCASNumerationType kcnt;
0155     return &kcnt;
0156 }
0157 
0158 KalziumCASNumerationType::KalziumCASNumerationType()
0159     : KalziumNumerationType()
0160 {
0161     // cache them
0162     m_items << QStringLiteral("IA");
0163     m_items << QStringLiteral("IIA");
0164     m_items << QStringLiteral("IIIB");
0165     m_items << QStringLiteral("IVB");
0166     m_items << QStringLiteral("VB");
0167     m_items << QStringLiteral("VIB");
0168     m_items << QStringLiteral("VIIB");
0169     m_items << QStringLiteral("VIII");
0170     m_items << QStringLiteral("VIII");
0171     m_items << QStringLiteral("VIII");
0172     m_items << QStringLiteral("IB");
0173     m_items << QStringLiteral("IIB");
0174     m_items << QStringLiteral("IIIA");
0175     m_items << QStringLiteral("IVA");
0176     m_items << QStringLiteral("VA");
0177     m_items << QStringLiteral("VIA");
0178     m_items << QStringLiteral("VIIA");
0179     m_items << QStringLiteral("VIIIA");
0180 }
0181 
0182 QByteArray KalziumCASNumerationType::name() const
0183 {
0184     return "CAS";
0185 }
0186 
0187 QString KalziumCASNumerationType::description() const
0188 {
0189     return i18n("CAS");
0190 }
0191 
0192 KalziumOldIUPACNumerationType *KalziumOldIUPACNumerationType::instance()
0193 {
0194     static KalziumOldIUPACNumerationType koint;
0195     return &koint;
0196 }
0197 
0198 KalziumOldIUPACNumerationType::KalziumOldIUPACNumerationType()
0199     : KalziumNumerationType()
0200 {
0201     // cache them
0202     m_items << QStringLiteral("1A");
0203     m_items << QStringLiteral("2A");
0204     m_items << QStringLiteral("3A");
0205     m_items << QStringLiteral("4A");
0206     m_items << QStringLiteral("5A");
0207     m_items << QStringLiteral("6A");
0208     m_items << QStringLiteral("7A");
0209     m_items << QStringLiteral("8");
0210     m_items << QStringLiteral("8");
0211     m_items << QStringLiteral("8");
0212     m_items << QStringLiteral("1B");
0213     m_items << QStringLiteral("2B");
0214     m_items << QStringLiteral("3B");
0215     m_items << QStringLiteral("4B");
0216     m_items << QStringLiteral("5B");
0217     m_items << QStringLiteral("6B");
0218     m_items << QStringLiteral("7B");
0219     m_items << QStringLiteral("0");
0220 }
0221 
0222 QByteArray KalziumOldIUPACNumerationType::name() const
0223 {
0224     return "OldIUPAC";
0225 }
0226 
0227 QString KalziumOldIUPACNumerationType::description() const
0228 {
0229     return i18n("Old IUPAC");
0230 }