Browse Source

Switch from old MaidenheadLocator to libqth

master
squeaky otter 6 years ago
parent
commit
1871fa1080
11 changed files with 62 additions and 149 deletions
  1. +3
    -0
      .gitmodules
  2. +1
    -0
      libqth
  3. +0
    -90
      qthLog/maidenheadlocator.cpp
  4. +0
    -29
      qthLog/maidenheadlocator.h
  5. +15
    -10
      qthLog/qsoglobalmap.cpp
  6. +1
    -1
      qthLog/qsoglobalmap.h
  7. +4
    -4
      qthLog/qthLog.pro
  8. +32
    -3
      qthLog/qthlogmw.cpp
  9. +3
    -1
      qthLog/qthlogmw.h
  10. +2
    -11
      qthLog/updatecty.cpp
  11. +1
    -0
      qthLog/updatecty.h

+ 3
- 0
.gitmodules View File

@ -4,3 +4,6 @@
[submodule "QWidgetMap"]
path = QWidgetMap
url = https://github.com/chris5287/QWidgetMap.git
[submodule "libqth"]
path = libqth
url = https://github.com/ggramaize/libqth.git

+ 1
- 0
libqth

@ -0,0 +1 @@
Subproject commit c31c55a431793a0595ac37c397922a189ab296d9

+ 0
- 90
qthLog/maidenheadlocator.cpp View File

@ -1,90 +0,0 @@
/* Maidenhead Locator
* Got from: https://ve3nrt.wordpress.com/2010/10/03/maidenhead-putting-the-code-together/
*/
#include "maidenheadlocator.h"
/* Simple struction to store a lat/lon coordinate pair */
struct position {
double latitude;
double longitude;
};
struct gridSquare {
struct position sw;
struct position ne;
};
/* Convert position to a Maidenhead Grid Locator (string) */
// QPair<lat,long>
QString positionToMaidenhead(QPair<double, double> pos) {
pos.second = fabs(pos.second); // hack
/*
* We use CTY.csv which have a longitude defined in positive for West
* Where in fact, West IS NEGATIVE, and EAST positive.
* So We do a fabs(longitude) to put it positively or it will fucks everything
* This was "decided in mid-1980 and not going to change".
*/
qDebug() << "positionToMaidenhead"
<< "latitude" << pos.first
<< "longitude" << pos.second;
QString grid;
const int pairs=4;
const double scaling[]={360.,360./18.,(360./18.)/10., \
((360./18.)/10.)/24.,(((360./18.)/10.)/24.)/10., \
((((360./18.)/10.)/24.)/10.)/24., \
(((((360./18.)/10.)/24.)/10.)/24.)/10.};
int i;
int index;
for (i=0;i<pairs;i++) {
index = (int)floor(fmod((180.0+pos.second), \
scaling[i])/scaling[i+1]);
grid[i*2] = (i&1) ? 0x30+index : (i&2) ? 0x61+index : 0x41+index;
index = (int)floor(fmod((90.0+pos.first), \
(scaling[i]/2))/(scaling[i+1]/2));
grid[i*2+1] = (i&1) ? 0x30+index : (i&2) ? 0x61+index : 0x41+index;
}
grid[pairs*2]=0;
qDebug() << "positionToMaidenhead" << grid.simplified().remove(QChar::Null).toUpper();
// Remove leading whitespaces if any & NULL terminator also uppercase
return grid.simplified().remove(QChar::Null).toUpper();
}
QPair<QPair<double, double>, QPair<double, double> > maidenheadToGrid(const char *grid) {
int i;
double size=480.;
double sw_lon = -180.;
double sw_lat = -90.;
for (i=0;grid[i*2]!=0;i++) {
if (i&1) {
size/=10;
sw_lon += (grid[i*2]-48)*size;
sw_lat += (grid[i*2+1]-48)*size/2;
} else {
size/=24;
sw_lon += ((grid[i*2] &31)-1)*size;
sw_lat += ((grid[i*2+1]&31)-1)*size/2;
}
qDebug() << i << size << sw_lon << sw_lat;
// printf(“%i,%f,%f,%f\n”,i,size,g->sw.longitude,g->sw.latitude);
}
double ne_lon = sw_lon+size;
double ne_lat = sw_lat+size/2;
QPair<QPair<double, double>, QPair<double, double> > coordinates;
coordinates.first.first = sw_lon;
coordinates.first.second = sw_lat;
coordinates.second.first = ne_lon;
coordinates.second.second = ne_lat;
return coordinates;
}

+ 0
- 29
qthLog/maidenheadlocator.h View File

