Skip to content

Commit b663f12

Browse files
committed
UserFilter Export
1 parent eb4cf37 commit b663f12

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

logformat/LogFormat.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LogFormat::LogFormat(QTextStream& stream) :
2222
{
2323
FCT_IDENTIFICATION;
2424
this->defaults = nullptr;
25+
2526
}
2627

2728
LogFormat::~LogFormat() {
@@ -176,9 +177,63 @@ QString LogFormat::getWhereClause()
176177
: "upper(qsl_sent_via) = upper(:qsl_sent_via)");
177178
}
178179

180+
if ( setFilterQSOFilter)
181+
{
182+
whereClause << ( getUserFilter() );
183+
}
184+
179185
return whereClause.join(" AND ");
180186
}
181187

188+
QString LogFormat::getUserFilter()
189+
{
190+
FCT_IDENTIFICATION;
191+
QSettings settings;
192+
QString QSOFilterString = settings.value("logbook/filters/user").toString();
193+
194+
QString UserFilter="";
195+
196+
if ( !QSOFilterString.isEmpty() )
197+
{
198+
QSqlQuery userFilterQuery;
199+
if ( ! userFilterQuery.prepare("SELECT "
200+
"'(' || GROUP_CONCAT( ' ' || c.name || ' ' || CASE WHEN r.value IS NULL AND o.sql_operator IN ('=', 'like') THEN 'IS' "
201+
" WHEN r.value IS NULL and r.operator_id NOT IN ('=', 'like') THEN 'IS NOT' "
202+
" WHEN o.sql_operator = ('starts with') THEN 'like' "
203+
" ELSE o.sql_operator END || "
204+
"' (' || quote(CASE o.sql_operator WHEN 'like' THEN '%' || r.value || '%' "
205+
" WHEN 'not like' THEN '%' || r.value || '%' "
206+
" WHEN 'starts with' THEN r.value || '%' "
207+
" ELSE r.value END) || ') ', m.sql_operator) || ')' "
208+
"FROM qso_filters f, qso_filter_rules r, "
209+
"qso_filter_operators o, qso_filter_matching_types m, "
210+
"PRAGMA_TABLE_INFO('contacts') c "
211+
"WHERE f.filter_name = :filterName "
212+
" AND f.filter_name = r.filter_name "
213+
" AND o.operator_id = r.operator_id "
214+
" AND m.matching_id = f.matching_type "
215+
" AND c.cid = r.table_field_index") )
216+
{
217+
qWarning() << "Cannot prepare select statement";
218+
return "";
219+
}
220+
221+
userFilterQuery.bindValue(":filterName", QSOFilterString);
222+
223+
qCDebug(runtime) << "User filter SQL: " << userFilterQuery.lastQuery();
224+
225+
if ( userFilterQuery.exec() )
226+
{
227+
userFilterQuery.next();
228+
UserFilter.append(QString("( ") + userFilterQuery.value(0).toString() + ")");
229+
}
230+
else
231+
qCDebug(runtime) << "User filter error - " << userFilterQuery.lastError().text();
232+
}
233+
qWarning() << UserFilter;
234+
return UserFilter;
235+
}
236+
182237
void LogFormat::bindWhereClause(QSqlQuery &query)
183238
{
184239
FCT_IDENTIFICATION;

logformat/LogFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ class LogFormat : public QObject {
6565
void setFilterMyGridsquare(const QString &myGridsquare);
6666
void setFilterSentPaperQSL(bool includeNo, bool includeIgnore, bool includeAlreadySent);
6767
void setFilterSendVia(const QString &value);
68+
bool setFilterQSOFilter;
6869
QString getWhereClause();
6970
void bindWhereClause(QSqlQuery &);
7071
void setExportedFields(const QStringList& fieldsList);
7172
void setUpdateDxcc(bool updateDxcc);
7273
void setDuplicateQSOCallback(duplicateQSOBehaviour (*func)(QSqlRecord *, QSqlRecord *));
73-
74+
QString getUserFilter();
7475
virtual void importStart() {}
7576
virtual void importEnd() {}
7677
virtual bool importNext(QSqlRecord&) { return false; }

ui/ExportDialog.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ void ExportDialog::runExport()
165165
(ui->addlSentStatusCheckbox->isChecked()) ? ui->addlSentStatusAlreadySentCheckBox->isChecked() : false);
166166
}
167167

168+
format->setFilterQSOFilter = ui->applyQSOFilterCheckbox->isChecked();
169+
168170
long count = 0L;
169171

