Skip to content

Commit

Permalink
Add text filter to VAC page
Browse files Browse the repository at this point in the history
  • Loading branch information
kebekus committed Feb 17, 2025
1 parent 271adec commit 75a0242
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
39 changes: 36 additions & 3 deletions src/geomaps/VACLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QTemporaryDir>
#include <QTimer>

#include "Librarian.h"
#include "VACLibrary.h"
#include "fileFormats/TripKit.h"

Expand Down Expand Up @@ -266,10 +267,42 @@ QString GeoMaps::VACLibrary::rename(const QString& oldName, const QString& newNa
return {};
}

QVector<GeoMaps::VAC> GeoMaps::VACLibrary::vacsByDistance(const QGeoCoordinate& position)
QVector<GeoMaps::VAC> GeoMaps::VACLibrary::vacsByDistance(const QGeoCoordinate& position, const QString& filter)
{
std::sort(m_vacs.begin(), m_vacs.end(), [position](const GeoMaps::VAC& first, const GeoMaps::VAC& second) {return position.distanceTo(first.center()) < position.distanceTo(second.center()); });
return m_vacs;
QStringList filterWords;
foreach(auto word, filter.simplified().split(' ', Qt::SkipEmptyParts)) {
QString const simplifiedWord = GlobalObject::librarian()->simplifySpecialChars(word);
if (simplifiedWord.isEmpty()) {
continue;
}
filterWords.append(simplifiedWord);
}

QVector<GeoMaps::VAC> result;
const auto constvacs = m_vacs;
for(const auto& vac : constvacs) {
if (!vac.isValid())
{
continue;
}
bool allWordsFound = true;
for(const auto& word : filterWords)
{
QString const fullName = GlobalObject::librarian()->simplifySpecialChars(vac.name);
if (!fullName.contains(word, Qt::CaseInsensitive))
{
allWordsFound = false;
break;
}
}
if (allWordsFound)
{
result.append(vac);
}
}

std::sort(result.begin(), result.end(), [position](const GeoMaps::VAC& first, const GeoMaps::VAC& second) {return position.distanceTo(first.center()) < position.distanceTo(second.center()); });
return result;
}


Expand Down
4 changes: 3 additions & 1 deletion src/geomaps/VACLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ class VACLibrary : public QObject
*
* @param position Geographic position used for sorting
*
* @param filter List of words
*
* @returns List of all VACs installed
*/
[[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacsByDistance(const QGeoCoordinate& position);
[[nodiscard]] Q_INVOKABLE QVector<GeoMaps::VAC> vacsByDistance(const QGeoCoordinate& position, const QString& filter);

signals:
/*! \brief Notifier signal */
Expand Down
40 changes: 31 additions & 9 deletions src/qml/pages/VAC.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,41 @@ Page {
}
}

DecoratedListView {
ColumnLayout {
anchors.fill: parent
anchors.bottomMargin: SafeInsets.bottom

clip: true
model: {
// Mention downloadable in order to get updates
VACLibrary.vacs
Item {
Layout.preferredHeight: textInput.font.pixelSize/4.0
}

MyTextField {
id: textInput

Layout.fillWidth: true
Layout.leftMargin: font.pixelSize/2.0
Layout.rightMargin: font.pixelSize/2.0

focus: true

placeholderText: qsTr("Filter by Name")
}

DecoratedListView {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.bottomMargin: SafeInsets.bottom

clip: true
model: {
// Mention downloadable in order to get updates
VACLibrary.vacs

return VACLibrary.vacsByDistance(PositionProvider.lastValidCoordinate)
return VACLibrary.vacsByDistance(PositionProvider.lastValidCoordinate, textInput.text)
}
delegate: approachChartItem
ScrollIndicator.vertical: ScrollIndicator {}
}
delegate: approachChartItem
ScrollIndicator.vertical: ScrollIndicator {}

}

Label {
Expand Down

0 comments on commit 75a0242

Please sign in to comment.