summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/db
Side-by-side diff
Diffstat (limited to 'noncore/apps/tableviewer/db') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/db/common.cpp165
-rw-r--r--noncore/apps/tableviewer/db/datacache.cpp68
-rw-r--r--noncore/apps/tableviewer/db/datacache.h24
3 files changed, 130 insertions, 127 deletions
diff --git a/noncore/apps/tableviewer/db/common.cpp b/noncore/apps/tableviewer/db/common.cpp
index b58af85..c35dbea 100644
--- a/noncore/apps/tableviewer/db/common.cpp
+++ b/noncore/apps/tableviewer/db/common.cpp
@@ -13,14 +13,14 @@
**
** 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 "common.h"
+**********************************************************************/
+#include "common.h"
#include "datacache.h"
/* OPIE */
#include <opie2/odebug.h>
#include <qpe/timestring.h>
using namespace Opie::Core;
@@ -85,19 +85,19 @@ int parseNextNumber(QString *q) {
</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
+ A way of abstracting void * and keeping information on
the keytypes and behaviours in one place
*/
TVVariantPrivate::TVVariantPrivate()
{
typ = TVVariant::Invalid;
@@ -317,13 +317,13 @@ void TVVariant::load(QDataStream &s )
int x;
s >> x;
d->value.i = x;
}
break;
default:
- ofatal << "Unrecognized data type" << oendl;
+ ofatal << "Unrecognized data type" << oendl;
}
}
void TVVariant::save( QDataStream &s ) const
{
s << type();
@@ -379,13 +379,13 @@ const QString TVVariant::toString() const
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:
+ case Int:
return QString::number(d->value.i);
case Invalid:
default:
return QString::null;
}
return QString::null;
@@ -421,22 +421,22 @@ const QDate TVVariant::toDate() const
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);
@@ -451,13 +451,13 @@ const QTime TVVariant::toTime() const
#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
@@ -557,66 +557,66 @@ bool TVVariant::operator>( const TVVariant &v ) const
/*! 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;
+ 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
+ /* 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)
+ 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)
+ if (diff1 < 0)
diff1 = -diff1;
int diff2 = (i2 - iv);
- if (diff2 < 0)
+ if (diff2 < 0)
diff2 = -diff2;
- if (diff1 < 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)
+ if (diff1 < 0)
diff1 = -diff1;
int diff2 = i2.daysTo(iv);
- if (diff2 < 0)
+ if (diff2 < 0)
diff2 = -diff2;
if (diff1 < diff2)
return TRUE;
return FALSE;
}
@@ -624,16 +624,16 @@ bool TVVariant::closer(TVVariant n, TVVariant o)
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)
+ if (diff1 < 0)
diff1 = -diff1;
int diff2 = i2.msecsTo(iv);
- if (diff2 < 0)
+ if (diff2 < 0)
diff2 = -diff2;
if (diff1 < diff2)
return TRUE;
return FALSE;
}
default:
@@ -646,30 +646,30 @@ bool TVVariant::closer(TVVariant n, TVVariant o)
/*! 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;
+ 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
+ /* 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 Int:
case Date:
case Time:
return TRUE;
default:
/* don't know how to do 'closer' on this type, hence never closer
* or even close */
@@ -678,29 +678,29 @@ bool TVVariant::close(TVVariant n)
return FALSE;
}
/*!
\class Key
\brief document me!
-
+
document me!
*/
Key::Key() : kname(), kexample(), kflags(0) { }
Key::Key(QString name, TVVariant example, int flags) :
- kname(name), kexample(example), kflags(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)
+Key& Key::operator=(const Key& key)
{
kname = key.kname;
kexample = key.kexample;
kflags = key.kflags;
return *this;
}
@@ -774,19 +774,19 @@ void Key::setNewFlag(bool v)
headings by DBStore. It stores the names and types of the keys
*/
/*!
Constructs a KeyList
*/
-KeyList::KeyList() : QIntDict<Key>(20)
+KeyList::KeyList() : QIntDict<Key>(20)
{
setAutoDelete(TRUE);
}
/* Should be deep copy, but isn't */
-KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
+KeyList::KeyList(const KeyList &k) : QIntDict<Key>(k)
{
KeyListIterator it(k);
while(it.current()) {
replace(it.currentKey(), new Key(*it.current()));
++it;
}
@@ -819,13 +819,13 @@ bool KeyList::operator!=(const KeyList &other)
return FALSE;
}
/*!
Returns the number of keys stored in the KeyList
*/
-int KeyList::getNumFields() const
+int KeyList::getNumFields() const
{
return count();
}
/*!
Adds a new key to the KeyList
@@ -844,67 +844,66 @@ int KeyList::addKey(QString name, TVVariant example)
int KeyList::addKey(QString name, TVVariant::KeyType type)
{
/* generate a valid type for the example? */
TVVariant e = TVVariant("0");
switch(type) {
- case TVVariant::String:
+ case TVVariant::String:
return addKey(name, TVVariant("<undefined>").asString());
break;
- case TVVariant::Date:
+ case TVVariant::Date:
return addKey(name, TVVariant(QDate::currentDate()).asDate());
break;
- case TVVariant::Time:
+ case TVVariant::Time:
return addKey(name, TVVariant(QTime(0,0,0)).toTime());
break;
- case TVVariant::Int:
+ 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));
+ owarn << "KeyList::addKey() Cannot make default value for type " << type << ", Key not added." << oendl;
break;
}
return -1;
}
-void KeyList::setKeyFlags(int i, int flag)
+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
+bool KeyList::checkNewFlag(int i) const
{
if (find(i))
return find(i)->newFlag();
return false;
}
-void KeyList::setNewFlag(int i, bool f)
+void KeyList::setNewFlag(int i, bool f)
{
if(!find(i))
return;
find(i)->setNewFlag(f);
}
-bool KeyList::checkDeleteFlag(int i) const
+bool KeyList::checkDeleteFlag(int i) const
{
if (find(i))
return find(i)->delFlag();
return false;
}
-void KeyList::setDeleteFlag(int i, bool f)
+void KeyList::setDeleteFlag(int i, bool f)
{
if(!find(i))
return;
find(i)->setDelFlag(f);
}
@@ -915,13 +914,13 @@ QString KeyList::getKeyName(int i) const
{
if (find (i))
return find(i)->name();
return QString();
}
-void KeyList::setKeyName(int i, const QString &n)
+void KeyList::setKeyName(int i, const QString &n)
{
if(find(i))
find(i)->setName(n);
}
/*!
@@ -931,13 +930,13 @@ 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)
+void KeyList::setKeyType(int i, TVVariant::KeyType t)
{
if(!find(i))
return;
switch(t) {
case TVVariant::String:
find(i)->setExample(TVVariant(QString("default")));
@@ -1037,15 +1036,15 @@ QDataStream &operator>>( QDataStream &s, KeyList &k)
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
+ 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();
@@ -1083,13 +1082,13 @@ QDataStream &operator>>( QDataStream &s, DataElem &d)
int size;
TVVariant t;
Q_UINT16 index = 0;
s >> size; /* redundent data but makes streaming easier */
if (size != d.getNumFields()) {
- owarn << "DataSize mis-match" << oendl;
+ owarn << "DataSize mis-match" << oendl;
return s; /* sanity check failed.. don't load */
}
for(i = 0; i < size; i++) {
s >> index;
s >> t;
@@ -1106,68 +1105,68 @@ int DataElem::getNumFields() const
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
+ \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))
+ 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
+ \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
+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
+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)
+/*!
+ 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)
+/*!
+ 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);
}
@@ -1176,13 +1175,13 @@ TVVariant DataElem::getField(QString qs) const
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)
+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);
@@ -1205,26 +1204,24 @@ void DataElem::setField(int i, QString q)
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)
- );
+ owarn << "DataElem::setField(" << i << ", " << q << ") No valid type found" << oendl;
}
}
/*!
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
+ \param value a pointer to the (already allocated) value to set
*/
-void DataElem::setField(int i, TVVariant value)
+void DataElem::setField(int i, TVVariant value)
{
if (value.isValid()) {
values.remove(i);
values.replace(i, new TVVariant(value));
}
}
@@ -1233,25 +1230,25 @@ void DataElem::setField(int i, 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)
+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
+ \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);
}
@@ -1264,13 +1261,13 @@ void DataElem::unsetField(QString qs)
{
int i = contained->getKeyIndex(qs);
unsetField(i);
}
/*!
- Converts the data element to a Rich Text QString
+ Converts the data element to a Rich Text QString
*/
QString DataElem::toQString() const
{
/* lets make an attempt at this function */
int i;
QString scratch = "";
@@ -1287,21 +1284,21 @@ QString DataElem::toQString() const
++it;
}
return scratch;
}
/*! formats individual fields to strings so can be displayed */
-QString DataElem::toQString(int i) const
+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 DataElem::toSortableQString(int i) const
{
QString scratch = "";
if(hasValidValue(i)) {
switch (contained->getKeyType(i)) {
case TVVariant::String: {
scratch += getField(i).toString();
@@ -1310,19 +1307,19 @@ QString DataElem::toSortableQString(int i) const
case TVVariant::Int: {
scratch.sprintf("%08d", getField(i).toInt());
break;
}
case TVVariant::Date: {
static QDate epochD(1800, 1, 1);
- scratch.sprintf("%08d",
+ scratch.sprintf("%08d",
epochD.daysTo(getField(i).toDate()));
break;
}
case TVVariant::Time: {
static QTime epochT(0, 0, 0);
- scratch.sprintf("%08d",
+ scratch.sprintf("%08d",
epochT.msecsTo(getField(i).toTime()));
break;
}
default:
scratch += "Unknown type";
break;
@@ -1377,18 +1374,18 @@ bool DataElem::contains(int i, TVVariant v) const
if (qs1.contains(qs2) > 0) return TRUE;
break;
}
/* meaningless for ints */
/* meaningless for time */
/* meaningless for dates */
- case TVVariant::Int:
+ case TVVariant::Int:
case TVVariant::Time:
case TVVariant::Date:
break;
default:
- owarn << "Tried to compare unknown data type" << oendl;
+ owarn << "Tried to compare unknown data type" << oendl;
}
return FALSE;
}
bool DataElem::startsWith(int i, TVVariant v) const
{
@@ -1403,18 +1400,18 @@ bool DataElem::startsWith(int i, TVVariant v) const
QString qs2 = v.toString().lower();
return qs1.startsWith(qs2);
}
/* meaningless for ints */
/* meaningless for time */
/* meaningless for dates */
- case TVVariant::Int:
+ case TVVariant::Int:
case TVVariant::Time:
case TVVariant::Date:
return FALSE;
default:
- owarn << "Tried to compare unknown data type" << oendl;
+ owarn << "Tried to compare unknown data type" << oendl;
}
return FALSE;
}
bool DataElem::endsWith(int i, TVVariant v) const
{
@@ -1429,50 +1426,50 @@ bool DataElem::endsWith(int i, TVVariant v) const
QString qs2 = v.toString().lower();
return qs1.startsWith(qs2);
}
/* meaningless for ints */
/* meaningless for time */
/* meaningless for dates */
- case TVVariant::Int:
+ case TVVariant::Int:
case TVVariant::Time:
case TVVariant::Date:
return FALSE;
default:
- owarn << "Tried to compare unknown data type" << oendl;
+ 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
+ \return
<UL>
- <LI>TRUE if the first element is a closer match to the target than the
+ <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;
+ 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 */
- owarn << "Tried to compare two incompatable types" << oendl;
+ 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));
}
diff --git a/noncore/apps/tableviewer/db/datacache.cpp b/noncore/apps/tableviewer/db/datacache.cpp
index 6380e1b..de57961 100644
--- a/noncore/apps/tableviewer/db/datacache.cpp
+++ b/noncore/apps/tableviewer/db/datacache.cpp
@@ -13,13 +13,13 @@
**
** 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.
**
-**********************************************************************/
+**********************************************************************/
/*
* This file is used to load the xml files that represent the database.
* The main requirment for said file is each data entry must contain a key,
* otherwise any other data headings are allowed.
*/
@@ -60,16 +60,16 @@ DBStore::DBStore()
table_size = INIT_TABLE_SIZE;
current_elem = 0;
archive = 0;
}
-//TODO
+//TODO
/*!
- Reinitializes the table to empty (include a resize of the master table,
- which should free some memory)
+ Reinitializes the table to empty (include a resize of the master table,
+ which should free some memory)
*/
void DBStore::freeTable()
{
name = "";
if(archive) {
delete archive;
@@ -90,62 +90,62 @@ void DBStore::freeTable()
DBStore::~DBStore()
{
freeTable();
}
/*!
- This function opens the given xml file, loads it and sets up the
+ This function opens the given xml file, loads it and sets up the
appropriate data structures.
\param file_name A string representing the name of the file to be opened
\return true if successful, false otherwise.
*/
bool DBStore::openSource(QIODevice *inDev, const QString &source) {
- /* first check if db is already open, if contains data.. then clear */
+ /* first check if db is already open, if contains data.. then clear */
if(number_elems > 0) {
freeTable();
}
if (source == "text/x-xml-tableviewer") {
archive = new DBXml(this);
} else if (source == "text/csv") {
- archive = new DBCsv(this);
+ archive = new DBCsv(this);
} else
- return false;
+ return false;
return (archive->openSource(inDev));
}
-bool DBStore::saveSource(QIODevice *outDev, const QString &source)
+bool DBStore::saveSource(QIODevice *outDev, const QString &source)
{
/* saving a new file */
if(!archive) {
if (source == "text/x-xml-tableviewer") {
archive = new DBXml(this);
- } else if (source == "text/x-xml-tableviewer") {
+ } else if (source == "text/x-xml-tableviewer") {
archive = new DBCsv(this);
} else
- return false;
+ return false;
}
/* changing file type */
if(archive->type() != source) {
delete archive;
if (source == "text/x-xml-tableviewer") {
archive = new DBXml(this);
- } else if (source == "text/x-xml-tableviewer") {
+ } else if (source == "text/x-xml-tableviewer") {
archive = new DBCsv(this);
- } else
- return false;
+ } else
+ return false;
}
return (archive->saveSource(outDev));
}
-/*!
+/*!
This function is used to add new elements to the database. If the database
has already reached the maximum allowable size this function does not alter
the database.
\param delm An already allocated and initialized data element to be added
*/
@@ -153,15 +153,15 @@ void DBStore::addItem(DataElem *delem)
{
addItemInternal(delem);
}
void DBStore::addItemInternal(DataElem *delem)
{
- /* if already full, don't over fill, do a qWarning though */
+ /* if already full, don't over fill, do a owarn though */
if (full) {
- owarn << "Attempted to add items to already full table" << oendl;
+ owarn << "Attempted to add items to already full table" << oendl;
return;
}
master_table.insert(number_elems, delem);
current_elem = number_elems;
@@ -182,43 +182,43 @@ void DBStore::addItemInternal(DataElem *delem)
}
}
void DBStore::removeItem(DataElem *r)
{
int position = master_table.findRef(r);
- if(position != -1) {
- /* there is at least one item, this is it */
- /* replace this with the last element, decrease the element count */
- master_table.insert(position, master_table.at(--number_elems));
- master_table.remove(number_elems);
- delete r;
- }
+ if(position != -1) {
+ /* there is at least one item, this is it */
+ /* replace this with the last element, decrease the element count */
+ master_table.insert(position, master_table.at(--number_elems));
+ master_table.remove(number_elems);
+ delete r;
+ }
}
/*!
Sets the name of the database
\param n A string representing the new name of the database.
*/
void DBStore::setName(const QString &n)
{
- name = n;
+ name = n;
}
/*!
Gets the name of the database
\return A string representing the name of the database.
*/
QString DBStore::getName()
{
- return name;
+ return name;
}
/*!
- Retrieves a pointer to the key representation of the database for
+ Retrieves a pointer to the key representation of the database for
other classes to use as reference.
\return a pointer to the databases key representaion
*/
KeyList *DBStore::getKeys()
{
@@ -232,21 +232,21 @@ KeyList *DBStore::getKeys()
void DBStore::setKeys(KeyList *k)
{
kRep = k;
}
/*!
- Sets the current element to the first element of the database
+ Sets the current element to the first element of the database
*/
void DBStore::first()
{
current_elem = 0;
}
/*!
- Sets the current element to the last element of the database
+ Sets the current element to the last element of the database
*/
void DBStore::last()
{
current_elem = number_elems - 1;
}
@@ -254,13 +254,13 @@ void DBStore::last()
Sets the current element to the next element of the database if
there exists an element after the current one.
*/
bool DBStore::next()
{
unsigned int new_current_elem = current_elem + 1;
- if (current_elem < number_elems)
+ if (current_elem < number_elems)
/* was valid before inc (it is possible but unlikely that inc current
elem will change it from invalid to valid) */
if (new_current_elem < number_elems) {
/* is valid after inc */
current_elem = new_current_elem;
return true;
@@ -275,27 +275,27 @@ bool DBStore::next()
bool DBStore::previous()
{
unsigned int new_current_elem = current_elem -1;
if (current_elem < number_elems)
/* was valid */
if (new_current_elem < number_elems) {
- /* still is (if was 0, then now -1, but as is unsigned will wrap
+ /* still is (if was 0, then now -1, but as is unsigned will wrap
and hence be invalid */
current_elem = new_current_elem;
return true;
}
return false;
}
/*!
Returns the current data element in the database. Which element is current
- is affected by newly added items, findItem, next, previous, first and
+ is affected by newly added items, findItem, next, previous, first and
last functions
\return a pointer to the current data element
*/
-DataElem *DBStore::getCurrentData()
+DataElem *DBStore::getCurrentData()
{
- if (current_elem >= number_elems)
+ if (current_elem >= number_elems)
return NULL;
return master_table[current_elem];
}
diff --git a/noncore/apps/tableviewer/db/datacache.h b/noncore/apps/tableviewer/db/datacache.h
index c5dc637..e38050c 100644
--- a/noncore/apps/tableviewer/db/datacache.h
+++ b/noncore/apps/tableviewer/db/datacache.h
@@ -24,15 +24,21 @@
* otherwise any other data headings are allowed.
*/
#ifndef __DATACACHE_H__
#define __DATACACHE_H__
+#include "common.h"
+
+/* OPIE */
+#include <opie2/odebug.h>
+using namespace Opie::Core;
+
+/* QT */
#include <qstring.h>
#include <qvector.h>
-#include "common.h"
class DBStore;
/*! Abstract class that defines how database stuff can be accessed */
class DBAccess {
public:
@@ -42,18 +48,18 @@ public:
virtual QString type() {
return QString();
}
virtual bool openSource(QIODevice *) {
- qWarning("DBAccess::openSource not yet implemented");
+ owarn << "DBAccess::openSource not yet implemented" << oendl;
return false;
}
virtual bool saveSource(QIODevice *) {
- qWarning("DBAccess::saveSource(QString) not yet implemented");
+ owarn << "DBAccess::saveSource(QString) not yet implemented" << oendl;
return false;
}
protected:
DBStore *dstore;
QString source_name;
@@ -67,13 +73,13 @@ public:
bool openSource(QIODevice *, const QString &source);
bool saveSource(QIODevice *, const QString &source);
// Add an item
void addItem(DataElem *);
void addItemInternal(DataElem *);
- void removeItem(DataElem *);
+ void removeItem(DataElem *);
// Set the name of the database
void setName(const QString &name);
// Get the name of the database
QString getName();
@@ -103,28 +109,28 @@ public:
// Access functions.. iterator type stuff
void first();
void last();
- bool next();
- bool previous();
+ bool next();
+ bool previous();
- DataElem* getCurrentData();
+ DataElem* getCurrentData();
private:
/* does the work of freeing used memory */
void freeTable();
- QString name;
+ QString name;
QVector<DataElem> master_table;
DBAccess *archive;
KeyList *kRep;
unsigned int number_elems;
unsigned int table_size; /* should always be a power of 2 */
- bool full; /* since because we are using an int for indexing there is
+ bool full; /* since because we are using an int for indexing there is
an upper limit on the number of items we can store. */
unsigned int current_elem;
};
#endif