summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/ui/tvfilterview.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tableviewer/ui/tvfilterview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.cpp55
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
@@ -15,27 +15,33 @@
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>
25using 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
31TVFilterView::TVFilterView(TableState *t, QWidget* parent, 37TVFilterView::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");
@@ -85,27 +91,27 @@ TVFilterView::TVFilterView(TableState *t, QWidget* parent,
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*/
107TVFilterView::~TVFilterView() 113TVFilterView::~TVFilterView()
108{ 114{
109} 115}
110 116
111void TVFilterView::rebuildData() 117void TVFilterView::rebuildData()
@@ -115,41 +121,41 @@ void TVFilterView::rebuildData()
115void TVFilterView::reset() 121void TVFilterView::reset()
116{ 122{
117 keyNameCombo->clear(); 123 keyNameCombo->clear();
118 keyIds.clear(); 124 keyIds.clear();
119} 125}
120 126
121void TVFilterView::rebuildKeys() 127void 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
144bool TVFilterView::passesFilter(DataElem *d) { 150bool 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;
@@ -172,14 +178,13 @@ bool TVFilterView::passesFilter(DataElem *d) {
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
@@ -191,13 +196,13 @@ bool TVFilterView::filterActive() const
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 */
197void TVFilterView::newTerm() 202void 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
@@ -209,13 +214,13 @@ void TVFilterView::newTerm()
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
215void TVFilterView::updateTerm() 220void 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;
@@ -228,13 +233,13 @@ void TVFilterView::updateTerm()
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;
@@ -257,20 +262,20 @@ void TVFilterView::updateTerm()
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 */
270void TVFilterView::deleteTerm() 275void 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);
@@ -281,26 +286,26 @@ void TVFilterView::deleteTerm()
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 */
287void TVFilterView::clearTerms() 292void TVFilterView::clearTerms()
288{ 293{
289 while(current) 294 while(current)
290 deleteTerm(); 295 deleteTerm();
291} 296}
292 297
293void TVFilterView::setTerm(QListViewItem *target) 298void 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}