Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(MM_SRCS
fieldsmodel.cpp
filter/uniquevaluesfiltermodel.cpp
filter/valuemapfiltermodel.cpp
filter/searchproxymodel.cpp
filtercontroller.cpp
guidelinecontroller.cpp
hapticsmodel.cpp
Expand Down Expand Up @@ -152,6 +153,7 @@ set(MM_HDRS
fieldsmodel.h
filter/uniquevaluesfiltermodel.h
filter/valuemapfiltermodel.h
filter/searchproxymodel.h
filtercontroller.h
guidelinecontroller.h
hapticsmodel.h
Expand Down
30 changes: 30 additions & 0 deletions app/filter/searchproxymodel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "searchproxymodel.h"

SearchProxyModel::SearchProxyModel( QObject *parent )
: QSortFilterProxyModel{parent}
{
setFilterCaseSensitivity( Qt::CaseInsensitive );
}

QString SearchProxyModel::searchString() const
{
return mSearchString;
}

void SearchProxyModel::setSearchString( const QString &search )
{
if ( mSearchString == search )
return;
mSearchString = search;
setFilterFixedString( search );
emit searchStringChanged();
}
36 changes: 36 additions & 0 deletions app/filter/searchproxymodel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef SEARCHPROXYMODEL_H
#define SEARCHPROXYMODEL_H

#include <QSortFilterProxyModel>
#include <QtQml/qqmlregistration.h>

class SearchProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
QML_ELEMENT

Q_PROPERTY( QString searchString READ searchString WRITE setSearchString NOTIFY searchStringChanged )

public:
explicit SearchProxyModel( QObject *parent = nullptr );

QString searchString() const;
void setSearchString( const QString &newSearchString );

signals:
void searchStringChanged();

private:
QString mSearchString;
};

#endif // SEARCHPROXYMODEL_H
62 changes: 16 additions & 46 deletions app/filter/valuemapfiltermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,33 @@ ValueMapFilterModel::ValueMapFilterModel( QObject *parent )
int ValueMapFilterModel::rowCount( const QModelIndex &parent ) const
{
Q_UNUSED( parent )
return mFilteredItems.size();
return mItems.size();
}

QVariant ValueMapFilterModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || index.row() >= mFilteredItems.size() )
if ( !index.isValid() || index.row() >= mItems.size() )
return {};

const Item &item = mFilteredItems.at( index.row() );
const Item &item = mItems.at( index.row() );

switch ( role )
{
case Qt::DisplayRole:
case TextRole:
return item.text;
case ValueRole:
return item.value;
return item.description;
case KeyRole:
return item.key;
default:
return {};
}
}

QHash<int, QByteArray> ValueMapFilterModel::roleNames() const
{
return
{
{ TextRole, "text" },
{ ValueRole, "value" },
};
QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
roles[KeyRole] = QStringLiteral( "Key" ).toLatin1();

return roles;
}

QVariantMap ValueMapFilterModel::config() const
Expand All @@ -64,24 +62,10 @@ void ValueMapFilterModel::setConfig( const QVariantMap &config )
populate();
}

QString ValueMapFilterModel::searchText() const
{
return mSearchText;
}

void ValueMapFilterModel::setSearchText( const QString &searchText )
{
if ( mSearchText == searchText )
return;

mSearchText = searchText;
emit searchTextChanged();

applyFilter();
}

void ValueMapFilterModel::populate()
{
beginResetModel();

mItems.clear();

const QVariantList mapList = mConfig.value( QStringLiteral( "map" ) ).toList();
Expand All @@ -90,30 +74,16 @@ void ValueMapFilterModel::populate()
for ( const QVariant &entry : mapList )
{
const QVariantMap entryMap = entry.toMap();

if ( entryMap.isEmpty() )
continue;

// Each entry is a single-key map: {"Display Text": "stored_value"}
Item item;
item.text = entryMap.constBegin().key();
item.value = entryMap.constBegin().value().toString();
mItems.append( item );
}

applyFilter();
}
item.description = entryMap.constBegin().key();
item.key = entryMap.constBegin().value().toString();

