casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TBFilterRules.qo.h
Go to the documentation of this file.
1 //# TBFilterRules.qo.h: Rules used to filter rows based upon field values.
2 //# Copyright (C) 2005
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id: $
27 #ifndef TBFILTERRULES_H_
28 #define TBFILTERRULES_H_
29 
30 #include <casaqt/QtBrowser/TBFilterRules.ui.h>
32 
33 #include <QtGui>
34 
35 #include <casa/BasicSL/String.h>
36 
37 namespace casa {
38 
39 //# Forward Declarations
40 class TBTable;
41 class TBData;
42 
43 // <summary>
44 // Rule that can be used to filter rows based upon field values.
45 // <summary>
46 //
47 // <synopsis>
48 // A TBFilterRule is a single rule that consists of a field, a Comparator, and
49 // the rule parameters. A rule consists of one comparator and at least one
50 // value. A rule can be negated (i.e., "not equal"), or applied to any field
51 // (i.e., any field with a value > 5).
52 // </synopsis>
53 
54 class TBFilterRule {
55 public:
56  // Constructor that takes the rule parameters. value should be the value
57  // being compared against; value2 can only be NULL if
58  // the comparator only takes one argument. isNot should be true for
59  // negated rules, false otherwise. anyField should be true if the rule
60  // applies to any field, false otherwise. The rule "owns" value and value2
61  // in that, upon deletion, they are deleted as well.
63  TBData* value2 = NULL, bool isNot = false, bool anyField = false);
64 
65  ~TBFilterRule();
66 
67 
68  // Returns the field this rule applies to, or blank if it applies to any
69  // field.
71 
72  // Returns this rule's comparator.
74 
75  // Returns this rule's value.
76  TBData* getValue();
77 
78  // Returns this rule's second value, or blank if it doesn't have one.
79  TBData* getValue2();
80 
81  // Returns true if this rule is negated (i.e., "not equal" rather than
82  // "equal"), false otherwise.
83  bool getIsNot();
84 
85  // Returns true if this rule applies to any field, false otherwise.
86  bool getAnyField();
87 
88 
89  // Returns true if this rule is equal to the given rule, false otherwise.
90  bool equals(TBFilterRule* r);
91 
92  // Checks the given row in the given table. If the row passes, the index
93  // of the first field to pass is returned; if the row does not pass, -1 is
94  // returned.
95  int rowPasses(TBTable* table, int row);
96 
97 private:
98  // This rule's field.
100 
101  // This rule's comparator.
103 
104  // This rule's value.
106 
107  // This rule's second value.
109 
110  // Indicates whether this rule is negated or not.
111  bool isNot;
112 
113  // Indicates whether this rule applies to any field or not.
114  bool anyField;
115 
116 
117  // Checks all fields in the given row. If any of the fields pass, the
118  // index of the first field to pass is returned; otherwise, -1 is returned.
119  int anyFieldPasses(TBTable* table, int row);
120 };
121 
122 // <summary>
123 // A sequence of TBFilterRules that can be used to filter rows.
124 // <summary>
125 //
126 // <synopsis>
127 // A TBFilterRuleSequence is basically just a list of TBFilterRules. In the
128 // future, more complex sequences can be implemented such as logical clauses.
129 // In order for a row to pass a rule sequence, it must pass ALL rules in the
130 // sequence.
131 // </synopsis>
132 
134 public:
135  // Default Constructor.
137 
139 
140 
141  // Returns the number of rules in this sequence.
142  unsigned int size();
143 
144  // Returns the rule at index i in this sequence.
145  TBFilterRule* at(unsigned int i);
146 
147  // Returns the rules in this sequence.
148  std::vector<TBFilterRule*>* getRules();
149 
150 
151  // Checks the given row in the given table. If the row passes ALL of the
152  // rules in this sequence, the index of the first field that passed is
153  // returned. If the row fails at least one rule in the sequence, -1 is
154  // returned. See TBFilterRule::rowPasses().
155  int rowPasses(TBTable* table, int row);
156 
157  // Adds the given rule to the end of the sequence.
158  void addRule(TBFilterRule* rule);
159 
160  // Removes the rule at index i from this sequence.
161  void removeRule(int i);
162 
163 private:
164  // Rule sequence.
165  std::vector<TBFilterRule*> rules;
166 };
167 
168 // <summary>
169 // Widget to allow the user to enter a filter rule sequence.
170 // <summary>
171 //
172 // <synopsis>
173 // TBFilterRules can be presented to the user as a modal dialog or as a widget
174 // displayed in any layout. Once the user has finished entering the rules,
175 // the TBFilterRules emits a signal with the entered rules. Important: the
176 // caller/parent is responsible for connecting this signal and taking care of
177 // the dialog.
178 // </synopsis>
179 
180 class TBFilterRules : public QDialog, Ui::FilterRules {
181  Q_OBJECT
182 
183 public:
184  // Constructor that takes a table and an optional parent parameter. If
185  // parent is NULL, the GUI is presented as a dialog.
186  TBFilterRules(TBTable* table, QWidget* parent = NULL);
187 
188  ~TBFilterRules();
189 
190  // Renames the window title and run button text to distinguish between
191  // a search and a filter. If isSearch is true, the title is set to "Search
192  // Rules" and the run button text is set to "Search"; otherwise the title
193  // is set to "Filter Rules" and the run button text is set to "Run Filter."
194  // The default behavior is for filter, not search.
195  void renameForSearch(bool isSearch);
196 
197 signals:
198  // This signal is emitted when the user has entered a TBFilterRuleSequence
199  // and has indicated that he/she is finished. The entered rules are passed
200  // as a parameter as is a pointer to this widget. The parent/caller is
201  // responsible for implementing the rules and deleting the dialog upon
202  // completion.
204 
205 private:
206  // Associated table.
208 
209  // Entered rule sequence.
211 
212 private slots:
213  // Slot for the "run" button. Emits the runRequested() signal.
214  void runClicked();
215 
216  // Slot for when the field QComboBox changes. Updates the rule parameters
217  // to apply to the chosen field.
218  void fieldChosen(int i);
219 
220  // Slot for when the comparator QComboBox value changes. Updates the rule
221  // parameters accordingly.
222  void comparatorChosen(QString c);
223 
224  // Slot for the "add" button. If the user has just entered a new rule,
225  // it is added to the sequence. If the user is viewing a
226  // previously-entered rule, the display is cleared so that a new rule
227  // can be entered.
228  void addRule();
229 
230  // Slot for the "remove" button. Removes the currently selected rule
231  // from the sequence.
232  void removeRule();
233 
234  // Slot for when the user selects a rule in the list. Displays the
235  // selected rule.
236  void listIndexChanged(int i);
237 };
238 
239 }
240 
241 #endif /* TBFILTERRULES_H_ */
TBData * value
This rule&#39;s value.
void addRule()
Slot for the &quot;add&quot; button.
int anyFieldPasses(TBTable *table, int row)
Checks all fields in the given row.
tb::Comparator comparator
This rule&#39;s comparator.
TBData * getValue()
Returns this rule&#39;s value.
void removeRule()
Slot for the &quot;remove&quot; button.
std::vector< TBFilterRule * > rules
Rule sequence.
casacore::Data types used for loaded data.
Definition: TBData.h:51
bool isNot
Indicates whether this rule is negated or not.
bool equals(TBFilterRule *r)
Returns true if this rule is equal to the given rule, false otherwise.
void renameForSearch(bool isSearch)
Renames the window title and run button text to distinguish between a search and a filter...
TBFilterRules(TBTable *table, QWidget *parent=NULL)
Constructor that takes a table and an optional parent parameter.
int rowPasses(TBTable *table, int row)
Checks the given row in the given table.
Comparator
Enum listing the possible types of comparisons that can be made in, for example, a filter rule...
Definition: TBConstants.h:61
void addRule(TBFilterRule *rule)
Adds the given rule to the end of the sequence.
TBFilterRuleSequence()
Default Constructor.
tb::Comparator getComparator()
Returns this rule&#39;s comparator.
void runClicked()
Slot for the &quot;run&quot; button.
void removeRule(int i)
Removes the rule at index i from this sequence.
int rowPasses(TBTable *table, int row)
Checks the given row in the given table.
TBTable * table
Associated table.
bool getIsNot()
Returns true if this rule is negated (i.e., &quot;not equal&quot; rather than &quot;equal&quot;), false otherwise...
TBFilterRule * at(unsigned int i)
Returns the rule at index i in this sequence.
casacore::String getField()
Returns the field this rule applies to, or blank if it applies to any field.
Primary interface for the rest of the browser to a table.
Definition: TBTable.h:152
void listIndexChanged(int i)
Slot for when the user selects a rule in the list.
bool anyField
Indicates whether this rule applies to any field or not.
Rule that can be used to filter rows based upon field values.
Widget to allow the user to enter a filter rule sequence.
TBFilterRule(casacore::String field, tb::Comparator comparator, TBData *value, TBData *value2=NULL, bool isNot=false, bool anyField=false)
Constructor that takes the rule parameters.
void comparatorChosen(QString c)
Slot for when the comparator QComboBox value changes.
A sequence of TBFilterRules that can be used to filter rows.
unsigned int size()
Returns the number of rules in this sequence.
TBData * value2
This rule&#39;s second value.
bool getAnyField()
Returns true if this rule applies to any field, false otherwise.
const Double c
Fundamental physical constants (SI units):
String: the storage and methods of handling collections of characters.
Definition: String.h:223
std::vector< TBFilterRule * > * getRules()
Returns the rules in this sequence.
TBData * getValue2()
Returns this rule&#39;s second value, or blank if it doesn&#39;t have one.
void runRequested(TBFilterRuleSequence *rules, TBFilterRules *rDialog)
This signal is emitted when the user has entered a TBFilterRuleSequence and has indicated that he/she...
TBFilterRuleSequence * rules
Entered rule sequence.
casacore::String field
This rule&#39;s field.
void fieldChosen(int i)
Slot for when the field QComboBox changes.