Skip to content

Commit

Permalink
DXC: Added Full-text Search
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Sep 19, 2024
1 parent f2099b4 commit 567bdd1
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 7 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
TBC - 0.39.0
- [NEW] - DXC - Added Full-text search
- [NEW] - Select S in RST Edit when focused (issue #454)
- [CHANGED] - HamlibDrv - Added multiplatform reliable sleep
- [CHANGED] - Backup policy
Expand Down
2 changes: 2 additions & 0 deletions QLog.pro
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ SOURCES += \
models/LogbookModel.cpp \
models/RigTypeModel.cpp \
models/RotTypeModel.cpp \
models/SearchFilterProxyModel.cpp \
models/ShortcutEditorModel.cpp \
models/SqlListModel.cpp \
models/WsjtxTableModel.cpp \
Expand Down Expand Up @@ -241,6 +242,7 @@ HEADERS += \
models/LogbookModel.h \
models/RigTypeModel.h \
models/RotTypeModel.h \
models/SearchFilterProxyModel.h \
models/ShortcutEditorModel.h \
models/SqlListModel.h \
models/WsjtxTableModel.h \
Expand Down
25 changes: 25 additions & 0 deletions models/SearchFilterProxyModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "SearchFilterProxyModel.h"

SearchFilterProxyModel::SearchFilterProxyModel(QObject *parent)
: QSortFilterProxyModel{parent}
{}

void SearchFilterProxyModel::setSearchString(const QString &searchString)
{
this->searchString = searchString;
invalidateFilter();
}

bool SearchFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
// full-text search
for ( int col = 0; col < sourceModel()->columnCount(); ++col )
{
QModelIndex index = sourceModel()->index(source_row, col, source_parent);
QString data = index.data(Qt::DisplayRole).toString();

if ( data.contains(searchString, Qt::CaseInsensitive) )
return true;
}
return false;
}
21 changes: 21 additions & 0 deletions models/SearchFilterProxyModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef SEARCHFILTERPROXYMODEL_H
#define SEARCHFILTERPROXYMODEL_H

#include <QSortFilterProxyModel>

class SearchFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT

public:
SearchFilterProxyModel(QObject* parent = nullptr);
void setSearchString(const QString& searchString);

protected:
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;

private:
QString searchString;
};

#endif // SEARCHFILTERPROXYMODEL_H
49 changes: 44 additions & 5 deletions ui/DxWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,24 @@ DxWidget::DxWidget(QWidget *parent) :

ui->setupUi(this);

setSearchClosed();

ui->serverSelect->setStyleSheet(QStringLiteral("QComboBox {color: red}"));

dxTableModel = new DxTableModel(this);
wcyTableModel = new WCYTableModel(this);
wwvTableModel = new WWVTableModel(this);
toAllTableModel = new ToAllTableModel(this);

dxTableProxyModel = new SearchFilterProxyModel(ui->dxTable);
dxTableModel = new DxTableModel(dxTableProxyModel);
dxTableProxyModel->setSourceModel(dxTableModel);

QAction *separator = new QAction(this);
separator->setSeparator(true);

ui->dxTable->setModel(dxTableModel);
ui->dxTable->setModel(dxTableProxyModel);
ui->dxTable->addAction(ui->actionFilter);
ui->dxTable->addAction(ui->actionSearch);
ui->dxTable->addAction(ui->actionDisplayedColumns);
ui->dxTable->addAction(ui->actionClear);
ui->dxTable->addAction(separator);
Expand Down Expand Up @@ -1198,9 +1204,11 @@ void DxWidget::entryDoubleClicked(QModelIndex index)
{
FCT_IDENTIFICATION;

emit tuneDx(dxTableModel->getCallsign(index),
dxTableModel->getFrequency(index),
dxTableModel->getBandPlanode(index));
const QModelIndex &source_index = dxTableProxyModel->mapToSource(index);

emit tuneDx(dxTableModel->getCallsign(source_index),
dxTableModel->getFrequency(source_index),
dxTableModel->getBandPlanode(source_index));
}

void DxWidget::actionFilter()
Expand Down Expand Up @@ -1300,6 +1308,37 @@ void DxWidget::prepareQSOSpot(QSqlRecord qso)
}
}

