swift
modelfilter.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_GUI_MODELS_LISTMODELFILTER_H
7 #define SWIFT_GUI_MODELS_LISTMODELFILTER_H
8 
9 #include <memory>
10 
11 #include <QString>
12 #include <Qt>
13 
14 #include "misc/variant.h"
15 
16 namespace swift::gui::models
17 {
19  template <class ContainerType>
21  {
22  public:
24  IModelFilter(bool enabled = true) : m_enabled(enabled) {}
25 
27  virtual ~IModelFilter() {}
28 
30  virtual ContainerType filter(const ContainerType &container) const = 0;
31 
33  bool isValid() const { return m_valid; }
34 
36  virtual bool isEnabled() const { return m_enabled && isValid(); }
37 
39  void setEnabled(bool enable);
40 
42  virtual swift::misc::CVariant getAsValueObject() const { return {}; }
43 
44  protected:
46  bool stringMatchesFilterExpression(const QString &value, const QString &filter,
47  Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
48 
50  QString stripWildcard(const QString &value) const;
51 
52  bool m_valid = false;
53 
54  private:
55  bool m_enabled = true;
56  };
57 
59  template <class ContainerType>
61  {
62  public:
64  virtual std::unique_ptr<IModelFilter<ContainerType>> createModelFilter() const = 0;
65  };
66 } // namespace swift::gui::models
67 #endif // SWIFT_GUI_MODELS_LISTMODELFILTER_H
Model filter interface.
Definition: modelfilter.h:21
virtual bool isEnabled() const
Enabled?
Definition: modelfilter.h:36
void setEnabled(bool enable)
Enabled?
bool m_valid
is filter valid?
Definition: modelfilter.h:52
bool stringMatchesFilterExpression(const QString &value, const QString &filter, Qt::CaseSensitivity cs=Qt::CaseInsensitive) const
Standard string search supporting wildcard at begin and end: "*xyz", "abc*".
Definition: modelfilter.cpp:31
QString stripWildcard(const QString &value) const
Remove the * wildcards.
Definition: modelfilter.cpp:69
virtual swift::misc::CVariant getAsValueObject() const
Return an implementation-specific value object representing the filter.
Definition: modelfilter.h:42
bool isValid() const
Anything to do?
Definition: modelfilter.h:33
virtual ~IModelFilter()
Destructor.
Definition: modelfilter.h:27
IModelFilter(bool enabled=true)
Constructor.
Definition: modelfilter.h:24
virtual ContainerType filter(const ContainerType &container) const =0
Used container data.
Model filter interface for those who can generate such a filter (e.g. a widget or dialog)
Definition: modelfilter.h:61
virtual std::unique_ptr< IModelFilter< ContainerType > > createModelFilter() const =0
Get the filter, this is the filter itself, not its widget or dialog.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition: variant.h:66
Models to be used with views, mainly QTableView.