2015-01-14 18:51:30 +00:00
|
|
|
#ifndef DATABASE_H
|
|
|
|
#define DATABASE_H
|
|
|
|
/***************************************************************************
|
|
|
|
database.h - description
|
|
|
|
-------------------
|
|
|
|
begin : sept 2011
|
|
|
|
copyright : (C) 2011 by Jaime Robles
|
|
|
|
email : jaime@robles.es
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2015-11-23 17:36:29 +00:00
|
|
|
* This file is part of KLog. *
|
2015-01-14 18:51:30 +00:00
|
|
|
* *
|
2015-11-23 17:36:29 +00:00
|
|
|
* KLog is free software: you can redistribute it and/or modify *
|
2015-01-14 18:51:30 +00:00
|
|
|
* 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. *
|
|
|
|
* *
|
2015-11-23 17:36:29 +00:00
|
|
|
* KLog is distributed in the hope that it will be useful, *
|
2015-01-14 18:51:30 +00:00
|
|
|
* 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 *
|
2015-11-23 17:36:29 +00:00
|
|
|
* along with KLog. If not, see <http://www.gnu.org/licenses/>. *
|
2015-01-14 18:51:30 +00:00
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-04-20 17:55:01 +00:00
|
|
|
#include <QObject>
|
2015-01-14 18:51:30 +00:00
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QtSql>
|
|
|
|
#include <QString>
|
|
|
|
#include <QDateTime>
|
2015-04-20 17:55:01 +00:00
|
|
|
#include <QInputDialog>
|
2015-07-19 18:26:11 +00:00
|
|
|
#include <QProgressDialog>
|
|
|
|
#include "utilities.h"
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
class QSqlRelationalTableModel;
|
|
|
|
|
2016-01-09 11:35:01 +00:00
|
|
|
// Last db update 0.0.6
|
|
|
|
// Previous db update 0.0.7
|
2016-07-31 12:41:34 +00:00
|
|
|
const float DBVersionf = 0.009;
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
class DataBase
|
|
|
|
{
|
2015-03-18 18:42:16 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
public:
|
2015-04-20 17:55:01 +00:00
|
|
|
DataBase();
|
2015-01-14 18:51:30 +00:00
|
|
|
DataBase(const QString _softVersion, bool inmemoryonly = false);
|
|
|
|
~DataBase();
|
|
|
|
bool createConnection();
|
|
|
|
|
|
|
|
//bool beginTransaction();
|
|
|
|
|
|
|
|
bool isValidBand (const QString b);
|
2015-11-14 11:07:54 +00:00
|
|
|
bool isValidMode (const QString b, const bool _tmp);
|
2015-01-14 18:51:30 +00:00
|
|
|
bool isValidBandNumber (const int b);
|
|
|
|
bool isValidModeNumber (const int b);
|
|
|
|
QString getBandNameFromNumber(const int _n);
|
2015-11-14 11:07:54 +00:00
|
|
|
QString getModeNameFromNumber(const int _n, const bool _tmp);
|
|
|
|
QString getSubModeNameFromNumber(const int _n, const bool _tmp);
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
int getBandIdFromName(const QString b);
|
|
|
|
int getModeIdFromName(const QString b);
|
2015-11-14 11:07:54 +00:00
|
|
|
int getModeIdFromSubMode(const QString b, const bool _tmp);
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
bool createBandModeMaps();
|
|
|
|
int getBandIDFromName2(const QString b);
|
|
|
|
int getModeIDFromName2(const QString b);
|
|
|
|
QString getBandNameFromID2(const int _i);
|
|
|
|
QString getModeNameFromID2(const int _i);
|
|
|
|
|
|
|
|
int getBandIdFromFreq(const QString fr); //Freq should be in MHz
|
2015-04-19 17:24:07 +00:00
|
|
|
bool isThisFreqInBand(const QString b, const QString fr); //Freq should be in MHz
|
2015-01-14 18:51:30 +00:00
|
|
|
|
2015-11-23 17:36:29 +00:00
|
|
|
QString getFreqFromBandId(const int _i);
|
2015-01-18 20:04:46 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
bool unMarkAllQSO();
|
|
|
|
bool updateIfNeeded();
|
|
|
|
void compress();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool createDataBase();
|
|
|
|
bool isTheDBCreated();
|
|
|
|
bool updateToLatest();
|
|
|
|
bool updateTo003(); // Updates the DB to 0.0.3
|
|
|
|
bool updateTo004();
|
2015-02-23 19:25:55 +00:00
|
|
|
bool updateTo005();
|
2015-05-03 11:19:18 +00:00
|
|
|
bool updateTo006();
|
2015-11-14 11:07:54 +00:00
|
|
|
bool updateTo007();
|
2016-01-09 11:35:01 +00:00
|
|
|
bool updateTo008();
|
2016-07-31 12:41:34 +00:00
|
|
|
bool updateTo009(); // Updates DB and add the Satellite tables
|
2015-07-11 10:41:41 +00:00
|
|
|
bool updateTableLog(const int _v);
|
2015-06-13 11:12:15 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
bool createTheBandQuickReference();
|
|
|
|
bool createTheModeQuickReference();
|
2015-03-01 19:32:29 +00:00
|
|
|
|
2015-03-18 18:42:16 +00:00
|
|
|
bool updateLog(); // Updates the log table
|
2015-05-23 10:35:39 +00:00
|
|
|
bool createTableLog(bool temp = false); // false creates the prouction DB. True a temporal one.
|
2015-04-19 17:24:07 +00:00
|
|
|
bool createTableLogs();
|
2015-05-03 11:19:18 +00:00
|
|
|
bool createTablePropModes();
|
2015-05-23 18:34:30 +00:00
|
|
|
bool createTableClubLogStatus();
|
|
|
|
bool populateTableClubLogStatus();
|
2016-01-09 11:35:01 +00:00
|
|
|
|
2015-07-11 10:41:41 +00:00
|
|
|
bool createTableMode(const bool NoTmp);
|
|
|
|
bool populateTableMode(const bool NoTmp);
|
2016-01-09 11:35:01 +00:00
|
|
|
bool updateTheModeTableAndSyncLog();
|
|
|
|
|
2015-07-11 10:41:41 +00:00
|
|
|
bool createTableBand(const bool NoTmp);
|
|
|
|
bool populateTableBand(const bool NoTmp);
|
2015-03-01 19:32:29 +00:00
|
|
|
|
2016-07-31 12:41:34 +00:00
|
|
|
bool createTableSatellites(const bool NoTmp);
|
|
|
|
bool populateTableSatellites(const bool NoTmp);
|
|
|
|
|
2015-02-28 20:50:49 +00:00
|
|
|
bool recreateContestData();
|
|
|
|
bool createTableContest();
|
2015-02-23 19:25:55 +00:00
|
|
|
bool populateContestData();
|
2015-05-03 11:19:18 +00:00
|
|
|
bool populatePropagationModes();
|
|
|
|
|
2015-03-18 18:42:16 +00:00
|
|
|
bool howManyQSOsInLog(const int i);
|
2015-08-17 15:54:45 +00:00
|
|
|
//void showError(const QString _errorC);
|
2015-02-23 19:25:55 +00:00
|
|
|
|
2015-07-11 10:41:41 +00:00
|
|
|
bool moveFromModeIdToSubmodeId();
|
|
|
|
bool updateModeIdFromSubModeId();
|
|
|
|
bool updateBandIdTableLogToNewOnes();
|
2015-07-26 19:02:47 +00:00
|
|
|
bool updateBandIdTableAward(const int _db);
|
|
|
|
bool updateModeIdTableAward(const int _db);
|
2015-07-11 10:41:41 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
float dbVersion; // The current version of the DB. May differ from latestReaded if we are updating the DB!
|
|
|
|
QString softVersion;
|
|
|
|
float latestReaded; // The latest version of DB readed in the DB itself
|
|
|
|
bool inMemoryOnly; // The DB is to be created in memory, no file support... Faster but less safe!
|
|
|
|
QDateTime date;
|
|
|
|
QHash<QString, int> bandIDHash;
|
|
|
|
QHash<QString, int> modeIDHash;
|
|
|
|
QHash<int, QString> IDBandHash;
|
|
|
|
QHash<int, QString> IDModeHash;
|
2015-11-23 17:36:29 +00:00
|
|
|
QHash<int, QString> freqBandIdHash;
|
2015-01-18 20:04:46 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
QMap<QString, int> bandQMap;
|
|
|
|
QMap<QString, int> modeQMap;
|
|
|
|
|
2015-07-19 18:26:11 +00:00
|
|
|
Utilities *util;
|
2015-01-18 20:04:46 +00:00
|
|
|
|
2015-11-06 19:47:52 +00:00
|
|
|
QSqlDatabase db;
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DATABASE_H
|
|
|
|
|