OpenMS  3.0.0
FilterableList.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2022.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
38 
39 #include <QSet>
40 #include <QWidget>
41 
42 namespace Ui
43 {
44  class FilterableList;
45 }
46 
47 class QListWidgetItem;
48 
49 namespace OpenMS
50 {
51  namespace Internal
52  {
68  class FilterableList : public QWidget
69  {
70  Q_OBJECT
71 
72  public:
74  explicit FilterableList(QWidget* parent);
76 
78  QStringList getSelectedItems() const;
79 
81  QStringList getAllVisibleItems() const;
82 
83  public slots:
87  void setItems(const QStringList& items);
88 
91  void setBlacklistItems(const QStringList& blacklist_items);
92 
95  void addBlackListItems(const QStringList& additional_blacklist_items);
96 
99  void removeBlackListItems(const QStringList& outdated_blacklist_items);
100 
101 
102  signals:
104  void filterChanged(const QString& filter_text);
105 
107  void itemDoubleClicked(QListWidgetItem* item);
108 
109  private slots:
112  void filterEdited_(const QString& filter_text);
113 
116  void updateInternalList_();
117 
119  void updateVisibleList_();
120 
121  private:
123  QStringList items_;
124  // this needs to be a Set, otherwise items might be blacklisted twice, which will lead to an Exception (because it cannot find the item on the second round)
125  QSet<QString> blacklist_;
126  QStringList items_wo_bl_;
127  };
128  } // ns Internal
129 } // ns OpenMS
130 
131 // this is required to allow parent widgets (auto UIC'd from .ui) to have a FilterableList member
OpenMS::Internal::FilterableList::updateInternalList_
void updateInternalList_()
OpenMS::Internal::FilterableList
A widget which shows a list of text items, which can be filtered.
Definition: FilterableList.h:68
OpenMS::Internal::FilterableList::blacklist_
QSet< QString > blacklist_
blacklisted items, which are never shown, even if in items_;
Definition: FilterableList.h:125
QWidget
OpenMS::Internal::FilterableList::ui_
Ui::FilterableList * ui_
Definition: FilterableList.h:122
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::Internal::FilterableList::filterEdited_
void filterEdited_(const QString &filter_text)
Ui
Definition: SwathWizardBase.h:62
OpenMS::Internal::FilterableList::itemDoubleClicked
void itemDoubleClicked(QListWidgetItem *item)
emitted when this item was double clicked
OpenMS::Internal::FilterableList::FilterableList
FilterableList(QWidget *parent)
C'tor.
OpenMS::Internal::FilterableList::filterChanged
void filterChanged(const QString &filter_text)
emitted when the user has edited the filter
OpenMS::Internal::FilterableList::~FilterableList
~FilterableList()
OpenMS::Internal::FilterableList::setBlacklistItems
void setBlacklistItems(const QStringList &blacklist_items)
OpenMS::Internal::FilterableList::addBlackListItems
void addBlackListItems(const QStringList &additional_blacklist_items)
OpenMS::Internal::FilterableList::items_
QStringList items_
full list of items to show; when filtered only a subset is shown
Definition: FilterableList.h:123
OpenMS::Internal::FilterableList::items_wo_bl_
QStringList items_wo_bl_
items from item_ with blacklisted items removed
Definition: FilterableList.h:126
OpenMS::Internal::FilterableList::updateVisibleList_
void updateVisibleList_()
update shown items, based on current items_wo_bl_ and current filter
OpenMS::Internal::FilterableList::setItems
void setItems(const QStringList &items)
OpenMS::Internal::FilterableList::getAllVisibleItems
QStringList getAllVisibleItems() const
get all items which are visible (i.e. excludes the ones which are hidden by the filter)
OpenMS::Internal::FilterableList::removeBlackListItems
void removeBlackListItems(const QStringList &outdated_blacklist_items)
OpenMS::Internal::FilterableList::getSelectedItems
QStringList getSelectedItems() const
get the currently selected items of all visible items, i.e. must pass the filter and be selected
FilterableList
OpenMS::Internal::FilterableList FilterableList
Definition: FilterableList.h:132