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
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* 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 <http://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QtSql>
|
|
|
|
#include <QString>
|
|
|
|
#include <QDateTime>
|
2015-03-18 18:42:16 +00:00
|
|
|
#include <QObject>
|
2015-01-14 18:51:30 +00:00
|
|
|
|
|
|
|
class QSqlRelationalTableModel;
|
|
|
|
|
2015-02-23 19:25:55 +00:00
|
|
|
// Last db update 0.0.5
|
|
|
|
// Previous db update 0.0.4
|
|
|
|
const float DBVersionf = 0.005;
|
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:
|
|
|
|
DataBase(const QString _softVersion, bool inmemoryonly = false);
|
|
|
|
~DataBase();
|
|
|
|
bool createConnection();
|
|
|
|
|
|
|
|
//bool beginTransaction();
|
|
|
|
|
|
|
|
bool isValidBand (const QString b);
|
|
|
|
bool isValidMode (const QString b);
|
|
|
|
bool isValidBandNumber (const int b);
|
|
|
|
bool isValidModeNumber (const int b);
|
|
|
|
QString getBandNameFromNumber(const int _n);
|
|
|
|
QString getModeNameFromNumber(const int _n);
|
|
|
|
|
|
|
|
int getBandIdFromName(const QString b);
|
|
|
|
int getModeIdFromName(const QString b);
|
|
|
|
|
|
|
|
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-01-18 20:04:46 +00:00
|
|
|
double getFreqFromBandId(const int _i);
|
|
|
|
|
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-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
|
|
|
|
bool createTableLog(); //Creates log=0 or selectedlog=1
|
2015-03-01 19:32:29 +00:00
|
|
|
|
2015-02-28 20:50:49 +00:00
|
|
|
bool recreateContestData();
|
|
|
|
bool createTableContest();
|
2015-02-23 19:25:55 +00:00
|
|
|
bool populateContestData();
|
2015-03-18 18:42:16 +00:00
|
|
|
bool howManyQSOsInLog(const int i);
|
2015-02-23 19:25:55 +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-01-18 20:04:46 +00:00
|
|
|
QHash<int, double> freqBandIdHash;
|
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
QMap<QString, int> bandQMap;
|
|
|
|
QMap<QString, int> modeQMap;
|
|
|
|
|
2015-01-18 20:04:46 +00:00
|
|
|
|
2015-01-14 18:51:30 +00:00
|
|
|
//QSqlDatabase *db;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DATABASE_H
|
|
|
|
|