File indexing completed on 2024-04-21 05:48:16

0001 /**
0002  * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #ifndef FILTER_H
0007 #define FILTER_H
0008 
0009 #include <QWidget>
0010 #include <QtCore/QMap>
0011 
0012 class QToolButton;
0013 
0014 class QLineEdit;
0015 class KComboBox;
0016 
0017 class Tag;
0018 class State;
0019 
0020 /** The structure that contain all filter terms
0021  * @author Sébastien Laoût
0022  */
0023 struct FilterData {
0024 public:
0025     // Useful Enum for tagFilterType:
0026     enum TagFilterType { DontCareTagsFilter = 0, NotTaggedFilter, TaggedFilter, TagFilter, StateFilter };
0027     // Constructor and Destructor:
0028     FilterData()
0029     {
0030         isFiltering = false;
0031         tagFilterType = DontCareTagsFilter;
0032         tag = nullptr;
0033         state = nullptr;
0034     }
0035     ~FilterData()
0036     {
0037     }
0038     // Filter data:
0039     QString string;
0040     int tagFilterType;
0041     Tag *tag;
0042     State *state;
0043     bool isFiltering;
0044 };
0045 
0046 /** A QWidget that allow user to enter terms to filter in a Basket.
0047  * @author Sébastien Laoût
0048  */
0049 class FilterBar : public QWidget
0050 {
0051     Q_OBJECT
0052 public:
0053     explicit FilterBar(QWidget *parent = nullptr);
0054     ~FilterBar() override;
0055     const FilterData &filterData();
0056 Q_SIGNALS:
0057     void newFilter(const FilterData &data);
0058 public Q_SLOTS:
0059     void repopulateTagsCombo();
0060     void reset();
0061     void inAllBaskets();
0062     void setEditFocus();
0063     void filterTag(Tag *tag);
0064     void filterState(State *state);
0065     void setFilterData(const FilterData &data);
0066 
0067 public:
0068     bool hasEditFocus();
0069     QLineEdit *lineEdit()
0070     {
0071         return m_lineEdit;
0072     }
0073 private Q_SLOTS:
0074     void changeFilter();
0075     void tagChanged(int index);
0076 
0077 private:
0078     FilterData m_data;
0079     QLineEdit *m_lineEdit;
0080     QToolButton *m_resetButton;
0081     KComboBox *m_tagsBox;
0082     QToolButton *m_inAllBasketsButton;
0083 
0084     QMap<int, Tag *> m_tagsMap;
0085     QMap<int, State *> m_statesMap;
0086 };
0087 
0088 #endif // FILTER_H