klog/database.h

135 lines
4.7 KiB
C
Raw Normal View History

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/>. *
* *
*****************************************************************************/
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-01-14 18:51:30 +00:00
class QSqlRelationalTableModel;
2015-05-03 11:19:18 +00:00
// Last db update 0.0.6
// Previous db update 0.0.5
const float DBVersionf = 0.006;
2015-01-14 18:51:30 +00:00
class DataBase
{
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);
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
bool isThisFreqInBand(const QString b, const QString fr); //Freq should be in MHz
2015-01-14 18:51:30 +00:00
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-05-03 11:19:18 +00:00
bool updateTo006();
2015-06-13 11:12:15 +00:00
bool updateTableLog();
2015-01-14 18:51:30 +00:00
bool createTheBandQuickReference();
bool createTheModeQuickReference();
2015-03-01 19:32:29 +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.
bool createTableLogs();
2015-05-03 11:19:18 +00:00
bool createTablePropModes();
2015-05-23 18:34:30 +00:00
bool createTableClubLogStatus();
bool populateTableClubLogStatus();
2015-06-13 11:12:15 +00:00
bool createTableMode();
bool populateTableMode();
bool populateTableBand();
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-05-03 11:19:18 +00:00
bool populatePropagationModes();
bool howManyQSOsInLog(const int i);
void showError(const QString _errorC);
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