klog
datacache.h
1 #ifndef KLOG_DATACACHE_H
2 #define KLOG_DATACACHE_H
3 /***************************************************************************
4  datacache.h - description
5  -------------------
6  begin : Feb 2026
7  copyright : (C) 2026 by Jaime Robles
8  email : jaime@robles.es
9  ***************************************************************************/
10 
11 /*****************************************************************************
12  * This file is part of KLog. *
13  * *
14  * KLog is free software: you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation, either version 3 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * KLog is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with KLog. If not, see <https://www.gnu.org/licenses/>. *
26  * *
27  *****************************************************************************/
28 /*
29  This class implements Cache of data to prevent querying the database
30 
31 */
32 #include <QHash>
33 #include <QString>
34 #include "../frequency.h"
35 
36 struct BandEntry {
37  int id;
38  QString name;
39  Frequency minFreq;
40  Frequency maxFreq;
41 
42  // Helper to check inclusion
43  bool contains(Frequency freq) const { return (freq >= minFreq && freq <= maxFreq); }
44  // Helper to handle "Not Found" state
45  bool isValid() const { return !name.isEmpty(); }
46 };
47 
48 struct ModeEntry {
49  int id;
50  QString submode; // e.g. "USB", "FT8", "JT9C"
51  QString mode; // e.g. "SSB", "FT8", "JT9"
52  QString cabrillo = QString();
53  bool deprecated = false;
54  bool isValid() const { return !mode.isEmpty(); }
55 };
56 
57 struct EntityEntry {
58  int dxcc;
59  QString name;
60 };
61 
62 class DataCache
63 {
64  friend class tst_DataCache;
65 
66 public:
67  DataCache();
68  ~DataCache();
69 
70  // 1. Add Data (Call this when loading from DB)
71  void addBand(int id, const QString &name, Frequency min, Frequency max);
72  bool isBandListOK() const;
73 
74  // 2. Lookup by Frequency (Returns ID + Name via the struct)
75  BandEntry getBandFromFreq(Frequency freq) const;
76  BandEntry getBandFromName(const QString &name) const;
77  BandEntry getBandFromId(int id) const;
78 
79  void addMode(int id, const QString &submode, const QString &mode, const QString &cabrillo, bool deprecated);
80  bool isModeListOK() const;
81 
82  ModeEntry getModeFromSubmode(const QString &submode) const;
83  ModeEntry getModeFromId(int id) const;
84  int getModeIdFromSubmode(const QString &submode) const; // quick shortcut
85  QString getModeNameFromSubmode(const QString &submode) const; // quick shortcut
86  bool isModeDeprecated(const QString &submode) const;
87 
88  void addEntity(int dxcc, const QString &name);
89  EntityEntry getEntityFromDXCC(int dxcc) const; // quick shortcut
90  QString getEntityNameFromDXCC(int dxcc) const; // quick shortcut
91  bool isEntityListOK() const;
92 
93 private:
94  QList<BandEntry> bandList;
95  QList<ModeEntry> modeList;
96  QList<EntityEntry> entityList;
97  bool bandListIsBuilt, modeListIsBuilt, entityListIsBuilt;
98 };
99 
100 #endif // DATACACHE_H
Definition: tst_datacache.cpp:5
Definition: datacache.h:62
Definition: datacache.h:57
Definition: datacache.h:48
Definition: frequency.h:36
Definition: datacache.h:36