Diffstat (limited to 'noncore/apps/tableviewer/db/common.cpp') (more/less context) (ignore 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 @@ -1,76 +1,84 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ -#include <stdlib.h> +#include "common.h" +#include "datacache.h" + +/* OPIE */ +#include <opie2/odebug.h> +#include <qpe/timestring.h> +using namespace Opie::Core; + +/* QT */ #include <qstring.h> #include <qheader.h> #include <qvector.h> #include <qdatetime.h> -#include <qpe/timestring.h> -#include "common.h" -#include "datacache.h" + +/* STD */ #include <assert.h> +#include <stdlib.h> static const int del_flag = 0x1; static const int new_flag = 0x2; /* Helper function */ int parseNextNumber(QString *q) { QChar c; uint i; int result = 0; bool found_digits = FALSE; for(i = 0; i < q->length(); i++) { c = q->at(i); if (c.isDigit()) { if (found_digits) result *= 10; found_digits = TRUE; result += c.digitValue(); } else { if (found_digits) break; /* just skip this char */ } } /* now truncate q */ if (found_digits) q->remove(0, i); return result; } /*! \class QStringVector \brief A Vector of QStrings that can be sorted and searched Implmented in order to allow reverse lookup on the string name */ /*! This function implements the compare function in order to allow the searching and sorting of the QStringVector to occur \returns an int which is either <UL> <LI> < 0 if the first string is smaller than the second,</LI> <LI> > 0 if the first string is bigger then the second,</LI> <LI> == 0 if the first string is equal to the second.</LI> @@ -267,97 +275,97 @@ TVVariant::KeyType TVVariant::nameToType(const QString &name) return Date; if(!qstrcmp("Time", name)) return Time; if(!qstrcmp("Int", name)) return Int; return Invalid; } void TVVariant::load(QDataStream &s ) { KeyType t; s >> t; d->typ = t; switch(t) { case Invalid: d->typ = t; break; case String: { QString *x = new QString; s >> *x; d->value.ptr = x; } break; case Time: { QTime *x = new QTime; s >> *x; d->value.ptr = x; } break; case Date: { QDate *x = new QDate; s >> *x; d->value.ptr = x; } break; case Int: { int x; s >> x; d->value.i = x; } break; default: - qFatal("Unrecognized data type"); + ofatal << "Unrecognized data type" << oendl; } } void TVVariant::save( QDataStream &s ) const { s << type(); switch( d->typ ) { case String: s << *((QString *)d->value.ptr); break; case Date: s << *((QDate *)d->value.ptr); break; case Time: s << *((QTime *)d->value.ptr); break; case Int: s << d->value.i; break; case Invalid: break; } } QDataStream& operator>>(QDataStream& s, TVVariant& p) { p.load( s ); return s; } QDataStream& operator<<(QDataStream &s, const TVVariant& p) { p.save( s ); return s; } QDataStream& operator>> (QDataStream &s, TVVariant::KeyType& p) { Q_UINT8 u = 0; s >> u; p = (TVVariant::KeyType) u; return s; } QDataStream& operator<< (QDataStream& s, const TVVariant::KeyType& p) { @@ -1033,97 +1041,97 @@ QDataStream &operator>>( QDataStream &s, KeyList &k) /*! Constructs a DataElem. This function needs a container because the size, types of keys and primary key are all defined by the containing database */ DataElem::DataElem(DBStore *c) : values(20) { int size; contained = c; size = c->getNumFields(); values.setAutoDelete(TRUE); } /*! Destroys a DataElem and frees memory used by the DataElem */ DataElem::~DataElem() { } QDataStream &operator<<( QDataStream &s, const DataElem &d) { int size = d.getNumFields(); s << size; /* redundent data but makes streaming easier */ KeyList k = d.getKeys(); KeyListIterator it(k); while(it.current()) { s << (Q_UINT16)it.currentKey(); s << d.getField(it.currentKey()); ++it; } return s; } QDataStream &operator>>( QDataStream &s, DataElem &d) { int i; int size; TVVariant t; int index = 0; s >> size; /* redundent data but makes streaming easier */ if (size != d.getNumFields()) { - qWarning("DataSize mis-match"); + owarn << "DataSize mis-match" << oendl; return s; /* sanity check failed.. don't load */ } for(i = 0; i < size; i++) { s >> (Q_UINT16)index; s >> t; d.setField(index, t); } return s; } /*! Returns the number of possible (not valid) fields in the data element */ int DataElem::getNumFields() const { return contained->getNumFields(); } KeyList DataElem::getKeys() const { return *(contained->getKeys()); } /*! This function determines whether field index i of the element has been set yet. \return A boolean value that is TRUE if the specfied field of this element has been set and FALSE if the field has not yet been set */ bool DataElem::hasValidValue(int i) const { if(!values.find(i)) return FALSE; if(!contained->getKeys()->validIndex(i)) return FALSE; return values.find(i)->isValid(); } /*! This function determines whether field name qs of the element has been set yet. \return A boolean value that is TRUE if the specfied field of this element has been set and FALSE if the field has not yet been set */ bool DataElem::hasValidValue(QString qs) const { int i = contained->getKeyIndex(qs); @@ -1332,139 +1340,139 @@ bool DataElem::lessThan(int i, TVVariant v) const if (getField(i).type() != v.type()) return FALSE; return (getField(i) < v); } bool DataElem::moreThan(int i, TVVariant v) const { if (!hasValidValue(i)) return FALSE; if (getField(i).type() != v.type()) return FALSE; return (getField(i) > v); } bool DataElem::equalTo(int i, TVVariant v) const { if (!hasValidValue(i)) return FALSE; if (getField(i).type() != v.type()) return FALSE; return (getField(i) == v); } bool DataElem::contains(int i, TVVariant v) const { if (!hasValidValue(i)) return FALSE; if (getField(i).type() != v.type()) return FALSE; switch(getField(i).type()) { case TVVariant::String: { QString qs1 = getField(i).toString().lower(); QString qs2 = v.toString().lower(); if (qs1.contains(qs2) > 0) return TRUE; break; } /* meaningless for ints */ /* meaningless for time */ /* meaningless for dates */ case TVVariant::Int: case TVVariant::Time: case TVVariant::Date: break; default: - qWarning("Tried to compare unknown data type"); + owarn << "Tried to compare unknown data type" << oendl; } return FALSE; } bool DataElem::startsWith(int i, TVVariant v) const { if (!hasValidValue(i)) return FALSE; if (getField(i).type() != v.type()) return FALSE; switch(getField(i).type()) { case TVVariant::String: { QString qs1 = getField(i).toString().lower(); QString qs2 = v.toString().lower(); return qs1.startsWith(qs2); } /* meaningless for ints */ /* meaningless for time */ /* meaningless for dates */ case TVVariant::Int: case TVVariant::Time: case TVVariant::Date: return FALSE; default: - qWarning("Tried to compare unknown data type"); + owarn << "Tried to compare unknown data type" << oendl; } return FALSE; } bool DataElem::endsWith(int i, TVVariant v) const { if (!hasValidValue(i)) return FALSE; if (getField(i).type() != v.type()) return FALSE; switch(getField(i).type()) { case TVVariant::String: { QString qs1 = getField(i).toString().lower(); QString qs2 = v.toString().lower(); return qs1.startsWith(qs2); } /* meaningless for ints */ /* meaningless for time */ /* meaningless for dates */ case TVVariant::Int: case TVVariant::Time: case TVVariant::Date: return FALSE; default: - qWarning("Tried to compare unknown data type"); + owarn << "Tried to compare unknown data type" << oendl; } return FALSE; } /*! Determins which of the first to parameters are closer to the third, target parameter. \return <UL> <LI>TRUE if the first element is a closer match to the target than the second element</LI> <LI>FALSE if the first element is not a closer match to the target than the second element</LI> </UL> */ bool DataElem::closer(DataElem*d1, DataElem *d2, TVVariant target, int column) { int type; if(!d1) return FALSE; if (!d1->hasValidValue(column)) return FALSE; if(!target.isValid()) return FALSE; type = d1->getField(column).type(); if(d2) { if (type != d2->getField(column).type()) { /* can't do compare */ - qWarning("Tried to compare two incompatable types"); + owarn << "Tried to compare two incompatable types" << oendl; return FALSE; } return target.closer(d1->getField(column), d2->getField(column)); } return target.close(d1->getField(column)); } |