Diffstat (limited to 'noncore/apps/tableviewer/db/common.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/db/common.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp index dbf9370..6e544ba 100644 --- a/noncore/apps/tableviewer/db/common.cpp +++ b/noncore/apps/tableviewer/db/common.cpp | |||
@@ -8,33 +8,41 @@ | |||
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 "common.h" |
21 | #include "datacache.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | #include <qpe/timestring.h> | ||
26 | using namespace Opie::Core; | ||
27 | |||
28 | /* QT */ | ||
21 | #include <qstring.h> | 29 | #include <qstring.h> |
22 | #include <qheader.h> | 30 | #include <qheader.h> |
23 | #include <qvector.h> | 31 | #include <qvector.h> |
24 | #include <qdatetime.h> | 32 | #include <qdatetime.h> |
25 | #include <qpe/timestring.h> | 33 | |
26 | #include "common.h" | 34 | /* STD */ |
27 | #include "datacache.h" | ||
28 | #include <assert.h> | 35 | #include <assert.h> |
36 | #include <stdlib.h> | ||
29 | 37 | ||
30 | static const int del_flag = 0x1; | 38 | static const int del_flag = 0x1; |
31 | static const int new_flag = 0x2; | 39 | static const int new_flag = 0x2; |
32 | 40 | ||
33 | /* Helper function */ | 41 | /* Helper function */ |
34 | 42 | ||
35 | int parseNextNumber(QString *q) { | 43 | int parseNextNumber(QString *q) { |
36 | QChar c; | 44 | QChar c; |
37 | uint i; | 45 | uint i; |
38 | int result = 0; | 46 | int result = 0; |
39 | 47 | ||
40 | bool found_digits = FALSE; | 48 | bool found_digits = FALSE; |
@@ -303,25 +311,25 @@ void TVVariant::load(QDataStream &s ) | |||
303 | s >> *x; | 311 | s >> *x; |
304 | d->value.ptr = x; | 312 | d->value.ptr = x; |
305 | } | 313 | } |
306 | break; | 314 | break; |
307 | case Int: | 315 | case Int: |
308 | { | 316 | { |
309 | int x; | 317 | int x; |
310 | s >> x; | 318 | s >> x; |
311 | d->value.i = x; | 319 | d->value.i = x; |
312 | } | 320 | } |
313 | break; | 321 | break; |
314 | default: | 322 | default: |
315 | qFatal("Unrecognized data type"); | 323 | ofatal << "Unrecognized data type" << oendl; |
316 | } | 324 | } |
317 | } | 325 | } |
318 | 326 | ||
319 | void TVVariant::save( QDataStream &s ) const | 327 | void TVVariant::save( QDataStream &s ) const |
320 | { | 328 | { |
321 | s << type(); | 329 | s << type(); |
322 | 330 | ||
323 | switch( d->typ ) { | 331 | switch( d->typ ) { |
324 | case String: | 332 | case String: |
325 | s << *((QString *)d->value.ptr); | 333 | s << *((QString *)d->value.ptr); |
326 | break; | 334 | break; |
327 | case Date: | 335 | case Date: |
@@ -1069,25 +1077,25 @@ QDataStream &operator<<( QDataStream &s, const DataElem &d) | |||
1069 | return s; | 1077 | return s; |
1070 | } | 1078 | } |
1071 | 1079 | ||
1072 | QDataStream &operator>>( QDataStream &s, DataElem &d) | 1080 | QDataStream &operator>>( QDataStream &s, DataElem &d) |
1073 | { | 1081 | { |
1074 | int i; | 1082 | int i; |
1075 | int size; | 1083 | int size; |
1076 | TVVariant t; | 1084 | TVVariant t; |
1077 | int index = 0; | 1085 | int index = 0; |
1078 | 1086 | ||
1079 | s >> size; /* redundent data but makes streaming easier */ | 1087 | s >> size; /* redundent data but makes streaming easier */ |
1080 | if (size != d.getNumFields()) { | 1088 | if (size != d.getNumFields()) { |
1081 | qWarning("DataSize mis-match"); | 1089 | owarn << "DataSize mis-match" << oendl; |
1082 | return s; /* sanity check failed.. don't load */ | 1090 | return s; /* sanity check failed.. don't load */ |
1083 | } | 1091 | } |
1084 | 1092 | ||
1085 | for(i = 0; i < size; i++) { | 1093 | for(i = 0; i < size; i++) { |
1086 | s >> (Q_UINT16)index; | 1094 | s >> (Q_UINT16)index; |
1087 | s >> t; | 1095 | s >> t; |
1088 | d.setField(index, t); | 1096 | d.setField(index, t); |
1089 | } | 1097 | } |
1090 | return s; | 1098 | return s; |
1091 | } | 1099 | } |
1092 | 1100 | ||
1093 | /*! Returns the number of possible (not valid) fields in the data element */ | 1101 | /*! Returns the number of possible (not valid) fields in the data element */ |
@@ -1368,25 +1376,25 @@ bool DataElem::contains(int i, TVVariant v) const | |||
1368 | QString qs2 = v.toString().lower(); | 1376 | QString qs2 = v.toString().lower(); |
1369 | if (qs1.contains(qs2) > 0) return TRUE; | 1377 | if (qs1.contains(qs2) > 0) return TRUE; |
1370 | break; | 1378 | break; |
1371 | } | 1379 | } |
1372 | /* meaningless for ints */ | 1380 | /* meaningless for ints */ |
1373 | /* meaningless for time */ | 1381 | /* meaningless for time */ |
1374 | /* meaningless for dates */ | 1382 | /* meaningless for dates */ |
1375 | case TVVariant::Int: | 1383 | case TVVariant::Int: |
1376 | case TVVariant::Time: | 1384 | case TVVariant::Time: |
1377 | case TVVariant::Date: | 1385 | case TVVariant::Date: |
1378 | break; | 1386 | break; |
1379 | default: | 1387 | default: |
1380 | qWarning("Tried to compare unknown data type"); | 1388 | owarn << "Tried to compare unknown data type" << oendl; |
1381 | } | 1389 | } |
1382 | return FALSE; | 1390 | return FALSE; |
1383 | } | 1391 | } |
1384 | 1392 | ||
1385 | bool DataElem::startsWith(int i, TVVariant v) const | 1393 | bool DataElem::startsWith(int i, TVVariant v) const |
1386 | { | 1394 | { |
1387 | if (!hasValidValue(i)) return FALSE; | 1395 | if (!hasValidValue(i)) return FALSE; |
1388 | 1396 | ||
1389 | if (getField(i).type() != v.type()) | 1397 | if (getField(i).type() != v.type()) |
1390 | return FALSE; | 1398 | return FALSE; |
1391 | 1399 | ||
1392 | switch(getField(i).type()) { | 1400 | switch(getField(i).type()) { |
@@ -1394,25 +1402,25 @@ bool DataElem::startsWith(int i, TVVariant v) const | |||
1394 | QString qs1 = getField(i).toString().lower(); | 1402 | QString qs1 = getField(i).toString().lower(); |
1395 | QString qs2 = v.toString().lower(); | 1403 | QString qs2 = v.toString().lower(); |
1396 | return qs1.startsWith(qs2); | 1404 | return qs1.startsWith(qs2); |
1397 | } | 1405 | } |
1398 | /* meaningless for ints */ | 1406 | /* meaningless for ints */ |
1399 | /* meaningless for time */ | 1407 | /* meaningless for time */ |
1400 | /* meaningless for dates */ | 1408 | /* meaningless for dates */ |
1401 | case TVVariant::Int: | 1409 | case TVVariant::Int: |
1402 | case TVVariant::Time: | 1410 | case TVVariant::Time: |
1403 | case TVVariant::Date: | 1411 | case TVVariant::Date: |
1404 | return FALSE; | 1412 | return FALSE; |
1405 | default: | 1413 | default: |
1406 | qWarning("Tried to compare unknown data type"); | 1414 | owarn << "Tried to compare unknown data type" << oendl; |
1407 | } | 1415 | } |
1408 | return FALSE; | 1416 | return FALSE; |
1409 | } | 1417 | } |
1410 | 1418 | ||
1411 | bool DataElem::endsWith(int i, TVVariant v) const | 1419 | bool DataElem::endsWith(int i, TVVariant v) const |
1412 | { | 1420 | { |
1413 | if (!hasValidValue(i)) return FALSE; | 1421 | if (!hasValidValue(i)) return FALSE; |
1414 | 1422 | ||
1415 | if (getField(i).type() != v.type()) | 1423 | if (getField(i).type() != v.type()) |
1416 | return FALSE; | 1424 | return FALSE; |
1417 | 1425 | ||
1418 | switch(getField(i).type()) { | 1426 | switch(getField(i).type()) { |
@@ -1420,25 +1428,25 @@ bool DataElem::endsWith(int i, TVVariant v) const | |||
1420 | QString qs1 = getField(i).toString().lower(); | 1428 | QString qs1 = getField(i).toString().lower(); |
1421 | QString qs2 = v.toString().lower(); | 1429 | QString qs2 = v.toString().lower(); |
1422 | return qs1.startsWith(qs2); | 1430 | return qs1.startsWith(qs2); |
1423 | } | 1431 | } |
1424 | /* meaningless for ints */ | 1432 | /* meaningless for ints */ |
1425 | /* meaningless for time */ | 1433 | /* meaningless for time */ |
1426 | /* meaningless for dates */ | 1434 | /* meaningless for dates */ |
1427 | case TVVariant::Int: | 1435 | case TVVariant::Int: |
1428 | case TVVariant::Time: | 1436 | case TVVariant::Time: |
1429 | case TVVariant::Date: | 1437 | case TVVariant::Date: |
1430 | return FALSE; | 1438 | return FALSE; |
1431 | default: | 1439 | default: |
1432 | qWarning("Tried to compare unknown data type"); | 1440 | owarn << "Tried to compare unknown data type" << oendl; |
1433 | } | 1441 | } |
1434 | return FALSE; | 1442 | return FALSE; |
1435 | } | 1443 | } |
1436 | 1444 | ||
1437 | /*! | 1445 | /*! |
1438 | Determins which of the first to parameters are closer to the third, target | 1446 | Determins which of the first to parameters are closer to the third, target |
1439 | parameter. | 1447 | parameter. |
1440 | 1448 | ||
1441 | \return | 1449 | \return |
1442 | <UL> | 1450 | <UL> |
1443 | <LI>TRUE if the first element is a closer match to the target than the | 1451 | <LI>TRUE if the first element is a closer match to the target than the |
1444 | second element</LI> | 1452 | second element</LI> |
@@ -1452,19 +1460,19 @@ bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) | |||
1452 | 1460 | ||
1453 | if(!d1) return FALSE; | 1461 | if(!d1) return FALSE; |
1454 | 1462 | ||
1455 | if (!d1->hasValidValue(column)) return FALSE; | 1463 | if (!d1->hasValidValue(column)) return FALSE; |
1456 | 1464 | ||
1457 | if(!target.isValid()) return FALSE; | 1465 | if(!target.isValid()) return FALSE; |
1458 | 1466 | ||
1459 | type = d1->getField(column).type(); | 1467 | type = d1->getField(column).type(); |
1460 | 1468 | ||
1461 | if(d2) { | 1469 | if(d2) { |
1462 | if (type != d2->getField(column).type()) { | 1470 | if (type != d2->getField(column).type()) { |
1463 | /* can't do compare */ | 1471 | /* can't do compare */ |
1464 | qWarning("Tried to compare two incompatable types"); | 1472 | owarn << "Tried to compare two incompatable types" << oendl; |
1465 | return FALSE; | 1473 | return FALSE; |
1466 | } | 1474 | } |
1467 | return target.closer(d1->getField(column), d2->getField(column)); | 1475 | return target.closer(d1->getField(column), d2->getField(column)); |
1468 | } | 1476 | } |
1469 | return target.close(d1->getField(column)); | 1477 | return target.close(d1->getField(column)); |
1470 | } | 1478 | } |