From 46a01aecab9300e6c8a2dd2b680d9ae16e1c2d5f Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Fri, 15 Nov 2024 19:40:43 +0100 Subject: [PATCH] Fixed #477 - New Contact: Renamed DXCC Tab to DX Stats and contains DXCC and Station Statistics --- Changelog | 1 + data/Band.h | 2 +- ui/DxccTableWidget.cpp | 148 +++++++++++++++++++++++----------------- ui/DxccTableWidget.h | 5 ++ ui/NewContactWidget.cpp | 4 ++ ui/NewContactWidget.ui | 55 ++++++++++++++- 6 files changed, 151 insertions(+), 64 deletions(-) diff --git a/Changelog b/Changelog index 86c264db..5a817318 100644 --- a/Changelog +++ b/Changelog @@ -10,6 +10,7 @@ TBC - 0.40.0 - [NEW] - Station Profile contains Operator Callsign (issue #441 @kyleboyle) - [NEW] - Station Profile contains County (issue #493 @kyleboyle) - [NEW] - Statistics - Adds time of day and better qso mapping (PR #501 @kyleboyle) +- [CHANGED] - New Contact - Renamed DXCC Tab to DX Stats contains DXCC and Station Statistics (issue #477) - [CHANGED] - QSL Import dialog - Detail text is selectable by mouse and keyboard - [CHANGED] - Removed Main Menu Layout; Activity Manager is in the bottom-left corner - Fixed issue when CW is always selected after Settings exiting or connecting the Rig diff --git a/data/Band.h b/data/Band.h index 033f2a24..a8a99516 100644 --- a/data/Band.h +++ b/data/Band.h @@ -9,7 +9,7 @@ class Band { double start; double end; QString satDesignator; - bool operator==(const Band &band) + bool operator==(const Band &band) const { return ( this->name == band.name && this->start == band.start diff --git a/ui/DxccTableWidget.cpp b/ui/DxccTableWidget.cpp index dbf04873..6681d87e 100644 --- a/ui/DxccTableWidget.cpp +++ b/ui/DxccTableWidget.cpp @@ -33,74 +33,100 @@ void DxccTableWidget::clear() show(); } -void DxccTableWidget::setDxcc(int dxcc, Band highlightedBand) +void DxccTableWidget::updateDxTable(const QString &condition, + const QVariant &conditionValue, + const Band &highlightedBand) { FCT_IDENTIFICATION; - qCDebug(function_parameters) << dxcc; + qCDebug(function_parameters) << condition << conditionValue; - if ( dxcc ) + const QList& dxccBands = BandPlan::bandsList(true, true); + + if ( dxccBands.isEmpty() ) + return; + + QString filter(QLatin1String("1 = 1")); + StationProfile profile = StationProfilesManager::instance()->getCurProfile1(); + QStringList stmt_band_part1; + QStringList stmt_band_part2; + + if ( profile != StationProfile() ) + filter.append(QString(" AND c.my_dxcc = %1").arg(profile.dxcc)); + + for ( const Band &band : dxccBands ) { - const QList& dxccBands = BandPlan::bandsList(true, true); - - if ( dxccBands.size() == 0 ) - return; - - QString filter(QLatin1String("1 = 1")); - StationProfile profile = StationProfilesManager::instance()->getCurProfile1(); - QStringList stmt_band_part1; - QStringList stmt_band_part2; - - if ( profile != StationProfile() ) - filter.append(QString(" AND c.my_dxcc = %1").arg(profile.dxcc)); - - for ( int i = 0; i < dxccBands.size(); i++ ) - { - stmt_band_part1 << QString(" MAX(CASE WHEN band = '%1' THEN CASE WHEN (eqsl_qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%2_eqsl'," - " MAX(CASE WHEN band = '%3' THEN CASE WHEN (lotw_qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%4_lotw'," - " MAX(CASE WHEN band = '%5' THEN CASE WHEN (qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%6_paper' ") - .arg(dxccBands[i].name, dxccBands[i].name, - dxccBands[i].name, dxccBands[i].name, - dxccBands[i].name, dxccBands[i].name); - stmt_band_part2 << QString(" c.'%1_eqsl' || c.'%2_lotw'|| c.'%3_paper' as '%4'").arg(dxccBands[i].name, dxccBands[i].name, - dxccBands[i].name, dxccBands[i].name); - } - - QString stmt = QString("WITH dxcc_summary AS " - " (" - " SELECT " - " m.dxcc , " - " %1 " - " FROM contacts c" - " LEFT OUTER JOIN modes m on c.mode = m.name" - " WHERE %2 AND c.dxcc = %3 GROUP BY m.dxcc ) " - " SELECT m.dxcc," - " %4 " - " FROM (SELECT DISTINCT dxcc" - " FROM modes) m" - " LEFT OUTER JOIN dxcc_summary c ON c.dxcc = m.dxcc " - " ORDER BY m.dxcc").arg(stmt_band_part1.join(",")) - .arg(filter) - .arg(dxcc) - .arg(stmt_band_part2.join(",")); - - qCDebug(runtime) << stmt; - - dxccTableModel->setQuery(stmt); - - // get default Brush from Mode column - Mode Column has always the default color - const QVariant &defaultBrush = dxccTableModel->headerData(0, Qt::Horizontal, Qt::BackgroundRole); - - dxccTableModel->setHeaderData(0, Qt::Horizontal, tr("Mode")); - - for ( int i = 0; i < dxccBands.size(); i++) - { - dxccTableModel->setHeaderData(i+1, Qt::Horizontal, ( highlightedBand == dxccBands[i] ) ? QBrush(Qt::darkGray) : defaultBrush, Qt::BackgroundRole); - dxccTableModel->setHeaderData(i+1, Qt::Horizontal, dxccBands[i].name); - } + stmt_band_part1 << QString(" MAX(CASE WHEN band = '%0' THEN CASE WHEN (eqsl_qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%0_eqsl'," + " MAX(CASE WHEN band = '%0' THEN CASE WHEN (lotw_qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%0_lotw'," + " MAX(CASE WHEN band = '%0' THEN CASE WHEN (qsl_rcvd = 'Y') THEN 2 ELSE 1 END ELSE 0 END) as '%0_paper' ") + .arg(band.name); + stmt_band_part2 << QString(" c.'%0_eqsl' || c.'%0_lotw'|| c.'%0_paper' as '%0'").arg(band.name); } + + QString stmt = QString("WITH dxcc_summary AS " + " (" + " SELECT " + " m.dxcc , " + " %1 " + " FROM contacts c" + " LEFT OUTER JOIN modes m on c.mode = m.name" + " WHERE %2 AND %3 GROUP BY m.dxcc ) " + " SELECT m.dxcc," + " %4 " + " FROM (SELECT DISTINCT dxcc" + " FROM modes) m" + " LEFT OUTER JOIN dxcc_summary c ON c.dxcc = m.dxcc " + " ORDER BY m.dxcc").arg(stmt_band_part1.join(","), + filter, + condition.arg(conditionValue.toString()), + stmt_band_part2.join(",")); + + qCDebug(runtime) << stmt; + + dxccTableModel->setQuery(stmt); + + // get default Brush from Mode column - Mode Column has always the default color + const QVariant &defaultBrush = dxccTableModel->headerData(0, Qt::Horizontal, Qt::BackgroundRole); + + dxccTableModel->setHeaderData(0, Qt::Horizontal, tr("Mode")); + + for ( int i = 0; i < dxccBands.size(); i++ ) + { + dxccTableModel->setHeaderData(i+1, Qt::Horizontal, ( highlightedBand == dxccBands.at(i) ) ? QBrush(Qt::darkGray) + : defaultBrush, Qt::BackgroundRole); + dxccTableModel->setHeaderData(i+1, Qt::Horizontal, dxccBands.at(i).name); + } + + show(); +} + +void DxccTableWidget::setDxCallsign(const QString &dxCallsign, Band band) +{ + FCT_IDENTIFICATION; + + qCDebug(function_parameters) << dxCallsign; + + if (!dxCallsign.isEmpty()) + updateDxTable("c.callsign = '%1'", dxCallsign.toUpper(), band); else + { dxccTableModel->clear(); + show(); + } - show(); +} + +void DxccTableWidget::setDxcc(int dxcc, Band highlightedBand) +{ + FCT_IDENTIFICATION; + + qCDebug(function_parameters) << dxcc; + + if ( dxcc ) + updateDxTable("c.dxcc = %1", dxcc, highlightedBand); + else + { + dxccTableModel->clear(); + show(); + } } diff --git a/ui/DxccTableWidget.h b/ui/DxccTableWidget.h index 3e93212b..f62756fe 100644 --- a/ui/DxccTableWidget.h +++ b/ui/DxccTableWidget.h @@ -16,8 +16,13 @@ class DxccTableWidget : public QTableView public slots: void clear(); void setDxcc(int dxcc, Band band); + void setDxCallsign(const QString &dxCallsign, Band band); private: + void updateDxTable(const QString &condition, + const QVariant &conditionValue, + const Band &highlightedBand); + DxccTableModel* dxccTableModel; }; diff --git a/ui/NewContactWidget.cpp b/ui/NewContactWidget.cpp index 5d6e3754..9dbb6b53 100644 --- a/ui/NewContactWidget.cpp +++ b/ui/NewContactWidget.cpp @@ -490,6 +490,7 @@ void NewContactWidget::setDxccInfo(const DxccEntity &curr) uiDynamic->ituEdit->setText(QString::number(dxccEntity.ituz)); updateCoordinates(dxccEntity.latlon[0], dxccEntity.latlon[1], COORD_DXCC); ui->dxccTableWidget->setDxcc(dxccEntity.dxcc, BandPlan::freq2Band(ui->freqTXEdit->value())); + ui->stationTableWidget->setDxCallsign(ui->callsignEdit->text(), BandPlan::freq2Band(ui->freqTXEdit->value())); uiDynamic->contEdit->setCurrentText(dxccEntity.cont); ui->flagView->setPixmap((!dxccEntity.flag.isEmpty() ) ? QPixmap(QString(":/flags/64/%1.png").arg(dxccEntity.flag)) : QPixmap() ); @@ -502,6 +503,7 @@ void NewContactWidget::setDxccInfo(const DxccEntity &curr) uiDynamic->ituEdit->clear(); clearCoordinates(); ui->dxccTableWidget->clear(); + ui->stationTableWidget->clear(); uiDynamic->contEdit->setCurrentText(""); ui->flagView->setPixmap(QPixmap()); ui->dxccStatus->clear(); @@ -937,6 +939,7 @@ void NewContactWidget::updateTXBand(double freq) updateSatMode(); updateDxccStatus(); ui->dxccTableWidget->setDxcc(dxccEntity.dxcc, BandPlan::freq2Band(ui->freqTXEdit->value())); + ui->stationTableWidget->setDxCallsign(ui->callsignEdit->text(), BandPlan::freq2Band(ui->freqTXEdit->value())); } void NewContactWidget::updateRXBand(double freq) @@ -1025,6 +1028,7 @@ void NewContactWidget::resetContact() uiDynamic->vuccEdit->clear(); uiDynamic->wwffEdit->clear(); ui->dxccTableWidget->clear(); + ui->stationTableWidget->clear(); ui->dxccStatus->clear(); ui->flagView->setPixmap(QPixmap()); uiDynamic->ageEdit->clear(); diff --git a/ui/NewContactWidget.ui b/ui/NewContactWidget.ui index 08fece26..928486f5 100644 --- a/ui/NewContactWidget.ui +++ b/ui/NewContactWidget.ui @@ -1370,7 +1370,7 @@ - + 0 @@ -1378,7 +1378,7 @@ - D&XCC + D&X Stats @@ -1396,6 +1396,13 @@ 0 + + + + <b>DXCC Statistics</b> + + + @@ -1445,6 +1452,50 @@ + + + + <b>Station Statistics</b> + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + QAbstractScrollArea::AdjustToContents + + + QAbstractItemView::NoEditTriggers + + + true + + + QAbstractItemView::NoSelection + + + 20 + + + 65 + + + 21 + + + 21 + + +