Diffstat (limited to 'noncore/apps/tableviewer/ui/tvfilterview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/ui/tvfilterview.cpp | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp index 22f1fb7..198c8b5 100644 --- a/noncore/apps/tableviewer/ui/tvfilterview.cpp +++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp | |||
@@ -9,39 +9,45 @@ | |||
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "tvfilterview.h" | 20 | #include "tvfilterview.h" |
21 | |||
22 | /* OPIE */ | ||
23 | #include <opie2/odebug.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | using namespace Opie::Core; | ||
26 | |||
27 | /* QT */ | ||
21 | #include <qtoolbutton.h> | 28 | #include <qtoolbutton.h> |
22 | #include <qcombobox.h> | 29 | #include <qcombobox.h> |
23 | #include <qlistview.h> | 30 | #include <qlistview.h> |
24 | #include <qlayout.h> | 31 | #include <qlayout.h> |
25 | #include <qheader.h> | 32 | #include <qheader.h> |
26 | #include <qpushbutton.h> | 33 | #include <qpushbutton.h> |
27 | #include <qlabel.h> | 34 | #include <qlabel.h> |
28 | 35 | ||
29 | #include <qpe/qpeapplication.h> | ||
30 | 36 | ||
31 | TVFilterView::TVFilterView(TableState *t, QWidget* parent, | 37 | TVFilterView::TVFilterView(TableState *t, QWidget* parent, |
32 | const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl) | 38 | const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl) |
33 | { | 39 | { |
34 | if ( !name ) | 40 | if ( !name ) |
35 | setName( "Filter View" ); | 41 | setName( "Filter View" ); |
36 | 42 | ||
37 | QVBoxLayout *vlayout = new QVBoxLayout(this); | 43 | QVBoxLayout *vlayout = new QVBoxLayout(this); |
38 | 44 | ||
39 | display = new QListView(this, "display"); | 45 | display = new QListView(this, "display"); |
40 | display->addColumn("Key"); | 46 | display->addColumn("Key"); |
41 | display->addColumn("Constraint"); | 47 | display->addColumn("Constraint"); |
42 | display->addColumn("Value"); | 48 | display->addColumn("Value"); |
43 | display->header()->setClickEnabled(FALSE); | 49 | display->header()->setClickEnabled(FALSE); |
44 | display->header()->setResizeEnabled(FALSE); | 50 | display->header()->setResizeEnabled(FALSE); |
45 | 51 | ||
46 | vlayout->addWidget(display); | 52 | vlayout->addWidget(display); |
47 | 53 | ||
@@ -79,83 +85,83 @@ TVFilterView::TVFilterView(TableState *t, QWidget* parent, | |||
79 | keyEntry->setEnabled(FALSE); | 85 | keyEntry->setEnabled(FALSE); |
80 | 86 | ||
81 | vlayout->addLayout(hlayout2); | 87 | vlayout->addLayout(hlayout2); |
82 | vlayout->addWidget(keyEntry); | 88 | vlayout->addWidget(keyEntry); |
83 | 89 | ||
84 | connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); | 90 | connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); |
85 | connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); | 91 | connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); |
86 | connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); | 92 | connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); |
87 | 93 | ||
88 | connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); | 94 | connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); |
89 | connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); | 95 | connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); |
90 | 96 | ||
91 | connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, | 97 | connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, |
92 | SLOT(setTerm(QListViewItem*))); | 98 | SLOT(setTerm(QListViewItem*))); |
93 | 99 | ||
94 | ts = t; | 100 | ts = t; |
95 | current = 0; | 101 | current = 0; |
96 | terms.setAutoDelete(true); | 102 | terms.setAutoDelete(true); |
97 | do_filter = false; | 103 | do_filter = false; |
98 | 104 | ||
99 | #ifdef Q_WS_QWS | 105 | #ifdef Q_WS_QWS |
100 | QPEApplication::showDialog( this ); | 106 | QPEApplication::showDialog( this ); |
101 | #endif | 107 | #endif |
102 | } | 108 | } |
103 | 109 | ||
104 | /*! | 110 | /*! |
105 | Destroys the TVFilterView widget | 111 | Destroys the TVFilterView widget |
106 | */ | 112 | */ |
107 | TVFilterView::~TVFilterView() | 113 | TVFilterView::~TVFilterView() |
108 | { | 114 | { |
109 | } | 115 | } |
110 | 116 | ||
111 | void TVFilterView::rebuildData() | 117 | void TVFilterView::rebuildData() |
112 | { | 118 | { |
113 | } | 119 | } |
114 | 120 | ||
115 | void TVFilterView::reset() | 121 | void TVFilterView::reset() |
116 | { | 122 | { |
117 | keyNameCombo->clear(); | 123 | keyNameCombo->clear(); |
118 | keyIds.clear(); | 124 | keyIds.clear(); |
119 | } | 125 | } |
120 | 126 | ||
121 | void TVFilterView::rebuildKeys() | 127 | void TVFilterView::rebuildKeys() |
122 | { | 128 | { |
123 | int i; | 129 | int i; |
124 | 130 | ||
125 | if (!ts) return; | 131 | if (!ts) return; |
126 | if(!ts->kRep) return; | 132 | if(!ts->kRep) return; |
127 | keyEntry->setTableState(ts); | 133 | keyEntry->setTableState(ts); |
128 | 134 | ||
129 | /* set up the list of keys that can be compared on */ | 135 | /* set up the list of keys that can be compared on */ |
130 | keyNameCombo->clear(); | 136 | keyNameCombo->clear(); |
131 | KeyListIterator it(*ts->kRep); | 137 | KeyListIterator it(*ts->kRep); |
132 | 138 | ||
133 | i = 0; | 139 | i = 0; |
134 | while(it.current()) { | 140 | while(it.current()) { |
135 | if(ts->kRep->validIndex(it.currentKey())) { | 141 | if(ts->kRep->validIndex(it.currentKey())) { |
136 | keyNameCombo->insertItem(it.current()->name()); | 142 | keyNameCombo->insertItem(it.current()->name()); |
137 | keyIds.insert(i, it.currentKey()); | 143 | keyIds.insert(i, it.currentKey()); |
138 | ++i; | 144 | ++i; |
139 | } | 145 | } |
140 | ++it; | 146 | ++it; |
141 | } | 147 | } |
142 | } | 148 | } |
143 | 149 | ||
144 | bool TVFilterView::passesFilter(DataElem *d) { | 150 | bool TVFilterView::passesFilter(DataElem *d) { |
145 | if (!filterActive()) return true; | 151 | if (!filterActive()) return true; |
146 | 152 | ||
147 | 153 | ||
148 | FilterTerm *t; | 154 | FilterTerm *t; |
149 | 155 | ||
150 | for (t = terms.first(); t != 0; t = terms.next() ) { | 156 | for (t = terms.first(); t != 0; t = terms.next() ) { |
151 | /* check against filter */ | 157 | /* check against filter */ |
152 | switch(t->ct) { | 158 | switch(t->ct) { |
153 | case ct_less: | 159 | case ct_less: |
154 | if (!d->lessThan(t->keyIndex, t->value)) | 160 | if (!d->lessThan(t->keyIndex, t->value)) |
155 | return false; | 161 | return false; |
156 | break; | 162 | break; |
157 | case ct_more: | 163 | case ct_more: |
158 | if (!d->moreThan(t->keyIndex, t->value)) | 164 | if (!d->moreThan(t->keyIndex, t->value)) |
159 | return false; | 165 | return false; |
160 | break; | 166 | break; |
161 | case ct_equal: | 167 | case ct_equal: |
@@ -166,81 +172,80 @@ bool TVFilterView::passesFilter(DataElem *d) { | |||
166 | if (!d->contains(t->keyIndex, t->value)) | 172 | if (!d->contains(t->keyIndex, t->value)) |
167 | return false; | 173 | return false; |
168 | break; | 174 | break; |
169 | case ct_startswith: | 175 | case ct_startswith: |
170 | if (!d->startsWith(t->keyIndex, t->value)) | 176 | if (!d->startsWith(t->keyIndex, t->value)) |
171 | return false; | 177 | return false; |
172 | break; | 178 | break; |
173 | case ct_endswith: | 179 | case ct_endswith: |
174 | if (!d->endsWith(t->keyIndex, t->value)) | 180 | if (!d->endsWith(t->keyIndex, t->value)) |
175 | return false; | 181 | return false; |
176 | break; | 182 | break; |
177 | default: | 183 | default: |
178 | qWarning("TVFilterView::passesFilter() " | 184 | owarn << "TVFilterView::passesFilter() unrecognized filter type" << oendl; |
179 | "unrecognized filter type"); | ||
180 | return false; | 185 | return false; |
181 | } | 186 | } |
182 | } | 187 | } |
183 | return true; | 188 | return true; |
184 | } | 189 | } |
185 | 190 | ||
186 | bool TVFilterView::filterActive() const | 191 | bool TVFilterView::filterActive() const |
187 | { | 192 | { |
188 | /* when button operated, also check the do_filter value | 193 | /* when button operated, also check the do_filter value |
189 | return do_filter; | 194 | return do_filter; |
190 | */ | 195 | */ |
191 | if (terms.isEmpty()) | 196 | if (terms.isEmpty()) |
192 | return false; | 197 | return false; |
193 | return true; | 198 | return true; |
194 | } | 199 | } |
195 | 200 | ||
196 | /* SLOTS */ | 201 | /* SLOTS */ |
197 | void TVFilterView::newTerm() | 202 | void TVFilterView::newTerm() |
198 | { | 203 | { |
199 | if (!ts) return; | 204 | if (!ts) return; |
200 | 205 | ||
201 | FilterTerm *term = new FilterTerm; | 206 | FilterTerm *term = new FilterTerm; |
202 | current = term; | 207 | current = term; |
203 | 208 | ||
204 | term->view = 0; | 209 | term->view = 0; |
205 | 210 | ||
206 | updateTerm(); | 211 | updateTerm(); |
207 | 212 | ||
208 | display->setSelected(term->view, true); | 213 | display->setSelected(term->view, true); |
209 | terms.append(term); | 214 | terms.append(term); |
210 | 215 | ||
211 | keyEntry->setEnabled(true); | 216 | keyEntry->setEnabled(true); |
212 | keyNameCombo->setEnabled(true); | 217 | keyNameCombo->setEnabled(true); |
213 | } | 218 | } |
214 | 219 | ||
215 | void TVFilterView::updateTerm() | 220 | void TVFilterView::updateTerm() |
216 | { | 221 | { |
217 | FilterTerm *term; | 222 | FilterTerm *term; |
218 | /* Read the widget values (keyname, compare type, value) | 223 | /* Read the widget values (keyname, compare type, value) |
219 | * and build the lists */ | 224 | * and build the lists */ |
220 | if (!ts) return; | 225 | if (!ts) return; |
221 | if (!current) return; | 226 | if (!current) return; |
222 | 227 | ||
223 | QString keyString; | 228 | QString keyString; |
224 | QString cmpString; | 229 | QString cmpString; |
225 | QString vString; | 230 | QString vString; |
226 | 231 | ||
227 | term = current; | 232 | term = current; |
228 | 233 | ||
229 | /* create new list item, set initial values, enable widgets */ | 234 | /* create new list item, set initial values, enable widgets */ |
230 | term->keyIndex = keyIds[keyNameCombo->currentItem()]; | 235 | term->keyIndex = keyIds[keyNameCombo->currentItem()]; |
231 | keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ | 236 | keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ |
232 | term->ct = keyEntry->getCompareType(), | 237 | term->ct = keyEntry->getCompareType(), |
233 | term->value = keyEntry->getCompareValue(); | 238 | term->value = keyEntry->getCompareValue(); |
234 | 239 | ||
235 | keyString = keyNameCombo->currentText(); | 240 | keyString = keyNameCombo->currentText(); |
236 | 241 | ||
237 | switch(term->ct) { | 242 | switch(term->ct) { |
238 | case ct_less: | 243 | case ct_less: |
239 | cmpString = " less than "; | 244 | cmpString = " less than "; |
240 | break; | 245 | break; |
241 | case ct_more: | 246 | case ct_more: |
242 | cmpString = " more than "; | 247 | cmpString = " more than "; |
243 | break; | 248 | break; |
244 | case ct_equal: | 249 | case ct_equal: |
245 | cmpString = " equal to "; | 250 | cmpString = " equal to "; |
246 | break; | 251 | break; |
@@ -251,56 +256,56 @@ void TVFilterView::updateTerm() | |||
251 | cmpString = " starting with "; | 256 | cmpString = " starting with "; |
252 | break; | 257 | break; |
253 | case ct_endswith: | 258 | case ct_endswith: |
254 | cmpString = " ending with "; | 259 | cmpString = " ending with "; |
255 | break; | 260 | break; |
256 | default: | 261 | default: |
257 | cmpString = " ERROR "; | 262 | cmpString = " ERROR "; |
258 | } | 263 | } |
259 | 264 | ||
260 | vString = term->value.toString(); | 265 | vString = term->value.toString(); |
261 | 266 | ||
262 | /* remove old view */ | 267 | /* remove old view */ |
263 | if (term->view) | 268 | if (term->view) |
264 | delete(term->view); | 269 | delete(term->view); |
265 | term->view = new QListViewItem(display, 0, keyString, cmpString, vString); | 270 | term->view = new QListViewItem(display, 0, keyString, cmpString, vString); |
266 | display->setSelected(term->view, true); | 271 | display->setSelected(term->view, true); |
267 | } | 272 | } |
268 | 273 | ||
269 | /* deletes current term */ | 274 | /* deletes current term */ |
270 | void TVFilterView::deleteTerm() | 275 | void TVFilterView::deleteTerm() |
271 | { | 276 | { |
272 | if(!current) return; | 277 | if(!current) return; |
273 | if (current->view) | 278 | if (current->view) |
274 | delete(current->view); | 279 | delete(current->view); |
275 | 280 | ||
276 | terms.removeRef(current); | 281 | terms.removeRef(current); |
277 | 282 | ||
278 | current = terms.first(); | 283 | current = terms.first(); |
279 | 284 | ||
280 | if(terms.isEmpty()) { | 285 | if(terms.isEmpty()) { |
281 | keyEntry->setEnabled(false); | 286 | keyEntry->setEnabled(false); |
282 | keyNameCombo->setEnabled(false); | 287 | keyNameCombo->setEnabled(false); |
283 | } | 288 | } |
284 | } | 289 | } |
285 | 290 | ||
286 | /* clears all terminations */ | 291 | /* clears all terminations */ |
287 | void TVFilterView::clearTerms() | 292 | void TVFilterView::clearTerms() |
288 | { | 293 | { |
289 | while(current) | 294 | while(current) |
290 | deleteTerm(); | 295 | deleteTerm(); |
291 | } | 296 | } |
292 | 297 | ||
293 | void TVFilterView::setTerm(QListViewItem *target) | 298 | void TVFilterView::setTerm(QListViewItem *target) |
294 | { | 299 | { |
295 | /* Iterate through the list to find item with view=target.. | 300 | /* Iterate through the list to find item with view=target.. |
296 | * set as current, delete */ | 301 | * set as current, delete */ |
297 | FilterTerm *term = current; | 302 | FilterTerm *term = current; |
298 | 303 | ||
299 | for (current = terms.first(); current != 0; current = terms.next() ) | 304 | for (current = terms.first(); current != 0; current = terms.next() ) |
300 | if (current->view == target) | 305 | if (current->view == target) |
301 | break; | 306 | break; |
302 | 307 | ||
303 | if (!current) { | 308 | if (!current) { |
304 | current = term; | 309 | current = term; |
305 | } | 310 | } |
306 | } | 311 | } |