From 06a813546a98533f1b5f70fc3bc4d3a5b9179711 Mon Sep 17 00:00:00 2001 From: Ladislav Foldyna Date: Sun, 20 Oct 2024 19:35:17 +0200 Subject: [PATCH] Export: Added User Filter - original idea #476 --- core/QSOFilterManager.cpp | 2 +- core/QSOFilterManager.h | 2 +- logformat/LogFormat.cpp | 20 +++++----- logformat/LogFormat.h | 2 + ui/ExportDialog.cpp | 27 ++++++++----- ui/ExportDialog.h | 1 + ui/ExportDialog.ui | 82 ++++++++++++++++++++++++++++----------- 7 files changed, 92 insertions(+), 44 deletions(-) diff --git a/core/QSOFilterManager.cpp b/core/QSOFilterManager.cpp index 72d90d3c..5df352a1 100644 --- a/core/QSOFilterManager.cpp +++ b/core/QSOFilterManager.cpp @@ -212,7 +212,7 @@ QSOFilter QSOFilterManager::getFilter(const QString &filterName) const return ret; } -QString QSOFilterManager::getWhereClause(const QString &filterName) const +QString QSOFilterManager::getWhereClause(const QString &filterName) { FCT_IDENTIFICATION; diff --git a/core/QSOFilterManager.h b/core/QSOFilterManager.h index 447257bf..d068d955 100644 --- a/core/QSOFilterManager.h +++ b/core/QSOFilterManager.h @@ -71,11 +71,11 @@ class QSOFilterManager : public QObject return &instance; } + static QString getWhereClause(const QString &filterName); bool save(const QSOFilter &filter); bool remove(const QString &filterName); QStringList getFilterList() const; QSOFilter getFilter(const QString &filterName) const; - QString getWhereClause(const QString &filterName) const; private: QSOFilterManager(QObject *parent = nullptr); diff --git a/logformat/LogFormat.cpp b/logformat/LogFormat.cpp index 1938ef6b..54895e72 100644 --- a/logformat/LogFormat.cpp +++ b/logformat/LogFormat.cpp @@ -11,6 +11,7 @@ #include "core/Callsign.h" #include "data/BandPlan.h" #include "models/LogbookModel.h" +#include "core/QSOFilterManager.h" MODULE_IDENTIFICATION("qlog.logformat.logformat"); @@ -142,6 +143,12 @@ void LogFormat::setFilterSendVia(const QString &value) this->filterSendVia = value; } +void LogFormat::setUserFilter(const QString &value) +{ + FCT_IDENTIFICATION; + userFilter = value; +} + QString LogFormat::getWhereClause() { FCT_IDENTIFICATION; @@ -151,30 +158,23 @@ QString LogFormat::getWhereClause() whereClause << "1 = 1"; //generic filter if ( isDateRange() ) - { whereClause << "(start_time BETWEEN :start_date AND :end_date)"; - } if ( !filterMyCallsign.isEmpty() ) - { whereClause << "upper(station_callsign) = upper(:stationCallsign)"; - } if ( !filterMyGridsquare.isEmpty() ) - { whereClause << "upper(my_gridsquare) = upper(:myGridsquare)"; - } if ( !filterSentPaperQSL.isEmpty() ) - { whereClause << QString("upper(qsl_sent) in (%1)").arg(filterSentPaperQSL.join(", ")); - } if ( !filterSendVia.isEmpty() ) - { whereClause << ( ( filterSendVia == " " ) ? "qsl_sent_via is NULL" : "upper(qsl_sent_via) = upper(:qsl_sent_via)"); - } + + if ( !userFilter.isEmpty() ) + whereClause << QSOFilterManager::getWhereClause(userFilter); return whereClause.join(" AND "); } diff --git a/logformat/LogFormat.h b/logformat/LogFormat.h index 37263511..64fb2d5c 100644 --- a/logformat/LogFormat.h +++ b/logformat/LogFormat.h @@ -65,6 +65,7 @@ class LogFormat : public QObject { void setFilterMyGridsquare(const QString &myGridsquare); void setFilterSentPaperQSL(bool includeNo, bool includeIgnore, bool includeAlreadySent); void setFilterSendVia(const QString &value); + void setUserFilter(const QString&value); QString getWhereClause(); void bindWhereClause(QSqlQuery &); void setExportedFields(const QStringList& fieldsList); @@ -119,6 +120,7 @@ class LogFormat : public QObject { QString filterSendVia; QStringList whereClause; QStringList exportedFields; + QString userFilter; bool updateDxcc = false; duplicateQSOBehaviour (*duplicateQSOFunc)(QSqlRecord *, QSqlRecord *); LogLocale locale; diff --git a/ui/ExportDialog.cpp b/ui/ExportDialog.cpp index 0688e28f..ebf35a0f 100644 --- a/ui/ExportDialog.cpp +++ b/ui/ExportDialog.cpp @@ -29,6 +29,12 @@ ExportDialog::ExportDialog(QWidget *parent) : ui->startDateEdit->setDate(QDate::currentDate()); ui->endDateEdit->setDisplayFormat(locale.formatDateShortWithYYYY()); ui->endDateEdit->setDate(QDate::currentDate().addDays(1)); + + ui->userFilterComboBox->setModel(new SqlListModel("SELECT filter_name " + "FROM qso_filters " + "ORDER BY filter_name COLLATE LOCALEAWARE ASC", + "", this)); + } ExportDialog::ExportDialog(const QList& qsos, QWidget *parent) : @@ -107,6 +113,13 @@ void ExportDialog::toggleSentStatus() ui->addlSentStatusAlreadySentCheckBox->setEnabled(ui->addlSentStatusCheckbox->isChecked()); } +void ExportDialog::toggleUserFilter() +{ + FCT_IDENTIFICATION; + + ui->userFilterComboBox->setEnabled(ui->userFilterCheckBox->isChecked()); +} + void ExportDialog::runExport() { FCT_IDENTIFICATION; @@ -138,25 +151,20 @@ void ExportDialog::runExport() } if ( ui->dateRangeCheckBox->isChecked() ) - { format->setFilterDateRange(ui->startDateEdit->date(), ui->endDateEdit->date()); - } if ( ui->myCallsignCheckBox->isChecked() ) - { format->setFilterMyCallsign(ui->myCallsignComboBox->currentText()); - } if ( ui->myGridCheckBox->isChecked() ) - { format->setFilterMyGridsquare(ui->myGridComboBox->currentText()); - } + + if ( ui->userFilterCheckBox->isChecked() ) + format->setUserFilter(ui->userFilterComboBox->currentText()); if ( ui->exportTypeCombo->currentData() == "qsl" && ui->qslSendViaCheckbox->isChecked() ) - { format->setFilterSendVia(ui->qslSendViaComboBox->currentData().toString()); - } if ( ui->exportTypeCombo->currentData() == "qsl" ) { @@ -190,7 +198,8 @@ void ExportDialog::runExport() ui->qslSendViaComboBox->setEnabled(false); ui->markAsSentCheckbox->setEnabled(false); ui->exportedColumnsCombo->setEnabled(false); - + ui->userFilterCheckBox->setEnabled(false); + ui->userFilterComboBox->setEnabled(false); if ( exportedColumns.count() > 0 ) { //translate column indexes to SQL column names diff --git a/ui/ExportDialog.h b/ui/ExportDialog.h index 6b9d1446..ca9668fd 100644 --- a/ui/ExportDialog.h +++ b/ui/ExportDialog.h @@ -31,6 +31,7 @@ public slots: void toggleMyGridsquare(); void toggleQslSendVia(); void toggleSentStatus(); + void toggleUserFilter(); void runExport(); void myCallsignChanged(const QString &myCallsign); void showColumnsSetting(); diff --git a/ui/ExportDialog.ui b/ui/ExportDialog.ui index e1a32035..71e437c2 100644 --- a/ui/ExportDialog.ui +++ b/ui/ExportDialog.ui @@ -7,7 +7,7 @@ 0 0 465 - 500 + 546 @@ -313,7 +313,7 @@ - + Export only QSOs that match the selected QSL Send Via value @@ -323,7 +323,7 @@ - + false @@ -333,7 +333,7 @@ - + Include unusual QSO Sent statuses @@ -343,7 +343,7 @@ - + @@ -443,6 +443,23 @@ + + + + User Filter + + + + + + + false + + + Export QSOs that match the selected user QSO Filter + + + @@ -477,6 +494,8 @@ myCallsignComboBox myGridCheckBox myGridComboBox + userFilterCheckBox + userFilterComboBox qslSendViaCheckbox qslSendViaComboBox addlSentStatusCheckbox @@ -493,8 +512,8 @@ runExport() - 257 - 461 + 266 + 536 157 @@ -509,8 +528,8 @@ reject() - 325 - 461 + 334 + 536 286 @@ -525,8 +544,8 @@ browse() - 441 - 65 + 368 + 67 157 @@ -589,8 +608,8 @@ myCallsignChanged(QString) - 515 - 294 + 443 + 302 232 @@ -605,8 +624,8 @@ showColumnsSetting() - 495 - 155 + 442 + 159 232 @@ -621,8 +640,8 @@ toggleQslSendVia() - 98 - 354 + 119 + 396 232 @@ -637,8 +656,8 @@ exportTypeChanged(int) - 448 - 123 + 443 + 126 232 @@ -653,8 +672,8 @@ exportedColumnsComboChanged(int) - 428 - 155 + 356 + 159 232 @@ -669,8 +688,8 @@ toggleSentStatus() - 153 - 385 + 174 + 428 237 @@ -678,6 +697,22 @@ + + userFilterCheckBox + stateChanged(int) + ExportDialog + toggleUserFilter() + + + 70 + 352 + + + 232 + 272 + + + toggleDateRange() @@ -691,5 +726,6 @@ exportTypeChanged(int) exportedColumnsComboChanged(int) toggleSentStatus() + toggleUserFilter()