klog
dataproxy_sqlite.h
1 #ifndef KLOG_DATAPROXY_SQLITE_H
2 #define KLOG_DATAPROXY_SQLITE_H
3 
4 /***************************************************************************
5  dataproxy_sqlite.h - description
6  -------------------
7  begin : feb 2015
8  copyright : (C) 2015 by Jaime Robles
9  email : jaime@robles.es
10  ***************************************************************************/
11 
12 /*****************************************************************************
13  * This file is part of KLog. *
14  * *
15  * KLog is free software: you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation, either version 3 of the License, or *
18  * (at your option) any later version. *
19  * *
20  * KLog is distributed in the hope that it will be useful, *
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23  * GNU General Public License for more details. *
24  * *
25  * You should have received a copy of the GNU General Public License *
26  * along with KLog. If not, see <https://www.gnu.org/licenses/>. *
27  * *
28  *****************************************************************************/
29 #include <QString>
30 #include <QStringList>
31 #include <QVariant>
32 #include <QObject>
33 #include <QSqlQuery>
34 #include <QPair>
35 #include <QMultiHash>
36 #include <QDateTime>
37 #include <QFuture>
38 #include <QList>
39 
40 #include "global.h"
41 #include "database/database.h"
42 #include "database/datacache.h"
43 #include "frequency.h"
44 #include "qso.h"
45 #include "utilities.h"
46 #include "klogdefinitions.h"
47 //#include "regionalaward.h"
48 
49 class QSO;
50 
51 enum
52 {
53  CQZones = 40,
54  ITUZones = 90,
55  DXCCEntities = 521 // http://www.adif.org/adif302.htm#Country%20Codes
56 };
57 
58 // Structure to hold the band limits for fast in-memory range checks
59 struct BandLimits
60 {
61  int id;
62  double lower;
63  double upper;
64 };
65 
66 class DataProxy_SQLite : public QObject
67 {
68  Q_OBJECT
69 
70 public:
71  DataProxy_SQLite(const QString &_parentFunction, const QString &_softVersion="0.0");
72  DataProxy_SQLite(const QString &_parentFunction, const QString &_softVersion, const QString &_dbPath);
74  void setLogLevel (const DebugLogLevel _l);
75  QString getSoftVersion();
76  void setPKGVersion(const QString &_pkgVersion);
77  QString getPKGVersion();
78  QString getDBVersion();
79  bool reconnectDB();
80 
81  void createLogModel();
82  void createLogPanel();
83  bool haveAtLeastOneLog();
84 
85  QStringList getColumnNamesFromTableLog();
86 
87  int getIdFromModeName(const QString& _modeName);
88  int getIdFromBandName(const QString& _bandName);
89  //int getSubModeIdFromSubMode(const QString &_subModeName);
90 
91  bool isValidMode(const QString& _modeName);
92  bool isValidBand(const QString& _bandName);
93 
94  //int getModeIdFromSubModeId(const int _sm);
95  // CACHE & HASH functions — superseded by loadCacheBG() + ensureCacheReady() (background thread)
96  KLOG_DEPRECATED bool createHashes();
97  void loadBandDataCache(); // internal: called only by createHashes()
98  void loadModeDataCache(); // internal: called only by createHashes()
99  void loadEntityDataCache(); // internal: called only by createHashes()
100 
101  QStringList getFields();
102  //KLOG_DEPRECATED QStringList getBands();
103  QStringList getModes(); // Returns the list of submodes
104  QStringList getSubModes();
105  QStringList getModesAndSubmodes();
106  QStringList sortBandNamesBottonUp(const QStringList _qs);
107  QStringList getBandIDs();
108  QStringList getModesIDs();
109  QStringList getBandsInLog(const int _log);
110  QStringList getModesInLog(const int _log);
111  int getMostUsedBand(const int _log);
112  int getMostUsedMode(const int _log);
113 
114  QString getNameFromBandId (const int _id);
115  KLOG_DEPRECATED QString getNameFromModeId(const int _id); // datacache
116 
117  QString getSubModeFromId (const int _id);
118  QString getNameFromSubMode (const QString &_sm); // Checks if a submode is deprecated TODO: CHeck if really needed
119  QList<int> getModeGroupIds(const int _modeId); // Returns all mode IDs sharing the same parent mode
120  // qString getNameFromSubMode (const QString &_sm); // DEPRECATED
121  bool isModeDeprecated (const QString &_sm);
122 
123  //Frequency getFreqFromBandId(const int _id);
124  int getBandIdFromFreq(const Frequency _n);
125  QString getBandNameFromFreq(const Frequency _n);
126 
127 
128  Frequency getLowLimitBandFromBandName(const QString &_sm);
129  Frequency getLowLimitBandFromBandId(const int _sm);
130  Frequency getUpperLimitBandFromBandName(const QString &_sm);
131  bool isThisFreqInBand(const QString &_band, const Frequency _fr);
132 
133  int getLastQSOid(); // Returns the MAX QSO id
134  int getLastInsertedQSO(); // Return the last inserted
135  QDate getFirstQSODateFromCall (const QString &_call); // If the callsign provided is not valid it provides the date of the first QSO
136  QDate getLastQSODateFromCall (const QString &_call); // If the callsign provided is not valid it provides the date of the last QSO
137 
138  bool addQSOFromWSJTX (const QString &_dxcall, const QString &_mode, const QString &_band, const double _freq,
139  const QString &_mygrid, const QString &_dxgrid,
140  const QString &_rstTX, const QString &_rstRX, const QString &_sRX, const QString &_sTX,
141  const QString &_comment,
142  const QString &_stationcallsign, const QString &_name, const QString &_operator,
143  const QDateTime &_datetime, const QDateTime &_datetime_off, const double txpower,
144  const int _dxcc, const int _logNumber, bool _sendQSL = true);
145 
146  int addQSO(QSO &_qso);
147  QSO fromDB(const int _qsoId);
148  bool updateQSOFromLoTW(const QSO &_lotwQso, const int _qsoId); // TODO: Check if still needed
149  bool applyLoTWFieldsToQSO(const QSO &_lotwQso, const int _qsoId);
150 
151 
152  //int addQSOQuery(const QSqlQuery &_q);
153 
154  bool deleteQSO(const int _qsoId);
155  int isWorkedB4(const QString &_qrz, const int _currentLog);
156  // qList<int> isThisQSODuplicated(const QString &_callingFunc, const QString &_qrz, const QDateTime &_dateTime, const int _band, const int _mode, const int _secs);
157  int isThisQSODuplicated(const QSO &_qso, const int _secs); // It calls int findDuplicateId
158  //int getDuplicatedQSOId(const QString &_qrz, const QDateTime &_datetime, const int _band, const int _mode);
159  //bool isDXCCConfirmed(const int _dxcc, const int _currentLog);
160  bool isQSLReceived(const int _qsoId);
161  bool isQSLLoTWReceived(const int _qsoId);
162  bool isQSOConfirmed(const int _qsoId, const bool _checkPaper, const bool _checkLoTW);
163  bool isQSLSent(const int _qsoId);
164 
165  bool qslSentViaDirect(const int _qsoId, const QDate &_updateDate);
166  bool qslSentViaBureau(const int _qsoId, const QDate &_updateDate);
167  bool qslRecViaBureau(const int _qsoId, const QDate &_updateDate);
168  bool qslRecViaBureau(const int _qsoId, const QDate &_updateDate, const bool _queueSentQSL);
169  bool qslRecViaDirect(const int _qsoId, const QDate &_updateDate);
170  bool qslRecViaDirect(const int _qsoId, const QDate &_updateDate, const bool _queueSentQSL);
171  bool qslSentAsRequested(const int _qsoId, const QDate &_updateDate);
172  bool qslRecAsRequested(const int _qsoId, const QDate &_updateDate);
173  bool setClubLogSent(const int _qsoId, const QString &_st, const QDate &_updateDate);
174  bool setLoTWQSLRec (const int _qsoId, const QString &_st, const QDate &_updateDate);
175 
176  bool isHF(const int _band);
177  bool isWARC(const int _band);
178  bool isVHF(const int _band);
179  bool isUHF(const int _band);
180 
181  int getBandFromId(const int _qsoId);
182  int getModeFromId(const int _qsoId);
183  int getDXCCFromId(const int _qsoId);
184  int getCQZFromId(const int _qsoId);
185  QList<int> getBandModeDXCCCQZlogIDFromId(const int _qsoId);
186 
187  QString getCallFromId(const int _qsoId);
188  QStringList getClubLogRealTimeFromId(const int _qsoId);
189 
190  QStringList getFilteredLocators(const QString &_band, const QString &_mode, const QString &_prop, const QString &_sat, bool _confirmed = false);
191  // Returns list of {id, callsign, band, mode} maps for QSOs matching a locator prefix and current filters
192  QVariantList getQSOsForLocator(const QString &_locator, const QString &_band, const QString &_mode, const QString &_prop, const QString &_sat, bool _confirmed = false);
193  //bool updateAwardWAZ();
194  // QRZ.com
195  bool QRZCOMModifyFullLog(const int _currentLog); // Mark all the log as modified to be sent to QRZ.com
196  bool QRZCOMSentQSOs(const QList<int> &_qsos); // Mark as uploaded
197  // QRZ.com
198  //EQSL
199  bool eQSLModifyFullLog(const int _currentLog); // Mark all the log as modified to be sent to eQSL
200  bool eQSLSentQSOs(const QList<int> &_qsos); // Mark as uploaded
201 
202  //EQSL
203 
204  //CLUBLOG
205  bool clublogSentQSOs(const QList<int> &_qsos); // Mark as uploaded
206  bool clublogModifyFullLog(const int _currentLog); // Mark all the log as modified to be sent to CLubLog
207  // CLUBLOG
208 
209  //LOTW
210  bool lotwSentQueue(const QDate &_updateDate, const int _currentLog); // Mark LOTW QSL SENT as Q (Queued)
211  bool lotwSentYes(const QDate &_updateDate, const int _currentLog, const QString &_station); // Update LOTW QSL SENT marked as Q as Y (Queued)
212  bool lotwSentQSOs(const QList<int> &_qsos);
213  int lotwUpdateQSLReception (const QString &_call, const QDateTime &_dateTime, const QString &_band, const QString &_mode, const QDate &_qslrdate);
214  QList<int> getQSOsListLoTWToSend(const QString &_stationCallsign, const QString &_myGrid, const QDate &_startDate, const QDate &_endDate, bool _justQueued=true, int _logN = -1);
215  // qStringList getQSOsListLoTWNotSent2(const QString &_stationCallsign, const QDate &_startDate, const QDate &_endDate, bool _justQueued=true);
216  QStringList getQSODetailsForLoTWDownload(const int _id);
217 
218  QList<int> getQSOsListeQSLNotSent(const QString &_stationCallsign, const QDate &_startDate, const QDate &_endDate, bool _justQueued=true);
219 
220  QList<int> getQSOsListClubLogToSent(const QString &_stationCallsign, const QDate &_startDate, const QDate &_endDate, bool _justModified=true, int _logN = -1);
221  QList<int> getQSOsListEQSLToSent(const QString &_stationCallsign,
222  const QDate &_startDate,
223  const QDate &_endDate,
224  bool _justModified = true,
225  int _logN = -1);
226  QList<int> getQSOsListQRZCOMToSent(const QString &_stationCallsign, const QDate &_startDate, const QDate &_endDate, bool _justModified=true, int _logN = -1);
227  QList<int> getQSOsListToBeExported(const QString &_stationCallsign, const QString &_grid, const QDate &_startDate, const QDate &_endDate, int _logN = -1);
228  QList<int> getQSOsAll();
229  QStringList getGridsToBeSent(const QString &_stationCallsign, const QDate &_startDate, const QDate &_endDate, const ExportMode _em, bool _justModified=true, int _logN = -1);
230 
231 
232  int getContinentIdFromContinentShortName(const QString &_n);
233  QString getContinentShortNameFromEntity(const int _n);
234  int getContinentIdFromEntity(const int _n);
235  QStringList getContinentShortNames();
236  bool isValidContinentShortName(const QString &_n);
237  bool isValidDXCC(const int _e);
238  QStringList filterValidFields(const QStringList &_fields);
239 
240  int getCQzFromPrefix(const QString &_p);
241  int getCQzFromEntity(const int _n);
242  int getITUzFromEntity(const int _n);
243  int getITUzFromPrefix(const QString &_p);
244  QString getEntityNameFromId(const int _n);
245  int getEntityIdFromName(const QString &_e);
246  QString getEntityMainPrefix(const int _entityN);
247  QMap<EntityData, int> getAllEntiNameISOAndPrefix();
248 
249  int getEntityIdFromMainPrefix(const QString &_e);
250  bool isNewCQz(int _c);
251  bool isNewEntity(int _e);
252  double getLongitudeFromEntity(const int _e);
253  double getLatitudeFromEntity(const int _e);
254  //KLOG_DEPRECATED int getDXCCFromPrefix(const QString &_p); // TODO: Replace by int World::getPrefixId(const QString &_prefix)
255  QString getEntityPrefixes(const int _enti);
256  QStringList getLongPrefixes();
257  QStringList getSpecialCallsigns();
258 
260  QString callsign;
261  int dxcc;
262  int cqz;
263  int ituz;
264  };
265  QList<SpecialCallsignInfo> getSpecialCallsignPairs();
266  bool addSpecialCallsign(const QString &callsign, int dxccId, int cqz = -1, int ituz = -1);
267  bool removeSpecialCallsign(const QString &callsign);
268  // Mirror of the +1000 logic in World::readCTYCSV(): given a callsign and its
269  // base ARRL DXCC, look up prefixesofentity to find the KLog sub-entity
270  // (id >= 1000 whose id % 1000 matches the base). Returns 0 if none found.
271  int getKLogSubEntityForCallsign(const QString &callsign, int baseDxcc);
272  QHash<QString, int> getWorldData();
273  //bool getFreqHashData();
274 
275  QStringList getEntitiesNames(bool _dxccOnly = true);
276  QStringList getEntitiesIds();
277  int getHowManyEntities();
278  int getMaxEntityID(bool limit = true); // limit = true implies that it will only shouw ARRL valid DXCC (i.e. will not count Sicily)
279  QList<int> getListOfDXCCIds(); // Returns the list of valid DXCC id
280  QStringList getOperatingYears(const int _currentLog);
281  void compressDB();
282  bool unMarkAllQSO(); // Unmarks all the marked QSO
283 
284  bool clearLog();
285 
286 
287  // Stats
288  int getQSOonYear(const int _year, const int _logNumber, const QList<int> &modeIds = {});
289  int getDXCConYear(const int _year, const int _logNumber, const QList<int> &modeIds = {});
290  int getCQzonYear(const int _year, const int _logNumber, const QList<int> &modeIds = {});
291  int getQSOsWithDXCC(const int _dxcc, const int _logNumber);
292  int getQSOsAtHour(const int _hour, const int _log);
293  int getQSOsAtHourOnBand(const int _hour, const int _band ,const int _log);
294  int getQSOsOnMonth(const int _month, const int _log);
295 
296  int getHowManyQSOInLog(const int _log, const QList<int> &modeIds = {});
297  int getHowManyConfirmedQSLInLog(const int _log, const QList<int> &modeIds = {});
298  int getHowManyQSLSentInLog(const int _log);
299 
300  int getQSOsWithContinent(const QString &_cont, const int _logNumber);
301 
302  int getQSOsInBand(const QString &_band, const int _log);
303  int getQSOsInMode(const QString &_mode, const int _log);
304  int getDXCCInBand(const int _bandid, const bool _confirmed, const int _log);
305 
306  QList<QList<int>> getTop10QSOPerDXCC(const int _log);
307 
308  // Stats - end
309  bool updateQSONumberPerLog();
310 
311  bool newDXMarathon(const int _dxcc, const int _cq, const int _year, const int _logNumber);
312 
313  QStringList getContestNames();
314  QStringList getContestCat(const int _catn);
315  QStringList getContestOverlays();
316  //int getContestTypeN(const int _co, const int _catop, const int _catas, const int _catpo, const int _catba, const int _catov, const int _catmo);
317  // qStringList getDataFromContestType(const int _n);
318  //int getLogTypeNumber(const QString &_logType);
319  // qString getLogTypeName(const int _logType);
320  // qString getLogTypeOfUserLog(const int _logN);
321  int getLogNumberFromQSOId(const int _qsoId);
322 
323  QStringList getBandNames();
324  QStringList getPropModeList();
325  bool isValidPropMode(const QString &_prop);
326 
327  bool clearSatList();
328  bool addSatellite(const QString &_arrlId, const QString &_name, const QString &_downLink, const QString &_upLink, const QString &_mode, int id = -1);
329  int getDBSatId(const QString &_arrlId);
330  QStringList getSatellitesList();
331  Frequency getSatelliteUplink(const QString &_sat, int _pair=0);
332  Frequency getSatelliteDownlink(const QString &_sat, int _pair=0);
333  QString getSatelliteMode(const QString &_sat);
334  QString getSatelliteFullUplink(const QString &_sat);
335  QString getSatelliteFullDownlink(const QString &_sat);
336  QString getSatelliteFullMode(const QString &_sat);
337  QString getSatelliteName(const QString &_sat);
338  QString getSateliteArrlIdFromId(const int _id);
339  //KLOG_DEPRECATED QStringList getQSLRcvdList();
340  // qStringList getQSLSentList();
341  //KLOG_DEPRECATED QStringList getClubLogStatusList();
342  KLOG_DEPRECATED QStringList getQSLViaList();
343  int getHowManyQSOPerPropMode(const QString &_p, const int _logn);
344 
345 
346  // qStringList getValidCatOptions(const int _currentCat, const int _lowerCa);
347 
348  //bool fillEmptyDXCCInTheLog();
349 
350  int getNumberOfManagedLogs();
351  QStringList getListOfManagedLogs();
352  int getMaxLogNumber();
353  QString getStationCallSignFromLog(const int _log);
354  QStringList getStationCallSignsFromLog(const int _log);
355  QStringList getStationCallSignsFromLogWithLoTWPendingToSend(const int _log);
356  QString getOperatorsFromLog(const int _log);
357  QString getCommentsFromLog(const int _log);
358  QString getLogDateFromLog(const int _log);
359  // qString getLogTypeNFromLog(const int _log);
360  bool addNewLog (const QStringList _qs);
361  bool doesThisLogExist(const int _log);
362 
363  bool updateISONames(); // Update the entities ISO 3166names for the flags
364  QString getISOName(const int _n);
365  bool addPrimarySubdivisions(); // Add the primary subdivisions to the BD
366  //bool setDXCCAwardStatus(const int _qsoId);
367  KLOG_DEPRECATED bool setWAZAwardStatus(const int _qsoId);
368 
369  //bool addRegionalAward(RegionalAward _regionalAward);
370  bool addDXCCEntitySubdivision(const QString &_name, const QString &_short, const QString &_pref, const QString &_group, const int _regId, const int _dxcc, const int _cq, const int _itu, const QDate &_startDate, const QDate &_endDate, const bool _deleted);
371  QList<PrimarySubdivision> getPrimarySubDivisions(const int _entity, const QString &_pref); // Get the Primary subdivisions for an entity
372 
373  //void getFoundInLog(const QString &_txt, const int _log=-1);
374  //KLOG_DEPRECATED QString getADIFQSO(const int _qsoId, ExportMode _em = ModeADIF);
375  KLOG_DEPRECATED QString getADIFValueFromRec(const QSqlRecord &_rec, const QString &_fieldName); // Should be optimized to qso::fromDB / qso::getADIF
376  KLOG_DEPRECATED QString getADIFFromQSOQuery(QSqlRecord _rec, ExportMode _em = ModeADIF, bool _justMarked = false, bool _onlyRequested = false, int _logN = -1); // Should be optimized to qso::fromDB / qso::getADIF
377  // qString getADIFFromQSOQuery2(QSqlRecord _rec, ExportMode _em = ModeADIF, bool _justMarked = false, bool _onlyRequested = false, int _logN = -1);
378 
379  bool showInvalidCallMessage(const QString &_call);
380 
381  QList<QSO*> getSatGridStats(int _log=-1);
382  QList<QSO*> getGridStats(int _log=-1);
383  QList<QSO*> getSatDXCCStats(int _log=-1);
384 
385  int getFieldInBand(ValidFieldsForStats _field, const QString &_band, bool confirmedOnly, QString _mode = "ALL", int _log=-1, const QList<int> &modeIds = {});
386  //bool queryPrepare(const QString &_query);
387  //bool queryBind(const QString &_field, const QString &value);
388  //bool queryExec();
389 
390  // Transaction Wrappers
391  bool beginTransaction();
392  bool commitTransaction();
393  bool rollbackTransaction();
394 
395  // Cache functions // DUPEs
396  void loadDuplicateCache(int logId);
397  void clearDuplicateCache();
398  void addDuplicateCache (int _qsoId, const QSO &qso, const int _bandId, const int _modeId);
399  void removeDuplicateCache(int _qsoId);
400  int findDuplicateId(const QString &call, const QDateTime &newTime, int bandId, int modeId, int marginSeconds);
401  inline int findDuplicateId(const QSO &qso, int marginSeconds)
402  {
403  int modeId = getIdFromModeName(qso.getSubmode().isEmpty() ? qso.getMode() : qso.getSubmode());
404  return findDuplicateId(qso.getCall(), qso.getDateTimeOn(), getIdFromBandName(qso.getBand()), modeId, marginSeconds);
405  }
406 
407  //QHash<QString, int> getHashTableData(const DataTableHash _data);
408 
409 
410 private:
411  typedef QPair<int, QDateTime> QsoInfo; // QSOid link to QSO-DateTime
412  static QDateTime normalizeForCache(const QDateTime &dt)
413  {
414  // Trunca a segundos y fuerza Qt::UTC para comparaciones consistentes
415  return QDateTime(dt.date(), QTime(dt.time().hour(),
416  dt.time().minute(),
417  dt.time().second()),
418  QTimeZone::UTC);
419  }
420 
421  bool dbCreated;
422  DataBase *db;
423  QSqlQuery m_insertQuery; // Pre-prepared query, just once
424  QSqlQuery m_updateQuery; // To manage ADIF import query
425  bool m_queriesPrepared = false; // Pre-prepared query status
426 
427  QStringList sortBandIdBottonUp(const QStringList _qs);
428  Frequency getFreqFromRange(const QString &_fr, int _pair, FreqUnits FreUnits); //May even receive: 145.900-146.00 and should return the mid in the range (145.950)
429  QStringList getColumnNamesFromTable(const QString &_tableName);
430  QString getStringQueryStationCallSign (const QString &_a); // Creates part of a query regarding the station_call field
431  QString getStringQueryMyGrid (const QString &_a); // Creates part of a query regarding the my_gridsquare field
432  QString getStringQueryLogNumber (const int _a); // Creates part of a query regarding the lognumber field
433  QString getAddQueryString(); // Gets the query to add a QSO
434  QString getModifyQueryString(); // Gets the query to modify a QSO
435  QSqlQuery getPreparedQuery(const QString &_s, const QSO &_qso); // Prepares the query to add QSOs
436  void prepareStaticQueries(); // prepares the static query to save time in run time
437  void bindQSOValues(QSqlQuery &query, const QSO &_qso);
438  //void mapModeNameSubmode(); // Maps mode/Submode/id using submodeToName & nameToMainId
439 
440  // Helper function to simplify several functions
441  QString getStringQueryForQSOsLists(const QString &_stationCallsign,
442  const OnLineProvider &_provider,
443  const bool _justModified,
444  const QDate &_startDate,
445  const QDate &_endDate,
446  const int _logN);
447  QString getQueryJustModifiedString(const OnLineProvider &_provider, const bool _justModified);
448 
449  void logEvent(const QString &_func, const QString &_msg, DebugLogLevel _level);
450  //QSO *qso;
451  bool searching;
452  int executionN;
453  Utilities *util;
454  DebugLogLevel logLevel;
455  QString pkgVersion;
456 
457  //KLOG_DEPRECATED QList<BandLimits> m_bandLimits; // List to store all band limits, populated once on startup
458  //KLOG_DEPRECATED QHash<int, Frequency> freqBandIDHash; // Move to DataCache
459  //KLOG_DEPRECATED QHash<QString, int> bandIDs; // Move to DataCache
460  //KLOG_DEPRECATED QHash<QString, int> modeIDs; // Move to DataCache
461 
462  DataCache m_cache; // Bands/Modes/Entity cache — populated lazily via ensureCacheReady()
463 
464  // Background cache loading (Proposal 6)
465  struct CacheLoadResult {
466  QList<BandEntry> bands;
467  QList<ModeEntry> modes;
468  QList<EntityEntry> entities;
469  bool ok = false;
470  };
471  static CacheLoadResult loadCacheBG(const QString &dbPath); // Runs in a worker thread
472  void ensureCacheReady(); // Waits for background load and populates m_cache (idempotent)
473  QFuture<CacheLoadResult> m_cacheFuture;
474  bool m_cachePopulated = false;
475 
476  //KLOG_DEPRECATED QHash<int, QString> modeIdToName; // Move to DataCache
477  //KLOG_DEPRECATED QHash<QString, QList<int>> nameToModeIds; // Move to DataCache
478 
479  using DupeCacheData = QMultiHash<QString, QsoInfo>;
480  static DupeCacheData loadDupeCacheBG(const QString &dbPath, int logId);
481  void ensureDupeCacheReady();
482  QFuture<DupeCacheData> m_dupeCacheFuture;
483  bool m_dupeCacheLoading = false;
484 
485  QMultiHash<QString, QsoInfo>
486  m_qsoCache; // List for DUPES The String is the "hash" created generateGroupingKey IDs vs QDateTime
487  static QString generateGroupingKey(const QString &call, int bandId, int modeId);
488 
489  //bool loadBandLimits(); // Function to populate the m_bandLimits list from the database
490  QMetaObject::Connection connections; // To track the connection so its possible to disconnect
491  // qSqlQuery preparedQuery;
492  // qSqlRelationalTableModel *logModel;
493 private slots:
494  void slotCaptureDebugLogs(const QString &_func, const QString &_msg, DebugLogLevel _l);
495 signals:
496  void qsoFound(const QStringList _qs); // Each: QString with format: Fieldname:value
497  void queryError(QString functionFailed, QString errorCodeS, QString nativeError, QString failedQuery); // To alert about any failed query execution
498  void debugLog (QString _func, QString _msg, DebugLogLevel _level);
499  void qsoDeleted(int qsoId);
500  void logChanged(); // General signal for log change
501 };
502 
503 #endif //DATAPROXY_SQLITE_H
Definition: database.h:49
Definition: utilities.h:54
Definition: dataproxy_sqlite.h:259
Definition: qso.h:40
Definition: datacache.h:62
Definition: dataproxy_sqlite.h:59
Definition: frequency.h:36
Definition: dataproxy_sqlite.h:66