Skip to content

Commit

Permalink
Export: Added User Filter - original idea #476
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Nov 5, 2024
1 parent e2272ea commit 06a8135
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 44 deletions.
2 changes: 1 addition & 1 deletion core/QSOFilterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion core/QSOFilterManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions logformat/LogFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand All @@ -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 ");
}
Expand Down
2 changes: 2 additions & 0 deletions logformat/LogFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 18 additions & 9 deletions ui/ExportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QSqlRecord>& qsos, QWidget *parent) :
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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" )
{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ui/ExportDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public slots:
void toggleMyGridsquare();
void toggleQslSendVia();
void toggleSentStatus();
void toggleUserFilter();
void runExport();
void myCallsignChanged(const QString &myCallsign);
void showColumnsSetting();
Expand Down
82 changes: 59 additions & 23 deletions ui/ExportDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>465</width>
<height>500</height>
<height>546</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -313,7 +313,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="qslSendViaCheckbox">
<property name="toolTip">
<string>Export only QSOs that match the selected QSL Send Via value</string>
Expand All @@ -323,7 +323,7 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QComboBox" name="qslSendViaComboBox">
<property name="enabled">
<bool>false</bool>
Expand All @@ -333,7 +333,7 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QCheckBox" name="addlSentStatusCheckbox">
<property name="toolTip">
<string>Include unusual QSO Sent statuses</string>
Expand All @@ -343,7 +343,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<layout class="QHBoxLayout" name="sentStatusLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -443,6 +443,23 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="userFilterCheckBox">
<property name="text">
<string>User Filter</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="userFilterComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Export QSOs that match the selected user QSO Filter</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -477,6 +494,8 @@
<tabstop>myCallsignComboBox</tabstop>
<tabstop>myGridCheckBox</tabstop>
<tabstop>myGridComboBox</tabstop>
<tabstop>userFilterCheckBox</tabstop>
<tabstop>userFilterComboBox</tabstop>
<tabstop>qslSendViaCheckbox</tabstop>
<tabstop>qslSendViaComboBox</tabstop>
<tabstop>addlSentStatusCheckbox</tabstop>
Expand All @@ -493,8 +512,8 @@
<slot>runExport()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>461</y>
<x>266</x>
<y>536</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand All @@ -509,8 +528,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>461</y>
<x>334</x>
<y>536</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand All @@ -525,8 +544,8 @@
<slot>browse()</slot>
<hints>
<hint type="sourcelabel">
<x>441</x>
<y>65</y>
<x>368</x>
<y>67</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand Down Expand Up @@ -589,8 +608,8 @@
<slot>myCallsignChanged(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>515</x>
<y>294</y>
<x>443</x>
<y>302</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
Expand All @@ -605,8 +624,8 @@
<slot>showColumnsSetting()</slot>
<hints>
<hint type="sourcelabel">
<x>495</x>
<y>155</y>
<x>442</x>
<y>159</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
Expand All @@ -621,8 +640,8 @@
<slot>toggleQslSendVia()</slot>
<hints>
<hint type="sourcelabel">
<x>98</x>
<y>354</y>
<x>119</x>
<y>396</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
Expand All @@ -637,8 +656,8 @@
<slot>exportTypeChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>448</x>
<y>123</y>
<x>443</x>
<y>126</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
Expand All @@ -653,8 +672,8 @@
<slot>exportedColumnsComboChanged(int)</slot>
<hints>
<hint type="sourcelabel">
<x>428</x>
<y>155</y>
<x>356</x>
<y>159</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
Expand All @@ -669,15 +688,31 @@
<slot>toggleSentStatus()</slot>
<hints>
<hint type="sourcelabel">
<x>153</x>
<y>385</y>
<x>174</x>
<y>428</y>
</hint>
<hint type="destinationlabel">
<x>237</x>
<y>220</y>
</hint>
</hints>
</connection>
<connection>
<sender>userFilterCheckBox</sender>
<signal>stateChanged(int)</signal>
<receiver>ExportDialog</receiver>
<slot>toggleUserFilter()</slot>
<hints>
<hint type="sourcelabel">
<x>70</x>
<y>352</y>
</hint>
<hint type="destinationlabel">
<x>232</x>
<y>272</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>toggleDateRange()</slot>
Expand All @@ -691,5 +726,6 @@
<slot>exportTypeChanged(int)</slot>
<slot>exportedColumnsComboChanged(int)</slot>
<slot>toggleSentStatus()</slot>
<slot>toggleUserFilter()</slot>
</slots>
</ui>

0 comments on commit 06a8135

Please sign in to comment.