USGS

Isis 3.0 Object Programmers' Reference

Home

FilterWidget.h
1 #ifndef FilterWidget_H
2 #define FilterWidget_H
3 
4 
5 // parent
6 #include <QWidget>
7 
8 // these are included because it is needed inside a templated method
9 #include "FilterGroup.h"
10 
11 
12 class QLabel;
13 template< class T > class QList;
14 class QPushButton;
15 class QString;
16 class QTextEdit;
17 class QVBoxLayout;
18 
19 
20 namespace Isis {
21  class ControlCubeGraphNode;
22  class ControlMeasure;
23  class ControlPoint;
24 
25  namespace CnetViz {
26  class FilterGroup;
27 
47  class FilterWidget : public QWidget {
48  Q_OBJECT
49 
50  public:
51  explicit FilterWidget(QString);
52  FilterWidget(const FilterWidget &);
53  virtual ~FilterWidget();
54 
55  template< typename T >
56  bool evaluate(const T *t, bool (AbstractFilter::*meth)() const) const {
57  // if andFiltersTogether is true then we break out of the loop as
58  // soon as any selectors evaluate to false. If andFiltersTogether
59  // is false then we are ORing them so we break out as soon as any
60  // selector evaluates to true. Whether we are looking for
61  // successes or failures depends on whether we are ANDing or ORing
62  // the filters (selectors) together!!!
63  bool looking = true;
64  for (int i = 0; looking && i < m_filterGroups->size(); i++) {
65  if (m_filterGroups->at(i)->hasFilter(meth))
66  looking = !(m_filterGroups->at(i)->evaluate(t, meth) ^
67  m_andGroupsTogether);
68  }
69 
70  // It is good that we are still looking for failures if we were
71  // ANDing filters together, but it is bad if we were ORing them
72  // since in this case we were looking for success (unless of
73  // course there were no filters to look through).
74  return !(looking ^ m_andGroupsTogether) || !hasFilter(meth);
75  }
76 
77  bool evaluate(const ControlCubeGraphNode *node) const;
78  bool evaluate(const ControlPoint *point) const;
79  bool evaluate(const ControlMeasure *measure) const;
80 
81  bool hasFilter(bool (AbstractFilter:: *)() const) const;
82 
83  FilterWidget &operator=(FilterWidget other);
84 
85 
86  signals:
87  void filterChanged();
88  void scrollToBottom();
89 
90 
91  private:
92  void nullify();
93  void init();
94  QList< FilterGroup * > groupsWithCondition(
95  bool (FilterGroup:: *)() const) const;
96 
97  void updateDescription(QLabel *label,
98  bool (AbstractFilter:: *)() const,
99  QString(AbstractFilter:: *)() const,
100  QString);
101 
102  void addGroup(FilterGroup *newGroup);
103 
104 
105  private slots:
106  void addGroup();
107  void deleteGroup(FilterGroup *);
108  void changeGroupCombinationLogic(int);
109  void updateDescription();
110  void maybeScroll(FilterGroup *);
111 
112 
113  private:
114  QPushButton *m_addGroupButton;
115  QButtonGroup *m_buttonGroup;
116  QLabel *m_imageDescription;
117  QLabel *m_imageDummy;
118  QLabel *m_pointDescription;
119  QLabel *m_pointDummy;
120  QLabel *m_measureDescription;
121  QLabel *m_measureDummy;
122  QVBoxLayout *m_mainLayout;
123  QWidget *m_logicWidget;
124 
125  bool m_andGroupsTogether;
126 
127  QList< FilterGroup * > * m_filterGroups;
128  QString *m_filterType;
129  };
130  }
131 }
132 
133 #endif