File: callsign.h

package info (click to toggle)
klog 2.4.3-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 12,344 kB
  • sloc: cpp: 51,720; makefile: 15
file content (112 lines) | stat: -rw-r--r-- 5,839 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef KLOG_CALLSIGN_H
#define KLOG_CALLSIGN_H
/***************************************************************************
                          callsign.h  -  description
                             -------------------
    begin                : ago 2024
    copyright            : (C) 2024 by Jaime Robles
    email                : jaime@robles.es
 ***************************************************************************/

/*****************************************************************************
 * This file is part of KLog.                                                *
 *                                                                           *
 *    KLog is free software: you can redistribute it and/or modify           *
 *    it under the terms of the GNU General Public License as published by   *
 *    the Free Software Foundation, either version 3 of the License, or      *
 *    (at your option) any later version.                                    *
 *                                                                           *
 *    KLog is distributed in the hope that it will be useful,                *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *    GNU General Public License for more details.                           *
 *                                                                           *
 *    You should have received a copy of the GNU General Public License      *
 *    along with KLog.  If not, see <https://www.gnu.org/licenses/>.         *
 *                                                                           *
 *****************************************************************************/
/*
    This class implements the object callsign to centralize all about callsigns
    The inspiration and part of the code is coming from QLog: https://github.com/foldynl/QLog/blob/master/core/Callsign.h
    Thank you Lada, OK1MLG.

    Important: https://cqwpx.com/rules.htm
    This classs hould not need to query the DB neither the DataProxy Class
*/
#include <QDebug>
#include <QObject>
#include <QRegularExpression>

class Callsign : public QObject
{
    Q_OBJECT
public:
    Callsign(const QString &callsign, QObject *parent = nullptr);
    ~Callsign();
    void operator()(const QString &newCallsign);

    //static QStringList secondarySpecialSuffixes;

    // K1/EA4K/QRP
    // Needed fields for a call are:
    // - hostFullPrefix (QString)   K1
    // - hostPrefix     (QString)   K
    // - hostAreaNumber (int)       1
    // - homeCallsign               EA4K
    // - homeFullPrefix (QString)   EA4
    // - homePrefix     (QString)   EA
    // - homeAreaNumber (int)       4
    // - homeSuffix     (QString)   K
    // - suffix         (QString)   QRP

    QString getCallsign();                                  // Returns the FULL callsign                                                                        (fullCall)
    QString getHostFullPrefix();    // The complete host prefix (simple + area number if exists)  , if only prefix it should be false   (hostFullPrefix)
    QString getHostPrefix();        // The host prefix (simple without area number if exists), if only prefix it should be false        (hostPrefix)
    int     getHostAreaNumber();    // Get host area number, if only prefix it should be false                                          (hostAreaNumber)
                                                            // if getHomeIfEmpty is true and no hostprefix is identified, it will return homePrefix


    QString getHomeCallsign();              // Returns the base / home callsign like EA4K in K1/EA4K, or EA4K/QRP   (fullCall)
    QString getHomeFullPrefix();            // The complete home prefix (simple + area number if exists)            (homeFullPrefix)
    QString getHomePrefix();                // The Home prefix without area number                                  (homePrefix)
    int     getHomeAreaNumber();            // Get the home area number                                             (homeAreaNumber)
    QString getHomeSuffix();                // The suffix of the home call                                          (homeSuffix)
    QString getSuffix();                    // Additional suffixes like /P, /QRP, /MM, ...                          (generalSuffix)

    bool isValid();                             // True if it is a full callsign
    bool isValidPrefix();                       // True if it is a prefix, but not a call
    bool isSimple();                            // True if it has no / nor \ characters, no prefix nor suffix
    bool isAOneLetterHostPrefix();   // True if is the prefix starts by B|F|G|I|K|M|N|R|U|W and is valid
    void clear();

private:
    static QString              getSpecialPrefixes();
    static QString              callsignRegExString();
    static QRegularExpression   callsignRegEx();
    static QString              prefixRegExString();
    static QRegularExpression   prefixRegEx();

    void    initialize(const QString &callsign);    // A helper to perform the initialization and prevent code duplication
                       //Returns the list of special prefixes for the REGEX

    QString fullCall;           // K1/EA4K/QRP
    QString hostFullPrefix;     // K1
    QString hostPrefix;         // K
    int     hostAreaNumber;     // 1
    QString homeCallsign;       // EA4K
    QString homeFullPrefix;     // EA4
    QString homePrefix;         // EA
    QString homeSuffix;         // K
    int     homeAreaNumber;     // 4
    QString generalSuffix;      // QRP


    bool valid;         // The entered string is a correct callsign
    bool prefValid;     // The entered string is a correct prefix




};

#endif // CALLSIGN_H