void ValueMapFilterModel::applyFilter()
{
beginResetModel();
mFilteredItems.clear();

for ( const Item &item : std::as_const( mItems ) )
{
if ( mSearchText.isEmpty() || item.text.contains( mSearchText, Qt::CaseInsensitive ) )
{
mFilteredItems.append( item );
}
mItems.append( item );
}

endResetModel();
Expand Down
16 changes: 4 additions & 12 deletions app/filter/valuemapfiltermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ class ValueMapFilterModel : public QAbstractListModel
QML_ELEMENT

Q_PROPERTY( QVariantMap config READ config WRITE setConfig NOTIFY configChanged )
Q_PROPERTY( QString searchText READ searchText WRITE setSearchText NOTIFY searchTextChanged )

public:
enum Roles
{
TextRole = Qt::UserRole + 1,
ValueRole
KeyRole = Qt::UserRole + 1, // DisplayRole is used for description
};
Q_ENUM( Roles )

Expand All @@ -43,27 +41,21 @@ class ValueMapFilterModel : public QAbstractListModel
QVariantMap config() const;
void setConfig( const QVariantMap &config );

QString searchText() const;
void setSearchText( const QString &searchText );

signals:
void configChanged();
void searchTextChanged();

private:
void populate();
void applyFilter();

struct Item
{
QString text;
QString value;
QString description;
QString key;
};

QVariantMap mConfig;
QString mSearchText;

QList<Item> mItems;
QList<Item> mFilteredItems;
};

#endif // VALUEMAPFILTERMODEL_H
1 change: 1 addition & 0 deletions app/qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(MM_QML
filters/components/MMFilterBanner.qml
filters/components/MMFilterBoolInput.qml
filters/components/MMFilterDateRange.qml
filters/components/MMFilterDropdownValueMapInput.qml
filters/components/MMFilterDropdownValueRelationInput.qml
filters/components/MMFilterDropdownUniqueValuesInput.qml
filters/components/MMFilterRangeInput.qml
Expand Down
11 changes: 10 additions & 1 deletion app/qml/filters/MMFiltersPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ MMComponents.MMDrawer {
base['isMultiSelect'] = isMulti

const dropdownConfig = __activeProject.filterController.getDropdownConfiguration( modelData.filterId )
console.log( "--> dropdown config:", JSON.stringify( dropdownConfig ) )

if ( !Object.keys( dropdownConfig ).length )
{
Expand All @@ -156,6 +155,16 @@ MMComponents.MMDrawer {
base["fieldName"] = dropdownConfig["field_name"]
setSource( "components/MMFilterDropdownUniqueValuesInput.qml", base )
}
else if ( dropdownConfig["type"] === "value_relation" )
{
base["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueRelationInput.qml", base )
}
else if ( dropdownConfig["type"] === "value_map" )
{
base["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueMapInput.qml", base )
}
}
}

Expand Down
16 changes: 10 additions & 6 deletions app/qml/filters/components/MMFilterDropdownUniqueValuesInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import QtQuick

import MMInput as MM
import "../../components"
import "../../components" as MMComponents

Column {
id: root
Expand All @@ -28,7 +28,7 @@ Column {

spacing: __style.margin8

MMText {
MMComponents.MMText {
width: parent.width

text: root.filterName
Expand Down Expand Up @@ -72,13 +72,17 @@ Column {
// TODO: add indication that model is loading features
// TODO: add animation when drawer height is changed

sourceComponent: MMListMultiselectDrawer {
sourceComponent: MMComponents.MMListMultiselectDrawer {
drawerHeader.title: root.filterName

withSearch: true
withSearch: uniqueValuesModel.rowCount() > 5
multiSelect: root.isMultiSelect

list.model: uniqueValuesModel
list.model: MM.SearchProxyModel {
id: searchProxyModel

sourceModel: uniqueValuesModel
}

textRole: "display"
secondaryTextRole: ""
Expand All @@ -93,7 +97,7 @@ Column {
close()
}

onSearchTextChanged: console.log("--> Search me") // TODO: search
onSearchTextChanged: ( searchText ) => searchProxyModel.searchString = searchText

onClosed: dropdownDrawerLoader.active = false

Expand Down
Loading
Loading