casa
$Rev:20696$
|
00001 //# TBFilterRules.qo.h: Rules used to filter rows based upon field values. 00002 //# Copyright (C) 2005 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef TBFILTERRULES_H_ 00028 #define TBFILTERRULES_H_ 00029 00030 #include <casaqt/QtBrowser/TBFilterRules.ui.h> 00031 #include <casaqt/QtBrowser/TBConstants.h> 00032 00033 #include <QtGui> 00034 00035 #include <casa/BasicSL/String.h> 00036 00037 #include <casa/namespace.h> 00038 using namespace std; 00039 00040 namespace casa { 00041 00042 //# Forward Declarations 00043 class TBTable; 00044 class TBData; 00045 00046 // <summary> 00047 // Rule that can be used to filter rows based upon field values. 00048 // <summary> 00049 // 00050 // <synopsis> 00051 // A TBFilterRule is a single rule that consists of a field, a Comparator, and 00052 // the rule parameters. A rule consists of one comparator and at least one 00053 // value. A rule can be negated (i.e., "not equal"), or applied to any field 00054 // (i.e., any field with a value > 5). 00055 // </synopsis> 00056 00057 class TBFilterRule { 00058 public: 00059 // Constructor that takes the rule parameters. value should be the value 00060 // being compared against; value2 can only be NULL if 00061 // the comparator only takes one argument. isNot should be true for 00062 // negated rules, false otherwise. anyField should be true if the rule 00063 // applies to any field, false otherwise. The rule "owns" value and value2 00064 // in that, upon deletion, they are deleted as well. 00065 TBFilterRule(String field, Comparator comparator, TBData* value, 00066 TBData* value2 = NULL, bool isNot = false, bool anyField = false); 00067 00068 ~TBFilterRule(); 00069 00070 00071 // Returns the field this rule applies to, or blank if it applies to any 00072 // field. 00073 String getField(); 00074 00075 // Returns this rule's comparator. 00076 Comparator getComparator(); 00077 00078 // Returns this rule's value. 00079 TBData* getValue(); 00080 00081 // Returns this rule's second value, or blank if it doesn't have one. 00082 TBData* getValue2(); 00083 00084 // Returns true if this rule is negated (i.e., "not equal" rather than 00085 // "equal"), false otherwise. 00086 bool getIsNot(); 00087 00088 // Returns true if this rule applies to any field, false otherwise. 00089 bool getAnyField(); 00090 00091 00092 // Returns true if this rule is equal to the given rule, false otherwise. 00093 bool equals(TBFilterRule* r); 00094 00095 // Checks the given row in the given table. If the row passes, the index 00096 // of the first field to pass is returned; if the row does not pass, -1 is 00097 // returned. 00098 int rowPasses(TBTable* table, int row); 00099 00100 private: 00101 // This rule's field. 00102 String field; 00103 00104 // This rule's comparator. 00105 Comparator comparator; 00106 00107 // This rule's value. 00108 TBData* value; 00109 00110 // This rule's second value. 00111 TBData* value2; 00112 00113 // Indicates whether this rule is negated or not. 00114 bool isNot; 00115 00116 // Indicates whether this rule applies to any field or not. 00117 bool anyField; 00118 00119 00120 // Checks all fields in the given row. If any of the fields pass, the 00121 // index of the first field to pass is returned; otherwise, -1 is returned. 00122 int anyFieldPasses(TBTable* table, int row); 00123 }; 00124 00125 // <summary> 00126 // A sequence of TBFilterRules that can be used to filter rows. 00127 // <summary> 00128 // 00129 // <synopsis> 00130 // A TBFilterRuleSequence is basically just a list of TBFilterRules. In the 00131 // future, more complex sequences can be implemented such as logical clauses. 00132 // In order for a row to pass a rule sequence, it must pass ALL rules in the 00133 // sequence. 00134 // </synopsis> 00135 00136 class TBFilterRuleSequence { 00137 public: 00138 // Default Constructor. 00139 TBFilterRuleSequence(); 00140 00141 ~TBFilterRuleSequence(); 00142 00143 00144 // Returns the number of rules in this sequence. 00145 unsigned int size(); 00146 00147 // Returns the rule at index i in this sequence. 00148 TBFilterRule* at(unsigned int i); 00149 00150 // Returns the rules in this sequence. 00151 vector<TBFilterRule*>* getRules(); 00152 00153 00154 // Checks the given row in the given table. If the row passes ALL of the 00155 // rules in this sequence, the index of the first field that passed is 00156 // returned. If the row fails at least one rule in the sequence, -1 is 00157 // returned. See TBFilterRule::rowPasses(). 00158 int rowPasses(TBTable* table, int row); 00159 00160 // Adds the given rule to the end of the sequence. 00161 void addRule(TBFilterRule* rule); 00162 00163 // Removes the rule at index i from this sequence. 00164 void removeRule(int i); 00165 00166 private: 00167 // Rule sequence. 00168 vector<TBFilterRule*> rules; 00169 }; 00170 00171 // <summary> 00172 // Widget to allow the user to enter a filter rule sequence. 00173 // <summary> 00174 // 00175 // <synopsis> 00176 // TBFilterRules can be presented to the user as a modal dialog or as a widget 00177 // displayed in any layout. Once the user has finished entering the rules, 00178 // the TBFilterRules emits a signal with the entered rules. Important: the 00179 // caller/parent is responsible for connecting this signal and taking care of 00180 // the dialog. 00181 // </synopsis> 00182 00183 class TBFilterRules : public QDialog, Ui::FilterRules { 00184 Q_OBJECT 00185 00186 public: 00187 // Constructor that takes a table and an optional parent parameter. If 00188 // parent is NULL, the GUI is presented as a dialog. 00189 TBFilterRules(TBTable* table, QWidget* parent = NULL); 00190 00191 ~TBFilterRules(); 00192 00193 // Renames the window title and run button text to distinguish between 00194 // a search and a filter. If isSearch is true, the title is set to "Search 00195 // Rules" and the run button text is set to "Search"; otherwise the title 00196 // is set to "Filter Rules" and the run button text is set to "Run Filter." 00197 // The default behavior is for filter, not search. 00198 void renameForSearch(bool isSearch); 00199 00200 signals: 00201 // This signal is emitted when the user has entered a TBFilterRuleSequence 00202 // and has indicated that he/she is finished. The entered rules are passed 00203 // as a parameter as is a pointer to this widget. The parent/caller is 00204 // responsible for implementing the rules and deleting the dialog upon 00205 // completion. 00206 void runRequested(TBFilterRuleSequence* rules, TBFilterRules* rDialog); 00207 00208 private: 00209 // Associated table. 00210 TBTable* table; 00211 00212 // Entered rule sequence. 00213 TBFilterRuleSequence* rules; 00214 00215 private slots: 00216 // Slot for the "run" button. Emits the runRequested() signal. 00217 void runClicked(); 00218 00219 // Slot for when the field QComboBox changes. Updates the rule parameters 00220 // to apply to the chosen field. 00221 void fieldChosen(int i); 00222 00223 // Slot for when the comparator QComboBox value changes. Updates the rule 00224 // parameters accordingly. 00225 void comparatorChosen(QString c); 00226 00227 // Slot for the "add" button. If the user has just entered a new rule, 00228 // it is added to the sequence. If the user is viewing a 00229 // previously-entered rule, the display is cleared so that a new rule 00230 // can be entered. 00231 void addRule(); 00232 00233 // Slot for the "remove" button. Removes the currently selected rule 00234 // from the sequence. 00235 void removeRule(); 00236 00237 // Slot for when the user selects a rule in the list. Displays the 00238 // selected rule. 00239 void listIndexChanged(int i); 00240 }; 00241 00242 } 00243 00244 #endif /* TBFILTERRULES_H_ */