summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/db/common.cpp2
-rw-r--r--noncore/apps/tableviewer/db/csvsource.cpp1
-rw-r--r--noncore/apps/tableviewer/ui/commonwidgets.cpp6
-rw-r--r--noncore/apps/tableviewer/ui/tvbrowseview.cpp4
-rw-r--r--noncore/apps/tableviewer/ui/tveditview.cpp4
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.cpp4
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit.cpp4
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.cpp4
8 files changed, 15 insertions, 14 deletions
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp
index 71844a5..dbf9370 100644
--- a/noncore/apps/tableviewer/db/common.cpp
+++ b/noncore/apps/tableviewer/db/common.cpp
@@ -1,1470 +1,1470 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 <stdlib.h> 20#include <stdlib.h>
21#include <qstring.h> 21#include <qstring.h>
22#include <qheader.h> 22#include <qheader.h>
23#include <qvector.h> 23#include <qvector.h>
24#include <qdatetime.h> 24#include <qdatetime.h>
25#include <qpe/timestring.h> 25#include <qpe/timestring.h>
26#include "common.h" 26#include "common.h"
27#include "datacache.h" 27#include "datacache.h"
28#include <assert.h> 28#include <assert.h>
29 29
30static const int del_flag = 0x1; 30static const int del_flag = 0x1;
31static const int new_flag = 0x2; 31static const int new_flag = 0x2;
32 32
33/* Helper function */ 33/* Helper function */
34 34
35int parseNextNumber(QString *q) { 35int parseNextNumber(QString *q) {
36 QChar c; 36 QChar c;
37 uint i; 37 uint i;
38 int result = 0; 38 int result = 0;
39 39
40 bool found_digits = FALSE; 40 bool found_digits = FALSE;
41 for(i = 0; i < q->length(); i++) { 41 for(i = 0; i < q->length(); i++) {
42 c = q->at(i); 42 c = q->at(i);
43 if (c.isDigit()) { 43 if (c.isDigit()) {
44 if (found_digits) 44 if (found_digits)
45 result *= 10; 45 result *= 10;
46 found_digits = TRUE; 46 found_digits = TRUE;
47 result += c.digitValue(); 47 result += c.digitValue();
48 } else { 48 } else {
49 if (found_digits) 49 if (found_digits)
50 break; 50 break;
51 /* just skip this char */ 51 /* just skip this char */
52 } 52 }
53 } 53 }
54 /* now truncate q */ 54 /* now truncate q */
55 if (found_digits) 55 if (found_digits)
56 q->remove(0, i); 56 q->remove(0, i);
57 return result; 57 return result;
58} 58}
59 59
60/*! 60/*!
61 \class QStringVector 61 \class QStringVector
62 \brief A Vector of QStrings that can be sorted and searched 62 \brief A Vector of QStrings that can be sorted and searched
63 63
64 Implmented in order to allow reverse lookup on the string name 64 Implmented in order to allow reverse lookup on the string name
65 65
66*/ 66*/
67 67
68/*! 68/*!
69 This function implements the compare function in order to allow the 69 This function implements the compare function in order to allow the
70 searching and sorting of the QStringVector to occur 70 searching and sorting of the QStringVector to occur
71 71
72 \returns an int which is either 72 \returns an int which is either
73 <UL> 73 <UL>
74 <LI> < 0 if the first string is smaller than the second,</LI> 74 <LI> < 0 if the first string is smaller than the second,</LI>
75 <LI> > 0 if the first string is bigger then the second,</LI> 75 <LI> > 0 if the first string is bigger then the second,</LI>
76 <LI> == 0 if the first string is equal to the second.</LI> 76 <LI> == 0 if the first string is equal to the second.</LI>
77 </UL> 77 </UL>
78*/ 78*/
79int QStringVector::compareItems(Item a, Item b) 79int QStringVector::compareItems(Item a, Item b)
80{ 80{
81 QString *qa = (QString *)a; 81 QString *qa = (QString *)a;
82 QString *qb = (QString *)b; 82 QString *qb = (QString *)b;
83 83
84 return QString::compare(*qa, *qb); 84 return QString::compare(*qa, *qb);
85} 85}
86 86
87/*! 87/*!
88 \class TVVariant 88 \class TVVariant
89 A way of abstracting void * and keeping information on 89 A way of abstracting void * and keeping information on
90 the keytypes and behaviours in one place 90 the keytypes and behaviours in one place
91*/ 91*/
92 92
93TVVariantPrivate::TVVariantPrivate() 93TVVariantPrivate::TVVariantPrivate()
94{ 94{
95 typ = TVVariant::Invalid; 95 typ = TVVariant::Invalid;
96} 96}
97 97
98TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d) 98TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d)
99{ 99{
100 switch(d->typ) 100 switch(d->typ)
101 { 101 {
102 case TVVariant::Invalid: 102 case TVVariant::Invalid:
103 break; 103 break;
104 case TVVariant::String: 104 case TVVariant::String:
105 value.ptr = new QString(*((QString *)d->value.ptr)); 105 value.ptr = new QString(*((QString *)d->value.ptr));
106 break; 106 break;
107 case TVVariant::Date: 107 case TVVariant::Date:
108 value.ptr = new QDate(*((QDate *)d->value.ptr)); 108 value.ptr = new QDate(*((QDate *)d->value.ptr));
109 break; 109 break;
110 case TVVariant::Time: 110 case TVVariant::Time:
111 value.ptr = new QTime(*((QTime *)d->value.ptr)); 111 value.ptr = new QTime(*((QTime *)d->value.ptr));
112 break; 112 break;
113 case TVVariant::Int: 113 case TVVariant::Int:
114 value.i = d->value.i; 114 value.i = d->value.i;
115 break; 115 break;
116 default: 116 default:
117 ASSERT( 0 ); 117 ASSERT( 0 );
118 } 118 }
119 119
120 typ = d->typ; 120 typ = d->typ;
121} 121}
122 122
123TVVariantPrivate::~TVVariantPrivate() 123TVVariantPrivate::~TVVariantPrivate()
124{ 124{
125 clear(); 125 clear();
126} 126}
127 127
128void TVVariantPrivate::clear() 128void TVVariantPrivate::clear()
129{ 129{
130 switch( typ ) 130 switch( typ )
131 { 131 {
132 case TVVariant::String: 132 case TVVariant::String:
133 delete (QString *)value.ptr; 133 delete (QString *)value.ptr;
134 break; 134 break;
135 case TVVariant::Date: 135 case TVVariant::Date:
136 delete (QDate *)value.ptr; 136 delete (QDate *)value.ptr;
137 break; 137 break;
138 case TVVariant::Time: 138 case TVVariant::Time:
139 delete (QTime *)value.ptr; 139 delete (QTime *)value.ptr;
140 break; 140 break;
141 case TVVariant::Invalid: 141 case TVVariant::Invalid:
142 case TVVariant::Int: 142 case TVVariant::Int:
143 break; 143 break;
144 } 144 }
145 145
146 typ = TVVariant::Invalid; 146 typ = TVVariant::Invalid;
147} 147}
148 148
149/*! 149/*!
150 \class TVVariant 150 \class TVVariant
151 blah 151 blah
152*/ 152*/
153 153
154TVVariant::TVVariant() 154TVVariant::TVVariant()
155{ 155{
156 d = new TVVariantPrivate; 156 d = new TVVariantPrivate;
157} 157}
158 158
159TVVariant::~TVVariant() 159TVVariant::~TVVariant()
160{ 160{
161 if (d->deref()) 161 if (d->deref())
162 delete d; 162 delete d;
163} 163}
164 164
165TVVariant::TVVariant(const TVVariant& p) 165TVVariant::TVVariant(const TVVariant& p)
166{ 166{
167 d = new TVVariantPrivate; 167 d = new TVVariantPrivate;
168 *this = p; 168 *this = p;
169} 169}
170 170
171TVVariant::TVVariant(QDataStream& s) 171TVVariant::TVVariant(QDataStream& s)
172{ 172{
173 d = new TVVariantPrivate; 173 d = new TVVariantPrivate;
174 s >> *this; 174 s >> *this;
175} 175}
176 176
177TVVariant::TVVariant(const QString &val) 177TVVariant::TVVariant(const QString &val)
178{ 178{
179 d = new TVVariantPrivate; 179 d = new TVVariantPrivate;
180 d->typ = String; 180 d->typ = String;
181 d->value.ptr = new QString(val); 181 d->value.ptr = new QString(val);
182} 182}
183 183
184TVVariant::TVVariant(const QDate &val) 184TVVariant::TVVariant(const QDate &val)
185{ 185{
186 d = new TVVariantPrivate; 186 d = new TVVariantPrivate;
187 d->typ = Date; 187 d->typ = Date;
188 d->value.ptr = new QDate(val); 188 d->value.ptr = new QDate(val);
189} 189}
190 190
191TVVariant::TVVariant(const QTime &val) 191TVVariant::TVVariant(const QTime &val)
192{ 192{
193 d = new TVVariantPrivate; 193 d = new TVVariantPrivate;
194 d->typ = Time; 194 d->typ = Time;
195 d->value.ptr = new QTime(val); 195 d->value.ptr = new QTime(val);
196} 196}
197 197
198TVVariant::TVVariant( int val ) 198TVVariant::TVVariant( int val )
199{ 199{
200 d = new TVVariantPrivate; 200 d = new TVVariantPrivate;
201 d->typ = Int; 201 d->typ = Int;
202 d->value.i = val; 202 d->value.i = val;
203} 203}
204 204
205TVVariant& TVVariant::operator=(const TVVariant& variant ) 205TVVariant& TVVariant::operator=(const TVVariant& variant )
206{ 206{
207 TVVariant& other = (TVVariant&) variant; 207 TVVariant& other = (TVVariant&) variant;
208 208
209 other.d->ref(); 209 other.d->ref();
210 if ( d->deref() ) 210 if ( d->deref() )
211 delete d; 211 delete d;
212 212
213 d = other.d; 213 d = other.d;
214 214
215 return *this; 215 return *this;
216} 216}
217 217
218void TVVariant::detach() 218void TVVariant::detach()
219{ 219{
220 if (d->count == 1) 220 if (d->count == 1)
221 return; 221 return;
222 222
223 d->deref(); 223 d->deref();
224 d = new TVVariantPrivate(d); 224 d = new TVVariantPrivate(d);
225} 225}
226 226
227const QString TVVariant::typeName() const 227const QString TVVariant::typeName() const
228{ 228{
229 return typeToName(d->typ); 229 return typeToName(d->typ);
230} 230}
231 231
232void TVVariant::clear() 232void TVVariant::clear()
233{ 233{
234 if (d->count > 1) 234 if (d->count > 1)
235 { 235 {
236 d->deref(); 236 d->deref();
237 d = new TVVariantPrivate; 237 d = new TVVariantPrivate;
238 return; 238 return;
239 } 239 }
240 240
241 d->clear(); 241 d->clear();
242} 242}
243 243
244const QString TVVariant::typeToName(KeyType typ) 244const QString TVVariant::typeToName(KeyType typ)
245{ 245{
246 switch(typ) { 246 switch(typ) {
247 case String: 247 case String:
248 return QString("String"); 248 return QString("String");
249 case Date: 249 case Date:
250 return QString("Date"); 250 return QString("Date");
251 case Time: 251 case Time:
252 return QString("Time"); 252 return QString("Time");
253 case Int: 253 case Int:
254 return QString("Int"); 254 return QString("Int");
255 case Invalid: 255 case Invalid:
256 default: 256 default:
257 return QString("Invalid"); 257 return QString("Invalid");
258 } 258 }
259 return QString("Invalid"); 259 return QString("Invalid");
260} 260}
261 261
262TVVariant::KeyType TVVariant::nameToType(const QString &name) 262TVVariant::KeyType TVVariant::nameToType(const QString &name)
263{ 263{
264 if(!qstrcmp("String", name)) 264 if(!qstrcmp("String", name))
265 return String; 265 return String;
266 if(!qstrcmp("Date", name)) 266 if(!qstrcmp("Date", name))
267 return Date; 267 return Date;
268 if(!qstrcmp("Time", name)) 268 if(!qstrcmp("Time", name))
269 return Time; 269 return Time;
270 if(!qstrcmp("Int", name)) 270 if(!qstrcmp("Int", name))
271 return Int; 271 return Int;
272 272
273 return Invalid; 273 return Invalid;
274} 274}
275 275
276void TVVariant::load(QDataStream &s ) 276void TVVariant::load(QDataStream &s )
277{ 277{
278 KeyType t; 278 KeyType t;
279 s >> t; 279 s >> t;
280 280
281 d->typ = t; 281 d->typ = t;
282 switch(t) { 282 switch(t) {
283 case Invalid: 283 case Invalid:
284 d->typ = t; 284 d->typ = t;
285 break; 285 break;
286 case String: 286 case String:
287 { 287 {
288 QString *x = new QString; 288 QString *x = new QString;
289 s >> *x; 289 s >> *x;
290 d->value.ptr = x; 290 d->value.ptr = x;
291 } 291 }
292 break; 292 break;
293 case Time: 293 case Time:
294 { 294 {
295 QTime *x = new QTime; 295 QTime *x = new QTime;
296 s >> *x; 296 s >> *x;
297 d->value.ptr = x; 297 d->value.ptr = x;
298 } 298 }
299 break; 299 break;
300 case Date: 300 case Date:
301 { 301 {
302 QDate *x = new QDate; 302 QDate *x = new QDate;
303 s >> *x; 303 s >> *x;
304 d->value.ptr = x; 304 d->value.ptr = x;
305 } 305 }
306 break; 306 break;
307 case Int: 307 case Int:
308 { 308 {
309 int x; 309 int x;
310 s >> x; 310 s >> x;
311 d->value.i = x; 311 d->value.i = x;
312 } 312 }
313 break; 313 break;
314 default: 314 default:
315 qFatal("Unrecognized data type"); 315 qFatal("Unrecognized data type");
316 } 316 }
317} 317}
318 318
319void TVVariant::save( QDataStream &s ) const 319void TVVariant::save( QDataStream &s ) const
320{ 320{
321 s << type(); 321 s << type();
322 322
323 switch( d->typ ) { 323 switch( d->typ ) {
324 case String: 324 case String:
325 s << *((QString *)d->value.ptr); 325 s << *((QString *)d->value.ptr);
326 break; 326 break;
327 case Date: 327 case Date:
328 s << *((QDate *)d->value.ptr); 328 s << *((QDate *)d->value.ptr);
329 break; 329 break;
330 case Time: 330 case Time:
331 s << *((QTime *)d->value.ptr); 331 s << *((QTime *)d->value.ptr);
332 break; 332 break;
333 case Int: 333 case Int:
334 s << d->value.i; 334 s << d->value.i;
335 break; 335 break;
336 case Invalid: 336 case Invalid:
337 break; 337 break;
338 } 338 }
339} 339}
340 340
341QDataStream& operator>>(QDataStream& s, TVVariant& p) 341QDataStream& operator>>(QDataStream& s, TVVariant& p)
342{ 342{
343 p.load( s ); 343 p.load( s );
344 return s; 344 return s;
345} 345}
346 346
347QDataStream& operator<<(QDataStream &s, const TVVariant& p) 347QDataStream& operator<<(QDataStream &s, const TVVariant& p)
348{ 348{
349 p.save( s ); 349 p.save( s );
350 return s; 350 return s;
351} 351}
352 352
353QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p) 353QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p)
354{ 354{
355 Q_UINT8 u = 0; 355 Q_UINT8 u = 0;
356 s >> u; 356 s >> u;
357 p = (TVVariant::KeyType) u; 357 p = (TVVariant::KeyType) u;
358 358
359 return s; 359 return s;
360} 360}
361 361
362QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p) 362QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p)
363{ 363{
364 s << (Q_UINT8)p; 364 s << (Q_UINT8)p;
365 return s; 365 return s;
366} 366}
367 367
368const QString TVVariant::toString() const 368const QString TVVariant::toString() const
369{ 369{
370 switch(d->typ) { 370 switch(d->typ) {
371 case String: 371 case String:
372 return *((QString*)d->value.ptr); 372 return *((QString*)d->value.ptr);
373 case Date: 373 case Date:
374 return ((QDate*)d->value.ptr)->toString(); 374 return ((QDate*)d->value.ptr)->toString();
375 case Time: 375 case Time:
376 return ((QTime*)d->value.ptr)->toString(); 376 return ((QTime*)d->value.ptr)->toString();
377 case Int: 377 case Int:
378 return QString::number(d->value.i); 378 return QString::number(d->value.i);
379 case Invalid: 379 case Invalid:
380 default: 380 default:
381 return QString::null; 381 return QString::null;
382 } 382 }
383 return QString::null; 383 return QString::null;
384} 384}
385 385
386// TODO DO, this properly, */ 386// TODO DO, this properly, */
387int TVVariant::toInt() const 387int TVVariant::toInt() const
388{ 388{
389 if(d->typ == Int) 389 if(d->typ == Int)
390 return d->value.i; 390 return d->value.i;
391 391
392 if(d->typ == String) { 392 if(d->typ == String) {
393 QString tmpq(*(QString *)d->value.ptr); 393 QString tmpq(*(QString *)d->value.ptr);
394 return parseNextNumber(&tmpq); 394 return parseNextNumber(&tmpq);
395 } 395 }
396 396
397 return 0; 397 return 0;
398} 398}
399 399
400const QDate TVVariant::toDate() const 400const QDate TVVariant::toDate() const
401{ 401{
402 if(d->typ == Date) 402 if(d->typ == Date)
403 return *((QDate *)d->value.ptr); 403 return *((QDate *)d->value.ptr);
404 404
405 if(d->typ == String) { 405 if(d->typ == String) {
406 QString q = toString(); 406 QString q = toString();
407 407
408 /* date format is day mon d yyyy */ 408 /* date format is day mon d yyyy */
409 /* ignore the first three letters, read the next 409 /* ignore the first three letters, read the next
410 three for month.. etc */ 410 three for month.. etc */
411 411
412 int day = parseNextNumber(&q); 412 int day = parseNextNumber(&q);
413 int month = parseNextNumber(&q); 413 int month = parseNextNumber(&q);
414 int year = parseNextNumber(&q); 414 int year = parseNextNumber(&q);
415 if (!QDate::isValid(year, month, day)) 415 if (!QDate::isValid(year, month, day))
416 return QDate(); 416 return QDate();
417 return QDate(year, month, day); 417 return QDate(year, month, day);
418 } 418 }
419 419
420 420
421 return QDate(); 421 return QDate();
422} 422}
423 423
424const QTime TVVariant::toTime() const 424const QTime TVVariant::toTime() const
425{ 425{
426 if(d->typ == Time) 426 if(d->typ == Time)
427 return *((QTime *)d->value.ptr); 427 return *((QTime *)d->value.ptr);
428 428
429 if(d->typ == String) { 429 if(d->typ == String) {
430 QString q = toString(); 430 QString q = toString();
431 int hour = parseNextNumber(&q); 431 int hour = parseNextNumber(&q);
432 int minute = parseNextNumber(&q); 432 int minute = parseNextNumber(&q);
433 int second = parseNextNumber(&q); 433 int second = parseNextNumber(&q);
434 int msecond = parseNextNumber(&q); 434 int msecond = parseNextNumber(&q);
435 if (!QTime::isValid(hour, minute, second, msecond)) 435 if (!QTime::isValid(hour, minute, second, msecond))
436 return QTime(); 436 return QTime();
437 return QTime(hour, minute, second, msecond); 437 return QTime(hour, minute, second, msecond);
438 } 438 }
439 439
440 return QTime(); 440 return QTime();
441} 441}
442 442
443#define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \ 443#define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \
444 if ( d->typ != f ) \ 444 if ( d->typ != f ) \
445 *this = TVVariant( to##f() ); \ 445 *this = TVVariant( to##f() ); \
446 else \ 446 else \
447 detach(); \ 447 detach(); \
448 return *((Q##f*)d->value.ptr); } 448 return *((Q##f*)d->value.ptr); }
449 449
450TV_VARIANT_AS(String) 450TV_VARIANT_AS(String)
451TV_VARIANT_AS(Date) 451TV_VARIANT_AS(Date)
452TV_VARIANT_AS(Time) 452TV_VARIANT_AS(Time)
453 453
454#undef TV_VARIANT_AS 454#undef TV_VARIANT_AS
455 455
456int& TVVariant::asInt() 456int& TVVariant::asInt()
457{ 457{
458 detach(); 458 detach();
459 if (d->typ != Int) { 459 if (d->typ != Int) {
460 d->value.i = toInt(); 460 d->value.i = toInt();
461 d->typ = Int; 461 d->typ = Int;
462 } 462 }
463 return d->value.i; 463 return d->value.i;
464} 464}
465 465
466/*! 466/*!
467 valid cast is 467 valid cast is
468 anything to String 468 anything to String
469 same to same 469 same to same
470*/ 470*/
471bool TVVariant::canCast(KeyType t) const 471bool TVVariant::canCast(KeyType t) const
472{ 472{
473 if(d->typ == t) 473 if(d->typ == t)
474 return TRUE; 474 return TRUE;
475 475
476 if(t == String) 476 if(t == String)
477 return TRUE; 477 return TRUE;
478 478
479 if(t == Int) { 479 if(t == Int) {
480 if (d->typ == Date) 480 if (d->typ == Date)
481 return TRUE; 481 return TRUE;
482 if (d->typ == Time) 482 if (d->typ == Time)
483 return TRUE; 483 return TRUE;
484 if (d->typ == String) 484 if (d->typ == String)
485 return TRUE; 485 return TRUE;
486 } 486 }
487 487
488 return FALSE; 488 return FALSE;
489} 489}
490 490
491bool TVVariant::operator==( const TVVariant &v ) const 491bool TVVariant::operator==( const TVVariant &v ) const
492{ 492{
493 switch(d->typ) { 493 switch(d->typ) {
494 case String: 494 case String:
495 return v.toString() == toString(); 495 return v.toString() == toString();
496 case Date: 496 case Date:
497 return v.toDate() == toDate(); 497 return v.toDate() == toDate();
498 case Time: 498 case Time:
499 return v.toTime() == toTime(); 499 return v.toTime() == toTime();
500 case Int: 500 case Int:
501 return v.toInt() == toInt(); 501 return v.toInt() == toInt();
502 case Invalid: 502 case Invalid:
503 break; 503 break;
504 } 504 }
505 505
506 return FALSE; 506 return FALSE;
507} 507}
508 508
509bool TVVariant::operator!=( const TVVariant &v ) const 509bool TVVariant::operator!=( const TVVariant &v ) const
510{ 510{
511 return !( v == *this); 511 return !( v == *this);
512} 512}
513 513
514bool TVVariant::operator<( const TVVariant &v ) const 514bool TVVariant::operator<( const TVVariant &v ) const
515{ 515{
516 switch(d->typ) { 516 switch(d->typ) {
517 case String: 517 case String:
518 return toString().lower() < v.toString().lower(); 518 return toString().lower() < v.toString().lower();
519 case Date: 519 case Date:
520 return toDate() < v.toDate(); 520 return toDate() < v.toDate();
521 case Time: 521 case Time:
522 return toTime() < v.toTime(); 522 return toTime() < v.toTime();
523 case Int: 523 case Int:
524 return toInt() < v.toInt(); 524 return toInt() < v.toInt();
525 case Invalid: 525 case Invalid:
526 default: 526 default:
527 break; 527 break;
528 } 528 }
529 return FALSE; 529 return FALSE;
530} 530}
531 531
532bool TVVariant::operator>( const TVVariant &v ) const 532bool TVVariant::operator>( const TVVariant &v ) const
533{ 533{
534 switch(d->typ) { 534 switch(d->typ) {
535 case String: 535 case String:
536 return toString().lower() > v.toString().lower(); 536 return toString().lower() > v.toString().lower();
537 case Date: 537 case Date:
538 return toDate() > v.toDate(); 538 return toDate() > v.toDate();
539 case Time: 539 case Time:
540 return toTime() > v.toTime(); 540 return toTime() > v.toTime();
541 case Int: 541 case Int:
542 return toInt() > v.toInt(); 542 return toInt() > v.toInt();
543 case Invalid: 543 case Invalid:
544 default: 544 default:
545 break; 545 break;
546 } 546 }
547 return FALSE; 547 return FALSE;
548} 548}
549 549
550/*! True if n is closer to this than o */ 550/*! True if n is closer to this than o */
551bool TVVariant::closer(TVVariant n, TVVariant o) 551bool TVVariant::closer(TVVariant n, TVVariant o)
552{ 552{
553 /* Nothing is close to an invalid, so nothing can be closer */ 553 /* Nothing is close to an invalid, so nothing can be closer */
554 if(d->typ == Invalid) 554 if(d->typ == Invalid)
555 return FALSE; 555 return FALSE;
556 556
557 /* can't be closer if of different type */ 557 /* can't be closer if of different type */
558 if(n.type() != type()) 558 if(n.type() != type())
559 return FALSE; 559 return FALSE;
560 560
561 /* if new shares type, and old doesn't, then new is closer */ 561 /* if new shares type, and old doesn't, then new is closer */
562 if(o.type() != type()) 562 if(o.type() != type())
563 return TRUE; 563 return TRUE;
564 564
565 switch(type()){ 565 switch(type()){
566 case String: { 566 case String: {
567 /* case for strings is close is a substring.. closer is 567 /* case for strings is close is a substring.. closer is
568 * earlier alphabetically */ 568 * earlier alphabetically */
569 QString qs1 = n.toString().lower(); 569 QString qs1 = n.toString().lower();
570 QString qs2 = o.toString().lower(); 570 QString qs2 = o.toString().lower();
571 QString qsv = toString().lower(); 571 QString qsv = toString().lower();
572 572
573 if (!qs1.startsWith(qsv)) 573 if (!qs1.startsWith(qsv))
574 return FALSE; 574 return FALSE;
575 575
576 /* contains sub-str, if later than is not closer */ 576 /* contains sub-str, if later than is not closer */
577 if(QString::compare(qs1, qs2) > 0) 577 if(QString::compare(qs1, qs2) > 0)
578 return FALSE; 578 return FALSE;
579 return TRUE; 579 return TRUE;
580 } 580 }
581 case Int: { 581 case Int: {
582 /* case for int is smallest absolute difference */ 582 /* case for int is smallest absolute difference */
583 int i1 = n.toInt(); 583 int i1 = n.toInt();
584 int i2 = o.toInt(); 584 int i2 = o.toInt();
585 int iv = toInt(); 585 int iv = toInt();
586 586
587 int diff1 = (i1 - iv); 587 int diff1 = (i1 - iv);
588 if (diff1 < 0) 588 if (diff1 < 0)
589 diff1 = -diff1; 589 diff1 = -diff1;
590 int diff2 = (i2 - iv); 590 int diff2 = (i2 - iv);
591 if (diff2 < 0) 591 if (diff2 < 0)
592 diff2 = -diff2; 592 diff2 = -diff2;
593 593
594 if (diff1 < diff2) 594 if (diff1 < diff2)
595 return TRUE; 595 return TRUE;
596 return FALSE; 596 return FALSE;
597 } 597 }
598 case Date: { 598 case Date: {
599 QDate i1 = n.toDate(); 599 QDate i1 = n.toDate();
600 QDate i2 = o.toDate(); 600 QDate i2 = o.toDate();
601 QDate iv = toDate(); 601 QDate iv = toDate();
602 602
603 /* definition of closer is the least difference in days */ 603 /* definition of closer is the least difference in days */
604 int diff1 = i1.daysTo(iv); 604 int diff1 = i1.daysTo(iv);
605 if (diff1 < 0) 605 if (diff1 < 0)
606 diff1 = -diff1; 606 diff1 = -diff1;
607 int diff2 = i2.daysTo(iv); 607 int diff2 = i2.daysTo(iv);
608 if (diff2 < 0) 608 if (diff2 < 0)
609 diff2 = -diff2; 609 diff2 = -diff2;
610 610
611 if (diff1 < diff2) 611 if (diff1 < diff2)
612 return TRUE; 612 return TRUE;
613 return FALSE; 613 return FALSE;
614 } 614 }
615 case Time: { 615 case Time: {
616 QTime i1 = n.toTime(); 616 QTime i1 = n.toTime();
617 QTime i2 = o.toTime(); 617 QTime i2 = o.toTime();
618 QTime iv = toTime(); 618 QTime iv = toTime();
619 619
620 /* definition of closer is the least difference in days */ 620 /* definition of closer is the least difference in days */
621 int diff1 = i1.msecsTo(iv); 621 int diff1 = i1.msecsTo(iv);
622 if (diff1 < 0) 622 if (diff1 < 0)
623 diff1 = -diff1; 623 diff1 = -diff1;
624 int diff2 = i2.msecsTo(iv); 624 int diff2 = i2.msecsTo(iv);
625 if (diff2 < 0) 625 if (diff2 < 0)
626 diff2 = -diff2; 626 diff2 = -diff2;
627 if (diff1 < diff2) 627 if (diff1 < diff2)
628 return TRUE; 628 return TRUE;
629 return FALSE; 629 return FALSE;
630 } 630 }
631 default: 631 default:
632 /* don't know how to do 'closer' on this type, hence never closer 632 /* don't know how to do 'closer' on this type, hence never closer
633 * or even close */ 633 * or even close */
634 break; 634 break;
635 } 635 }
636 return FALSE; 636 return FALSE;
637} 637}
638 638
639/*! True if n is close to this */ 639/*! True if n is close to this */
640bool TVVariant::close(TVVariant n) 640bool TVVariant::close(TVVariant n)
641{ 641{
642 /* Nothing is close to an invalid, so nothing can be closer */ 642 /* Nothing is close to an invalid, so nothing can be closer */
643 if(type() == Invalid) 643 if(type() == Invalid)
644 return FALSE; 644 return FALSE;
645 645
646 /* can't be close if of different type */ 646 /* can't be close if of different type */
647 if(n.type() != type()) 647 if(n.type() != type())
648 return FALSE; 648 return FALSE;
649 649
650 switch(type()){ 650 switch(type()){
651 case String: { 651 case String: {
652 /* case for strings is close is a substring.. closer is 652 /* case for strings is close is a substring.. closer is
653 * earlier alphabetically */ 653 * earlier alphabetically */
654 QString qs1 = n.toString().lower(); 654 QString qs1 = n.toString().lower();
655 QString qsv = toString().lower(); 655 QString qsv = toString().lower();
656 656
657 if (!qs1.startsWith(qsv)) 657 if (!qs1.startsWith(qsv))
658 return FALSE; 658 return FALSE;
659 return TRUE; 659 return TRUE;
660 } 660 }
661 case Int: 661 case Int:
662 case Date: 662 case Date:
663 case Time: 663 case Time:
664 return TRUE; 664 return TRUE;
665 default: 665 default:
666 /* don't know how to do 'closer' on this type, hence never closer 666 /* don't know how to do 'closer' on this type, hence never closer
667 * or even close */ 667 * or even close */
668 break; 668 break;
669 } 669 }
670 return FALSE; 670 return FALSE;
671} 671}
672 672
673/*! 673/*!
674 \class Key 674 \class Key
675 \brief document me! 675 \brief document me!
676 676
677 document me! 677 document me!
678*/ 678*/
679 679
680Key::Key() : kname(), kexample(), kflags(0) { } 680Key::Key() : kname(), kexample(), kflags(0) { }
681 681
682Key::Key(QString name, TVVariant example, int flags = 0) : 682Key::Key(QString name, TVVariant example, int flags) :
683 kname(name), kexample(example), kflags(flags) { } 683 kname(name), kexample(example), kflags(flags) { }
684 684
685Key::Key(const Key &other) 685Key::Key(const Key &other)
686{ 686{
687 kname = other.kname; 687 kname = other.kname;
688 kexample = other.kexample; 688 kexample = other.kexample;
689 kflags = other.kflags; 689 kflags = other.kflags;
690} 690}
691 691
692Key& Key::operator=(const Key& key) 692Key& Key::operator=(const Key& key)
693{ 693{
694 kname = key.kname; 694 kname = key.kname;
695 kexample = key.kexample; 695 kexample = key.kexample;
696 kflags = key.kflags; 696 kflags = key.kflags;
697 return *this; 697 return *this;
698} 698}
699 699
700QString Key::name() const 700QString Key::name() const
701{ 701{
702 return QString(kname); 702 return QString(kname);
703} 703}
704 704
705TVVariant Key::example() const 705TVVariant Key::example() const
706{ 706{
707 return TVVariant(kexample); 707 return TVVariant(kexample);
708} 708}
709 709
710TVVariant::KeyType Key::type() const 710TVVariant::KeyType Key::type() const
711{ 711{
712 return kexample.type(); 712 return kexample.type();
713} 713}
714 714
715void Key::setName(const QString &name) 715void Key::setName(const QString &name)
716{ 716{
717 kname = QString(name); 717 kname = QString(name);
718} 718}
719 719
720void Key::setExample(const TVVariant &e) 720void Key::setExample(const TVVariant &e)
721{ 721{
722 kexample = TVVariant(e); 722 kexample = TVVariant(e);
723} 723}
724 724
725int Key::flags() const 725int Key::flags() const
726{ 726{
727 return kflags; 727 return kflags;
728} 728}
729 729
730void Key::setFlags(int fl) 730void Key::setFlags(int fl)
731{ 731{
732 kflags = fl; 732 kflags = fl;
733} 733}
734 734
735bool Key::delFlag() const 735bool Key::delFlag() const
736{ 736{
737 if(kflags & del_flag) 737 if(kflags & del_flag)
738 return TRUE; 738 return TRUE;
739 return FALSE; 739 return FALSE;
740} 740}
741 741
742bool Key::newFlag() const 742bool Key::newFlag() const
743{ 743{
744 if(kflags & new_flag) 744 if(kflags & new_flag)
745 return TRUE; 745 return TRUE;
746 return FALSE; 746 return FALSE;
747} 747}
748 748
749void Key::setDelFlag(bool v) 749void Key::setDelFlag(bool v)
750{ 750{
751 if(delFlag() != v) 751 if(delFlag() != v)
752 kflags = kflags ^ del_flag; 752 kflags = kflags ^ del_flag;
753} 753}
754 754
755void Key::setNewFlag(bool v) 755void Key::setNewFlag(bool v)
756{ 756{
757 if(newFlag() != v) 757 if(newFlag() != v)
758 kflags = kflags ^ new_flag; 758 kflags = kflags ^ new_flag;
759} 759}
760 760
761/*! 761/*!
762 \class KeyList 762 \class KeyList
763 \brief A represntation of keys used for a table. 763 \brief A represntation of keys used for a table.
764 764
765 The KeyList class is used to store the representation of keys used in table 765 The KeyList class is used to store the representation of keys used in table
766 headings by DBStore. It stores the names and types of the keys 766 headings by DBStore. It stores the names and types of the keys
767*/ 767*/
768 768
769/*! 769/*!
770 Constructs a KeyList 770 Constructs a KeyList
771*/ 771*/
772KeyList::KeyList() : QIntDict<Key>(20) 772KeyList::KeyList() : QIntDict<Key>(20)
773{ 773{
774 setAutoDelete(TRUE); 774 setAutoDelete(TRUE);
775} 775}
776 776
777/* Should be deep copy, but isn't */ 777/* Should be deep copy, but isn't */
778KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k) 778KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
779{ 779{
780 KeyListIterator it(k); 780 KeyListIterator it(k);
781 while(it.current()) { 781 while(it.current()) {
782 replace(it.currentKey(), new Key(*it.current())); 782 replace(it.currentKey(), new Key(*it.current()));
783 ++it; 783 ++it;
784 } 784 }
785 785
786 setAutoDelete(TRUE); 786 setAutoDelete(TRUE);
787} 787}
788 788
789/*! 789/*!
790 Destroys a KeyList 790 Destroys a KeyList
791*/ 791*/
792KeyList::~KeyList() { 792KeyList::~KeyList() {
793} 793}
794 794
795/* Do a comparision base on Keys */ 795/* Do a comparision base on Keys */
796bool KeyList::operator!=(const KeyList &other) 796bool KeyList::operator!=(const KeyList &other)
797{ 797{
798 KeyListIterator it(*this); 798 KeyListIterator it(*this);
799 799
800 if (other.getNumFields() != getNumFields()) 800 if (other.getNumFields() != getNumFields())
801 return TRUE; 801 return TRUE;
802 802
803 while(it.current()) { 803 while(it.current()) {
804 //it.currentKey(), it.current(); 804 //it.currentKey(), it.current();
805 if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey())) 805 if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey()))
806 return TRUE; 806 return TRUE;
807 if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey())) 807 if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey()))
808 return TRUE; 808 return TRUE;
809 ++it; 809 ++it;
810 } 810 }
811 return FALSE; 811 return FALSE;
812} 812}
813 813
814/*! 814/*!
815 Returns the number of keys stored in the KeyList 815 Returns the number of keys stored in the KeyList
816*/ 816*/
817int KeyList::getNumFields() const 817int KeyList::getNumFields() const
818{ 818{
819 return count(); 819 return count();
820} 820}
821 821
822/*! 822/*!
823 Adds a new key to the KeyList 823 Adds a new key to the KeyList
824 824
825 \param name the name of the new key 825 \param name the name of the new key
826 \param type the type of the new key 826 \param type the type of the new key
827*/ 827*/
828int KeyList::addKey(QString name, TVVariant example) 828int KeyList::addKey(QString name, TVVariant example)
829{ 829{
830 int i = count(); 830 int i = count();
831 while(find(i) && (i > -1)) 831 while(find(i) && (i > -1))
832 i--; 832 i--;
833 replace(i, new Key(name, example, 0)); 833 replace(i, new Key(name, example, 0));
834 return i; 834 return i;
835} 835}
836 836
837int KeyList::addKey(QString name, TVVariant::KeyType type) 837int KeyList::addKey(QString name, TVVariant::KeyType type)
838{ 838{
839 /* generate a valid type for the example? */ 839 /* generate a valid type for the example? */
840 TVVariant e = TVVariant("0"); 840 TVVariant e = TVVariant("0");
841 switch(type) { 841 switch(type) {
842 case TVVariant::String: 842 case TVVariant::String:
843 return addKey(name, TVVariant("<undefined>").asString()); 843 return addKey(name, TVVariant("<undefined>").asString());
844 break; 844 break;
845 case TVVariant::Date: 845 case TVVariant::Date:
846 return addKey(name, TVVariant(QDate::currentDate()).asDate()); 846 return addKey(name, TVVariant(QDate::currentDate()).asDate());
847 break; 847 break;
848 case TVVariant::Time: 848 case TVVariant::Time:
849 return addKey(name, TVVariant(QTime(0,0,0)).toTime()); 849 return addKey(name, TVVariant(QTime(0,0,0)).toTime());
850 break; 850 break;
851 case TVVariant::Int: 851 case TVVariant::Int:
852 return addKey(name, TVVariant(0).toInt()); 852 return addKey(name, TVVariant(0).toInt());
853 break; 853 break;
854 default: 854 default:
855 qWarning(QObject::tr("KeyList::addKey() Cannot make default " 855 qWarning(QObject::tr("KeyList::addKey() Cannot make default "
856 "value for type %1, Key not added.").arg(type)); 856 "value for type %1, Key not added.").arg(type));
857 break; 857 break;
858 } 858 }
859 return -1; 859 return -1;
860} 860}
861 861
862void KeyList::setKeyFlags(int i, int flag) 862void KeyList::setKeyFlags(int i, int flag)
863{ 863{
864 if(find(i)) 864 if(find(i))
865 find(i)->setFlags(flag); 865 find(i)->setFlags(flag);
866} 866}
867 867
868int KeyList::getKeyFlags(int i) const 868int KeyList::getKeyFlags(int i) const
869{ 869{
870 if(find(i)) 870 if(find(i))
871 return find(i)->flags(); 871 return find(i)->flags();
872 return 0; 872 return 0;
873} 873}
874 874
875bool KeyList::checkNewFlag(int i) const 875bool KeyList::checkNewFlag(int i) const
876{ 876{
877 if (find(i)) 877 if (find(i))
878 return find(i)->newFlag(); 878 return find(i)->newFlag();
879 return false; 879 return false;
880} 880}
881 881
882void KeyList::setNewFlag(int i, bool f) 882void KeyList::setNewFlag(int i, bool f)
883{ 883{
884 if(!find(i)) 884 if(!find(i))
885 return; 885 return;
886 find(i)->setNewFlag(f); 886 find(i)->setNewFlag(f);
887} 887}
888 888
889bool KeyList::checkDeleteFlag(int i) const 889bool KeyList::checkDeleteFlag(int i) const
890{ 890{
891 if (find(i)) 891 if (find(i))
892 return find(i)->delFlag(); 892 return find(i)->delFlag();
893 return false; 893 return false;
894} 894}
895 895
896void KeyList::setDeleteFlag(int i, bool f) 896void KeyList::setDeleteFlag(int i, bool f)
897{ 897{
898 if(!find(i)) 898 if(!find(i))
899 return; 899 return;
900 find(i)->setDelFlag(f); 900 find(i)->setDelFlag(f);
901} 901}
902 902
903/*! 903/*!
904 Returns the name of the key at index i 904 Returns the name of the key at index i
905*/ 905*/
906QString KeyList::getKeyName(int i) const 906QString KeyList::getKeyName(int i) const
907{ 907{
908 if (find (i)) 908 if (find (i))
909 return find(i)->name(); 909 return find(i)->name();
910 return QString(); 910 return QString();
911} 911}
912 912
913void KeyList::setKeyName(int i, const QString &n) 913void KeyList::setKeyName(int i, const QString &n)
914{ 914{
915 if(find(i)) 915 if(find(i))
916 find(i)->setName(n); 916 find(i)->setName(n);
917} 917}
918 918
919/*! 919/*!
920 Returns the type of the key at index i 920 Returns the type of the key at index i
921*/ 921*/
922TVVariant::KeyType KeyList::getKeyType(int i) const 922TVVariant::KeyType KeyList::getKeyType(int i) const
923{ 923{
924 if(find(i)) 924 if(find(i))
925 return find(i)->type(); 925 return find(i)->type();
926 return TVVariant::Invalid; 926 return TVVariant::Invalid;
927} 927}
928 928
929void KeyList::setKeyType(int i, TVVariant::KeyType t) 929void KeyList::setKeyType(int i, TVVariant::KeyType t)
930{ 930{
931 if(!find(i)) 931 if(!find(i))
932 return; 932 return;
933 switch(t) { 933 switch(t) {
934 case TVVariant::String: 934 case TVVariant::String:
935 find(i)->setExample(TVVariant(QString("default"))); 935 find(i)->setExample(TVVariant(QString("default")));
936 return; 936 return;
937 case TVVariant::Int: 937 case TVVariant::Int:
938 find(i)->setExample(TVVariant(int(0))); 938 find(i)->setExample(TVVariant(int(0)));
939 return; 939 return;
940 case TVVariant::Date: 940 case TVVariant::Date:
941 find(i)->setExample(TVVariant(QDate::currentDate())); 941 find(i)->setExample(TVVariant(QDate::currentDate()));
942 return; 942 return;
943 case TVVariant::Time: 943 case TVVariant::Time:
944 find(i)->setExample(TVVariant(QTime(0,0,0,0))); 944 find(i)->setExample(TVVariant(QTime(0,0,0,0)));
945 return; 945 return;
946 default: 946 default:
947 break; 947 break;
948 } 948 }
949 return; 949 return;
950} 950}
951 951
952TVVariant KeyList::getKeyExample(int i) const 952TVVariant KeyList::getKeyExample(int i) const
953{ 953{
954 if(find(i)) 954 if(find(i))
955 return find(i)->example(); 955 return find(i)->example();
956 return TVVariant(); 956 return TVVariant();
957} 957}
958 958
959void KeyList::setKeyExample(int i, TVVariant example) 959void KeyList::setKeyExample(int i, TVVariant example)
960{ 960{
961 if(find(i)) 961 if(find(i))
962 find(i)->setExample(example); 962 find(i)->setExample(example);
963} 963}
964 964
965/*! 965/*!
966 Returns the index of the key with name q 966 Returns the index of the key with name q
967*/ 967*/
968int KeyList::getKeyIndex(QString q) const 968int KeyList::getKeyIndex(QString q) const
969{ 969{
970 KeyListIterator it(*this); 970 KeyListIterator it(*this);
971 971
972 while(it.current()) { 972 while(it.current()) {
973 if(it.current()->name() == q) 973 if(it.current()->name() == q)
974 return it.currentKey(); 974 return it.currentKey();
975 ++it; 975 ++it;
976 } 976 }
977 return -1; 977 return -1;
978} 978}
979 979
980bool KeyList::validIndex(int i) const 980bool KeyList::validIndex(int i) const
981{ 981{
982 if(!find(i)) 982 if(!find(i))
983 return FALSE; 983 return FALSE;
984 if(find(i)->delFlag()) 984 if(find(i)->delFlag())
985 return FALSE; 985 return FALSE;
986 return TRUE; 986 return TRUE;
987} 987}
988 988
989QDataStream &operator<<( QDataStream &s, const KeyList &k) 989QDataStream &operator<<( QDataStream &s, const KeyList &k)
990{ 990{
991 s << k.getNumFields(); 991 s << k.getNumFields();
992 992
993 KeyListIterator it(k); 993 KeyListIterator it(k);
994 994
995 while(it.current()) { 995 while(it.current()) {
996 s << (Q_UINT16)it.currentKey(); 996 s << (Q_UINT16)it.currentKey();
997 s << it.current()->name(); 997 s << it.current()->name();
998 s << it.current()->example(); 998 s << it.current()->example();
999 s << (Q_UINT16)it.current()->flags(); 999 s << (Q_UINT16)it.current()->flags();
1000 ++it; 1000 ++it;
1001 } 1001 }
1002 return s; 1002 return s;
1003} 1003}
1004 1004
1005QDataStream &operator>>( QDataStream &s, KeyList &k) 1005QDataStream &operator>>( QDataStream &s, KeyList &k)
1006{ 1006{
1007 int i; 1007 int i;
1008 int size; 1008 int size;
1009 int index = 0; 1009 int index = 0;
1010 int flags = 0; 1010 int flags = 0;
1011 TVVariant type = TVVariant(); 1011 TVVariant type = TVVariant();
1012 QString name; 1012 QString name;
1013 1013
1014 s >> size; 1014 s >> size;
1015 1015
1016 for (i=0; i < size; i++) { 1016 for (i=0; i < size; i++) {
1017 s >> (Q_UINT16 &)index; 1017 s >> (Q_UINT16 &)index;
1018 s >> name; 1018 s >> name;
1019 s >> type; 1019 s >> type;
1020 s >> (Q_UINT16 &)flags; 1020 s >> (Q_UINT16 &)flags;
1021 k.replace(index, new Key(name, type, flags)); 1021 k.replace(index, new Key(name, type, flags));
1022 } 1022 }
1023 return s; 1023 return s;
1024} 1024}
1025 1025
1026/*! 1026/*!
1027 \class DataElem 1027 \class DataElem
1028 \brief A class representing a single row or element of a table in a DBStore 1028 \brief A class representing a single row or element of a table in a DBStore
1029 1029
1030 This class holds the data of a row in a table. 1030 This class holds the data of a row in a table.
1031*/ 1031*/
1032 1032
1033 1033
1034/*! 1034/*!
1035 Constructs a DataElem. This function needs a container because the 1035 Constructs a DataElem. This function needs a container because the
1036 size, types of keys and primary key are all defined by the containing 1036 size, types of keys and primary key are all defined by the containing
1037 database 1037 database
1038*/ 1038*/
1039DataElem::DataElem(DBStore *c) : values(20) 1039DataElem::DataElem(DBStore *c) : values(20)
1040{ 1040{
1041 int size; 1041 int size;
1042 contained = c; 1042 contained = c;
1043 size = c->getNumFields(); 1043 size = c->getNumFields();
1044 values.setAutoDelete(TRUE); 1044 values.setAutoDelete(TRUE);
1045} 1045}
1046 1046
1047/*! 1047/*!
1048 Destroys a DataElem and frees memory used by the DataElem 1048 Destroys a DataElem and frees memory used by the DataElem
1049*/ 1049*/
1050DataElem::~DataElem() { 1050DataElem::~DataElem() {
1051} 1051}
1052 1052
1053 1053
1054 1054
1055QDataStream &operator<<( QDataStream &s, const DataElem &d) 1055QDataStream &operator<<( QDataStream &s, const DataElem &d)
1056{ 1056{
1057 int size = d.getNumFields(); 1057 int size = d.getNumFields();
1058 1058
1059 s << size; /* redundent data but makes streaming easier */ 1059 s << size; /* redundent data but makes streaming easier */
1060 KeyList k = d.getKeys(); 1060 KeyList k = d.getKeys();
1061 1061
1062 KeyListIterator it(k); 1062 KeyListIterator it(k);
1063 1063
1064 while(it.current()) { 1064 while(it.current()) {
1065 s << (Q_UINT16)it.currentKey(); 1065 s << (Q_UINT16)it.currentKey();
1066 s << d.getField(it.currentKey()); 1066 s << d.getField(it.currentKey());
1067 ++it; 1067 ++it;
1068 } 1068 }
1069 return s; 1069 return s;
1070} 1070}
1071 1071
1072QDataStream &operator>>( QDataStream &s, DataElem &d) 1072QDataStream &operator>>( QDataStream &s, DataElem &d)
1073{ 1073{
1074 int i; 1074 int i;
1075 int size; 1075 int size;
1076 TVVariant t; 1076 TVVariant t;
1077 int index = 0; 1077 int index = 0;
1078 1078
1079 s >> size; /* redundent data but makes streaming easier */ 1079 s >> size; /* redundent data but makes streaming easier */
1080 if (size != d.getNumFields()) { 1080 if (size != d.getNumFields()) {
1081 qWarning("DataSize mis-match"); 1081 qWarning("DataSize mis-match");
1082 return s; /* sanity check failed.. don't load */ 1082 return s; /* sanity check failed.. don't load */
1083 } 1083 }
1084 1084
1085 for(i = 0; i < size; i++) { 1085 for(i = 0; i < size; i++) {
1086 s >> (Q_UINT16)index; 1086 s >> (Q_UINT16)index;
1087 s >> t; 1087 s >> t;
1088 d.setField(index, t); 1088 d.setField(index, t);
1089 } 1089 }
1090 return s; 1090 return s;
1091} 1091}
1092 1092
1093/*! Returns the number of possible (not valid) fields in the data element */ 1093/*! Returns the number of possible (not valid) fields in the data element */
1094int DataElem::getNumFields() const 1094int DataElem::getNumFields() const
1095{ 1095{
1096 return contained->getNumFields(); 1096 return contained->getNumFields();
1097} 1097}
1098 1098
1099KeyList DataElem::getKeys() const 1099KeyList DataElem::getKeys() const
1100{ 1100{
1101 return *(contained->getKeys()); 1101 return *(contained->getKeys());
1102} 1102}
1103 1103
1104/*! 1104/*!
1105 This function determines whether field index i of the element has been 1105 This function determines whether field index i of the element has been
1106 set yet. 1106 set yet.
1107 1107
1108 \return A boolean value that is TRUE if the specfied field of this 1108 \return A boolean value that is TRUE if the specfied field of this
1109 element has been set and FALSE if the field has not yet been set 1109 element has been set and FALSE if the field has not yet been set
1110*/ 1110*/
1111bool DataElem::hasValidValue(int i) const 1111bool DataElem::hasValidValue(int i) const
1112{ 1112{
1113 if(!values.find(i)) 1113 if(!values.find(i))
1114 return FALSE; 1114 return FALSE;
1115 if(!contained->getKeys()->validIndex(i)) 1115 if(!contained->getKeys()->validIndex(i))
1116 return FALSE; 1116 return FALSE;
1117 return values.find(i)->isValid(); 1117 return values.find(i)->isValid();
1118} 1118}
1119 1119
1120/*! 1120/*!
1121 This function determines whether field name qs of the element has been 1121 This function determines whether field name qs of the element has been
1122 set yet. 1122 set yet.
1123 1123
1124 \return A boolean value that is TRUE if the specfied field of this 1124 \return A boolean value that is TRUE if the specfied field of this
1125 element has been set and FALSE if the field has not yet been set 1125 element has been set and FALSE if the field has not yet been set
1126*/ 1126*/
1127bool DataElem::hasValidValue(QString qs) const 1127bool DataElem::hasValidValue(QString qs) const
1128{ 1128{
1129 int i = contained->getKeyIndex(qs); 1129 int i = contained->getKeyIndex(qs);
1130 return hasValidValue(i); 1130 return hasValidValue(i);
1131} 1131}
1132 1132
1133/*! returns the type of the field specified by index i */ 1133/*! returns the type of the field specified by index i */
1134TVVariant::KeyType DataElem::getFieldType(int i) const 1134TVVariant::KeyType DataElem::getFieldType(int i) const
1135{ 1135{
1136 return contained->getKeyType(i); 1136 return contained->getKeyType(i);
1137} 1137}
1138 1138
1139/*! returns the type of the field specified by name qs */ 1139/*! returns the type of the field specified by name qs */
1140TVVariant::KeyType DataElem::getFieldType(QString qs) const 1140TVVariant::KeyType DataElem::getFieldType(QString qs) const
1141{ 1141{
1142 int i = contained->getKeyIndex(qs); 1142 int i = contained->getKeyIndex(qs);
1143 return contained->getKeyType(i); 1143 return contained->getKeyType(i);
1144} 1144}
1145 1145
1146/*! 1146/*!
1147 returns a pointer to the data stored in field index i for this 1147 returns a pointer to the data stored in field index i for this
1148 data element, (value may not be valid) 1148 data element, (value may not be valid)
1149*/ 1149*/
1150TVVariant DataElem::getField(int i) const 1150TVVariant DataElem::getField(int i) const
1151{ 1151{
1152 if(hasValidValue(i)) 1152 if(hasValidValue(i))
1153 return TVVariant(*values.find(i)); 1153 return TVVariant(*values.find(i));
1154 return TVVariant(); 1154 return TVVariant();
1155} 1155}
1156 1156
1157/*! 1157/*!
1158 returns a pointer to the data stored in field name qs for this 1158 returns a pointer to the data stored in field name qs for this
1159 data element, (value may not be valid) 1159 data element, (value may not be valid)
1160*/ 1160*/
1161TVVariant DataElem::getField(QString qs) const 1161TVVariant DataElem::getField(QString qs) const
1162{ 1162{
1163 int i = contained->getKeyIndex(qs); 1163 int i = contained->getKeyIndex(qs);
1164 return getField(i); 1164 return getField(i);
1165} 1165}
1166 1166
1167/*! 1167/*!
1168 Sets the value of the elements field index i to the value represented in 1168 Sets the value of the elements field index i to the value represented in
1169 the QString q. 1169 the QString q.
1170 1170
1171 \param i index of the field to set 1171 \param i index of the field to set
1172 \param q a string that can be parsed to get the value to be set 1172 \param q a string that can be parsed to get the value to be set
1173*/ 1173*/
1174void DataElem::setField(int i, QString q) 1174void DataElem::setField(int i, QString q)
1175{ 1175{
1176 /* from the type of the field, parse q and store */ 1176 /* from the type of the field, parse q and store */
1177 TVVariant::KeyType kt = contained->getKeyType(i); 1177 TVVariant::KeyType kt = contained->getKeyType(i);
1178 1178
1179 TVVariant t = TVVariant(q); 1179 TVVariant t = TVVariant(q);
1180 1180
1181 switch(kt) { 1181 switch(kt) {
1182 case TVVariant::Int: { 1182 case TVVariant::Int: {
1183 t.asInt(); 1183 t.asInt();
1184 setField(i, t); 1184 setField(i, t);
1185 return; 1185 return;
1186 } 1186 }
1187 case TVVariant::String: { 1187 case TVVariant::String: {
1188 t.asString(); 1188 t.asString();
1189 setField(i, t); 1189 setField(i, t);
1190 return; 1190 return;
1191 } 1191 }
1192 case TVVariant::Date: { 1192 case TVVariant::Date: {
1193 t.asDate(); 1193 t.asDate();
1194 setField(i, t); 1194 setField(i, t);
1195 return; 1195 return;
1196 } 1196 }
1197 case TVVariant::Time: { 1197 case TVVariant::Time: {
1198 t.asTime(); 1198 t.asTime();
1199 setField(i, t); 1199 setField(i, t);
1200 return; 1200 return;
1201 } 1201 }
1202 default: 1202 default:
1203 qWarning( 1203 qWarning(
1204 QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q) 1204 QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q)
1205 ); 1205 );
1206 } 1206 }
1207} 1207}
1208 1208
1209/*! 1209/*!
1210 Sets the value of the elements field index i to the value at the pointer 1210 Sets the value of the elements field index i to the value at the pointer
1211 value. 1211 value.
1212 1212
1213 \param i index of the field to set 1213 \param i index of the field to set
1214 \param value a pointer to the (already allocated) value to set 1214 \param value a pointer to the (already allocated) value to set
1215*/ 1215*/
1216void DataElem::setField(int i, TVVariant value) 1216void DataElem::setField(int i, TVVariant value)
1217{ 1217{
1218 if (value.isValid()) { 1218 if (value.isValid()) {
1219 values.remove(i); 1219 values.remove(i);
1220 values.replace(i, new TVVariant(value)); 1220 values.replace(i, new TVVariant(value));
1221 } 1221 }
1222} 1222}
1223 1223
1224/*! 1224/*!
1225 Sets the value of the elements field name qs to the value represented in 1225 Sets the value of the elements field name qs to the value represented in
1226 the QString q. 1226 the QString q.
1227 1227
1228 \param qs name of the field to set 1228 \param qs name of the field to set
1229 \param q a string that can be parsed to get the value to be set 1229 \param q a string that can be parsed to get the value to be set
1230*/ 1230*/
1231void DataElem::setField(QString qs, QString q) 1231void DataElem::setField(QString qs, QString q)
1232{ 1232{
1233 /* from the type of the field, parse q and store */ 1233 /* from the type of the field, parse q and store */
1234 int i = contained->getKeyIndex(qs); 1234 int i = contained->getKeyIndex(qs);
1235 setField(i, qs); 1235 setField(i, qs);
1236} 1236}
1237 1237
1238/*! 1238/*!
1239 Sets the value of the elements field name qs to the value at the pointer 1239 Sets the value of the elements field name qs to the value at the pointer
1240 value. 1240 value.
1241 1241
1242 \param qs name of the field to set 1242 \param qs name of the field to set
1243 \param value a pointer to the (already allocated) value to set 1243 \param value a pointer to the (already allocated) value to set
1244*/ 1244*/
1245void DataElem::setField(QString qs, TVVariant value) 1245void DataElem::setField(QString qs, TVVariant value)
1246{ 1246{
1247 int i = contained->getKeyIndex(qs); 1247 int i = contained->getKeyIndex(qs);
1248 setField(i, value); 1248 setField(i, value);
1249} 1249}
1250 1250
1251void DataElem::unsetField(int i) { 1251void DataElem::unsetField(int i) {
1252 values.remove(i); 1252 values.remove(i);
1253} 1253}
1254 1254
1255void DataElem::unsetField(QString qs) 1255void DataElem::unsetField(QString qs)
1256{ 1256{
1257 int i = contained->getKeyIndex(qs); 1257 int i = contained->getKeyIndex(qs);
1258 unsetField(i); 1258 unsetField(i);
1259} 1259}
1260 1260
1261/*! 1261/*!
1262 Converts the data element to a Rich Text QString 1262 Converts the data element to a Rich Text QString
1263*/ 1263*/
1264QString DataElem::toQString() const 1264QString DataElem::toQString() const
1265{ 1265{
1266 /* lets make an attempt at this function */ 1266 /* lets make an attempt at this function */
1267 int i; 1267 int i;
1268 QString scratch = ""; 1268 QString scratch = "";
1269 1269
1270 QIntDictIterator<TVVariant> it(values); 1270 QIntDictIterator<TVVariant> it(values);
1271 1271
1272 while (it.current()) { 1272 while (it.current()) {
1273 i = it.currentKey(); 1273 i = it.currentKey();
1274 if(hasValidValue(i)) { 1274 if(hasValidValue(i)) {
1275 scratch += "<B>" + contained->getKeyName(i) + ":</B> "; 1275 scratch += "<B>" + contained->getKeyName(i) + ":</B> ";
1276 scratch += getField(i).toString(); 1276 scratch += getField(i).toString();
1277 scratch += "<br>"; 1277 scratch += "<br>";
1278 } 1278 }
1279 ++it; 1279 ++it;
1280 } 1280 }
1281 return scratch; 1281 return scratch;
1282} 1282}
1283 1283
1284/*! formats individual fields to strings so can be displayed */ 1284/*! formats individual fields to strings so can be displayed */
1285QString DataElem::toQString(int i) const 1285QString DataElem::toQString(int i) const
1286{ 1286{
1287 if(hasValidValue(i)) { 1287 if(hasValidValue(i)) {
1288 return getField(i).toString(); 1288 return getField(i).toString();
1289 } 1289 }
1290 return ""; 1290 return "";
1291} 1291}
1292/*! formats individual fields to strings so can be sorted by QListView */ 1292/*! formats individual fields to strings so can be sorted by QListView */
1293QString DataElem::toSortableQString(int i) const 1293QString DataElem::toSortableQString(int i) const
1294{ 1294{
1295 QString scratch = ""; 1295 QString scratch = "";
1296 if(hasValidValue(i)) { 1296 if(hasValidValue(i)) {
1297 switch (contained->getKeyType(i)) { 1297 switch (contained->getKeyType(i)) {
1298 case TVVariant::String: { 1298 case TVVariant::String: {
1299 scratch += getField(i).toString(); 1299 scratch += getField(i).toString();
1300 break; 1300 break;
1301 } 1301 }
1302 case TVVariant::Int: { 1302 case TVVariant::Int: {
1303 scratch.sprintf("%08d", getField(i).toInt()); 1303 scratch.sprintf("%08d", getField(i).toInt());
1304 break; 1304 break;
1305 } 1305 }
1306 case TVVariant::Date: { 1306 case TVVariant::Date: {
1307 static QDate epochD(1800, 1, 1); 1307 static QDate epochD(1800, 1, 1);
1308 scratch.sprintf("%08d", 1308 scratch.sprintf("%08d",
1309 epochD.daysTo(getField(i).toDate())); 1309 epochD.daysTo(getField(i).toDate()));
1310 break; 1310 break;
1311 } 1311 }
1312 case TVVariant::Time: { 1312 case TVVariant::Time: {
1313 static QTime epochT(0, 0, 0); 1313 static QTime epochT(0, 0, 0);
1314 scratch.sprintf("%08d", 1314 scratch.sprintf("%08d",
1315 epochT.msecsTo(getField(i).toTime())); 1315 epochT.msecsTo(getField(i).toTime()));
1316 break; 1316 break;
1317 } 1317 }
1318 default: 1318 default:
1319 scratch += "Unknown type"; 1319 scratch += "Unknown type";
1320 break; 1320 break;
1321 } 1321 }
1322 } 1322 }
1323 return scratch; 1323 return scratch;
1324} 1324}
1325 1325
1326/* compare functions */ 1326/* compare functions */
1327 1327
1328bool DataElem::lessThan(int i, TVVariant v) const 1328bool DataElem::lessThan(int i, TVVariant v) const
1329{ 1329{
1330 if (!hasValidValue(i)) return FALSE; 1330 if (!hasValidValue(i)) return FALSE;
1331 1331
1332 if (getField(i).type() != v.type()) 1332 if (getField(i).type() != v.type())
1333 return FALSE; 1333 return FALSE;
1334 1334
1335 return (getField(i) < v); 1335 return (getField(i) < v);
1336} 1336}
1337 1337
1338bool DataElem::moreThan(int i, TVVariant v) const 1338bool DataElem::moreThan(int i, TVVariant v) const
1339{ 1339{
1340 if (!hasValidValue(i)) return FALSE; 1340 if (!hasValidValue(i)) return FALSE;
1341 1341
1342 if (getField(i).type() != v.type()) 1342 if (getField(i).type() != v.type())
1343 return FALSE; 1343 return FALSE;
1344 1344
1345 return (getField(i) > v); 1345 return (getField(i) > v);
1346} 1346}
1347 1347
1348bool DataElem::equalTo(int i, TVVariant v) const 1348bool DataElem::equalTo(int i, TVVariant v) const
1349{ 1349{
1350 if (!hasValidValue(i)) return FALSE; 1350 if (!hasValidValue(i)) return FALSE;
1351 1351
1352 if (getField(i).type() != v.type()) 1352 if (getField(i).type() != v.type())
1353 return FALSE; 1353 return FALSE;
1354 1354
1355 return (getField(i) == v); 1355 return (getField(i) == v);
1356} 1356}
1357 1357
1358bool DataElem::contains(int i, TVVariant v) const 1358bool DataElem::contains(int i, TVVariant v) const
1359{ 1359{
1360 if (!hasValidValue(i)) return FALSE; 1360 if (!hasValidValue(i)) return FALSE;
1361 1361
1362 if (getField(i).type() != v.type()) 1362 if (getField(i).type() != v.type())
1363 return FALSE; 1363 return FALSE;
1364 1364
1365 switch(getField(i).type()) { 1365 switch(getField(i).type()) {
1366 case TVVariant::String: { 1366 case TVVariant::String: {
1367 QString qs1 = getField(i).toString().lower(); 1367 QString qs1 = getField(i).toString().lower();
1368 QString qs2 = v.toString().lower(); 1368 QString qs2 = v.toString().lower();
1369 if (qs1.contains(qs2) > 0) return TRUE; 1369 if (qs1.contains(qs2) > 0) return TRUE;
1370 break; 1370 break;
1371 } 1371 }
1372 /* meaningless for ints */ 1372 /* meaningless for ints */
1373 /* meaningless for time */ 1373 /* meaningless for time */
1374 /* meaningless for dates */ 1374 /* meaningless for dates */
1375 case TVVariant::Int: 1375 case TVVariant::Int:
1376 case TVVariant::Time: 1376 case TVVariant::Time:
1377 case TVVariant::Date: 1377 case TVVariant::Date:
1378 break; 1378 break;
1379 default: 1379 default:
1380 qWarning("Tried to compare unknown data type"); 1380 qWarning("Tried to compare unknown data type");
1381 } 1381 }
1382 return FALSE; 1382 return FALSE;
1383} 1383}
1384 1384
1385bool DataElem::startsWith(int i, TVVariant v) const 1385bool DataElem::startsWith(int i, TVVariant v) const
1386{ 1386{
1387 if (!hasValidValue(i)) return FALSE; 1387 if (!hasValidValue(i)) return FALSE;
1388 1388
1389 if (getField(i).type() != v.type()) 1389 if (getField(i).type() != v.type())
1390 return FALSE; 1390 return FALSE;
1391 1391
1392 switch(getField(i).type()) { 1392 switch(getField(i).type()) {
1393 case TVVariant::String: { 1393 case TVVariant::String: {
1394 QString qs1 = getField(i).toString().lower(); 1394 QString qs1 = getField(i).toString().lower();
1395 QString qs2 = v.toString().lower(); 1395 QString qs2 = v.toString().lower();
1396 return qs1.startsWith(qs2); 1396 return qs1.startsWith(qs2);
1397 } 1397 }
1398 /* meaningless for ints */ 1398 /* meaningless for ints */
1399 /* meaningless for time */ 1399 /* meaningless for time */
1400 /* meaningless for dates */ 1400 /* meaningless for dates */
1401 case TVVariant::Int: 1401 case TVVariant::Int:
1402 case TVVariant::Time: 1402 case TVVariant::Time:
1403 case TVVariant::Date: 1403 case TVVariant::Date:
1404 return FALSE; 1404 return FALSE;
1405 default: 1405 default:
1406 qWarning("Tried to compare unknown data type"); 1406 qWarning("Tried to compare unknown data type");
1407 } 1407 }
1408 return FALSE; 1408 return FALSE;
1409} 1409}
1410 1410
1411bool DataElem::endsWith(int i, TVVariant v) const 1411bool DataElem::endsWith(int i, TVVariant v) const
1412{ 1412{
1413 if (!hasValidValue(i)) return FALSE; 1413 if (!hasValidValue(i)) return FALSE;
1414 1414
1415 if (getField(i).type() != v.type()) 1415 if (getField(i).type() != v.type())
1416 return FALSE; 1416 return FALSE;
1417 1417
1418 switch(getField(i).type()) { 1418 switch(getField(i).type()) {
1419 case TVVariant::String: { 1419 case TVVariant::String: {
1420 QString qs1 = getField(i).toString().lower(); 1420 QString qs1 = getField(i).toString().lower();
1421 QString qs2 = v.toString().lower(); 1421 QString qs2 = v.toString().lower();
1422 return qs1.startsWith(qs2); 1422 return qs1.startsWith(qs2);
1423 } 1423 }
1424 /* meaningless for ints */ 1424 /* meaningless for ints */
1425 /* meaningless for time */ 1425 /* meaningless for time */
1426 /* meaningless for dates */ 1426 /* meaningless for dates */
1427 case TVVariant::Int: 1427 case TVVariant::Int:
1428 case TVVariant::Time: 1428 case TVVariant::Time:
1429 case TVVariant::Date: 1429 case TVVariant::Date:
1430 return FALSE; 1430 return FALSE;
1431 default: 1431 default:
1432 qWarning("Tried to compare unknown data type"); 1432 qWarning("Tried to compare unknown data type");
1433 } 1433 }
1434 return FALSE; 1434 return FALSE;
1435} 1435}
1436 1436
1437/*! 1437/*!
1438 Determins which of the first to parameters are closer to the third, target 1438 Determins which of the first to parameters are closer to the third, target
1439 parameter. 1439 parameter.
1440 1440
1441 \return 1441 \return
1442 <UL> 1442 <UL>
1443 <LI>TRUE if the first element is a closer match to the target than the 1443 <LI>TRUE if the first element is a closer match to the target than the
1444 second element</LI> 1444 second element</LI>
1445 <LI>FALSE if the first element is not a closer match to the target than 1445 <LI>FALSE if the first element is not a closer match to the target than
1446 the second element</LI> 1446 the second element</LI>
1447 </UL> 1447 </UL>
1448*/ 1448*/
1449bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) 1449bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column)
1450{ 1450{
1451 int type; 1451 int type;
1452 1452
1453 if(!d1) return FALSE; 1453 if(!d1) return FALSE;
1454 1454
1455 if (!d1->hasValidValue(column)) return FALSE; 1455 if (!d1->hasValidValue(column)) return FALSE;
1456 1456
1457 if(!target.isValid()) return FALSE; 1457 if(!target.isValid()) return FALSE;
1458 1458
1459 type = d1->getField(column).type(); 1459 type = d1->getField(column).type();
1460 1460
1461 if(d2) { 1461 if(d2) {
1462 if (type != d2->getField(column).type()) { 1462 if (type != d2->getField(column).type()) {
1463 /* can't do compare */ 1463 /* can't do compare */
1464 qWarning("Tried to compare two incompatable types"); 1464 qWarning("Tried to compare two incompatable types");
1465 return FALSE; 1465 return FALSE;
1466 } 1466 }
1467 return target.closer(d1->getField(column), d2->getField(column)); 1467 return target.closer(d1->getField(column), d2->getField(column));
1468 } 1468 }
1469 return target.close(d1->getField(column)); 1469 return target.close(d1->getField(column));
1470} 1470}
diff --git a/noncore/apps/tableviewer/db/csvsource.cpp b/noncore/apps/tableviewer/db/csvsource.cpp
index 2561b4b..ea36300 100644
--- a/noncore/apps/tableviewer/db/csvsource.cpp
+++ b/noncore/apps/tableviewer/db/csvsource.cpp
@@ -1,207 +1,208 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 "csvsource.h" 20#include "csvsource.h"
21#include "common.h" 21#include "common.h"
22#include "datacache.h" 22#include "datacache.h"
23#include <qtextstream.h> 23#include <qtextstream.h>
24#include <qstringlist.h> 24#include <qstringlist.h>
25#include <qmap.h> 25#include <qmap.h>
26#include <qregexp.h> 26#include <qregexp.h>
27 27
28DBCsv::DBCsv(DBStore *d) 28DBCsv::DBCsv(DBStore *d)
29{ 29{
30 dstore = d; 30 dstore = d;
31} 31}
32 32
33DBCsv::~DBCsv() 33DBCsv::~DBCsv()
34{ 34{
35} 35}
36 36
37QString DBCsv::type() 37QString DBCsv::type()
38{ 38{
39 return "csv"; 39 return "csv";
40} 40}
41 41
42QStringList readElem(QString in) 42QStringList readElem(QString in)
43{ 43{
44 QStringList out; 44 QStringList out;
45 45
46 if (in.isEmpty()) 46 if (in.isEmpty())
47 return out; 47 return out;
48 48
49 bool firstChar = TRUE; 49 bool firstChar = TRUE;
50 bool quotedElem = FALSE; 50 bool quotedElem = FALSE;
51 uint index = 0; 51 uint index = 0;
52 while(index < in.length()) { 52 while(index < in.length()) {
53 if(firstChar) { 53 if(firstChar) {
54 /* skip whitespace */ 54 /* skip whitespace */
55 while(index < in.length() && in[index] == ' ') 55 while(index < in.length() && in[index] == ' ')
56 index++; 56 index++;
57 if(in[index] == '"') { 57 if(in[index] == '"') {
58 quotedElem = TRUE; 58 quotedElem = TRUE;
59 index++; 59 index++;
60 } 60 }
61 } 61 }
62 /* real first char */ 62 /* real first char */
63 QString elem; 63 QString elem;
64 if(quotedElem) { 64 if(quotedElem) {
65 while(index < in.length() && in[index] != '"') { 65 while(index < in.length() && in[index] != '"') {
66 /* check for escape character */ 66 /* check for escape character */
67 if (in[index] == '\\') { 67 if (in[index] == '\\') {
68 if (index++ < in.length()) { 68 if (index++ < in.length()) {
69 elem.append(in[index]); 69 elem.append(in[index]);
70 index++; 70 index++;
71 } 71 }
72 } else { 72 } else {
73 elem.append(in[index]); 73 elem.append(in[index]);
74 index++; 74 index++;
75 } 75 }
76 } 76 }
77 } else { 77 } else {
78 while(index < in.length() && in[index] != ',') { 78 while(index < in.length() && in[index] != ',') {
79 if (in[index] == '\\') { 79 if (in[index] == '\\') {
80 if (index++ < in.length()) { 80 if (index++ < in.length()) {
81 elem.append(in[index]); 81 elem.append(in[index]);
82 index++; 82 index++;
83 } 83 }
84 } else { 84 } else {
85 elem.append(in[index]); 85 elem.append(in[index]);
86 index++; 86 index++;
87 } 87 }
88 } 88 }
89 } 89 }
90 /* we have our current elem */ 90 /* we have our current elem */
91 out << elem.stripWhiteSpace(); 91 out << elem.stripWhiteSpace();
92 firstChar = TRUE; 92 firstChar = TRUE;
93 quotedElem = FALSE; 93 quotedElem = FALSE;
94 /* skip till a , or end of line */ 94 /* skip till a , or end of line */
95 while (index < in.length() && in[index] != ',') index++; 95 while (index < in.length() && in[index] != ',') index++;
96 if(index == in.length()) 96 if(index == in.length())
97 return out; 97 return out;
98 else 98 else
99 index++; 99 index++;
100 } 100 }
101 return out;
101} 102}
102 103
103bool DBCsv::openSource(QIODevice *inDev) 104bool DBCsv::openSource(QIODevice *inDev)
104{ 105{
105 QTextStream tsIn(inDev); 106 QTextStream tsIn(inDev);
106 QString in = tsIn.readLine().stripWhiteSpace(); 107 QString in = tsIn.readLine().stripWhiteSpace();
107 QStringList keys; 108 QStringList keys;
108 109
109 keys = readElem(in); 110 keys = readElem(in);
110 111
111 QMap<int,int> keyIndexes; 112 QMap<int,int> keyIndexes;
112 113
113 KeyList *keyR = new KeyList(); 114 KeyList *keyR = new KeyList();
114 QStringList::Iterator i = keys.begin(); 115 QStringList::Iterator i = keys.begin();
115 116
116 uint fileIndex = 0; 117 uint fileIndex = 0;
117 while(i != keys.end()) { 118 while(i != keys.end()) {
118 if ((*i).isEmpty()) 119 if ((*i).isEmpty())
119 keyIndexes.insert(fileIndex, keyR->addKey("Unamed", TVVariant::String)); 120 keyIndexes.insert(fileIndex, keyR->addKey("Unamed", TVVariant::String));
120 else 121 else
121 keyIndexes.insert(fileIndex, keyR->addKey(*i, TVVariant::String)); 122 keyIndexes.insert(fileIndex, keyR->addKey(*i, TVVariant::String));
122 i++; 123 i++;
123 fileIndex++; 124 fileIndex++;
124 } 125 }
125 dstore->setKeys(keyR); 126 dstore->setKeys(keyR);
126 127
127 in = tsIn.readLine().stripWhiteSpace(); 128 in = tsIn.readLine().stripWhiteSpace();
128 while(!in.isNull()) { 129 while(!in.isNull()) {
129 QStringList elems = readElem(in); 130 QStringList elems = readElem(in);
130 131
131 i = elems.begin(); 132 i = elems.begin();
132 fileIndex = 0; 133 fileIndex = 0;
133 DataElem *current_data = new DataElem(dstore); 134 DataElem *current_data = new DataElem(dstore);
134 while(i != elems.end()) { 135 while(i != elems.end()) {
135 if(!(*i).isEmpty()) { 136 if(!(*i).isEmpty()) {
136 current_data->setField(keyIndexes[fileIndex], *i); 137 current_data->setField(keyIndexes[fileIndex], *i);
137 } 138 }
138 fileIndex++; 139 fileIndex++;
139 i++; 140 i++;
140 } 141 }
141 dstore->addItem(current_data); 142 dstore->addItem(current_data);
142 in = tsIn.readLine().stripWhiteSpace(); 143 in = tsIn.readLine().stripWhiteSpace();
143 } 144 }
144 145
145 return TRUE; 146 return TRUE;
146} 147}
147 148
148bool DBCsv::saveSource(QIODevice *outDev) 149bool DBCsv::saveSource(QIODevice *outDev)
149{ 150{
150 /* try not to use the escape character when possible. */ 151 /* try not to use the escape character when possible. */
151 int i; 152 int i;
152 DataElem *elem; 153 DataElem *elem;
153 KeyList *k; 154 KeyList *k;
154 QTextStream outstream(outDev); 155 QTextStream outstream(outDev);
155 156
156 k = dstore->getKeys(); 157 k = dstore->getKeys();
157 KeyListIterator it(*k); 158 KeyListIterator it(*k);
158 while(it.current()) { 159 while(it.current()) {
159 if(!it.current()->delFlag()) { 160 if(!it.current()->delFlag()) {
160 QString name = it.current()->name(); 161 QString name = it.current()->name();
161 162
162 name.replace(QRegExp("\\"), "\\\\"); 163 name.replace(QRegExp("\\"), "\\\\");
163 name.replace(QRegExp("\""), "\\\""); 164 name.replace(QRegExp("\""), "\\\"");
164 if(name.find(',') != -1) { 165 if(name.find(',') != -1) {
165 name.prepend('\"'); 166 name.prepend('\"');
166 name.append('\"'); 167 name.append('\"');
167 } 168 }
168 169
169 outstream << name; 170 outstream << name;
170 } 171 }
171 ++it; 172 ++it;
172 if(it.current()) 173 if(it.current())
173 outstream << ", "; 174 outstream << ", ";
174 } 175 }
175 outstream << "\n"; 176 outstream << "\n";
176 177
177 dstore->first(); 178 dstore->first();
178 179
179 do { 180 do {
180 elem = dstore->getCurrentData(); 181 elem = dstore->getCurrentData();
181 if(!elem) 182 if(!elem)
182 break; 183 break;
183 it.toFirst(); 184 it.toFirst();
184 while(it.current()) { 185 while(it.current()) {
185 i = it.currentKey(); 186 i = it.currentKey();
186 if (elem->hasValidValue(i)) { 187 if (elem->hasValidValue(i)) {
187 QString name = elem->toQString(i); 188 QString name = elem->toQString(i);
188 189
189 name.replace(QRegExp("\\"), "\\\\"); 190 name.replace(QRegExp("\\"), "\\\\");
190 name.replace(QRegExp("\""), "\\\""); 191 name.replace(QRegExp("\""), "\\\"");
191 if(name.find(',') != -1) { 192 if(name.find(',') != -1) {
192 name.prepend('\"'); 193 name.prepend('\"');
193 name.append('\"'); 194 name.append('\"');
194 } 195 }
195 196
196 outstream << name; 197 outstream << name;
197 } 198 }
198 ++it; 199 ++it;
199 if(it.current()) 200 if(it.current())
200 outstream << ", "; 201 outstream << ", ";
201 } 202 }
202 outstream << "\n"; 203 outstream << "\n";
203 } while (dstore->next()); 204 } while (dstore->next());
204 205
205 return TRUE; 206 return TRUE;
206} 207}
207 208
diff --git a/noncore/apps/tableviewer/ui/commonwidgets.cpp b/noncore/apps/tableviewer/ui/commonwidgets.cpp
index bf4c36f..4c47951 100644
--- a/noncore/apps/tableviewer/ui/commonwidgets.cpp
+++ b/noncore/apps/tableviewer/ui/commonwidgets.cpp
@@ -1,210 +1,210 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 20
21#include <qlineedit.h> 21#include <qlineedit.h>
22#include <qlayout.h> 22#include <qlayout.h>
23#include <qlabel.h> 23#include <qlabel.h>
24#include <qcombobox.h> 24#include <qcombobox.h>
25 25
26#include <qpe/datebookmonth.h> 26#include <qpe/datebookmonth.h>
27#include <qpopupmenu.h> 27#include <qpopupmenu.h>
28#include <qspinbox.h> 28#include <qspinbox.h>
29#include "commonwidgets.h" 29#include "commonwidgets.h"
30 30
31DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) 31DateEdit::DateEdit( QWidget *parent, const char *name, WFlags f )
32 : QToolButton(parent, name) 32 : QToolButton(parent, name)
33{ 33{
34 QPopupMenu *m1 = new QPopupMenu(this); 34 QPopupMenu *m1 = new QPopupMenu(this);
35 dateSelector = new DateBookMonth(m1, 0, TRUE); 35 dateSelector = new DateBookMonth(m1, 0, TRUE);
36 m1->insertItem(dateSelector); 36 m1->insertItem(dateSelector);
37 setPopup(m1); 37 setPopup(m1);
38 setPopupDelay(0); 38 setPopupDelay(0);
39 39
40 connect(dateSelector, SIGNAL(dateClicked(int, int, int)), 40 connect(dateSelector, SIGNAL(dateClicked(int, int, int)),
41 this, SLOT(subValueChanged())); 41 this, SLOT(subValueChanged()));
42 42
43 setText(dateSelector->selectedDate().toString()); 43 setText(dateSelector->selectedDate().toString());
44} 44}
45 45
46 46
47DateEdit::~DateEdit() {} 47DateEdit::~DateEdit() {}
48 48
49QDate DateEdit::date() const 49QDate DateEdit::date() const
50{ 50{
51 return dateSelector->selectedDate(); 51 return dateSelector->selectedDate();
52} 52}
53 53
54void DateEdit::setDate(QDate d) 54void DateEdit::setDate(QDate d)
55{ 55{
56 dateSelector->setDate(d.year(), d.month(), d.day()); 56 dateSelector->setDate(d.year(), d.month(), d.day());
57 setText(d.toString()); 57 setText(d.toString());
58} 58}
59 59
60QSizePolicy DateEdit::sizePolicy() const 60QSizePolicy DateEdit::sizePolicy() const
61{ 61{
62 QSizePolicy sp; 62 QSizePolicy sp;
63 sp.setHorData(QToolButton::sizePolicy().horData()); 63 sp.setHorData(QToolButton::sizePolicy().horData());
64 sp.setVerData(QSizePolicy::Fixed); 64 sp.setVerData(QSizePolicy::Fixed);
65 65
66 return sp; 66 return sp;
67} 67}
68 68
69void DateEdit::clear() 69void DateEdit::clear()
70{ 70{
71 QDate today = QDate::currentDate(); 71 QDate today = QDate::currentDate();
72 72
73 dateSelector->setDate(today.year(), today.month(), today.day()); 73 dateSelector->setDate(today.year(), today.month(), today.day());
74 setText(today.toString()); 74 setText(today.toString());
75} 75}
76 76
77void DateEdit::subValueChanged() 77void DateEdit::subValueChanged()
78{ 78{
79 QDate current = dateSelector->selectedDate(); 79 QDate current = dateSelector->selectedDate();
80 80
81 setText(current.toString()); 81 setText(current.toString());
82 emit valueChanged(current); 82 emit valueChanged(current);
83} 83}
84 84
85TimeEdit::TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) 85TimeEdit::TimeEdit( QWidget *parent, const char *name, WFlags f )
86 : QWidget(parent, name, f) 86 : QWidget(parent, name, f)
87{ 87{
88 QHBoxLayout *layout = new QHBoxLayout(this, 0); 88 QHBoxLayout *layout = new QHBoxLayout(this, 0);
89 89
90 layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this)); 90 layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this));
91 hourKey->setWrapping(true); 91 hourKey->setWrapping(true);
92 hourKey->setMinimumWidth(30); 92 hourKey->setMinimumWidth(30);
93 hourKey->setMaximumWidth(35); 93 hourKey->setMaximumWidth(35);
94 94
95 layout->addWidget(new QLabel(" : ", this)); 95 layout->addWidget(new QLabel(" : ", this));
96 layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this)); 96 layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this));
97 minuteKey->setWrapping(true); 97 minuteKey->setWrapping(true);
98 minuteKey->setMinimumWidth(30); 98 minuteKey->setMinimumWidth(30);
99 minuteKey->setMaximumWidth(35); 99 minuteKey->setMaximumWidth(35);
100 100
101 layout->addWidget(new QLabel(" : ", this)); 101 layout->addWidget(new QLabel(" : ", this));
102 layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0)); 102 layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0));
103 secondKey->setWrapping(true); 103 secondKey->setWrapping(true);
104 secondKey->setMinimumWidth(30); 104 secondKey->setMinimumWidth(30);
105 secondKey->setMaximumWidth(35); 105 secondKey->setMaximumWidth(35);
106 106
107 layout->addWidget(ampm = new QComboBox(this)); 107 layout->addWidget(ampm = new QComboBox(this));
108 ampm->insertItem("AM"); 108 ampm->insertItem("AM");
109 ampm->insertItem("PM"); 109 ampm->insertItem("PM");
110 110
111 layout->addStretch(-1); 111 layout->addStretch(-1);
112 112
113 clear(); 113 clear();
114 114
115 connect(secondKey, SIGNAL(valueChanged(const QString&)), 115 connect(secondKey, SIGNAL(valueChanged(const QString&)),
116 this, SLOT(subValueChanged())); 116 this, SLOT(subValueChanged()));
117 connect(minuteKey, SIGNAL(valueChanged(const QString&)), 117 connect(minuteKey, SIGNAL(valueChanged(const QString&)),
118 this, SLOT(subValueChanged())); 118 this, SLOT(subValueChanged()));
119 connect(hourKey, SIGNAL(valueChanged(const QString&)), 119 connect(hourKey, SIGNAL(valueChanged(const QString&)),
120 this, SLOT(subValueChanged())); 120 this, SLOT(subValueChanged()));
121 connect(ampm, SIGNAL(activated(int)), 121 connect(ampm, SIGNAL(activated(int)),
122 this, SLOT(subValueChanged())); 122 this, SLOT(subValueChanged()));
123} 123}
124 124
125 125
126TimeEdit::~TimeEdit() {} 126TimeEdit::~TimeEdit() {}
127 127
128QTime TimeEdit::time() const 128QTime TimeEdit::time() const
129{ 129{
130 int s,m,h; 130 int s,m,h;
131 131
132 s = secondKey->text().toInt(); 132 s = secondKey->text().toInt();
133 m = minuteKey->text().toInt(); 133 m = minuteKey->text().toInt();
134 h = hourKey->text().toInt(); 134 h = hourKey->text().toInt();
135 135
136 if(ampm->currentItem() == 1) { 136 if(ampm->currentItem() == 1) {
137 /* pm */ 137 /* pm */
138 h = h + 12; 138 h = h + 12;
139 } 139 }
140 /* hour now ranges 1->24 */ 140 /* hour now ranges 1->24 */
141 141
142 if (h == 12) 142 if (h == 12)
143 h = 0; 143 h = 0;
144 if (h == 24) 144 if (h == 24)
145 h = 12; 145 h = 12;
146 146
147 if(QTime::isValid(h, m, s)) 147 if(QTime::isValid(h, m, s))
148 return QTime(h, m, s); 148 return QTime(h, m, s);
149 return QTime(0, 0, 0); 149 return QTime(0, 0, 0);
150} 150}
151 151
152void TimeEdit::setTime(QTime t) 152void TimeEdit::setTime(QTime t)
153{ 153{
154 int h = t.hour(); 154 int h = t.hour();
155 secondKey->setValue(t.second()); 155 secondKey->setValue(t.second());
156 minuteKey->setValue(t.minute()); 156 minuteKey->setValue(t.minute());
157 157
158 /* h 0..23 */ 158 /* h 0..23 */
159 if (h > 11) { 159 if (h > 11) {
160 h -= 12; 160 h -= 12;
161 ampm->setCurrentItem(1); 161 ampm->setCurrentItem(1);
162 } else { 162 } else {
163 ampm->setCurrentItem(0); 163 ampm->setCurrentItem(0);
164 } 164 }
165 165
166 if (h == 0) h = 12; 166 if (h == 0) h = 12;
167 hourKey->setValue(h); 167 hourKey->setValue(h);
168} 168}
169 169
170QSizePolicy TimeEdit::sizePolicy() const 170QSizePolicy TimeEdit::sizePolicy() const
171{ 171{
172 QSizePolicy sp; 172 QSizePolicy sp;
173 sp.setHorData(QSizePolicy::Preferred); 173 sp.setHorData(QSizePolicy::Preferred);
174 sp.setVerData(QSizePolicy::Fixed); 174 sp.setVerData(QSizePolicy::Fixed);
175 175
176 return sp; 176 return sp;
177} 177}
178 178
179void TimeEdit::clear() 179void TimeEdit::clear()
180{ 180{
181 secondKey->setValue(0); 181 secondKey->setValue(0);
182 minuteKey->setValue(0); 182 minuteKey->setValue(0);
183 hourKey->setValue(12); 183 hourKey->setValue(12);
184 184
185 ampm->setCurrentItem(0); 185 ampm->setCurrentItem(0);
186} 186}
187 187
188void TimeEdit::subValueChanged() 188void TimeEdit::subValueChanged()
189{ 189{
190 emit valueChanged(time()); 190 emit valueChanged(time());
191} 191}
192 192
193IntEdit::IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ) 193IntEdit::IntEdit( QWidget *parent, const char *name, WFlags f )
194 : QSpinBox(INT_MIN, INT_MAX, 1, parent, name) 194 : QSpinBox(INT_MIN, INT_MAX, 1, parent, name)
195{ 195{
196 setValue(0); 196 setValue(0);
197} 197}
198 198
199 199
200IntEdit::~IntEdit() {} 200IntEdit::~IntEdit() {}
201 201
202int IntEdit::value() 202int IntEdit::value()
203{ 203{
204 return cleanText().toInt(); 204 return cleanText().toInt();
205} 205}
206 206
207void IntEdit::clear() 207void IntEdit::clear()
208{ 208{
209 setValue(0); 209 setValue(0);
210} 210}
diff --git a/noncore/apps/tableviewer/ui/tvbrowseview.cpp b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
index 9bfc791..f5f2555 100644
--- a/noncore/apps/tableviewer/ui/tvbrowseview.cpp
+++ b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
@@ -1,122 +1,122 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 "tvbrowseview.h" 20#include "tvbrowseview.h"
21#include "browsekeyentry.h" 21#include "browsekeyentry.h"
22#include <qtoolbutton.h> 22#include <qtoolbutton.h>
23#include <qtextview.h> 23#include <qtextview.h>
24#include <qtextbrowser.h> 24#include <qtextbrowser.h>
25#include <qlayout.h> 25#include <qlayout.h>
26 26
27/*! 27/*!
28 \class TVBrowseView 28 \class TVBrowseView
29 \brief The widget describing how to draw the browse view user interface 29 \brief The widget describing how to draw the browse view user interface
30 30
31 This widget allows for the user to browse through the table, one element 31 This widget allows for the user to browse through the table, one element
32 at a time, or search on a single key. Its main goal is to show a 32 at a time, or search on a single key. Its main goal is to show a
33 single element in a readable format and make it easy for the user to 33 single element in a readable format and make it easy for the user to
34 rapidly find specific elements in the table. 34 rapidly find specific elements in the table.
35*/ 35*/
36 36
37/*! 37/*!
38 Constructs a new TVBrowseView widget 38 Constructs a new TVBrowseView widget
39*/ 39*/
40TVBrowseView::TVBrowseView(TableState *t, QWidget* parent = 0, const char *name = 0, 40TVBrowseView::TVBrowseView(TableState *t, QWidget* parent, const char *name,
41 WFlags fl =0) 41 WFlags fl )
42{ 42{
43 if (!name) 43 if (!name)
44 setName("BrowseView"); 44 setName("BrowseView");
45 45
46// setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) ); 46// setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) );
47 QVBoxLayout *vlayout = new QVBoxLayout(this); 47 QVBoxLayout *vlayout = new QVBoxLayout(this);
48 textViewDisplay = new QTextBrowser(this, "textViewDisplay"); 48 textViewDisplay = new QTextBrowser(this, "textViewDisplay");
49 vlayout->addWidget( textViewDisplay ); 49 vlayout->addWidget( textViewDisplay );
50 50
51 keyEntry = new TVBrowseKeyEntry(this, "keyEntry"); 51 keyEntry = new TVBrowseKeyEntry(this, "keyEntry");
52 vlayout->addWidget( keyEntry ); 52 vlayout->addWidget( keyEntry );
53 53
54 /* connect the signals down */ 54 /* connect the signals down */
55 55
56 connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)), 56 connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)),
57 this, SIGNAL(searchOnKey(int, TVVariant))); 57 this, SIGNAL(searchOnKey(int, TVVariant)));
58 connect(keyEntry, SIGNAL(sortChanged(int)), 58 connect(keyEntry, SIGNAL(sortChanged(int)),
59 this, SIGNAL(sortChanged(int))); 59 this, SIGNAL(sortChanged(int)));
60 60
61 ts = t; 61 ts = t;
62 keyEntry->setTableState(t); 62 keyEntry->setTableState(t);
63} 63}
64 64
65/*! 65/*!
66 Destroys the TVBrowseView widget 66 Destroys the TVBrowseView widget
67*/ 67*/
68TVBrowseView::~TVBrowseView() 68TVBrowseView::~TVBrowseView()
69{ 69{
70} 70}
71 71
72void TVBrowseView::rebuildData() 72void TVBrowseView::rebuildData()
73{ 73{
74 if(!ts) 74 if(!ts)
75 return; 75 return;
76 if(!ts->current_elem) { 76 if(!ts->current_elem) {
77 /* also disable buttons */ 77 /* also disable buttons */
78 textViewDisplay->setText(""); 78 textViewDisplay->setText("");
79 return; 79 return;
80 } 80 }
81 81
82 setDisplayText(ts->current_elem); 82 setDisplayText(ts->current_elem);
83} 83}
84 84
85/* Reset to initial state */ 85/* Reset to initial state */
86void TVBrowseView::reset() 86void TVBrowseView::reset()
87{ 87{
88 textViewDisplay->setText(""); 88 textViewDisplay->setText("");
89 keyEntry->reset(); 89 keyEntry->reset();
90} 90}
91 91
92/*! 92/*!
93 sets the data element to be displayed to element 93 sets the data element to be displayed to element
94*/ 94*/
95void TVBrowseView::setDisplayText(const DataElem *element) 95void TVBrowseView::setDisplayText(const DataElem *element)
96{ 96{
97 QString rep = ""; 97 QString rep = "";
98 98
99 KeyListIterator it(*ts->kRep); 99 KeyListIterator it(*ts->kRep);
100 100
101 while (it.current()) { 101 while (it.current()) {
102 if (element->hasValidValue(it.currentKey())) { 102 if (element->hasValidValue(it.currentKey())) {
103 if(it.currentKey() == ts->current_column) { 103 if(it.currentKey() == ts->current_column) {
104 rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>" 104 rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>"
105 + it.current()->name() 105 + it.current()->name()
106 + ":</FONT></B> "; 106 + ":</FONT></B> ";
107 } else { 107 } else {
108 rep += "<B>" + it.current()->name() + ":</B> "; 108 rep += "<B>" + it.current()->name() + ":</B> ";
109 } 109 }
110 rep += element->toQString(it.currentKey()) + "<BR>"; 110 rep += element->toQString(it.currentKey()) + "<BR>";
111 } 111 }
112 ++it; 112 ++it;
113 } 113 }
114 114
115 textViewDisplay->setText(rep); 115 textViewDisplay->setText(rep);
116 textViewDisplay->scrollToAnchor("ckey"); 116 textViewDisplay->scrollToAnchor("ckey");
117} 117}
118 118
119void TVBrowseView::rebuildKeys() 119void TVBrowseView::rebuildKeys()
120{ 120{
121 keyEntry->rebuildKeys(); 121 keyEntry->rebuildKeys();
122} 122}
diff --git a/noncore/apps/tableviewer/ui/tveditview.cpp b/noncore/apps/tableviewer/ui/tveditview.cpp
index ba2bd06..23e2b42 100644
--- a/noncore/apps/tableviewer/ui/tveditview.cpp
+++ b/noncore/apps/tableviewer/ui/tveditview.cpp
@@ -1,235 +1,235 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 20
21 21
22/* The edit view widget. For each key in the DB display an 22/* The edit view widget. For each key in the DB display an
23 * appropriate edit box, and a 'key' button to change that particular 23 * appropriate edit box, and a 'key' button to change that particular
24 * key information (delete or edit). 24 * key information (delete or edit).
25 * 25 *
26 * Bottem line should be a 'new key' button. Should be able to scroll 26 * Bottem line should be a 'new key' button. Should be able to scroll
27 * in both directions. 27 * in both directions.
28 */ 28 */
29 29
30#include "tveditview.h" 30#include "tveditview.h"
31#include "commonwidgets.h" 31#include "commonwidgets.h"
32 32
33#include <qlayout.h> 33#include <qlayout.h>
34#include <qgrid.h> 34#include <qgrid.h>
35#include <qvbox.h> 35#include <qvbox.h>
36#include <qlineedit.h> 36#include <qlineedit.h>
37#include <qcheckbox.h> 37#include <qcheckbox.h>
38#include <qlist.h> 38#include <qlist.h>
39#include <qlabel.h> 39#include <qlabel.h>
40#include <qscrollview.h> 40#include <qscrollview.h>
41#include <qsignalmapper.h> 41#include <qsignalmapper.h>
42 42
43TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent = 0, 43TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent,
44 const char *name = 0, WFlags fl =0) : QDialog(parent, name, true, fl) 44 const char *name, WFlags fl ) : QDialog(parent, name, true, fl)
45{ 45{
46 if (!name) 46 if (!name)
47 setName("TVEditView"); 47 setName("TVEditView");
48 48
49 QVBoxLayout *layout = new QVBoxLayout(this, 0); /* only so that will resize 49 QVBoxLayout *layout = new QVBoxLayout(this, 0); /* only so that will resize
50 correctly in other 50 correctly in other
51 widgets */ 51 widgets */
52 52
53 toggles = new QSignalMapper(this); 53 toggles = new QSignalMapper(this);
54 QScrollView *sv = new QScrollView(this, 0); 54 QScrollView *sv = new QScrollView(this, 0);
55 sv->setResizePolicy(QScrollView::AutoOneFit); 55 sv->setResizePolicy(QScrollView::AutoOneFit);
56 56
57 layout->addWidget(sv); 57 layout->addWidget(sv);
58 58
59 editDisplay = new QGrid(3, sv, 0); 59 editDisplay = new QGrid(3, sv, 0);
60 editDisplay->setSpacing(3); 60 editDisplay->setSpacing(3);
61 sv->addChild(editDisplay); 61 sv->addChild(editDisplay);
62 62
63 connect(toggles, SIGNAL(mapped(int)), this, SLOT(toggleEnabled(int))); 63 connect(toggles, SIGNAL(mapped(int)), this, SLOT(toggleEnabled(int)));
64 64
65 setData(s, d); 65 setData(s, d);
66#ifdef Q_WS_QWS 66#ifdef Q_WS_QWS
67 showMaximized(); 67 showMaximized();
68#endif 68#endif
69} 69}
70 70
71TVEditView::~TVEditView() 71TVEditView::~TVEditView()
72{ 72{
73} 73}
74 74
75/*! set up the widgets in the grid, Set up initial values */ 75/*! set up the widgets in the grid, Set up initial values */
76void TVEditView::setData(TableState *t, DataElem *d) 76void TVEditView::setData(TableState *t, DataElem *d)
77{ 77{
78 78
79 /* TODO need to somehow clear old children... a delete of each 79 /* TODO need to somehow clear old children... a delete of each
80 * child? */ 80 * child? */
81 keyIds.clear(); 81 keyIds.clear();
82 82
83 KeyListIterator it(*t->kRep); 83 KeyListIterator it(*t->kRep);
84 84
85 int i = 0; 85 int i = 0;
86 while(it.current()) { 86 while(it.current()) {
87 if (t->kRep->validIndex(it.currentKey())) { 87 if (t->kRep->validIndex(it.currentKey())) {
88 new QLabel(it.current()->name(), editDisplay); 88 new QLabel(it.current()->name(), editDisplay);
89 keyIds.insert(i, it.currentKey()); 89 keyIds.insert(i, it.currentKey());
90 if (d->hasValidValue(it.currentKey())) { 90 if (d->hasValidValue(it.currentKey())) {
91 switch(it.current()->type()) { 91 switch(it.current()->type()) {
92 case TVVariant::String: { 92 case TVVariant::String: {
93 QLineEdit *edit = new QLineEdit(editDisplay, 0); 93 QLineEdit *edit = new QLineEdit(editDisplay, 0);
94 edit->setText(d->getField(it.currentKey()).toString()); 94 edit->setText(d->getField(it.currentKey()).toString());
95 edits.append(edit); 95 edits.append(edit);
96 break; 96 break;
97 } 97 }
98 case TVVariant::Int: { 98 case TVVariant::Int: {
99 IntEdit *edit = new IntEdit(editDisplay, 0); 99 IntEdit *edit = new IntEdit(editDisplay, 0);
100 edit->setValue(d->getField(it.currentKey()).toInt()); 100 edit->setValue(d->getField(it.currentKey()).toInt());
101 edits.append(edit); 101 edits.append(edit);
102 break; 102 break;
103 } 103 }
104 case TVVariant::Time: { 104 case TVVariant::Time: {
105 TimeEdit *edit = new TimeEdit(editDisplay, 0); 105 TimeEdit *edit = new TimeEdit(editDisplay, 0);
106 edit->setTime(d->getField(it.currentKey()).toTime()); 106 edit->setTime(d->getField(it.currentKey()).toTime());
107 edits.append(edit); 107 edits.append(edit);
108 break; 108 break;
109 } 109 }
110 case TVVariant::Date: { 110 case TVVariant::Date: {
111 DateEdit *edit = new DateEdit(editDisplay, 0); 111 DateEdit *edit = new DateEdit(editDisplay, 0);
112 edit->setDate(d->getField(it.currentKey()).toDate()); 112 edit->setDate(d->getField(it.currentKey()).toDate());
113 edits.append(edit); 113 edits.append(edit);
114 break; 114 break;
115 } 115 }
116 default: 116 default:
117 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay)); 117 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
118 } 118 }
119 QCheckBox *tb = new QCheckBox(editDisplay); 119 QCheckBox *tb = new QCheckBox(editDisplay);
120 tb->setChecked(TRUE); 120 tb->setChecked(TRUE);
121 toggles->setMapping(tb, i); 121 toggles->setMapping(tb, i);
122 connect(tb, SIGNAL(clicked()), toggles, SLOT(map())); 122 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
123 buttons.append(tb); 123 buttons.append(tb);
124 } else { 124 } else {
125 /* No valid value.. set to null */ 125 /* No valid value.. set to null */
126 switch(it.current()->type()) { 126 switch(it.current()->type()) {
127 case TVVariant::String: { 127 case TVVariant::String: {
128 QLineEdit *edit = new QLineEdit(editDisplay, 0); 128 QLineEdit *edit = new QLineEdit(editDisplay, 0);
129 edit->setEnabled(false); 129 edit->setEnabled(false);
130 edits.append(edit); 130 edits.append(edit);
131 break; 131 break;
132 } 132 }
133 case TVVariant::Int: { 133 case TVVariant::Int: {
134 IntEdit *edit = new IntEdit(editDisplay, 0); 134 IntEdit *edit = new IntEdit(editDisplay, 0);
135 edit->setEnabled(false); 135 edit->setEnabled(false);
136 edits.append(edit); 136 edits.append(edit);
137 break; 137 break;
138 } 138 }
139 case TVVariant::Time: { 139 case TVVariant::Time: {
140 TimeEdit *edit = new TimeEdit(editDisplay, 0); 140 TimeEdit *edit = new TimeEdit(editDisplay, 0);
141 edit->setEnabled(false); 141 edit->setEnabled(false);
142 edits.append(edit); 142 edits.append(edit);
143 break; 143 break;
144 } 144 }
145 case TVVariant::Date: { 145 case TVVariant::Date: {
146 DateEdit *edit = new DateEdit(editDisplay, 0); 146 DateEdit *edit = new DateEdit(editDisplay, 0);
147 edit->setEnabled(false); 147 edit->setEnabled(false);
148 edits.append(edit); 148 edits.append(edit);
149 break; 149 break;
150 } 150 }
151 default: 151 default:
152 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay)); 152 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
153 } 153 }
154 QCheckBox *tb = new QCheckBox(editDisplay); 154 QCheckBox *tb = new QCheckBox(editDisplay);
155 tb->setChecked(FALSE); 155 tb->setChecked(FALSE);
156 toggles->setMapping(tb, i); 156 toggles->setMapping(tb, i);
157 connect(tb, SIGNAL(clicked()), toggles, SLOT(map())); 157 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
158 buttons.append(tb); 158 buttons.append(tb);
159 } 159 }
160 i++; 160 i++;
161 } 161 }
162 ++it; 162 ++it;
163 } 163 }
164 num_edits = i; 164 num_edits = i;
165} 165}
166 166
167void TVEditView::toggleEnabled(int i) { 167void TVEditView::toggleEnabled(int i) {
168 168
169 if(edits.at(i)->isEnabled()) { 169 if(edits.at(i)->isEnabled()) {
170 edits.at(i)->setEnabled(false); 170 edits.at(i)->setEnabled(false);
171 buttons.at(i)->setChecked(FALSE); 171 buttons.at(i)->setChecked(FALSE);
172 } else { 172 } else {
173 edits.at(i)->setEnabled(true); 173 edits.at(i)->setEnabled(true);
174 buttons.at(i)->setChecked(TRUE); 174 buttons.at(i)->setChecked(TRUE);
175 } 175 }
176} 176}
177 177
178bool TVEditView::openEditItemDialog(TableState *ts, DataElem *d, 178bool TVEditView::openEditItemDialog(TableState *ts, DataElem *d,
179 QWidget *parent) 179 QWidget *parent)
180{ 180{
181 int i; 181 int i;
182 int keyId; 182 int keyId;
183 183
184 if(!ts) return 0; 184 if(!ts) return 0;
185 if(!d) return 0; 185 if(!d) return 0;
186 if(!ts->kRep) return 0; 186 if(!ts->kRep) return 0;
187 187
188 TVEditView *dlg = new TVEditView(ts, d, parent); 188 TVEditView *dlg = new TVEditView(ts, d, parent);
189 189
190 if (dlg->exec() == QDialog::Accepted ) { 190 if (dlg->exec() == QDialog::Accepted ) {
191 /* update the element, basically for each 191 /* update the element, basically for each
192 edits, if isEnabled, set Value, else unsetField */ 192 edits, if isEnabled, set Value, else unsetField */
193 193
194 for(i = 0; i < dlg->num_edits; i++) { 194 for(i = 0; i < dlg->num_edits; i++) {
195 keyId = dlg->keyIds[i]; 195 keyId = dlg->keyIds[i];
196 if(dlg->edits.at(i)->isEnabled()) { 196 if(dlg->edits.at(i)->isEnabled()) {
197 switch(d->getFieldType(keyId)) { 197 switch(d->getFieldType(keyId)) {
198 case TVVariant::String: { 198 case TVVariant::String: {
199 TVVariant value = TVVariant( 199 TVVariant value = TVVariant(
200 ((QLineEdit *)dlg->edits.at(i))->text()); 200 ((QLineEdit *)dlg->edits.at(i))->text());
201 d->setField(keyId, value); 201 d->setField(keyId, value);
202 break; 202 break;
203 } 203 }
204 case TVVariant::Int: { 204 case TVVariant::Int: {
205 TVVariant value = TVVariant( 205 TVVariant value = TVVariant(
206 ((IntEdit *)dlg->edits.at(i))->value()); 206 ((IntEdit *)dlg->edits.at(i))->value());
207 d->setField(keyId, value); 207 d->setField(keyId, value);
208 break; 208 break;
209 } 209 }
210 case TVVariant::Time: { 210 case TVVariant::Time: {
211 TVVariant value = TVVariant( 211 TVVariant value = TVVariant(
212 ((TimeEdit *)dlg->edits.at(i))->time()); 212 ((TimeEdit *)dlg->edits.at(i))->time());
213 d->setField(keyId, value); 213 d->setField(keyId, value);
214 break; 214 break;
215 } 215 }
216 case TVVariant::Date: { 216 case TVVariant::Date: {
217 TVVariant value = TVVariant( 217 TVVariant value = TVVariant(
218 ((DateEdit *)dlg->edits.at(i))->date()); 218 ((DateEdit *)dlg->edits.at(i))->date());
219 d->setField(keyId, value); 219 d->setField(keyId, value);
220 break; 220 break;
221 } 221 }
222 default: 222 default:
223 break; 223 break;
224 } 224 }
225 } else { 225 } else {
226 /* unset the field */ 226 /* unset the field */
227 d->unsetField(keyId); 227 d->unsetField(keyId);
228 } 228 }
229 } 229 }
230 delete dlg; 230 delete dlg;
231 return TRUE; 231 return TRUE;
232 } 232 }
233 233
234 return FALSE; 234 return FALSE;
235} 235}
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp
index 72d39d6..0182127 100644
--- a/noncore/apps/tableviewer/ui/tvfilterview.cpp
+++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp
@@ -1,304 +1,304 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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#include <qtoolbutton.h> 21#include <qtoolbutton.h>
22#include <qcombobox.h> 22#include <qcombobox.h>
23#include <qlistview.h> 23#include <qlistview.h>
24#include <qlayout.h> 24#include <qlayout.h>
25#include <qheader.h> 25#include <qheader.h>
26#include <qpushbutton.h> 26#include <qpushbutton.h>
27#include <qlabel.h> 27#include <qlabel.h>
28 28
29TVFilterView::TVFilterView(TableState *t, QWidget* parent = 0, 29TVFilterView::TVFilterView(TableState *t, QWidget* parent,
30 const char *name = 0, WFlags fl =0) : QDialog(parent, name, TRUE, fl) 30 const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl)
31{ 31{
32 if ( !name ) 32 if ( !name )
33 setName( "Filter View" ); 33 setName( "Filter View" );
34 34
35 QVBoxLayout *vlayout = new QVBoxLayout(this); 35 QVBoxLayout *vlayout = new QVBoxLayout(this);
36 36
37 display = new QListView(this, "display"); 37 display = new QListView(this, "display");
38 display->addColumn("Key"); 38 display->addColumn("Key");
39 display->addColumn("Constraint"); 39 display->addColumn("Constraint");
40 display->addColumn("Value"); 40 display->addColumn("Value");
41 display->header()->setClickEnabled(FALSE); 41 display->header()->setClickEnabled(FALSE);
42 display->header()->setResizeEnabled(FALSE); 42 display->header()->setResizeEnabled(FALSE);
43 43
44 vlayout->addWidget(display); 44 vlayout->addWidget(display);
45 45
46 QHBoxLayout *hlayout = new QHBoxLayout; 46 QHBoxLayout *hlayout = new QHBoxLayout;
47 hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum)); 47 hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
48 48
49 newFilterButton = new QPushButton(this, "new Filter"); 49 newFilterButton = new QPushButton(this, "new Filter");
50 newFilterButton->setMaximumSize(QSize(50, 32767)); 50 newFilterButton->setMaximumSize(QSize(50, 32767));
51 newFilterButton->setText("New"); 51 newFilterButton->setText("New");
52 hlayout->addWidget(newFilterButton); 52 hlayout->addWidget(newFilterButton);
53 53
54 deleteFilterButton = new QPushButton(this, "delete Filter"); 54 deleteFilterButton = new QPushButton(this, "delete Filter");
55 deleteFilterButton->setMaximumSize(QSize(50, 32767)); 55 deleteFilterButton->setMaximumSize(QSize(50, 32767));
56 deleteFilterButton->setText("Delete"); 56 deleteFilterButton->setText("Delete");
57 hlayout->addWidget(deleteFilterButton); 57 hlayout->addWidget(deleteFilterButton);
58 58
59 clearFilterButton = new QPushButton(this, "delete Filter"); 59 clearFilterButton = new QPushButton(this, "delete Filter");
60 clearFilterButton->setMaximumSize(QSize(60, 32767)); 60 clearFilterButton->setMaximumSize(QSize(60, 32767));
61 clearFilterButton->setText("Clear All"); 61 clearFilterButton->setText("Clear All");
62 hlayout->addWidget(clearFilterButton); 62 hlayout->addWidget(clearFilterButton);
63 63
64 vlayout->addLayout(hlayout); 64 vlayout->addLayout(hlayout);
65 65
66 QHBoxLayout *hlayout2 = new QHBoxLayout; 66 QHBoxLayout *hlayout2 = new QHBoxLayout;
67 67
68 keyNameCombo = new QComboBox(FALSE, this, "key name"); 68 keyNameCombo = new QComboBox(FALSE, this, "key name");
69 keyNameCombo->setEnabled(FALSE); 69 keyNameCombo->setEnabled(FALSE);
70 hlayout2->addWidget(keyNameCombo); 70 hlayout2->addWidget(keyNameCombo);
71 71
72 QLabel *label = new QLabel(this); 72 QLabel *label = new QLabel(this);
73 label->setText("has value"); 73 label->setText("has value");
74 hlayout2->addWidget(label); 74 hlayout2->addWidget(label);
75 75
76 keyEntry = new TVFilterKeyEntry(this, "key entry"); 76 keyEntry = new TVFilterKeyEntry(this, "key entry");
77 keyEntry->setEnabled(FALSE); 77 keyEntry->setEnabled(FALSE);
78 78
79 vlayout->addLayout(hlayout2); 79 vlayout->addLayout(hlayout2);
80 vlayout->addWidget(keyEntry); 80 vlayout->addWidget(keyEntry);
81 81
82 connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() )); 82 connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() ));
83 connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm())); 83 connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm()));
84 connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms())); 84 connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms()));
85 85
86 connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() )); 86 connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() ));
87 connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() )); 87 connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() ));
88 88
89 connect(display, SIGNAL(selectionChanged(QListViewItem*)), this, 89 connect(display, SIGNAL(selectionChanged(QListViewItem*)), this,
90 SLOT(setTerm(QListViewItem *))); 90 SLOT(setTerm(QListViewItem *)));
91 91
92 ts = t; 92 ts = t;
93 current = 0; 93 current = 0;
94 terms.setAutoDelete(true); 94 terms.setAutoDelete(true);
95 do_filter = false; 95 do_filter = false;
96 96
97#ifdef Q_WS_QWS 97#ifdef Q_WS_QWS
98 showMaximized(); 98 showMaximized();
99#endif 99#endif
100} 100}
101 101
102/*! 102/*!
103 Destroys the TVFilterView widget 103 Destroys the TVFilterView widget
104*/ 104*/
105TVFilterView::~TVFilterView() 105TVFilterView::~TVFilterView()
106{ 106{
107} 107}
108 108
109void TVFilterView::rebuildData() 109void TVFilterView::rebuildData()
110{ 110{
111} 111}
112 112
113void TVFilterView::reset() 113void TVFilterView::reset()
114{ 114{
115 keyNameCombo->clear(); 115 keyNameCombo->clear();
116 keyIds.clear(); 116 keyIds.clear();
117} 117}
118 118
119void TVFilterView::rebuildKeys() 119void TVFilterView::rebuildKeys()
120{ 120{
121 int i; 121 int i;
122 122
123 if (!ts) return; 123 if (!ts) return;
124 if(!ts->kRep) return; 124 if(!ts->kRep) return;
125 keyEntry->setTableState(ts); 125 keyEntry->setTableState(ts);
126 126
127 /* set up the list of keys that can be compared on */ 127 /* set up the list of keys that can be compared on */
128 keyNameCombo->clear(); 128 keyNameCombo->clear();
129 KeyListIterator it(*ts->kRep); 129 KeyListIterator it(*ts->kRep);
130 130
131 i = 0; 131 i = 0;
132 while(it.current()) { 132 while(it.current()) {
133 if(ts->kRep->validIndex(it.currentKey())) { 133 if(ts->kRep->validIndex(it.currentKey())) {
134 keyNameCombo->insertItem(it.current()->name()); 134 keyNameCombo->insertItem(it.current()->name());
135 keyIds.insert(i, it.currentKey()); 135 keyIds.insert(i, it.currentKey());
136 ++i; 136 ++i;
137 } 137 }
138 ++it; 138 ++it;
139 } 139 }
140} 140}
141 141
142bool TVFilterView::passesFilter(DataElem *d) { 142bool TVFilterView::passesFilter(DataElem *d) {
143 if (!filterActive()) return true; 143 if (!filterActive()) return true;
144 144
145 145
146 FilterTerm *t; 146 FilterTerm *t;
147 147
148 for (t = terms.first(); t != 0; t = terms.next() ) { 148 for (t = terms.first(); t != 0; t = terms.next() ) {
149 /* check against filter */ 149 /* check against filter */
150 switch(t->ct) { 150 switch(t->ct) {
151 case ct_less: 151 case ct_less:
152 if (!d->lessThan(t->keyIndex, t->value)) 152 if (!d->lessThan(t->keyIndex, t->value))
153 return false; 153 return false;
154 break; 154 break;
155 case ct_more: 155 case ct_more:
156 if (!d->moreThan(t->keyIndex, t->value)) 156 if (!d->moreThan(t->keyIndex, t->value))
157 return false; 157 return false;
158 break; 158 break;
159 case ct_equal: 159 case ct_equal:
160 if (!d->equalTo(t->keyIndex, t->value)) 160 if (!d->equalTo(t->keyIndex, t->value))
161 return false; 161 return false;
162 break; 162 break;
163 case ct_contains: 163 case ct_contains:
164 if (!d->contains(t->keyIndex, t->value)) 164 if (!d->contains(t->keyIndex, t->value))
165 return false; 165 return false;
166 break; 166 break;
167 case ct_startswith: 167 case ct_startswith:
168 if (!d->startsWith(t->keyIndex, t->value)) 168 if (!d->startsWith(t->keyIndex, t->value))
169 return false; 169 return false;
170 break; 170 break;
171 case ct_endswith: 171 case ct_endswith:
172 if (!d->endsWith(t->keyIndex, t->value)) 172 if (!d->endsWith(t->keyIndex, t->value))
173 return false; 173 return false;
174 break; 174 break;
175 default: 175 default:
176 qWarning("TVFilterView::passesFilter() " 176 qWarning("TVFilterView::passesFilter() "
177 "unrecognized filter type"); 177 "unrecognized filter type");
178 return false; 178 return false;
179 } 179 }
180 } 180 }
181 return true; 181 return true;
182} 182}
183 183
184bool TVFilterView::filterActive() const 184bool TVFilterView::filterActive() const
185{ 185{
186 /* when button operated, also check the do_filter value 186 /* when button operated, also check the do_filter value
187 return do_filter; 187 return do_filter;
188 */ 188 */
189 if (terms.isEmpty()) 189 if (terms.isEmpty())
190 return false; 190 return false;
191 return true; 191 return true;
192} 192}
193 193
194/* SLOTS */ 194/* SLOTS */
195void TVFilterView::newTerm() 195void TVFilterView::newTerm()
196{ 196{
197 if (!ts) return; 197 if (!ts) return;
198 198
199 FilterTerm *term = new FilterTerm; 199 FilterTerm *term = new FilterTerm;
200 current = term; 200 current = term;
201 201
202 term->view = 0; 202 term->view = 0;
203 203
204 updateTerm(); 204 updateTerm();
205 205
206 display->setSelected(term->view, true); 206 display->setSelected(term->view, true);
207 terms.append(term); 207 terms.append(term);
208 208
209 keyEntry->setEnabled(true); 209 keyEntry->setEnabled(true);
210 keyNameCombo->setEnabled(true); 210 keyNameCombo->setEnabled(true);
211} 211}
212 212
213void TVFilterView::updateTerm() 213void TVFilterView::updateTerm()
214{ 214{
215 FilterTerm *term; 215 FilterTerm *term;
216 /* Read the widget values (keyname, compare type, value) 216 /* Read the widget values (keyname, compare type, value)
217 * and build the lists */ 217 * and build the lists */
218 if (!ts) return; 218 if (!ts) return;
219 if (!current) return; 219 if (!current) return;
220 220
221 QString keyString; 221 QString keyString;
222 QString cmpString; 222 QString cmpString;
223 QString vString; 223 QString vString;
224 224
225 term = current; 225 term = current;
226 226
227 /* create new list item, set initial values, enable widgets */ 227 /* create new list item, set initial values, enable widgets */
228 term->keyIndex = keyIds[keyNameCombo->currentItem()]; 228 term->keyIndex = keyIds[keyNameCombo->currentItem()];
229 keyEntry->setKey(term->keyIndex); /* so the next two items make sense */ 229 keyEntry->setKey(term->keyIndex); /* so the next two items make sense */
230 term->ct = keyEntry->getCompareType(), 230 term->ct = keyEntry->getCompareType(),
231 term->value = keyEntry->getCompareValue(); 231 term->value = keyEntry->getCompareValue();
232 232
233 keyString = keyNameCombo->currentText(); 233 keyString = keyNameCombo->currentText();
234 234
235 switch(term->ct) { 235 switch(term->ct) {
236 case ct_less: 236 case ct_less:
237 cmpString = " less than "; 237 cmpString = " less than ";
238 break; 238 break;
239 case ct_more: 239 case ct_more:
240 cmpString = " more than "; 240 cmpString = " more than ";
241 break; 241 break;
242 case ct_equal: 242 case ct_equal:
243 cmpString = " equal to "; 243 cmpString = " equal to ";
244 break; 244 break;
245 case ct_contains: 245 case ct_contains:
246 cmpString = " containing "; 246 cmpString = " containing ";
247 break; 247 break;
248 case ct_startswith: 248 case ct_startswith:
249 cmpString = " starting with "; 249 cmpString = " starting with ";
250 break; 250 break;
251 case ct_endswith: 251 case ct_endswith:
252 cmpString = " ending with "; 252 cmpString = " ending with ";
253 break; 253 break;
254 default: 254 default:
255 cmpString = " ERROR "; 255 cmpString = " ERROR ";
256 } 256 }
257 257
258 vString = term->value.toString(); 258 vString = term->value.toString();
259 259
260 /* remove old view */ 260 /* remove old view */
261 if (term->view) 261 if (term->view)
262 delete(term->view); 262 delete(term->view);
263 term->view = new QListViewItem(display, 0, keyString, cmpString, vString); 263 term->view = new QListViewItem(display, 0, keyString, cmpString, vString);
264 display->setSelected(term->view, true); 264 display->setSelected(term->view, true);
265} 265}
266 266
267/* deletes current term */ 267/* deletes current term */
268void TVFilterView::deleteTerm() 268void TVFilterView::deleteTerm()
269{ 269{
270 if(!current) return; 270 if(!current) return;
271 if (current->view) 271 if (current->view)
272 delete(current->view); 272 delete(current->view);
273 273
274 terms.removeRef(current); 274 terms.removeRef(current);
275 275
276 current = terms.first(); 276 current = terms.first();
277 277
278 if(terms.isEmpty()) { 278 if(terms.isEmpty()) {
279 keyEntry->setEnabled(false); 279 keyEntry->setEnabled(false);
280 keyNameCombo->setEnabled(false); 280 keyNameCombo->setEnabled(false);
281 } 281 }
282} 282}
283 283
284/* clears all terminations */ 284/* clears all terminations */
285void TVFilterView::clearTerms() 285void TVFilterView::clearTerms()
286{ 286{
287 while(current) 287 while(current)
288 deleteTerm(); 288 deleteTerm();
289} 289}
290 290
291void TVFilterView::setTerm(QListViewItem *target) 291void TVFilterView::setTerm(QListViewItem *target)
292{ 292{
293 /* Iterate through the list to find item with view=target.. 293 /* Iterate through the list to find item with view=target..
294 * set as current, delete */ 294 * set as current, delete */
295 FilterTerm *term = current; 295 FilterTerm *term = current;
296 296
297 for (current = terms.first(); current != 0; current = terms.next() ) 297 for (current = terms.first(); current != 0; current = terms.next() )
298 if (current->view == target) 298 if (current->view == target)
299 break; 299 break;
300 300
301 if (!current) { 301 if (!current) {
302 current = term; 302 current = term;
303 } 303 }
304} 304}
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit.cpp b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
index fb7b7fe..4849e87 100644
--- a/noncore/apps/tableviewer/ui/tvkeyedit.cpp
+++ b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
@@ -1,254 +1,254 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 "tvkeyedit.h" 20#include "tvkeyedit.h"
21#include <qtoolbutton.h> 21#include <qtoolbutton.h>
22#include <qlineedit.h> 22#include <qlineedit.h>
23#include <qcombobox.h> 23#include <qcombobox.h>
24#include <qlistview.h> 24#include <qlistview.h>
25#include <qmessagebox.h> 25#include <qmessagebox.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <qpushbutton.h> 27#include <qpushbutton.h>
28 28
29/* QList view item... ?? that can store and update the values that I will 29/* QList view item... ?? that can store and update the values that I will
30 * be changing */ 30 * be changing */
31 31
32class TVKEListViewItem : public QListViewItem 32class TVKEListViewItem : public QListViewItem
33{ 33{
34public: 34public:
35 TVKEListViewItem(QString n, TVVariant::KeyType kt, int p, QListView *parent) : 35 TVKEListViewItem(QString n, TVVariant::KeyType kt, int p, QListView *parent) :
36 QListViewItem(parent) 36 QListViewItem(parent)
37 { 37 {
38 name = n; 38 name = n;
39 keyType = kt; 39 keyType = kt;
40 position = p; 40 position = p;
41 } 41 }
42 42
43 QString text(int i) const 43 QString text(int i) const
44 { 44 {
45 if(i) { 45 if(i) {
46 return TVVariant::typeToName(keyType); 46 return TVVariant::typeToName(keyType);
47 } 47 }
48 return name; 48 return name;
49 } 49 }
50 50
51 /* always sort by key index, ignore i */ 51 /* always sort by key index, ignore i */
52 QString key(int, bool) const 52 QString key(int, bool) const
53 { 53 {
54 return QString().sprintf("%08d", position); 54 return QString().sprintf("%08d", position);
55 } 55 }
56 56
57 void setText(int i, const QString &) 57 void setText(int i, const QString &)
58 { 58 {
59 ; 59 ;
60 } 60 }
61 61
62 QString getName() const 62 QString getName() const
63 { 63 {
64 return name; 64 return name;
65 } 65 }
66 66
67 void setName(QString n) 67 void setName(QString n)
68 { 68 {
69 name = n; 69 name = n;
70 repaint(); 70 repaint();
71 } 71 }
72 72
73 TVVariant::KeyType getKeyType() const 73 TVVariant::KeyType getKeyType() const
74 { 74 {
75 return keyType; 75 return keyType;
76 } 76 }
77 77
78 void setKeyType(TVVariant::KeyType k) 78 void setKeyType(TVVariant::KeyType k)
79 { 79 {
80 keyType = k; 80 keyType = k;
81 repaint(); 81 repaint();
82 } 82 }
83 83
84 inline int getPos() const 84 inline int getPos() const
85 { 85 {
86 return position; 86 return position;
87 } 87 }
88 88
89private: 89private:
90 QString name; 90 QString name;
91 TVVariant::KeyType keyType; 91 TVVariant::KeyType keyType;
92 int position; 92 int position;
93}; 93};
94 94
95TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent = 0, const char *name = 0, 95TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent, const char *name,
96 WFlags fl = 0) : TVKeyEdit_gen(parent, name, true, fl) 96 WFlags fl) : TVKeyEdit_gen(parent, name, true, fl)
97{ 97{
98 int i; 98 int i;
99 ts = t; 99 ts = t;
100 100
101 if(!ts) return; 101 if(!ts) return;
102 if(!ts->kRep) return; 102 if(!ts->kRep) return;
103 103
104 working_state = *ts->kRep; 104 working_state = *ts->kRep;
105 105
106 i = 1; 106 i = 1;
107 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i)); 107 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
108 i++; 108 i++;
109 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i)); 109 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
110 i++; 110 i++;
111 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i)); 111 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
112 i++; 112 i++;
113 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i)); 113 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
114 114
115 KeyListIterator it(*ts->kRep); 115 KeyListIterator it(*ts->kRep);
116 while(it.current()) { 116 while(it.current()) {
117 if(t->kRep->validIndex(it.currentKey())) { 117 if(t->kRep->validIndex(it.currentKey())) {
118 new TVKEListViewItem(it.current()->name(), 118 new TVKEListViewItem(it.current()->name(),
119 it.current()->type(), 119 it.current()->type(),
120 it.currentKey(), 120 it.currentKey(),
121 display); 121 display);
122 } 122 }
123 ++it; 123 ++it;
124 } 124 }
125 num_keys = ts->kRep->getNumFields(); 125 num_keys = ts->kRep->getNumFields();
126 if(display->childCount() > 0) { 126 if(display->childCount() > 0) {
127 display->setCurrentItem(display->firstChild()); 127 display->setCurrentItem(display->firstChild());
128 setTerm(display->currentItem()); 128 setTerm(display->currentItem());
129 } else { 129 } else {
130 deleteKeyButton->setEnabled(FALSE); 130 deleteKeyButton->setEnabled(FALSE);
131 clearKeysButton->setEnabled(FALSE); 131 clearKeysButton->setEnabled(FALSE);
132 keyNameEdit->setEnabled(FALSE); 132 keyNameEdit->setEnabled(FALSE);
133 keyTypeEdit->setEnabled(FALSE); 133 keyTypeEdit->setEnabled(FALSE);
134 } 134 }
135 135
136 display->setSorting(0); 136 display->setSorting(0);
137#ifdef Q_WS_QWS 137#ifdef Q_WS_QWS
138 showMaximized(); 138 showMaximized();
139#endif 139#endif
140} 140}
141 141
142/*! 142/*!
143 Destroys the TVKeyEdit widget 143 Destroys the TVKeyEdit widget
144*/ 144*/
145TVKeyEdit::~TVKeyEdit() 145TVKeyEdit::~TVKeyEdit()
146{ 146{
147} 147}
148 148
149/* SLOTS */ 149/* SLOTS */
150void TVKeyEdit::newTerm() 150void TVKeyEdit::newTerm()
151{ 151{
152 /* new item, make current Item */ 152 /* new item, make current Item */
153 int i; 153 int i;
154 154
155 i = working_state.addKey("<New Key>", TVVariant::String); 155 i = working_state.addKey("<New Key>", TVVariant::String);
156 //working_state.setNewFlag(i, TRUE); 156 //working_state.setNewFlag(i, TRUE);
157 TVKEListViewItem *nItem = new TVKEListViewItem("<New Key>", 157 TVKEListViewItem *nItem = new TVKEListViewItem("<New Key>",
158 TVVariant::String, 158 TVVariant::String,
159 i, 159 i,
160 display); 160 display);
161 display->setCurrentItem(nItem); 161 display->setCurrentItem(nItem);
162 setTerm(nItem); 162 setTerm(nItem);
163 163
164 num_keys++; 164 num_keys++;
165 if(display->childCount() == 1) { 165 if(display->childCount() == 1) {
166 deleteKeyButton->setEnabled(TRUE); 166 deleteKeyButton->setEnabled(TRUE);
167 clearKeysButton->setEnabled(TRUE); 167 clearKeysButton->setEnabled(TRUE);
168 keyNameEdit->setEnabled(TRUE); 168 keyNameEdit->setEnabled(TRUE);
169 keyTypeEdit->setEnabled(TRUE); 169 keyTypeEdit->setEnabled(TRUE);
170 } 170 }
171} 171}
172 172
173void TVKeyEdit::updateTerm(const QString &newName) 173void TVKeyEdit::updateTerm(const QString &newName)
174{ 174{
175 /* TODO if name matches a deleted term, prompt for 175 /* TODO if name matches a deleted term, prompt for
176 renewing old data instead */ 176 renewing old data instead */
177 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem(); 177 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
178 if(i) { 178 if(i) {
179 i->setName(newName); 179 i->setName(newName);
180 working_state.setKeyName(i->getPos(), newName); 180 working_state.setKeyName(i->getPos(), newName);
181 } 181 }
182} 182}
183 183
184void TVKeyEdit::updateTerm(int t) 184void TVKeyEdit::updateTerm(int t)
185{ 185{
186 /* t is an index to a combo in a menu, NOT a type */ 186 /* t is an index to a combo in a menu, NOT a type */
187 t++; /* menu counts from 0, types count from 1 */ 187 t++; /* menu counts from 0, types count from 1 */
188 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem(); 188 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
189 if (i) { 189 if (i) {
190 i->setKeyType((TVVariant::KeyType)t); 190 i->setKeyType((TVVariant::KeyType)t);
191 working_state.setKeyType(i->getPos(), (TVVariant::KeyType)t); 191 working_state.setKeyType(i->getPos(), (TVVariant::KeyType)t);
192 } 192 }
193} 193}
194 194
195/* deletes current term 195/* deletes current term
196 * really just marks key as deleted so is now invalid. 196 * really just marks key as deleted so is now invalid.
197 * the actual delete will happen when data is 'cleaned' 197 * the actual delete will happen when data is 'cleaned'
198 * or when file is saved. 198 * or when file is saved.
199 */ 199 */
200 200
201void TVKeyEdit::deleteTerm() 201void TVKeyEdit::deleteTerm()
202{ 202{
203 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem(); 203 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
204 if (i) { 204 if (i) {
205 working_state.setDeleteFlag(i->getPos(), TRUE); 205 working_state.setDeleteFlag(i->getPos(), TRUE);
206 delete i; 206 delete i;
207 } 207 }
208 if(!display->childCount()) { 208 if(!display->childCount()) {
209 /* disable the delete and clear buttons, etc */ 209 /* disable the delete and clear buttons, etc */
210 deleteKeyButton->setEnabled(FALSE); 210 deleteKeyButton->setEnabled(FALSE);
211 clearKeysButton->setEnabled(FALSE); 211 clearKeysButton->setEnabled(FALSE);
212 keyNameEdit->setEnabled(FALSE); 212 keyNameEdit->setEnabled(FALSE);
213 keyTypeEdit->setEnabled(FALSE); 213 keyTypeEdit->setEnabled(FALSE);
214 } 214 }
215} 215}
216 216
217/* clears all terminations */ 217/* clears all terminations */
218void TVKeyEdit::clearTerms() 218void TVKeyEdit::clearTerms()
219{ 219{
220 /* should pop up a warning */ 220 /* should pop up a warning */
221 if (QMessageBox::warning(this, "Delete all keys", 221 if (QMessageBox::warning(this, "Delete all keys",
222 "Are you sure you want to\ndelete all the keys?", 222 "Are you sure you want to\ndelete all the keys?",
223 "Yes", "No") == 0) 223 "Yes", "No") == 0)
224 { 224 {
225 while(display->currentItem()) 225 while(display->currentItem())
226 deleteTerm(); 226 deleteTerm();
227 } 227 }
228} 228}
229 229
230void TVKeyEdit::setTerm(QListViewItem *target) 230void TVKeyEdit::setTerm(QListViewItem *target)
231{ 231{
232 /* need to update the widgets to show keys values */ 232 /* need to update the widgets to show keys values */
233 keyNameEdit->setText(((TVKEListViewItem *)target)->getName()); 233 keyNameEdit->setText(((TVKEListViewItem *)target)->getName());
234 int t = (int)(((TVKEListViewItem *)target)->getKeyType()); 234 int t = (int)(((TVKEListViewItem *)target)->getKeyType());
235 t--; 235 t--;
236 keyTypeEdit->setCurrentItem(t); 236 keyTypeEdit->setCurrentItem(t);
237} 237}
238 238
239KeyList* TVKeyEdit::openEditKeysDialog(TableState *t, QWidget *parent = 0) 239KeyList* TVKeyEdit::openEditKeysDialog(TableState *t, QWidget *parent = 0)
240{ 240{
241 if(!t) 241 if(!t)
242 return 0; 242 return 0;
243 if(!t->kRep) 243 if(!t->kRep)
244 return 0; 244 return 0;
245 245
246 TVKeyEdit *dlg = new TVKeyEdit(t, parent); 246 TVKeyEdit *dlg = new TVKeyEdit(t, parent);
247 247
248 if ((dlg->exec() == QDialog::Accepted) && 248 if ((dlg->exec() == QDialog::Accepted) &&
249 (dlg->working_state != *t->kRep)) 249 (dlg->working_state != *t->kRep))
250 { 250 {
251 return (new KeyList(dlg->working_state)); 251 return (new KeyList(dlg->working_state));
252 } 252 }
253 return 0; 253 return 0;
254} 254}
diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp
index 82d67c6..b25e813 100644
--- a/noncore/apps/tableviewer/ui/tvlistview.cpp
+++ b/noncore/apps/tableviewer/ui/tvlistview.cpp
@@ -1,315 +1,315 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
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 "tvlistview.h" 20#include "tvlistview.h"
21#include "../db/common.h" 21#include "../db/common.h"
22#include <qtoolbutton.h> 22#include <qtoolbutton.h>
23#include <qlistview.h> 23#include <qlistview.h>
24#include <qlayout.h> 24#include <qlayout.h>
25 25
26void TVListViewPrivate::setColumnWidth(int column, int width) 26void TVListViewPrivate::setColumnWidth(int column, int width)
27{ 27{
28 if(width > 70) width = 70; 28 if(width > 70) width = 70;
29 QListView::setColumnWidth(column, width); 29 QListView::setColumnWidth(column, width);
30} 30}
31 31
32void TVListViewPrivate::setSorting(int column, bool increasing) 32void TVListViewPrivate::setSorting(int column, bool increasing)
33{ 33{
34 emit sortChanged(column); 34 emit sortChanged(column);
35 QListView::setSorting(column, increasing); 35 QListView::setSorting(column, increasing);
36} 36}
37 37
38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name, 38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
39 WFlags fl) : QListView(parent, name, fl) { 39 WFlags fl) : QListView(parent, name, fl) {
40 ; 40 ;
41} 41}
42 42
43class TVListViewItem : public QListViewItem 43class TVListViewItem : public QListViewItem
44{ 44{
45public: 45public:
46 46
47 TVListViewItem(QListView *parent, DataElem *d); 47 TVListViewItem(QListView *parent, DataElem *d);
48 ~TVListViewItem(); 48 ~TVListViewItem();
49 49
50 QString text(int i) const 50 QString text(int i) const
51 { 51 {
52 return data_reference->toQString(i); 52 return data_reference->toQString(i);
53 } 53 }
54 54
55 /* Do nothing... all data for this item should be generated */ 55 /* Do nothing... all data for this item should be generated */
56 void setText(int i, const QString &) 56 void setText(int i, const QString &)
57 { 57 {
58 ; 58 ;
59 } 59 }
60 QString key(int i, bool a) const 60 QString key(int i, bool a) const
61 { 61 {
62 return data_reference->toSortableQString(i); 62 return data_reference->toSortableQString(i);
63 } 63 }
64 64
65 void setDataElem(DataElem *d) 65 void setDataElem(DataElem *d)
66 { 66 {
67 data_reference = d; 67 data_reference = d;
68 } 68 }
69 69
70 DataElem *getDataElem() { 70 DataElem *getDataElem() {
71 return data_reference; 71 return data_reference;
72 } 72 }
73private: 73private:
74 DataElem *data_reference; 74 DataElem *data_reference;
75}; 75};
76 76
77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d) 77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
78 : QListViewItem(parent) 78 : QListViewItem(parent)
79{ 79{
80 data_reference = d; 80 data_reference = d;
81} 81}
82 82
83TVListViewItem::~TVListViewItem() 83TVListViewItem::~TVListViewItem()
84{ 84{
85 data_reference = 0; 85 data_reference = 0;
86} 86}
87 87
88TVListView::TVListView(TableState *t, QWidget* parent = 0, 88TVListView::TVListView(TableState *t, QWidget* parent,
89 const char *name = 0, WFlags fl =0) : QWidget(parent, name, fl) 89 const char *name, WFlags fl ) : QWidget(parent, name, fl)
90{ 90{
91 if (!name) 91 if (!name)
92 setName("TVListView"); 92 setName("TVListView");
93 93
94 // the next two lines need to be rationalized. 94 // the next two lines need to be rationalized.
95 resize(318,457); 95 resize(318,457);
96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, 96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); 97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
98 setCaption(tr("List View")); 98 setCaption(tr("List View"));
99 99
100 QVBoxLayout *layout = new QVBoxLayout(this); 100 QVBoxLayout *layout = new QVBoxLayout(this);
101 layout->setSpacing(0); 101 layout->setSpacing(0);
102 layout->setMargin(0); 102 layout->setMargin(0);
103 103
104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay"); 104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
105 layout->addWidget(listViewDisplay); 105 layout->addWidget(listViewDisplay);
106 106
107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this, 107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this,
108 SLOT(setCurrent(QListViewItem *))); 108 SLOT(setCurrent(QListViewItem *)));
109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this, 109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
110 SLOT(setSorting(int))); 110 SLOT(setSorting(int)));
111 111
112 listViewDisplay->setShowSortIndicator(true); 112 listViewDisplay->setShowSortIndicator(true);
113 113
114 it = new QListViewItemIterator(listViewDisplay); 114 it = new QListViewItemIterator(listViewDisplay);
115 ts = t; 115 ts = t;
116} 116}
117 117
118TVListView::~TVListView() 118TVListView::~TVListView()
119{ 119{
120} 120}
121 121
122void TVListView::addItem(DataElem *d) 122void TVListView::addItem(DataElem *d)
123{ 123{
124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d); 124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
125 125
126 delete it; 126 delete it;
127 it = new QListViewItemIterator(i); 127 it = new QListViewItemIterator(i);
128} 128}
129 129
130/* remove current (it) item */ 130/* remove current (it) item */
131void TVListView::removeItem() 131void TVListView::removeItem()
132{ 132{
133 QListViewItemIterator other(*it); 133 QListViewItemIterator other(*it);
134 134
135 QListViewItemIterator tmp = *it; 135 QListViewItemIterator tmp = *it;
136 (*it)++; 136 (*it)++;
137 if (!it->current()) { 137 if (!it->current()) {
138 *it = tmp; 138 *it = tmp;
139 (*it)--; 139 (*it)--;
140 if (!it->current()) { 140 if (!it->current()) {
141 delete it; 141 delete it;
142 it = 0; 142 it = 0;
143 } 143 }
144 } 144 }
145 145
146 delete other.current(); 146 delete other.current();
147} 147}
148 148
149void TVListView::clearItems() 149void TVListView::clearItems()
150{ 150{
151 /* This is ok since the destructor for TVListItem does not know about 151 /* This is ok since the destructor for TVListItem does not know about
152 the data_reference pointer.. and hence will leave it alone */ 152 the data_reference pointer.. and hence will leave it alone */
153 listViewDisplay->clear(); 153 listViewDisplay->clear();
154 delete it; 154 delete it;
155 it = new QListViewItemIterator(listViewDisplay); 155 it = new QListViewItemIterator(listViewDisplay);
156} 156}
157 157
158void TVListView::first() 158void TVListView::first()
159{ 159{
160 delete it; 160 delete it;
161 it = new QListViewItemIterator(listViewDisplay); 161 it = new QListViewItemIterator(listViewDisplay);
162} 162}
163 163
164void TVListView::last() 164void TVListView::last()
165{ 165{
166 qWarning("TVListView::last not yet implemented"); 166 qWarning("TVListView::last not yet implemented");
167} 167}
168 168
169void TVListView::next() 169void TVListView::next()
170{ 170{
171 QListViewItemIterator tmp = *it; 171 QListViewItemIterator tmp = *it;
172 (*it)++; 172 (*it)++;
173 if (!it->current()) { 173 if (!it->current()) {
174 *it = tmp; 174 *it = tmp;
175 } 175 }
176} 176}
177 177
178void TVListView::previous() 178void TVListView::previous()
179{ 179{
180 QListViewItemIterator tmp = *it; 180 QListViewItemIterator tmp = *it;
181 (*it)--; 181 (*it)--;
182 if (!it->current()) { 182 if (!it->current()) {
183 *it = tmp; 183 *it = tmp;
184 } 184 }
185} 185}
186 186
187DataElem *TVListView::getCurrentData() { 187DataElem *TVListView::getCurrentData() {
188 if (it->current()) { 188 if (it->current()) {
189 return ((TVListViewItem *)it->current())->getDataElem(); 189 return ((TVListViewItem *)it->current())->getDataElem();
190 } 190 }
191 return NULL; 191 return NULL;
192} 192}
193 193
194/*! Now to implement the closest match function */ 194/*! Now to implement the closest match function */
195void TVListView::findItem(int keyId, TVVariant value) 195void TVListView::findItem(int keyId, TVVariant value)
196{ 196{
197 QListViewItem *i; 197 QListViewItem *i;
198 TVListViewItem *best_so_far = NULL; 198 TVListViewItem *best_so_far = NULL;
199 /* start at the beginning... go through till find the closest elem */ 199 /* start at the beginning... go through till find the closest elem */
200 i = listViewDisplay->firstChild(); 200 i = listViewDisplay->firstChild();
201 while (i) { 201 while (i) {
202 /* search stuff */ 202 /* search stuff */
203 if(best_so_far) { 203 if(best_so_far) {
204 if (DataElem::closer( 204 if (DataElem::closer(
205 ((TVListViewItem *)i)->getDataElem(), 205 ((TVListViewItem *)i)->getDataElem(),
206 best_so_far->getDataElem(), value, keyId)) 206 best_so_far->getDataElem(), value, keyId))
207 best_so_far = (TVListViewItem *)i; 207 best_so_far = (TVListViewItem *)i;
208 } else { 208 } else {
209 if (DataElem::closer( 209 if (DataElem::closer(
210 ((TVListViewItem *)i)->getDataElem(), 210 ((TVListViewItem *)i)->getDataElem(),
211 NULL, value, keyId)) 211 NULL, value, keyId))
212 best_so_far = (TVListViewItem *)i; 212 best_so_far = (TVListViewItem *)i;
213 } 213 }
214 214
215 i = i->itemBelow(); 215 i = i->itemBelow();
216 } 216 }
217 if (best_so_far) { 217 if (best_so_far) {
218 /* set best_so_far to current element */ 218 /* set best_so_far to current element */
219 delete it; 219 delete it;
220 it = new QListViewItemIterator(best_so_far); 220 it = new QListViewItemIterator(best_so_far);
221 } 221 }
222} 222}
223 223
224void TVListView::rebuildKeys() 224void TVListView::rebuildKeys()
225{ 225{
226 int i; 226 int i;
227 if(!ts) return; 227 if(!ts) return;
228 if(!ts->kRep) return; 228 if(!ts->kRep) return;
229 229
230 i = listViewDisplay->columns(); 230 i = listViewDisplay->columns();
231 231
232 while(i > 0) 232 while(i > 0)
233 listViewDisplay->removeColumn(--i); 233 listViewDisplay->removeColumn(--i);
234 234
235 KeyListIterator kit(*ts->kRep); 235 KeyListIterator kit(*ts->kRep);
236 i = 0; 236 i = 0;
237 while(kit.current()) { 237 while(kit.current()) {
238 if(!kit.current()->delFlag()) { 238 if(!kit.current()->delFlag()) {
239 listViewDisplay->addColumn(kit.current()->name()); 239 listViewDisplay->addColumn(kit.current()->name());
240 keyIds.insert(i, kit.currentKey()); 240 keyIds.insert(i, kit.currentKey());
241 ++i; 241 ++i;
242 } 242 }
243 ++kit; 243 ++kit;
244 } 244 }
245} 245}
246 246
247 247
248void TVListView::setSorting(int column) 248void TVListView::setSorting(int column)
249{ 249{
250 /* Without table state can't do anything */ 250 /* Without table state can't do anything */
251 if (ts == 0) 251 if (ts == 0)
252 return; 252 return;
253 if (keyIds[column] != ts->current_column) { 253 if (keyIds[column] != ts->current_column) {
254 ts->current_column = keyIds[column]; 254 ts->current_column = keyIds[column];
255 } 255 }
256} 256}
257 257
258void TVListView::rebuildData() { 258void TVListView::rebuildData() {
259 int i; 259 int i;
260 QMap<int, int>::Iterator kit; 260 QMap<int, int>::Iterator kit;
261 /* Need to set sort order */ 261 /* Need to set sort order */
262 if(!ts) 262 if(!ts)
263 return; 263 return;
264 264
265 /* revers lookup the column */ 265 /* revers lookup the column */
266 i = -1; 266 i = -1;
267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) { 267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) {
268 if (kit.data() == ts->current_column) { 268 if (kit.data() == ts->current_column) {
269 i = kit.key(); 269 i = kit.key();
270 break; 270 break;
271 } 271 }
272 } 272 }
273 if (i == -1) 273 if (i == -1)
274 return; 274 return;
275 275
276 listViewDisplay->setSorting(i); 276 listViewDisplay->setSorting(i);
277 listViewDisplay->sort(); 277 listViewDisplay->sort();
278 278
279 /* reset current element */ 279 /* reset current element */
280 listViewDisplay->setCurrentItem(it->current()); 280 listViewDisplay->setCurrentItem(it->current());
281 listViewDisplay->setSelected(it->current(), true); 281 listViewDisplay->setSelected(it->current(), true);
282 listViewDisplay->ensureItemVisible(it->current()); 282 listViewDisplay->ensureItemVisible(it->current());
283} 283}
284 284
285void TVListView::reset() 285void TVListView::reset()
286{ 286{
287 int i; 287 int i;
288 listViewDisplay->clear(); 288 listViewDisplay->clear();
289 289
290 i = listViewDisplay->columns(); 290 i = listViewDisplay->columns();
291 while (i > 0) 291 while (i > 0)
292 listViewDisplay->removeColumn(--i); 292 listViewDisplay->removeColumn(--i);
293 293
294 keyIds.clear(); 294 keyIds.clear();
295} 295}
296 296
297void TVListView::setCurrent(QListViewItem *i) 297void TVListView::setCurrent(QListViewItem *i)
298{ 298{
299 /* cast */ 299 /* cast */
300 TVListViewItem *t = (TVListViewItem *)i; 300 TVListViewItem *t = (TVListViewItem *)i;
301 301
302 if(!t) { 302 if(!t) {
303 /* set current to null */ 303 /* set current to null */
304 ts->current_elem = 0; 304 ts->current_elem = 0;
305 return; 305 return;
306 } 306 }
307 307
308 ts->current_elem = t->getDataElem(); 308 ts->current_elem = t->getDataElem();
309 /* now also set up the iterator */ 309 /* now also set up the iterator */
310 310
311 delete it; 311 delete it;
312 it = new QListViewItemIterator(i); 312 it = new QListViewItemIterator(i);
313 313
314 //emit browseView(); 314 //emit browseView();
315} 315}