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
@@ -554,257 +554,257 @@ bool TVVariant::closer(TVVariant n, TVVariant o)
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;
}
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,172 +1,172 @@
/**********************************************************************
** 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 {
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,158 +1,158 @@
/**********************************************************************
** 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;
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,224 +1,224 @@
/**********************************************************************
** 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)
{
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,217 +1,217 @@
/**********************************************************************
** 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) {