170172
connect(format, &LogFormat::exportProgress, this, &ExportDialog::setProgress);
@@ -190,6 +192,7 @@ void ExportDialog::runExport()
190192
ui->qslSendViaComboBox->setEnabled(false);
191193
ui->markAsSentCheckbox->setEnabled(false);
192194
ui->exportedColumnsCombo->setEnabled(false);
195+
ui->applyQSOFilterCheckbox->setEnabled(false);
193196

194197
if ( exportedColumns.count() > 0 )
195198
{

ui/ExportDialog.ui

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>465</width>
10-
<height>500</height>
10+
<height>592</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">
@@ -32,7 +32,7 @@
3232
<item row="0" column="0">
3333
<widget class="QLineEdit" name="fileEdit">
3434
<property name="focusPolicy">
35-
<enum>Qt::ClickFocus</enum>
35+
<enum>Qt::FocusPolicy::ClickFocus</enum>
3636
</property>
3737
<property name="readOnly">
3838
<bool>true</bool>
@@ -45,8 +45,7 @@
4545
<string>Browse</string>
4646
</property>
4747
<property name="icon">
48-
<iconset theme="folder-open">
49-
<normaloff>.</normaloff>.</iconset>
48+
<iconset theme="folder-open"/>
5049
</property>
5150
</widget>
5251
</item>
@@ -210,7 +209,7 @@
210209
</sizepolicy>
211210
</property>
212211
<property name="focusPolicy">
213-
<enum>Qt::ClickFocus</enum>
212+
<enum>Qt::FocusPolicy::ClickFocus</enum>
214213
</property>
215214
<property name="toolTip">
216215
<string>Export only QSOs that match the selected date range</string>
@@ -232,7 +231,7 @@
232231
<string notr="true">-</string>
233232
</property>
234233
<property name="alignment">
235-
<set>Qt::AlignCenter</set>
234+
<set>Qt::AlignmentFlag::AlignCenter</set>
236235
</property>
237236
</widget>
238237
</item>
@@ -248,7 +247,7 @@
248247
</sizepolicy>
249248
</property>
250249
<property name="focusPolicy">
251-
<enum>Qt::ClickFocus</enum>
250+
<enum>Qt::FocusPolicy::ClickFocus</enum>
252251
</property>
253252
<property name="toolTip">
254253
<string>Export only QSOs that match the selected date range</string>
@@ -261,7 +260,7 @@
261260
<item>
262261
<spacer name="horizontalSpacer_2">
263262
<property name="orientation">
264-
<enum>Qt::Horizontal</enum>
263+
<enum>Qt::Orientation::Horizontal</enum>
265264
</property>
266265
<property name="sizeHint" stdset="0">
267266
<size>
@@ -333,7 +332,7 @@
333332
</property>
334333
</widget>
335334
</item>
336-
<item row="4" column="0">
335+
<item row="5" column="0">
337336
<widget class="QCheckBox" name="addlSentStatusCheckbox">
338337
<property name="toolTip">
339338
<string>Include unusual QSO Sent statuses</string>
@@ -343,7 +342,7 @@
343342
</property>
344343
</widget>
345344
</item>
346-
<item row="4" column="1">
345+
<item row="5" column="1">
347346
<layout class="QHBoxLayout" name="sentStatusLayout">
348347
<item>
349348
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -443,6 +442,16 @@
443442
</item>
444443
</layout>
445444
</item>
445+
<item row="6" column="0">
446+
<widget class="QCheckBox" name="applyQSOFilterCheckbox">
447+
<property name="toolTip">
448+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Export only QSOs that match the selected user QSO Filter&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
449+
</property>
450+
<property name="text">
451+
<string>Apply QSO Filter to exported items</string>
452+
</property>
453+
</widget>
454+
</item>
446455
</layout>
447456
</widget>
448457
</item>
@@ -456,10 +465,10 @@
456465
<item>
457466
<widget class="QDialogButtonBox" name="buttonBox">
458467
<property name="orientation">
459-
<enum>Qt::Horizontal</enum>
468+
<enum>Qt::Orientation::Horizontal</enum>
460469
</property>
461470
<property name="standardButtons">
462-
<set>QDialogButtonBox::Close|QDialogButtonBox::Ok</set>
471+
<set>QDialogButtonBox::StandardButton::Close|QDialogButtonBox::StandardButton::Ok</set>
463472
</property>
464473
</widget>
465474
</item>

0 commit comments

Comments
 (0)