summaryrefslogtreecommitdiff
Side-by-side diff
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,1450 +1,1450 @@
/**********************************************************************
** 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 <qstring.h>
#include <qheader.h>
#include <qvector.h>
#include <qdatetime.h>
#include <qpe/timestring.h>
#include "common.h"
#include "datacache.h"
#include <assert.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>
</UL>
*/
int QStringVector::compareItems(Item a, Item b)
{
QString *qa = (QString *)a;
QString *qb = (QString *)b;
return QString::compare(*qa, *qb);
}
/*!
\class TVVariant
A way of abstracting void * and keeping information on
the keytypes and behaviours in one place
*/
TVVariantPrivate::TVVariantPrivate()
{
typ = TVVariant::Invalid;
}
TVVariantPrivate::TVVariantPrivate( TVVariantPrivate *d)
{
switch(d->typ)
{
case TVVariant::Invalid:
break;
case TVVariant::String:
value.ptr = new QString(*((QString *)d->value.ptr));
break;
case TVVariant::Date:
value.ptr = new QDate(*((QDate *)d->value.ptr));
break;
case TVVariant::Time:
value.ptr = new QTime(*((QTime *)d->value.ptr));
break;
case TVVariant::Int:
value.i = d->value.i;
break;
default:
ASSERT( 0 );
}
typ = d->typ;
}
TVVariantPrivate::~TVVariantPrivate()
{
clear();
}
void TVVariantPrivate::clear()
{
switch( typ )
{
case TVVariant::String:
delete (QString *)value.ptr;
break;
case TVVariant::Date:
delete (QDate *)value.ptr;
break;
case TVVariant::Time:
delete (QTime *)value.ptr;
break;
case TVVariant::Invalid:
case TVVariant::Int:
break;
}
typ = TVVariant::Invalid;
}
/*!
\class TVVariant
blah
*/
TVVariant::TVVariant()
{
d = new TVVariantPrivate;
}
TVVariant::~TVVariant()
{
if (d->deref())
delete d;
}
TVVariant::TVVariant(const TVVariant& p)
{
d = new TVVariantPrivate;
*this = p;
}
TVVariant::TVVariant(QDataStream& s)
{
d = new TVVariantPrivate;
s >> *this;
}
TVVariant::TVVariant(const QString &val)
{
d = new TVVariantPrivate;
d->typ = String;
d->value.ptr = new QString(val);
}
TVVariant::TVVariant(const QDate &val)
{
d = new TVVariantPrivate;
d->typ = Date;
d->value.ptr = new QDate(val);
}
TVVariant::TVVariant(const QTime &val)
{
d = new TVVariantPrivate;
d->typ = Time;
d->value.ptr = new QTime(val);
}
TVVariant::TVVariant( int val )
{
d = new TVVariantPrivate;
d->typ = Int;
d->value.i = val;
}
TVVariant& TVVariant::operator=(const TVVariant& variant )
{
TVVariant& other = (TVVariant&) variant;
other.d->ref();
if ( d->deref() )
delete d;
d = other.d;
return *this;
}
void TVVariant::detach()
{
if (d->count == 1)
return;
d->deref();
d = new TVVariantPrivate(d);
}
const QString TVVariant::typeName() const
{
return typeToName(d->typ);
}
void TVVariant::clear()
{
if (d->count > 1)
{
d->deref();
d = new TVVariantPrivate;
return;
}
d->clear();
}
const QString TVVariant::typeToName(KeyType typ)
{
switch(typ) {
case String:
return QString("String");
case Date:
return QString("Date");
case Time:
return QString("Time");
case Int:
return QString("Int");
case Invalid:
default:
return QString("Invalid");
}
return QString("Invalid");
}
TVVariant::KeyType TVVariant::nameToType(const QString &name)
{
if(!qstrcmp("String", name))
return String;
if(!qstrcmp("Date", 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");
}
}
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)
{
s << (Q_UINT8)p;
return s;
}
const QString TVVariant::toString() const
{
switch(d->typ) {
case String:
return *((QString*)d->value.ptr);
case Date:
return ((QDate*)d->value.ptr)->toString();
case Time:
return ((QTime*)d->value.ptr)->toString();
case Int:
return QString::number(d->value.i);
case Invalid:
default:
return QString::null;
}
return QString::null;
}
// TODO DO, this properly, */
int TVVariant::toInt() const
{
if(d->typ == Int)
return d->value.i;
if(d->typ == String) {
QString tmpq(*(QString *)d->value.ptr);
return parseNextNumber(&tmpq);
}
return 0;
}
const QDate TVVariant::toDate() const
{
if(d->typ == Date)
return *((QDate *)d->value.ptr);
if(d->typ == String) {
QString q = toString();
/* date format is day mon d yyyy */
/* ignore the first three letters, read the next
three for month.. etc */
int day = parseNextNumber(&q);
int month = parseNextNumber(&q);
int year = parseNextNumber(&q);
if (!QDate::isValid(year, month, day))
return QDate();
return QDate(year, month, day);
}
return QDate();
}
const QTime TVVariant::toTime() const
{
if(d->typ == Time)
return *((QTime *)d->value.ptr);
if(d->typ == String) {
QString q = toString();
int hour = parseNextNumber(&q);
int minute = parseNextNumber(&q);
int second = parseNextNumber(&q);
int msecond = parseNextNumber(&q);
if (!QTime::isValid(hour, minute, second, msecond))
return QTime();
return QTime(hour, minute, second, msecond);
}
return QTime();
}
#define TV_VARIANT_AS( f ) Q##f& TVVariant::as##f() { \
if ( d->typ != f ) \
*this = TVVariant( to##f() ); \
else \
detach(); \
return *((Q##f*)d->value.ptr); }
TV_VARIANT_AS(String)
TV_VARIANT_AS(Date)
TV_VARIANT_AS(Time)
#undef TV_VARIANT_AS
int& TVVariant::asInt()
{
detach();
if (d->typ != Int) {
d->value.i = toInt();
d->typ = Int;
}
return d->value.i;
}
/*!
valid cast is
anything to String
same to same
*/
bool TVVariant::canCast(KeyType t) const
{
if(d->typ == t)
return TRUE;
if(t == String)
return TRUE;
if(t == Int) {
if (d->typ == Date)
return TRUE;
if (d->typ == Time)
return TRUE;
if (d->typ == String)
return TRUE;
}
return FALSE;
}
bool TVVariant::operator==( const TVVariant &v ) const
{
switch(d->typ) {
case String:
return v.toString() == toString();
case Date:
return v.toDate() == toDate();
case Time:
return v.toTime() == toTime();
case Int:
return v.toInt() == toInt();
case Invalid:
break;
}
return FALSE;
}
bool TVVariant::operator!=( const TVVariant &v ) const
{
return !( v == *this);
}
bool TVVariant::operator<( const TVVariant &v ) const
{
switch(d->typ) {
case String:
return toString().lower() < v.toString().lower();
case Date:
return toDate() < v.toDate();
case Time:
return toTime() < v.toTime();
case Int:
return toInt() < v.toInt();
case Invalid:
default:
break;
}
return FALSE;
}
bool TVVariant::operator>( const TVVariant &v ) const
{
switch(d->typ) {
case String:
return toString().lower() > v.toString().lower();
case Date:
return toDate() > v.toDate();
case Time:
return toTime() > v.toTime();
case Int:
return toInt() > v.toInt();
case Invalid:
default:
break;
}
return FALSE;
}
/*! True if n is closer to this than o */
bool TVVariant::closer(TVVariant n, TVVariant o)
{
/* Nothing is close to an invalid, so nothing can be closer */
if(d->typ == Invalid)
return FALSE;
/* can't be closer if of different type */
if(n.type() != type())
return FALSE;
/* if new shares type, and old doesn't, then new is closer */
if(o.type() != type())
return TRUE;
switch(type()){
case String: {
/* case for strings is close is a substring.. closer is
* earlier alphabetically */
QString qs1 = n.toString().lower();
QString qs2 = o.toString().lower();
QString qsv = toString().lower();
if (!qs1.startsWith(qsv))
return FALSE;
/* contains sub-str, if later than is not closer */
if(QString::compare(qs1, qs2) > 0)
return FALSE;
return TRUE;
}
case Int: {
/* case for int is smallest absolute difference */
int i1 = n.toInt();
int i2 = o.toInt();
int iv = toInt();
int diff1 = (i1 - iv);
if (diff1 < 0)
diff1 = -diff1;
int diff2 = (i2 - iv);
if (diff2 < 0)
diff2 = -diff2;
if (diff1 < diff2)
return TRUE;
return FALSE;
}
case Date: {
QDate i1 = n.toDate();
QDate i2 = o.toDate();
QDate iv = toDate();
/* definition of closer is the least difference in days */
int diff1 = i1.daysTo(iv);
if (diff1 < 0)
diff1 = -diff1;
int diff2 = i2.daysTo(iv);
if (diff2 < 0)
diff2 = -diff2;
if (diff1 < diff2)
return TRUE;
return FALSE;
}
case Time: {
QTime i1 = n.toTime();
QTime i2 = o.toTime();
QTime iv = toTime();
/* definition of closer is the least difference in days */
int diff1 = i1.msecsTo(iv);
if (diff1 < 0)
diff1 = -diff1;
int diff2 = i2.msecsTo(iv);
if (diff2 < 0)
diff2 = -diff2;
if (diff1 < diff2)
return TRUE;
return FALSE;
}
default:
/* don't know how to do 'closer' on this type, hence never closer
* or even close */
break;
}
return FALSE;
}
/*! True if n is close to this */
bool TVVariant::close(TVVariant n)
{
/* Nothing is close to an invalid, so nothing can be closer */
if(type() == Invalid)
return FALSE;
/* can't be close if of different type */
if(n.type() != type())
return FALSE;
switch(type()){
case String: {
/* case for strings is close is a substring.. closer is
* earlier alphabetically */
QString qs1 = n.toString().lower();
QString qsv = toString().lower();
if (!qs1.startsWith(qsv))
return FALSE;
return TRUE;
}
case Int:
case Date:
case Time:
return TRUE;
default:
/* don't know how to do 'closer' on this type, hence never closer
* or even close */
break;
}
return FALSE;
}
/*!
\class Key
\brief document me!
document me!
*/
Key::Key() : kname(), kexample(), kflags(0) { }
-Key::Key(QString name, TVVariant example, int flags = 0) :
+Key::Key(QString name, TVVariant example, int flags) :
kname(name), kexample(example), kflags(flags) { }
Key::Key(const Key &other)
{
kname = other.kname;
kexample = other.kexample;
kflags = other.kflags;
}
Key& Key::operator=(const Key& key)
{
kname = key.kname;
kexample = key.kexample;
kflags = key.kflags;
return *this;
}
QString Key::name() const
{
return QString(kname);
}
TVVariant Key::example() const
{
return TVVariant(kexample);
}
TVVariant::KeyType Key::type() const
{
return kexample.type();
}
void Key::setName(const QString &name)
{
kname = QString(name);
}
void Key::setExample(const TVVariant &e)
{
kexample = TVVariant(e);
}
int Key::flags() const
{
return kflags;
}
void Key::setFlags(int fl)
{
kflags = fl;
}
bool Key::delFlag() const
{
if(kflags & del_flag)
return TRUE;
return FALSE;
}
bool Key::newFlag() const
{
if(kflags & new_flag)
return TRUE;
return FALSE;
}
void Key::setDelFlag(bool v)
{
if(delFlag() != v)
kflags = kflags ^ del_flag;
}
void Key::setNewFlag(bool v)
{
if(newFlag() != v)
kflags = kflags ^ new_flag;
}
/*!
\class KeyList
\brief A represntation of keys used for a table.
The KeyList class is used to store the representation of keys used in table
headings by DBStore. It stores the names and types of the keys
*/
/*!
Constructs a KeyList
*/
KeyList::KeyList() : QIntDict<Key>(20)
{
setAutoDelete(TRUE);
}
/* Should be deep copy, but isn't */
KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
{
KeyListIterator it(k);
while(it.current()) {
replace(it.currentKey(), new Key(*it.current()));
++it;
}
setAutoDelete(TRUE);
}
/*!
Destroys a KeyList
*/
KeyList::~KeyList() {
}
/* Do a comparision base on Keys */
bool KeyList::operator!=(const KeyList &other)
{
KeyListIterator it(*this);
if (other.getNumFields() != getNumFields())
return TRUE;
while(it.current()) {
//it.currentKey(), it.current();
if (other.getKeyName(it.currentKey()) != getKeyName(it.currentKey()))
return TRUE;
if (other.getKeyType(it.currentKey()) != getKeyType(it.currentKey()))
return TRUE;
++it;
}
return FALSE;
}
/*!
Returns the number of keys stored in the KeyList
*/
int KeyList::getNumFields() const
{
return count();
}
/*!
Adds a new key to the KeyList
\param name the name of the new key
\param type the type of the new key
*/
int KeyList::addKey(QString name, TVVariant example)
{
int i = count();
while(find(i) && (i > -1))
i--;
replace(i, new Key(name, example, 0));
return i;
}
int KeyList::addKey(QString name, TVVariant::KeyType type)
{
/* generate a valid type for the example? */
TVVariant e = TVVariant("0");
switch(type) {
case TVVariant::String:
return addKey(name, TVVariant("<undefined>").asString());
break;
case TVVariant::Date:
return addKey(name, TVVariant(QDate::currentDate()).asDate());
break;
case TVVariant::Time:
return addKey(name, TVVariant(QTime(0,0,0)).toTime());
break;
case TVVariant::Int:
return addKey(name, TVVariant(0).toInt());
break;
default:
qWarning(QObject::tr("KeyList::addKey() Cannot make default "
"value for type %1, Key not added.").arg(type));
break;
}
return -1;
}
void KeyList::setKeyFlags(int i, int flag)
{
if(find(i))
find(i)->setFlags(flag);
}
int KeyList::getKeyFlags(int i) const
{
if(find(i))
return find(i)->flags();
return 0;
}
bool KeyList::checkNewFlag(int i) const
{
if (find(i))
return find(i)->newFlag();
return false;
}
void KeyList::setNewFlag(int i, bool f)
{
if(!find(i))
return;
find(i)->setNewFlag(f);
}
bool KeyList::checkDeleteFlag(int i) const
{
if (find(i))
return find(i)->delFlag();
return false;
}
void KeyList::setDeleteFlag(int i, bool f)
{
if(!find(i))
return;
find(i)->setDelFlag(f);
}
/*!
Returns the name of the key at index i
*/
QString KeyList::getKeyName(int i) const
{
if (find (i))
return find(i)->name();
return QString();
}
void KeyList::setKeyName(int i, const QString &n)
{
if(find(i))
find(i)->setName(n);
}
/*!
Returns the type of the key at index i
*/
TVVariant::KeyType KeyList::getKeyType(int i) const
{
if(find(i))
return find(i)->type();
return TVVariant::Invalid;
}
void KeyList::setKeyType(int i, TVVariant::KeyType t)
{
if(!find(i))
return;
switch(t) {
case TVVariant::String:
find(i)->setExample(TVVariant(QString("default")));
return;
case TVVariant::Int:
find(i)->setExample(TVVariant(int(0)));
return;
case TVVariant::Date:
find(i)->setExample(TVVariant(QDate::currentDate()));
return;
case TVVariant::Time:
find(i)->setExample(TVVariant(QTime(0,0,0,0)));
return;
default:
break;
}
return;
}
TVVariant KeyList::getKeyExample(int i) const
{
if(find(i))
return find(i)->example();
return TVVariant();
}
void KeyList::setKeyExample(int i, TVVariant example)
{
if(find(i))
find(i)->setExample(example);
}
/*!
Returns the index of the key with name q
*/
int KeyList::getKeyIndex(QString q) const
{
KeyListIterator it(*this);
while(it.current()) {
if(it.current()->name() == q)
return it.currentKey();
++it;
}
return -1;
}
bool KeyList::validIndex(int i) const
{
if(!find(i))
return FALSE;
if(find(i)->delFlag())
return FALSE;
return TRUE;
}
QDataStream &operator<<( QDataStream &s, const KeyList &k)
{
s << k.getNumFields();
KeyListIterator it(k);
while(it.current()) {
s << (Q_UINT16)it.currentKey();
s << it.current()->name();
s << it.current()->example();
s << (Q_UINT16)it.current()->flags();
++it;
}
return s;
}
QDataStream &operator>>( QDataStream &s, KeyList &k)
{
int i;
int size;
int index = 0;
int flags = 0;
TVVariant type = TVVariant();
QString name;
s >> size;
for (i=0; i < size; i++) {
s >> (Q_UINT16 &)index;
s >> name;
s >> type;
s >> (Q_UINT16 &)flags;
k.replace(index, new Key(name, type, flags));
}
return s;
}
/*!
\class DataElem
\brief A class representing a single row or element of a table in a DBStore
This class holds the data of a row in a table.
*/
/*!
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");
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);
return hasValidValue(i);
}
/*! returns the type of the field specified by index i */
TVVariant::KeyType DataElem::getFieldType(int i) const
{
return contained->getKeyType(i);
}
/*! returns the type of the field specified by name qs */
TVVariant::KeyType DataElem::getFieldType(QString qs) const
{
int i = contained->getKeyIndex(qs);
return contained->getKeyType(i);
}
/*!
returns a pointer to the data stored in field index i for this
data element, (value may not be valid)
*/
TVVariant DataElem::getField(int i) const
{
if(hasValidValue(i))
return TVVariant(*values.find(i));
return TVVariant();
}
/*!
returns a pointer to the data stored in field name qs for this
data element, (value may not be valid)
*/
TVVariant DataElem::getField(QString qs) const
{
int i = contained->getKeyIndex(qs);
return getField(i);
}
/*!
Sets the value of the elements field index i to the value represented in
the QString q.
\param i index of the field to set
\param q a string that can be parsed to get the value to be set
*/
void DataElem::setField(int i, QString q)
{
/* from the type of the field, parse q and store */
TVVariant::KeyType kt = contained->getKeyType(i);
TVVariant t = TVVariant(q);
switch(kt) {
case TVVariant::Int: {
t.asInt();
setField(i, t);
return;
}
case TVVariant::String: {
t.asString();
setField(i, t);
return;
}
case TVVariant::Date: {
t.asDate();
setField(i, t);
return;
}
case TVVariant::Time: {
t.asTime();
setField(i, t);
return;
}
default:
qWarning(
QObject::tr("DataElem::setField(%1, %2) No valid type found").arg(i).arg(q)
);
}
}
/*!
Sets the value of the elements field index i to the value at the pointer
value.
\param i index of the field to set
\param value a pointer to the (already allocated) value to set
*/
void DataElem::setField(int i, TVVariant value)
{
if (value.isValid()) {
values.remove(i);
values.replace(i, new TVVariant(value));
}
}
/*!
Sets the value of the elements field name qs to the value represented in
the QString q.
\param qs name of the field to set
\param q a string that can be parsed to get the value to be set
*/
void DataElem::setField(QString qs, QString q)
{
/* from the type of the field, parse q and store */
int i = contained->getKeyIndex(qs);
setField(i, qs);
}
/*!
Sets the value of the elements field name qs to the value at the pointer
value.
\param qs name of the field to set
\param value a pointer to the (already allocated) value to set
*/
void DataElem::setField(QString qs, TVVariant value)
{
int i = contained->getKeyIndex(qs);
setField(i, value);
}
void DataElem::unsetField(int i) {
values.remove(i);
}
void DataElem::unsetField(QString qs)
{
int i = contained->getKeyIndex(qs);
unsetField(i);
}
/*!
Converts the data element to a Rich Text QString
*/
QString DataElem::toQString() const
{
/* lets make an attempt at this function */
int i;
QString scratch = "";
QIntDictIterator<TVVariant> it(values);
while (it.current()) {
i = it.currentKey();
if(hasValidValue(i)) {
scratch += "<B>" + contained->getKeyName(i) + ":</B> ";
scratch += getField(i).toString();
scratch += "<br>";
}
++it;
}
return scratch;
}
/*! formats individual fields to strings so can be displayed */
QString DataElem::toQString(int i) const
{
if(hasValidValue(i)) {
return getField(i).toString();
}
return "";
}
/*! formats individual fields to strings so can be sorted by QListView */
QString DataElem::toSortableQString(int i) const
{
QString scratch = "";
if(hasValidValue(i)) {
switch (contained->getKeyType(i)) {
case TVVariant::String: {
scratch += getField(i).toString();
break;
}
case TVVariant::Int: {
scratch.sprintf("%08d", getField(i).toInt());
break;
}
case TVVariant::Date: {
static QDate epochD(1800, 1, 1);
scratch.sprintf("%08d",
epochD.daysTo(getField(i).toDate()));
break;
}
case TVVariant::Time: {
static QTime epochT(0, 0, 0);
scratch.sprintf("%08d",
epochT.msecsTo(getField(i).toTime()));
break;
}
default:
scratch += "Unknown type";
break;
}
}
return scratch;
}
/* compare functions */
bool DataElem::lessThan(int i, TVVariant v) const
{
if (!hasValidValue(i)) return FALSE;
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");
}
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");
}
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");
}
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)
{
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 @@
/**********************************************************************
** 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 "csvsource.h"
#include "common.h"
#include "datacache.h"
#include <qtextstream.h>
#include <qstringlist.h>
#include <qmap.h>
#include <qregexp.h>
DBCsv::DBCsv(DBStore *d)
{
dstore = d;
}
DBCsv::~DBCsv()
{
}
QString DBCsv::type()
{
return "csv";
}
QStringList readElem(QString in)
{
QStringList out;
if (in.isEmpty())
return out;
bool firstChar = TRUE;
bool quotedElem = FALSE;
uint index = 0;
while(index < in.length()) {
if(firstChar) {
/* skip whitespace */
while(index < in.length() && in[index] == ' ')
index++;
if(in[index] == '"') {
quotedElem = TRUE;
index++;
}
}
/* real first char */
QString elem;
if(quotedElem) {
while(index < in.length() && in[index] != '"') {
/* check for escape character */
if (in[index] == '\\') {
if (index++ < in.length()) {
elem.append(in[index]);
index++;
}
} else {
elem.append(in[index]);
index++;
}
}
} else {
while(index < in.length() && in[index] != ',') {
if (in[index] == '\\') {
if (index++ < in.length()) {
elem.append(in[index]);
index++;
}
} else {
elem.append(in[index]);
index++;
}
}
}
/* we have our current elem */
out << elem.stripWhiteSpace();
firstChar = TRUE;
quotedElem = FALSE;
/* skip till a , or end of line */
while (index < in.length() && in[index] != ',') index++;
if(index == in.length())
return out;
else
index++;
}
+ return out;
}
bool DBCsv::openSource(QIODevice *inDev)
{
QTextStream tsIn(inDev);
QString in = tsIn.readLine().stripWhiteSpace();
QStringList keys;
keys = readElem(in);
QMap<int,int> keyIndexes;
KeyList *keyR = new KeyList();
QStringList::Iterator i = keys.begin();
uint fileIndex = 0;
while(i != keys.end()) {
if ((*i).isEmpty())
keyIndexes.insert(fileIndex, keyR->addKey("Unamed", TVVariant::String));
else
keyIndexes.insert(fileIndex, keyR->addKey(*i, TVVariant::String));
i++;
fileIndex++;
}
dstore->setKeys(keyR);
in = tsIn.readLine().stripWhiteSpace();
while(!in.isNull()) {
QStringList elems = readElem(in);
i = elems.begin();
fileIndex = 0;
DataElem *current_data = new DataElem(dstore);
while(i != elems.end()) {
if(!(*i).isEmpty()) {
current_data->setField(keyIndexes[fileIndex], *i);
}
fileIndex++;
i++;
}
dstore->addItem(current_data);
in = tsIn.readLine().stripWhiteSpace();
}
return TRUE;
}
bool DBCsv::saveSource(QIODevice *outDev)
{
/* try not to use the escape character when possible. */
int i;
DataElem *elem;
KeyList *k;
QTextStream outstream(outDev);
k = dstore->getKeys();
KeyListIterator it(*k);
while(it.current()) {
if(!it.current()->delFlag()) {
QString name = it.current()->name();
name.replace(QRegExp("\\"), "\\\\");
name.replace(QRegExp("\""), "\\\"");
if(name.find(',') != -1) {
name.prepend('\"');
name.append('\"');
}
outstream << name;
}
++it;
if(it.current())
outstream << ", ";
}
outstream << "\n";
dstore->first();
do {
elem = dstore->getCurrentData();
if(!elem)
break;
it.toFirst();
while(it.current()) {
i = it.currentKey();
if (elem->hasValidValue(i)) {
QString name = elem->toQString(i);
name.replace(QRegExp("\\"), "\\\\");
name.replace(QRegExp("\""), "\\\"");
if(name.find(',') != -1) {
name.prepend('\"');
name.append('\"');
}
outstream << name;
}
++it;
if(it.current())
outstream << ", ";
}
outstream << "\n";
} while (dstore->next());
return TRUE;
}
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 @@
/**********************************************************************
** 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 <qlineedit.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qcombobox.h>
#include <qpe/datebookmonth.h>
#include <qpopupmenu.h>
#include <qspinbox.h>
#include "commonwidgets.h"
-DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
+DateEdit::DateEdit( QWidget *parent, const char *name, WFlags f )
: QToolButton(parent, name)
{
QPopupMenu *m1 = new QPopupMenu(this);
dateSelector = new DateBookMonth(m1, 0, TRUE);
m1->insertItem(dateSelector);
setPopup(m1);
setPopupDelay(0);
connect(dateSelector, SIGNAL(dateClicked(int, int, int)),
this, SLOT(subValueChanged()));
setText(dateSelector->selectedDate().toString());
}
DateEdit::~DateEdit() {}
QDate DateEdit::date() const
{
return dateSelector->selectedDate();
}
void DateEdit::setDate(QDate d)
{
dateSelector->setDate(d.year(), d.month(), d.day());
setText(d.toString());
}
QSizePolicy DateEdit::sizePolicy() const
{
QSizePolicy sp;
sp.setHorData(QToolButton::sizePolicy().horData());
sp.setVerData(QSizePolicy::Fixed);
return sp;
}
void DateEdit::clear()
{
QDate today = QDate::currentDate();
dateSelector->setDate(today.year(), today.month(), today.day());
setText(today.toString());
}
void DateEdit::subValueChanged()
{
QDate current = dateSelector->selectedDate();
setText(current.toString());
emit valueChanged(current);
}
-TimeEdit::TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
+TimeEdit::TimeEdit( QWidget *parent, const char *name, WFlags f )
: QWidget(parent, name, f)
{
QHBoxLayout *layout = new QHBoxLayout(this, 0);
layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this));
hourKey->setWrapping(true);
hourKey->setMinimumWidth(30);
hourKey->setMaximumWidth(35);
layout->addWidget(new QLabel(" : ", this));
layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this));
minuteKey->setWrapping(true);
minuteKey->setMinimumWidth(30);
minuteKey->setMaximumWidth(35);
layout->addWidget(new QLabel(" : ", this));
layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0));
secondKey->setWrapping(true);
secondKey->setMinimumWidth(30);
secondKey->setMaximumWidth(35);
layout->addWidget(ampm = new QComboBox(this));
ampm->insertItem("AM");
ampm->insertItem("PM");
layout->addStretch(-1);
clear();
connect(secondKey, SIGNAL(valueChanged(const QString&)),
this, SLOT(subValueChanged()));
connect(minuteKey, SIGNAL(valueChanged(const QString&)),
this, SLOT(subValueChanged()));
connect(hourKey, SIGNAL(valueChanged(const QString&)),
this, SLOT(subValueChanged()));
connect(ampm, SIGNAL(activated(int)),
this, SLOT(subValueChanged()));
}
TimeEdit::~TimeEdit() {}
QTime TimeEdit::time() const
{
int s,m,h;
s = secondKey->text().toInt();
m = minuteKey->text().toInt();
h = hourKey->text().toInt();
if(ampm->currentItem() == 1) {
/* pm */
h = h + 12;
}
/* hour now ranges 1->24 */
if (h == 12)
h = 0;
if (h == 24)
h = 12;
if(QTime::isValid(h, m, s))
return QTime(h, m, s);
return QTime(0, 0, 0);
}
void TimeEdit::setTime(QTime t)
{
int h = t.hour();
secondKey->setValue(t.second());
minuteKey->setValue(t.minute());
/* h 0..23 */
if (h > 11) {
h -= 12;
ampm->setCurrentItem(1);
} else {
ampm->setCurrentItem(0);
}
if (h == 0) h = 12;
hourKey->setValue(h);
}
QSizePolicy TimeEdit::sizePolicy() const
{
QSizePolicy sp;
sp.setHorData(QSizePolicy::Preferred);
sp.setVerData(QSizePolicy::Fixed);
return sp;
}
void TimeEdit::clear()
{
secondKey->setValue(0);
minuteKey->setValue(0);
hourKey->setValue(12);
ampm->setCurrentItem(0);
}
void TimeEdit::subValueChanged()
{
emit valueChanged(time());
}
-IntEdit::IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
+IntEdit::IntEdit( QWidget *parent, const char *name, WFlags f )
: QSpinBox(INT_MIN, INT_MAX, 1, parent, name)
{
setValue(0);
}
IntEdit::~IntEdit() {}
int IntEdit::value()
{
return cleanText().toInt();
}
void IntEdit::clear()
{
setValue(0);
}
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 @@
/**********************************************************************
** 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 "tvbrowseview.h"
#include "browsekeyentry.h"
#include <qtoolbutton.h>
#include <qtextview.h>
#include <qtextbrowser.h>
#include <qlayout.h>
/*!
\class TVBrowseView
\brief The widget describing how to draw the browse view user interface
This widget allows for the user to browse through the table, one element
at a time, or search on a single key. Its main goal is to show a
single element in a readable format and make it easy for the user to
rapidly find specific elements in the table.
*/
/*!
Constructs a new TVBrowseView widget
*/
-TVBrowseView::TVBrowseView(TableState *t, QWidget* parent = 0, const char *name = 0,
- WFlags fl =0)
+TVBrowseView::TVBrowseView(TableState *t, QWidget* parent, const char *name,
+ WFlags fl )
{
if (!name)
setName("BrowseView");
// setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) );
QVBoxLayout *vlayout = new QVBoxLayout(this);
textViewDisplay = new QTextBrowser(this, "textViewDisplay");
vlayout->addWidget( textViewDisplay );
keyEntry = new TVBrowseKeyEntry(this, "keyEntry");
vlayout->addWidget( keyEntry );
/* connect the signals down */
connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)),
this, SIGNAL(searchOnKey(int, TVVariant)));
connect(keyEntry, SIGNAL(sortChanged(int)),
this, SIGNAL(sortChanged(int)));
ts = t;
keyEntry->setTableState(t);
}
/*!
Destroys the TVBrowseView widget
*/
TVBrowseView::~TVBrowseView()
{
}
void TVBrowseView::rebuildData()
{
if(!ts)
return;
if(!ts->current_elem) {
/* also disable buttons */
textViewDisplay->setText("");
return;
}
setDisplayText(ts->current_elem);
}
/* Reset to initial state */
void TVBrowseView::reset()
{
textViewDisplay->setText("");
keyEntry->reset();
}
/*!
sets the data element to be displayed to element
*/
void TVBrowseView::setDisplayText(const DataElem *element)
{
QString rep = "";
KeyListIterator it(*ts->kRep);
while (it.current()) {
if (element->hasValidValue(it.currentKey())) {
if(it.currentKey() == ts->current_column) {
rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>"
+ it.current()->name()
+ ":</FONT></B> ";
} else {
rep += "<B>" + it.current()->name() + ":</B> ";
}
rep += element->toQString(it.currentKey()) + "<BR>";
}
++it;
}
textViewDisplay->setText(rep);
textViewDisplay->scrollToAnchor("ckey");
}
void TVBrowseView::rebuildKeys()
{
keyEntry->rebuildKeys();
}
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 @@
/**********************************************************************
** 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.
**
**********************************************************************/
/* The edit view widget. For each key in the DB display an
* appropriate edit box, and a 'key' button to change that particular
* key information (delete or edit).
*
* Bottem line should be a 'new key' button. Should be able to scroll
* in both directions.
*/
#include "tveditview.h"
#include "commonwidgets.h"
#include <qlayout.h>
#include <qgrid.h>
#include <qvbox.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qlist.h>
#include <qlabel.h>
#include <qscrollview.h>
#include <qsignalmapper.h>
-TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
- const char *name = 0, WFlags fl =0) : QDialog(parent, name, true, fl)
+TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent,
+ const char *name, WFlags fl ) : QDialog(parent, name, true, fl)
{
if (!name)
setName("TVEditView");
QVBoxLayout *layout = new QVBoxLayout(this, 0); /* only so that will resize
correctly in other
widgets */
toggles = new QSignalMapper(this);
QScrollView *sv = new QScrollView(this, 0);
sv->setResizePolicy(QScrollView::AutoOneFit);
layout->addWidget(sv);
editDisplay = new QGrid(3, sv, 0);
editDisplay->setSpacing(3);
sv->addChild(editDisplay);
connect(toggles, SIGNAL(mapped(int)), this, SLOT(toggleEnabled(int)));
setData(s, d);
#ifdef Q_WS_QWS
showMaximized();
#endif
}
TVEditView::~TVEditView()
{
}
/*! set up the widgets in the grid, Set up initial values */
void TVEditView::setData(TableState *t, DataElem *d)
{
/* TODO need to somehow clear old children... a delete of each
* child? */
keyIds.clear();
KeyListIterator it(*t->kRep);
int i = 0;
while(it.current()) {
if (t->kRep->validIndex(it.currentKey())) {
new QLabel(it.current()->name(), editDisplay);
keyIds.insert(i, it.currentKey());
if (d->hasValidValue(it.currentKey())) {
switch(it.current()->type()) {
case TVVariant::String: {
QLineEdit *edit = new QLineEdit(editDisplay, 0);
edit->setText(d->getField(it.currentKey()).toString());
edits.append(edit);
break;
}
case TVVariant::Int: {
IntEdit *edit = new IntEdit(editDisplay, 0);
edit->setValue(d->getField(it.currentKey()).toInt());
edits.append(edit);
break;
}
case TVVariant::Time: {
TimeEdit *edit = new TimeEdit(editDisplay, 0);
edit->setTime(d->getField(it.currentKey()).toTime());
edits.append(edit);
break;
}
case TVVariant::Date: {
DateEdit *edit = new DateEdit(editDisplay, 0);
edit->setDate(d->getField(it.currentKey()).toDate());
edits.append(edit);
break;
}
default:
edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
}
QCheckBox *tb = new QCheckBox(editDisplay);
tb->setChecked(TRUE);
toggles->setMapping(tb, i);
connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
buttons.append(tb);
} else {
/* No valid value.. set to null */
switch(it.current()->type()) {
case TVVariant::String: {
QLineEdit *edit = new QLineEdit(editDisplay, 0);
edit->setEnabled(false);
edits.append(edit);
break;
}
case TVVariant::Int: {
IntEdit *edit = new IntEdit(editDisplay, 0);
edit->setEnabled(false);
edits.append(edit);
break;
}
case TVVariant::Time: {
TimeEdit *edit = new TimeEdit(editDisplay, 0);
edit->setEnabled(false);
edits.append(edit);
break;
}
case TVVariant::Date: {
DateEdit *edit = new DateEdit(editDisplay, 0);
edit->setEnabled(false);
edits.append(edit);
break;
}
default:
edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
}
QCheckBox *tb = new QCheckBox(editDisplay);
tb->setChecked(FALSE);
toggles->setMapping(tb, i);
connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
buttons.append(tb);
}
i++;
}
++it;
}
num_edits = i;
}
void TVEditView::toggleEnabled(int i) {
if(edits.at(i)->isEnabled()) {
edits.at(i)->setEnabled(false);
buttons.at(i)->setChecked(FALSE);
} else {
edits.at(i)->setEnabled(true);
buttons.at(i)->setChecked(TRUE);
}
}
bool TVEditView::openEditItemDialog(TableState *ts, DataElem *d,
QWidget *parent)
{
int i;
int keyId;
if(!ts) return 0;
if(!d) return 0;
if(!ts->kRep) return 0;
TVEditView *dlg = new TVEditView(ts, d, parent);
if (dlg->exec() == QDialog::Accepted ) {
/* update the element, basically for each
edits, if isEnabled, set Value, else unsetField */
for(i = 0; i < dlg->num_edits; i++) {
keyId = dlg->keyIds[i];
if(dlg->edits.at(i)->isEnabled()) {
switch(d->getFieldType(keyId)) {
case TVVariant::String: {
TVVariant value = TVVariant(
((QLineEdit *)dlg->edits.at(i))->text());
d->setField(keyId, value);
break;
}
case TVVariant::Int: {
TVVariant value = TVVariant(
((IntEdit *)dlg->edits.at(i))->value());
d->setField(keyId, value);
break;
}
case TVVariant::Time: {
TVVariant value = TVVariant(
((TimeEdit *)dlg->edits.at(i))->time());
d->setField(keyId, value);
break;
}
case TVVariant::Date: {
TVVariant value = TVVariant(
((DateEdit *)dlg->edits.at(i))->date());
d->setField(keyId, value);
break;
}
default:
break;
}
} else {
/* unset the field */
d->unsetField(keyId);
}
}
delete dlg;
return TRUE;
}
return FALSE;
}
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 @@
/**********************************************************************
** 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 "tvfilterview.h"
#include <qtoolbutton.h>
#include <qcombobox.h>
#include <qlistview.h>
#include <qlayout.h>
#include <qheader.h>
#include <qpushbutton.h>
#include <qlabel.h>
-TVFilterView::TVFilterView(TableState *t, QWidget* parent = 0,
- const char *name = 0, WFlags fl =0) : QDialog(parent, name, TRUE, fl)
+TVFilterView::TVFilterView(TableState *t, QWidget* parent,
+ const char *name, WFlags fl ) : QDialog(parent, name, TRUE, fl)
{
if ( !name )
setName( "Filter View" );
QVBoxLayout *vlayout = new QVBoxLayout(this);
display = new QListView(this, "display");
display->addColumn("Key");
display->addColumn("Constraint");
display->addColumn("Value");
display->header()->setClickEnabled(FALSE);
display->header()->setResizeEnabled(FALSE);
vlayout->addWidget(display);
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
newFilterButton = new QPushButton(this, "new Filter");
newFilterButton->setMaximumSize(QSize(50, 32767));
newFilterButton->setText("New");
hlayout->addWidget(newFilterButton);
deleteFilterButton = new QPushButton(this, "delete Filter");
deleteFilterButton->setMaximumSize(QSize(50, 32767));
deleteFilterButton->setText("Delete");
hlayout->addWidget(deleteFilterButton);
clearFilterButton = new QPushButton(this, "delete Filter");
clearFilterButton->setMaximumSize(QSize(60, 32767));
clearFilterButton->setText("Clear All");
hlayout->addWidget(clearFilterButton);
vlayout->addLayout(hlayout);
QHBoxLayout *hlayout2 = new QHBoxLayout;
keyNameCombo = new QComboBox(FALSE, this, "key name");
keyNameCombo->setEnabled(FALSE);
hlayout2->addWidget(keyNameCombo);
QLabel *label = new QLabel(this);
label->setText("has value");
hlayout2->addWidget(label);
keyEntry = new TVFilterKeyEntry(this, "key entry");
keyEntry->setEnabled(FALSE);
vlayout->addLayout(hlayout2);
vlayout->addWidget(keyEntry);
connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() ));
connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm()));
connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms()));
connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() ));
connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() ));
connect(display, SIGNAL(selectionChanged(QListViewItem*)), this,
SLOT(setTerm(QListViewItem *)));
ts = t;
current = 0;
terms.setAutoDelete(true);
do_filter = false;
#ifdef Q_WS_QWS
showMaximized();
#endif
}
/*!
Destroys the TVFilterView widget
*/
TVFilterView::~TVFilterView()
{
}
void TVFilterView::rebuildData()
{
}
void TVFilterView::reset()
{
keyNameCombo->clear();
keyIds.clear();
}
void TVFilterView::rebuildKeys()
{
int i;
if (!ts) return;
if(!ts->kRep) return;
keyEntry->setTableState(ts);
/* set up the list of keys that can be compared on */
keyNameCombo->clear();
KeyListIterator it(*ts->kRep);
i = 0;
while(it.current()) {
if(ts->kRep->validIndex(it.currentKey())) {
keyNameCombo->insertItem(it.current()->name());
keyIds.insert(i, it.currentKey());
++i;
}
++it;
}
}
bool TVFilterView::passesFilter(DataElem *d) {
if (!filterActive()) return true;
FilterTerm *t;
for (t = terms.first(); t != 0; t = terms.next() ) {
/* check against filter */
switch(t->ct) {
case ct_less:
if (!d->lessThan(t->keyIndex, t->value))
return false;
break;
case ct_more:
if (!d->moreThan(t->keyIndex, t->value))
return false;
break;
case ct_equal:
if (!d->equalTo(t->keyIndex, t->value))
return false;
break;
case ct_contains:
if (!d->contains(t->keyIndex, t->value))
return false;
break;
case ct_startswith:
if (!d->startsWith(t->keyIndex, t->value))
return false;
break;
case ct_endswith:
if (!d->endsWith(t->keyIndex, t->value))
return false;
break;
default:
qWarning("TVFilterView::passesFilter() "
"unrecognized filter type");
return false;
}
}
return true;
}
bool TVFilterView::filterActive() const
{
/* when button operated, also check the do_filter value
return do_filter;
*/
if (terms.isEmpty())
return false;
return true;
}
/* SLOTS */
void TVFilterView::newTerm()
{
if (!ts) return;
FilterTerm *term = new FilterTerm;
current = term;
term->view = 0;
updateTerm();
display->setSelected(term->view, true);
terms.append(term);
keyEntry->setEnabled(true);
keyNameCombo->setEnabled(true);
}
void TVFilterView::updateTerm()
{
FilterTerm *term;
/* Read the widget values (keyname, compare type, value)
* and build the lists */
if (!ts) return;
if (!current) return;
QString keyString;
QString cmpString;
QString vString;
term = current;
/* create new list item, set initial values, enable widgets */
term->keyIndex = keyIds[keyNameCombo->currentItem()];
keyEntry->setKey(term->keyIndex); /* so the next two items make sense */
term->ct = keyEntry->getCompareType(),
term->value = keyEntry->getCompareValue();
keyString = keyNameCombo->currentText();
switch(term->ct) {
case ct_less:
cmpString = " less than ";
break;
case ct_more:
cmpString = " more than ";
break;
case ct_equal:
cmpString = " equal to ";
break;
case ct_contains:
cmpString = " containing ";
break;
case ct_startswith:
cmpString = " starting with ";
break;
case ct_endswith:
cmpString = " ending with ";
break;
default:
cmpString = " ERROR ";
}
vString = term->value.toString();
/* remove old view */
if (term->view)
delete(term->view);
term->view = new QListViewItem(display, 0, keyString, cmpString, vString);
display->setSelected(term->view, true);
}
/* deletes current term */
void TVFilterView::deleteTerm()
{
if(!current) return;
if (current->view)
delete(current->view);
terms.removeRef(current);
current = terms.first();
if(terms.isEmpty()) {
keyEntry->setEnabled(false);
keyNameCombo->setEnabled(false);
}
}
/* clears all terminations */
void TVFilterView::clearTerms()
{
while(current)
deleteTerm();
}
void TVFilterView::setTerm(QListViewItem *target)
{
/* Iterate through the list to find item with view=target..
* set as current, delete */
FilterTerm *term = current;
for (current = terms.first(); current != 0; current = terms.next() )
if (current->view == target)
break;
if (!current) {
current = term;
}
}
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 @@
/**********************************************************************
** 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 "tvkeyedit.h"
#include <qtoolbutton.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qlistview.h>
#include <qmessagebox.h>
#include <stdlib.h>
#include <qpushbutton.h>
/* QList view item... ?? that can store and update the values that I will
* be changing */
class TVKEListViewItem : public QListViewItem
{
public:
TVKEListViewItem(QString n, TVVariant::KeyType kt, int p, QListView *parent) :
QListViewItem(parent)
{
name = n;
keyType = kt;
position = p;
}
QString text(int i) const
{
if(i) {
return TVVariant::typeToName(keyType);
}
return name;
}
/* always sort by key index, ignore i */
QString key(int, bool) const
{
return QString().sprintf("%08d", position);
}
void setText(int i, const QString &)
{
;
}
QString getName() const
{
return name;
}
void setName(QString n)
{
name = n;
repaint();
}
TVVariant::KeyType getKeyType() const
{
return keyType;
}
void setKeyType(TVVariant::KeyType k)
{
keyType = k;
repaint();
}
inline int getPos() const
{
return position;
}
private:
QString name;
TVVariant::KeyType keyType;
int position;
};
-TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent = 0, const char *name = 0,
- WFlags fl = 0) : TVKeyEdit_gen(parent, name, true, fl)
+TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent, const char *name,
+ WFlags fl) : TVKeyEdit_gen(parent, name, true, fl)
{
int i;
ts = t;
if(!ts) return;
if(!ts->kRep) return;
working_state = *ts->kRep;
i = 1;
keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
i++;
keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
i++;
keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
i++;
keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
KeyListIterator it(*ts->kRep);
while(it.current()) {
if(t->kRep->validIndex(it.currentKey())) {
new TVKEListViewItem(it.current()->name(),
it.current()->type(),
it.currentKey(),
display);
}
++it;
}
num_keys = ts->kRep->getNumFields();
if(display->childCount() > 0) {
display->setCurrentItem(display->firstChild());
setTerm(display->currentItem());
} else {
deleteKeyButton->setEnabled(FALSE);
clearKeysButton->setEnabled(FALSE);
keyNameEdit->setEnabled(FALSE);
keyTypeEdit->setEnabled(FALSE);
}
display->setSorting(0);
#ifdef Q_WS_QWS
showMaximized();
#endif
}
/*!
Destroys the TVKeyEdit widget
*/
TVKeyEdit::~TVKeyEdit()
{
}
/* SLOTS */
void TVKeyEdit::newTerm()
{
/* new item, make current Item */
int i;
i = working_state.addKey("<New Key>", TVVariant::String);
//working_state.setNewFlag(i, TRUE);
TVKEListViewItem *nItem = new TVKEListViewItem("<New Key>",
TVVariant::String,
i,
display);
display->setCurrentItem(nItem);
setTerm(nItem);
num_keys++;
if(display->childCount() == 1) {
deleteKeyButton->setEnabled(TRUE);
clearKeysButton->setEnabled(TRUE);
keyNameEdit->setEnabled(TRUE);
keyTypeEdit->setEnabled(TRUE);
}
}
void TVKeyEdit::updateTerm(const QString &newName)
{
/* TODO if name matches a deleted term, prompt for
renewing old data instead */
TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
if(i) {
i->setName(newName);
working_state.setKeyName(i->getPos(), newName);
}
}
void TVKeyEdit::updateTerm(int t)
{
/* t is an index to a combo in a menu, NOT a type */
t++; /* menu counts from 0, types count from 1 */
TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
if (i) {
i->setKeyType((TVVariant::KeyType)t);
working_state.setKeyType(i->getPos(), (TVVariant::KeyType)t);
}
}
/* deletes current term
* really just marks key as deleted so is now invalid.
* the actual delete will happen when data is 'cleaned'
* or when file is saved.
*/
void TVKeyEdit::deleteTerm()
{
TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
if (i) {
working_state.setDeleteFlag(i->getPos(), TRUE);
delete i;
}
if(!display->childCount()) {
/* disable the delete and clear buttons, etc */
deleteKeyButton->setEnabled(FALSE);
clearKeysButton->setEnabled(FALSE);
keyNameEdit->setEnabled(FALSE);
keyTypeEdit->setEnabled(FALSE);
}
}
/* clears all terminations */
void TVKeyEdit::clearTerms()
{
/* should pop up a warning */
if (QMessageBox::warning(this, "Delete all keys",
"Are you sure you want to\ndelete all the keys?",
"Yes", "No") == 0)
{
while(display->currentItem())
deleteTerm();
}
}
void TVKeyEdit::setTerm(QListViewItem *target)
{
/* need to update the widgets to show keys values */
keyNameEdit->setText(((TVKEListViewItem *)target)->getName());
int t = (int)(((TVKEListViewItem *)target)->getKeyType());
t--;
keyTypeEdit->setCurrentItem(t);
}
KeyList* TVKeyEdit::openEditKeysDialog(TableState *t, QWidget *parent = 0)
{
if(!t)
return 0;
if(!t->kRep)
return 0;
TVKeyEdit *dlg = new TVKeyEdit(t, parent);
if ((dlg->exec() == QDialog::Accepted) &&
(dlg->working_state != *t->kRep))
{
return (new KeyList(dlg->working_state));
}
return 0;
}
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 @@
/**********************************************************************
** 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 "tvlistview.h"
#include "../db/common.h"
#include <qtoolbutton.h>
#include <qlistview.h>
#include <qlayout.h>
void TVListViewPrivate::setColumnWidth(int column, int width)
{
if(width > 70) width = 70;
QListView::setColumnWidth(column, width);
}
void TVListViewPrivate::setSorting(int column, bool increasing)
{
emit sortChanged(column);
QListView::setSorting(column, increasing);
}
TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
WFlags fl) : QListView(parent, name, fl) {
;
}
class TVListViewItem : public QListViewItem
{
public:
TVListViewItem(QListView *parent, DataElem *d);
~TVListViewItem();
QString text(int i) const
{
return data_reference->toQString(i);
}
/* Do nothing... all data for this item should be generated */
void setText(int i, const QString &)
{
;
}
QString key(int i, bool a) const
{
return data_reference->toSortableQString(i);
}
void setDataElem(DataElem *d)
{
data_reference = d;
}
DataElem *getDataElem() {
return data_reference;
}
private:
DataElem *data_reference;
};
TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
: QListViewItem(parent)
{
data_reference = d;
}
TVListViewItem::~TVListViewItem()
{
data_reference = 0;
}
-TVListView::TVListView(TableState *t, QWidget* parent = 0,
- const char *name = 0, WFlags fl =0) : QWidget(parent, name, fl)
+TVListView::TVListView(TableState *t, QWidget* parent,
+ const char *name, WFlags fl ) : QWidget(parent, name, fl)
{
if (!name)
setName("TVListView");
// the next two lines need to be rationalized.
resize(318,457);
setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
(QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
setCaption(tr("List View"));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
layout->addWidget(listViewDisplay);
connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this,
SLOT(setCurrent(QListViewItem *)));
connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
SLOT(setSorting(int)));
listViewDisplay->setShowSortIndicator(true);
it = new QListViewItemIterator(listViewDisplay);
ts = t;
}
TVListView::~TVListView()
{
}
void TVListView::addItem(DataElem *d)
{
TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
delete it;
it = new QListViewItemIterator(i);
}
/* remove current (it) item */
void TVListView::removeItem()
{
QListViewItemIterator other(*it);
QListViewItemIterator tmp = *it;
(*it)++;
if (!it->current()) {
*it = tmp;
(*it)--;
if (!it->current()) {
delete it;
it = 0;
}
}
delete other.current();
}
void TVListView::clearItems()
{
/* This is ok since the destructor for TVListItem does not know about
the data_reference pointer.. and hence will leave it alone */
listViewDisplay->clear();
delete it;
it = new QListViewItemIterator(listViewDisplay);
}
void TVListView::first()
{
delete it;
it = new QListViewItemIterator(listViewDisplay);
}
void TVListView::last()
{
qWarning("TVListView::last not yet implemented");
}
void TVListView::next()
{
QListViewItemIterator tmp = *it;
(*it)++;
if (!it->current()) {
*it = tmp;
}
}
void TVListView::previous()
{
QListViewItemIterator tmp = *it;
(*it)--;
if (!it->current()) {
*it = tmp;
}
}
DataElem *TVListView::getCurrentData() {
if (it->current()) {
return ((TVListViewItem *)it->current())->getDataElem();
}
return NULL;
}
/*! Now to implement the closest match function */
void TVListView::findItem(int keyId, TVVariant value)
{
QListViewItem *i;
TVListViewItem *best_so_far = NULL;
/* start at the beginning... go through till find the closest elem */
i = listViewDisplay->firstChild();
while (i) {
/* search stuff */
if(best_so_far) {
if (DataElem::closer(
((TVListViewItem *)i)->getDataElem(),
best_so_far->getDataElem(), value, keyId))
best_so_far = (TVListViewItem *)i;
} else {
if (DataElem::closer(
((TVListViewItem *)i)->getDataElem(),
NULL, value, keyId))
best_so_far = (TVListViewItem *)i;
}
i = i->itemBelow();
}
if (best_so_far) {
/* set best_so_far to current element */
delete it;
it = new QListViewItemIterator(best_so_far);
}
}
void TVListView::rebuildKeys()
{
int i;
if(!ts) return;
if(!ts->kRep) return;
i = listViewDisplay->columns();
while(i > 0)
listViewDisplay->removeColumn(--i);
KeyListIterator kit(*ts->kRep);
i = 0;
while(kit.current()) {
if(!kit.current()->delFlag()) {
listViewDisplay->addColumn(kit.current()->name());
keyIds.insert(i, kit.currentKey());
++i;
}
++kit;
}
}
void TVListView::setSorting(int column)
{
/* Without table state can't do anything */
if (ts == 0)
return;
if (keyIds[column] != ts->current_column) {
ts->current_column = keyIds[column];
}
}
void TVListView::rebuildData() {
int i;
QMap<int, int>::Iterator kit;
/* Need to set sort order */
if(!ts)
return;
/* revers lookup the column */
i = -1;
for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) {
if (kit.data() == ts->current_column) {
i = kit.key();
break;
}
}
if (i == -1)
return;
listViewDisplay->setSorting(i);
listViewDisplay->sort();
/* reset current element */
listViewDisplay->setCurrentItem(it->current());
listViewDisplay->setSelected(it->current(), true);
listViewDisplay->ensureItemVisible(it->current());
}
void TVListView::reset()
{
int i;
listViewDisplay->clear();
i = listViewDisplay->columns();
while (i > 0)
listViewDisplay->removeColumn(--i);
keyIds.clear();
}
void TVListView::setCurrent(QListViewItem *i)
{
/* cast */
TVListViewItem *t = (TVListViewItem *)i;
if(!t) {
/* set current to null */
ts->current_elem = 0;
return;
}
ts->current_elem = t->getDataElem();
/* now also set up the iterator */
delete it;
it = new QListViewItemIterator(i);
//emit browseView();
}