Skip to content

Commit

Permalink
Fixed #477 - New Contact: Renamed DXCC Tab to DX Stats and contains D…
Browse files Browse the repository at this point in the history
…XCC and Station Statistics
  • Loading branch information
foldynl committed Nov 15, 2024
1 parent ccbcb70 commit 46a01ae
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 64 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion data/Band.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
148 changes: 87 additions & 61 deletions ui/DxccTableWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Band>& 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<Band>& 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();
}
}
5 changes: 5 additions & 0 deletions ui/DxccTableWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
4 changes: 4 additions & 0 deletions ui/NewContactWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
55 changes: 53 additions & 2 deletions ui/NewContactWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,15 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="dxccTab">
<widget class="QWidget" name="dxStatTab">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>D&amp;XCC</string>
<string>D&amp;X Stats</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
Expand All @@ -1396,6 +1396,13 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="dxccTableLabel">
<property name="text">
<string>&lt;b&gt;DXCC Statistics&lt;/b&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="DxccTableWidget" name="dxccTableWidget">
<property name="sizePolicy">
Expand Down Expand Up @@ -1445,6 +1452,50 @@
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="stationTableLabel">
<property name="text">
<string>&lt;b&gt;Station Statistics&lt;/b&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="DxccTableWidget" name="stationTableWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>20</number>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>65</number>
</attribute>
<attribute name="verticalHeaderMinimumSectionSize">
<number>21</number>
</attribute>
<attribute name="verticalHeaderDefaultSectionSize">
<number>21</number>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="myStationTab">
Expand Down

0 comments on commit 46a01ae

Please sign in to comment.