File indexing completed on 2024-05-12 16:45:37

0001 /***************************************************************************
0002     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
0003  ***************************************************************************/
0004 
0005 /***************************************************************************
0006  *                                                                         *
0007  *   This program is free software; you can redistribute it and/or         *
0008  *   modify it under the terms of the GNU General Public License as        *
0009  *   published by the Free Software Foundation; either version 2 of        *
0010  *   the License or (at your option) version 3 or any later version        *
0011  *   accepted by the membership of KDE e.V. (or its successor approved     *
0012  *   by the membership of KDE e.V.), which shall act as a proxy            *
0013  *   defined in Section 14 of version 3 of the license.                    *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful,       *
0016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0018  *   GNU General Public License for more details.                          *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0022  *                                                                         *
0023  ***************************************************************************/
0024 
0025 #include "coincollection.h"
0026 
0027 #include <KLocalizedString>
0028 
0029 namespace {
0030   static const char* coin_general = I18N_NOOP("General");
0031   static const char* coin_personal = I18N_NOOP("Personal");
0032 }
0033 
0034 using Tellico::Data::CoinCollection;
0035 
0036 CoinCollection::CoinCollection(bool addDefaultFields_, const QString& title_)
0037    : Collection(title_.isEmpty() ? i18n("My Coins") : title_) {
0038   setDefaultGroupField(QStringLiteral("denomination"));
0039   if(addDefaultFields_) {
0040     addFields(defaultFields());
0041   }
0042 }
0043 
0044 Tellico::Data::FieldList CoinCollection::defaultFields() {
0045   FieldList list;
0046   FieldPtr field;
0047 
0048   field = Field::createDefaultField(Field::TitleField);
0049   field->setProperty(QStringLiteral("template"), QStringLiteral("%{year}%{mintmark} %{type} %{denomination}"));
0050   field->setFlags(Field::NoDelete | Field::Derived);
0051   field->setFormatType(FieldFormat::FormatNone);
0052   list.append(field);
0053 
0054   field = new Field(QStringLiteral("type"), i18n("Type"));
0055   field->setCategory(i18n(coin_general));
0056   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0057   field->setFormatType(FieldFormat::FormatTitle);
0058   list.append(field);
0059 
0060   /* TRANSLATORS: denomination refers to the monetary value. */
0061   field = new Field(QStringLiteral("denomination"), i18nc("monetary denomination", "Denomination"));
0062   field->setCategory(i18n(coin_general));
0063   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0064   list.append(field);
0065 
0066   field = new Field(QStringLiteral("year"), i18n("Year"), Field::Number);
0067   field->setCategory(i18n(coin_general));
0068   field->setFlags(Field::AllowMultiple | Field::AllowGrouped);
0069   list.append(field);
0070 
0071   field = new Field(QStringLiteral("mintmark"), i18n("Mint Mark"));
0072   field->setCategory(i18n(coin_general));
0073   field->setFlags(Field::AllowGrouped);
0074   field->setFormatType(FieldFormat::FormatPlain);
0075   list.append(field);
0076 
0077   field = new Field(QStringLiteral("country"), i18n("Country"));
0078   field->setCategory(i18n(coin_general));
0079   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0080   field->setFormatType(FieldFormat::FormatPlain);
0081   list.append(field);
0082 
0083   field = new Field(QStringLiteral("currency"), i18n("Currency"));
0084   field->setCategory(i18n(coin_general));
0085   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0086   field->setFormatType(FieldFormat::FormatPlain);
0087   list.append(field);
0088 
0089   field = new Field(QStringLiteral("set"), i18n("Coin Set"), Field::Bool);
0090   field->setCategory(i18n(coin_general));
0091   list.append(field);
0092 
0093   QStringList grade = i18nc("Coin grade levels - "
0094                             "Proof-65,Proof-60,Mint State-65,Mint State-60,"
0095                             "Almost Uncirculated-55,Almost Uncirculated-50,"
0096                             "Extremely Fine-40,Very Fine-30,Very Fine-20,Fine-12,"
0097                             "Very Good-8,Good-4,Fair",
0098                             "Proof-65,Proof-60,Mint State-65,Mint State-60,"
0099                             "Almost Uncirculated-55,Almost Uncirculated-50,"
0100                             "Extremely Fine-40,Very Fine-30,Very Fine-20,Fine-12,"
0101                             "Very Good-8,Good-4,Fair")
0102 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
0103                       .split(QRegularExpression(QLatin1String("\\s*,\\s*")), QString::SkipEmptyParts);
0104 #else
0105                       .split(QRegularExpression(QLatin1String("\\s*,\\s*")), Qt::SkipEmptyParts);
0106 #endif
0107   field = new Field(QStringLiteral("grade"), i18n("Grade"), grade);
0108   field->setCategory(i18n(coin_general));
0109   field->setFlags(Field::AllowGrouped);
0110   list.append(field);
0111 
0112   QStringList service = i18nc("Coin grading services - "
0113                               "PCGS,NGC,ANACS,ICG,ASA,PCI",
0114                               "PCGS,NGC,ANACS,ICG,ASA,PCI")
0115 #if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
0116                         .split(QRegularExpression(QLatin1String("\\s*,\\s*")), QString::SkipEmptyParts);
0117 #else
0118                         .split(QRegularExpression(QLatin1String("\\s*,\\s*")), Qt::SkipEmptyParts);
0119 #endif
0120   field = new Field(QStringLiteral("service"), i18n("Grading Service"), service);
0121   field->setCategory(i18n(coin_general));
0122   field->setFlags(Field::AllowGrouped);
0123   list.append(field);
0124 
0125   field = new Field(QStringLiteral("pur_date"), i18n("Purchase Date"));
0126   field->setCategory(i18n(coin_personal));
0127   field->setFormatType(FieldFormat::FormatDate);
0128   list.append(field);
0129 
0130   field = new Field(QStringLiteral("pur_price"), i18n("Purchase Price"));
0131   field->setCategory(i18n(coin_personal));
0132   list.append(field);
0133 
0134   field = new Field(QStringLiteral("location"), i18n("Location"));
0135   field->setCategory(i18n(coin_personal));
0136   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0137   field->setFormatType(FieldFormat::FormatPlain);
0138   list.append(field);
0139 
0140   field = new Field(QStringLiteral("gift"), i18n("Gift"), Field::Bool);
0141   field->setCategory(i18n(coin_personal));
0142   list.append(field);
0143 
0144   field = new Field(QStringLiteral("obverse"), i18n("Obverse"), Field::Image);
0145   list.append(field);
0146 
0147   field = new Field(QStringLiteral("reverse"), i18n("Reverse"), Field::Image);
0148   list.append(field);
0149 
0150   field = new Field(QStringLiteral("comments"), i18n("Comments"), Field::Para);
0151   field->setCategory(i18n(coin_personal));
0152   list.append(field);
0153 
0154   list.append(Field::createDefaultField(Field::IDField));
0155   list.append(Field::createDefaultField(Field::CreatedDateField));
0156   list.append(Field::createDefaultField(Field::ModifiedDateField));
0157 
0158   return list;
0159 }