void DxWidget::setSearch(const QString &text)
{
FCT_IDENTIFICATION;

dxTableProxyModel->setSearchString(text);
}

void DxWidget::setSearchStatus(bool visible)
{
FCT_IDENTIFICATION;

ui->searchEdit->setVisible(visible);
ui->searchEdit->setFocus();
ui->searchCloseButton->setVisible(visible);

if (!visible)
ui->searchEdit->clear();
}

void DxWidget::setSearchVisible()
{
FCT_IDENTIFICATION;
setSearchStatus(!ui->searchEdit->isVisible());
}

void DxWidget::setSearchClosed()
{
FCT_IDENTIFICATION;
setSearchStatus(false);
}

void DxWidget::actionCommandSpotQSO()
{
FCT_IDENTIFICATION;
Expand Down
7 changes: 6 additions & 1 deletion ui/DxWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "data/ToAllSpot.h"
#include "core/LogLocale.h"
#include "core/DxServerString.h"
#include "models/SearchFilterProxyModel.h"

// in sec
#define DEDUPLICATION_TIME 3
Expand Down Expand Up @@ -112,7 +113,6 @@ class DeleteHighlightedDXServerWhenDelPressedEventFilter : public QObject
bool eventFilter(QObject *obj, QEvent *event);
};


class DxWidget : public QWidget {
Q_OBJECT

Expand All @@ -134,6 +134,10 @@ public slots:
void setLastQSO(QSqlRecord);
void reloadSetting();
void prepareQSOSpot(QSqlRecord);
void setSearch(const QString &);
void setSearchStatus(bool);
void setSearchVisible();
void setSearchClosed();

private slots:
void actionCommandSpotQSO();
Expand Down Expand Up @@ -172,6 +176,7 @@ private slots:
WCYTableModel* wcyTableModel;
WWVTableModel* wwvTableModel;
ToAllTableModel* toAllTableModel;
SearchFilterProxyModel* dxTableProxyModel;
QTcpSocket* socket;
Ui::DxWidget *ui;
QRegularExpression moderegexp;
Expand Down
105 changes: 105 additions & 0 deletions ui/DxWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,43 @@
</attribute>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="searchLayout">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="searchEdit">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Full-text search</string>
</property>
<property name="placeholderText">
<string>Search</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="searchCloseButton">
<property name="toolTip">
<string>Close Search</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="edit-clear">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="wcyPage">
Expand Down Expand Up @@ -587,6 +624,23 @@
<string>Clear all data</string>
</property>
</action>
<action name="actionSearch">
<property name="text">
<string>Search...</string>
</property>
<property name="toolTip">
<string>DXC - Search</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
<property name="shortcutContext">
<enum>Qt::ApplicationShortcut</enum>
</property>
<property name="changeableshortcut" stdset="0">
<bool>true</bool>
</property>
</action>
</widget>
<resources>
<include location="../res/icons/icons.qrc"/>
Expand Down Expand Up @@ -880,6 +934,54 @@
</hint>
</hints>
</connection>
<connection>
<sender>actionSearch</sender>
<signal>triggered()</signal>
<receiver>DxWidget</receiver>
<slot>setSearchVisible()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>170</x>
<y>255</y>
</hint>
</hints>
</connection>
<connection>
<sender>searchCloseButton</sender>
<signal>clicked()</signal>
<receiver>DxWidget</receiver>
<slot>setSearchClosed()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>462</y>
</hint>
<hint type="destinationlabel">
<x>170</x>
<y>255</y>
</hint>
</hints>
</connection>
<connection>
<sender>searchEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>DxWidget</receiver>
<slot>setSearch(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>170</x>
<y>463</y>
</hint>
<hint type="destinationlabel">
<x>170</x>
<y>255</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>send()</slot>
Expand All @@ -903,5 +1005,8 @@
<slot>actionForgetPassword()</slot>
<slot>actionKeepSpots()</slot>
<slot>actionClear()</slot>
<slot>setSearch(QString)</slot>
<slot>setSearchVisible()</slot>
<slot>setSearchClosed()</slot>
</slots>
</ui>
2 changes: 1 addition & 1 deletion ui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<x>0</x>
<y>0</y>
<width>913</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand Down

0 comments on commit 567bdd1

Please sign in to comment.