@ -1,29 +0,0 @@
#ifndef MAIDENHEADLOCATOR
#define MAIDENHEADLOCATOR
#include <math.h> /* Geography uses a lot of Math */
#include <stdio.h>
#include <QDebug>
#include <QPair>
/* nw +--------------+ ne+
* | N |
* |W E| lat
* | S |
* +sw +--------------+ se
*
* lon
*
* Longitude ranges from West (negative) 180 degrees to East (positive)
*/
// QPair<lat, long>
QString positionToMaidenhead(QPair<double, double> pos);
// QPair<sw, ne>
// nw, sw QPair<lon, lat>
QPair<QPair<double, double>, QPair<double, double> > maidenheadToGrid(const char *grid);
#endif // MAIDENHEADLOCATOR

+ 15
- 10
qthLog/qsoglobalmap.cpp View File

@ -121,18 +121,23 @@ void QsoGlobalMap::setupMaps() {
while (query.next()) {
const char *locator = query.value(3).toString().toStdString().c_str();
QPair<QPair<double, double>, QPair<double, double> > geoPos = maidenheadToGrid(locator);
// coordinates.first.first = sw_lon;
// coordinates.first.second = sw_lat;
// coordinates.second.first = ne_lon;
// coordinates.second.second = ne_lat;
size_t precision = 0;
size_t size = query.value(3).toString().length();
double lat = -300;
double lng = -300;
int retCode = qth_to_coords(locator, size, &lat, &lng, &precision);
if (retCode != 0) {
logger->log(QLog::ERROR, "QSOGLOBALMAP", "Error for qth " + query.value(3).toString());
continue; // ignore that one
}
qDebug() << query.value(1).toString() << " - " << query.value(3).toString();
qDebug() << "longitude sw" << geoPos.first.first << " ne" << geoPos.second.first;
qDebug() << "latitude sw" << geoPos.first.second << " ne" << geoPos.second.second;
QString str = QString("Got lat %1, lng %2 for qth %3")
.arg(QString::number(lat))
.arg(QString::number(lng))
.arg(query.value(3).toString());
logger->log(QLog::DEBUG, "QSOGLOBALMAP", str);
qwm::util::PointWorldCoord geoPoint = qwm::util::PointWorldCoord(geoPos.first.first, geoPos.first.second);
qwm::util::PointWorldCoord geoPoint = qwm::util::PointWorldCoord(lng, lat);
points.emplace_back(std::make_shared<qwm::draw::geometry::GeometryPointCircle>(geoPoint));
points.back()->setPen(pen);
points.back()->setMetadata("Callsign", query.value(1).toString());


+ 1
- 1
qthLog/qsoglobalmap.h View File

@ -29,9 +29,9 @@
#include <QWidgetMap/draw/other/ESRIShapefile.h>
#endif
#include "maidenheadlocator.h"
#include "qlog.h"
#include <QStandardPaths>
#include <../libqth/qth.h>
namespace Ui {
class QsoGlobalMap;


+ 4
- 4
qthLog/qthLog.pro View File

@ -25,14 +25,14 @@ SOURCES += main.cpp\
delegates/checkboxdelegate.cpp \
../crapdif/adif_export.cpp \
../crapdif/adif_parser.cpp \
maidenheadlocator.cpp \
qsoglobalmap.cpp \
qlog.cpp \
setupwizard.cpp \
downloader.cpp \
updatecty.cpp \
databaseupdater.cpp \
adifmanager.cpp
adifmanager.cpp \
../libqth/qth.c
HEADERS += qthlogmw.h \
preferences.h \
@ -45,14 +45,14 @@ HEADERS += qthlogmw.h \
delegates/checkboxdelegate.h \
../crapdif/adif_export.h \
../crapdif/adif_parse.h \
maidenheadlocator.h \
qsoglobalmap.h \
qlog.h \
setupwizard.h \
downloader.h \
updatecty.h \
databaseupdater.h \
adifmanager.h
adifmanager.h \
../libqth/qth.h
FORMS += qthlogmw.ui \
preferences.ui \


+ 32
- 3
qthLog/qthlogmw.cpp View File

@ -312,7 +312,7 @@ bool qthLogMW::doModelsInit() {
dbQsoModel->setRelation(dbQsoModel->fieldIndex("band_id"), QSqlRelation("band", "id", "name"));
dbQsoModel->setRelation(dbQsoModel->fieldIndex("mode_id"), QSqlRelation("mode", "id", "name"));
dbQsoModel->setRelation(dbQsoModel->fieldIndex("country"), QSqlRelation("entity", "dxcc", "name"));
dbQsoModel->setRelation(dbQsoModel->fieldIndex("my_country"), QSqlRelation("entity", "dxcc", "name"));
//dbQsoModel->setRelation(dbQsoModel->fieldIndex("my_country"), QSqlRelation("entity", "dxcc", "name"));
dbQsoModel->setEditStrategy(QSqlTableModel::OnRowChange);
dbQsoModel->setHeaderData(dbQsoModel->fieldIndex("id"), Qt::Horizontal, tr("Id"));
@ -357,6 +357,9 @@ void qthLogMW::updateTableQso() {
qDebug() << dbQsoModel->lastError().text();
}
qDebug().noquote() << dbQsoModel->query().executedQuery();
qDebug() << dbQsoModel->rowCount();
ui->tableViewQso->setColumnHidden(dbQsoModel->fieldIndex("id"), true);
ui->tableViewQso->setColumnHidden(dbQsoModel->fieldIndex("processed_dxcc"), true);
//ui->tableViewQso->setColumnHidden(dbQsoModel->fieldIndex("processed_qrz"), true);
@ -527,7 +530,20 @@ void qthLogMW::onRowSelected(QModelIndex,QModelIndex) {
QPair<double, double> _latlon;
_latlon.first = query.value(4).toDouble(); // latitude
_latlon.second = query.value(5).toDouble(); // longitude
QString _locator = positionToMaidenhead(_latlon);
char qth[9]; // there will be no terminator, let QString manage that
int retCode = coords_to_qth(_latlon.first,
_latlon.second,
3,
qth);
if (retCode == EDOM) {
QString str = "Failed to get qth lat, lng, 5, " +
QString::number(_latlon.first) + "/" +
QString::number(_latlon.second);
logger->log(QLog::ERROR, "get.dx.libqth", str);
return;
}
QString _locator(qth);
logger->log(QLog::DEBUG, "get.dx.stuff", "Got latitude " + QString::number(_latlon.first));
logger->log(QLog::DEBUG, "get.dx.stuff", "Got longitude " + QString::number(_latlon.second));
@ -788,7 +804,20 @@ void qthLogMW::onRecomputeDxccQso() {
QPair<double, double> _latlon;
_latlon.first = queryDxcc.value(5).toDouble(); // latitude
_latlon.second = queryDxcc.value(6).toDouble(); // longitude
QString _locator = positionToMaidenhead(_latlon);
char qth[9]; // there will be no terminator, let QString manage that
int retCode = coords_to_qth(_latlon.first,
_latlon.second,
3,
qth);
if (retCode == EDOM) {
QString str = "Failed to get qth lat, lng, 5, " +
QString::number(_latlon.first) + "/" +
QString::number(_latlon.second);
logger->log(QLog::ERROR, "get.dx.libqth", str);
return;
}
QString _locator(qth);
// Make UPDATE to QSO
QSqlQuery queryQso;


+ 3
- 1
qthLog/qthlogmw.h View File

@ -42,10 +42,12 @@
#include "helpers.h"
#include "../crapdif/adif_parse.h"
#include "../crapdif/adif_export.h"
#include "maidenheadlocator.h"
#include "qlog.h"
#include <databaseupdater.h>
#include <adifmanager.h>
#include "../libqth/qth.h"
#include <math.h> /* Geography uses a lot of Math */
#include <stdio.h>
#include <QRegExp>
#include <QRegExpValidator>


+ 2
- 11
qthLog/updatecty.cpp View File

@ -21,8 +21,6 @@ bool UpdateCty::update(QString filename) {
}
QString tq;
qint64 beginingOfFile;
int numberOfLines = 0;
int errorCode = -1;
QFile file(filename);
@ -30,18 +28,10 @@ bool UpdateCty::update(QString filename) {
logger->log(QLog::ERROR, "UPDATECTY", "File not found " + filename);
return false;
}
beginingOfFile = file.pos();
while (!file.atEnd()) {
//if ((file.readLine()).contains(';'))
numberOfLines++;
}
// The file is readed twice: 1: Main entity data; 2: prefixes.
// Starts with main data:
file.seek(beginingOfFile);
QSqlQuery query;
QSqlQuery queryP;
@ -81,7 +71,8 @@ bool UpdateCty::update(QString filename) {
query.addBindValue(stringList.at(5)); // ITU
query.addBindValue(stringList.at(3)); // Cont
query.addBindValue(stringList.at(6)); // Lat
query.addBindValue(stringList.at(7)); // Lon
double lon = fabs(stringList.at(7).toDouble());
query.addBindValue(lon); // Lon
query.addBindValue(stringList.at(8)); // UTC
query.addBindValue(stringList.at(2)); // dxcc
query.addBindValue(stringList.at(0)); // Mainprefix


+ 1
- 0
qthLog/updatecty.h View File

@ -14,6 +14,7 @@
#include <QSqlError>
#include <QString>
#include <QProgressDialog>
#include <math.h> /* Geography uses a lot of Math */
#include <qlog.h>


Loading…
Cancel
Save