summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/ui
Side-by-side diff
Diffstat (limited to 'noncore/apps/tableviewer/ui') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/ui/.cvsignore8
-rw-r--r--noncore/apps/tableviewer/ui/browsekeyentry.cpp206
-rw-r--r--noncore/apps/tableviewer/ui/browsekeyentry.h75
-rw-r--r--noncore/apps/tableviewer/ui/commonwidgets.cpp209
-rw-r--r--noncore/apps/tableviewer/ui/commonwidgets.h98
-rw-r--r--noncore/apps/tableviewer/ui/filterkeyentry.cpp208
-rw-r--r--noncore/apps/tableviewer/ui/filterkeyentry.h96
-rw-r--r--noncore/apps/tableviewer/ui/tvbrowseview.cpp122
-rw-r--r--noncore/apps/tableviewer/ui/tvbrowseview.h55
-rw-r--r--noncore/apps/tableviewer/ui/tveditview.cpp235
-rw-r--r--noncore/apps/tableviewer/ui/tveditview.h62
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.cpp304
-rw-r--r--noncore/apps/tableviewer/ui/tvfilterview.h88
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit.cpp254
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit.h56
-rw-r--r--noncore/apps/tableviewer/ui/tvkeyedit_gen.ui239
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.cpp315
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.h92
18 files changed, 2722 insertions, 0 deletions
diff --git a/noncore/apps/tableviewer/ui/.cvsignore b/noncore/apps/tableviewer/ui/.cvsignore
new file mode 100644
index 0000000..183c939
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/.cvsignore
@@ -0,0 +1,8 @@
+moc_*
+Makefile
+tvbrowseview_gen.h
+tvfilterview_gen.h
+tvkeyedit_gen.h
+tvbrowseview_gen.cpp
+tvfilterview_gen.cpp
+tvkeyedit_gen.cpp
diff --git a/noncore/apps/tableviewer/ui/browsekeyentry.cpp b/noncore/apps/tableviewer/ui/browsekeyentry.cpp
new file mode 100644
index 0000000..42e24dd
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/browsekeyentry.cpp
@@ -0,0 +1,206 @@
+/**********************************************************************
+** 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 "browsekeyentry.h"
+#include "commonwidgets.h"
+
+#include <qtoolbutton.h>
+#include <qwidgetstack.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+#include <qpopupmenu.h>
+#include <qhbox.h>
+#include <qdatetime.h>
+
+#include <qheader.h>
+// For qWarning(const char *)
+
+/*!
+ \class TVBrowseKeyEntry
+ \brief a Widget used enter keys into the TVBrowseViewWidget
+
+ The TVBrowseKeyEntry Widget provides the facility to enter
+ various key types to be search on in the table. The key can be changed
+ and the entry field will update to the correct sort of widget appropriately
+*/
+
+/*!
+ Constructs the widget
+*/
+TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
+ : QWidget(parent, name, f)
+{
+ QHBoxLayout *h_layout = new QHBoxLayout(this);
+
+ textKey = new QLineEdit(this, 0);
+ intKey = new IntEdit(this, 0);
+ dateKey = new DateEdit(this, 0);
+ timeKey = new TimeEdit(this, 0);
+
+ resetButton = new QPushButton(this, "reset");
+ resetButton->setMinimumSize(QSize(50, 0));
+ resetButton->setText(tr("Reset"));
+
+ changeKeyButton = new QToolButton(this, "changekey");
+ // TODO The icon stuff.
+ changeKeyButton->setText(tr("key"));
+
+ totalKeys = 0;
+ ts = 0;
+ keyMenu = new QPopupMenu(this, "keymenu");
+
+ ws = new QWidgetStack(this, 0);
+ ws->addWidget(textKey, TVVariant::String);
+ ws->addWidget(intKey, TVVariant::Int);
+ ws->addWidget(timeKey, TVVariant::Time);
+ ws->addWidget(dateKey, TVVariant::Date);
+
+ ws->raiseWidget(TVVariant::String);
+
+ // TODO connect slots and signals....
+ connect(changeKeyButton, SIGNAL(clicked()),
+ this, SLOT(changeKeyMenuSlot()));
+
+ connect(resetButton, SIGNAL(clicked()),
+ textKey, SLOT(clear()));
+ connect(resetButton, SIGNAL(clicked()),
+ intKey, SLOT(clear()));
+ connect(resetButton, SIGNAL(clicked()),
+ dateKey, SLOT(clear()));
+ connect(resetButton, SIGNAL(clicked()),
+ timeKey, SLOT(clear()));
+
+ h_layout->addWidget(ws);
+ h_layout->addWidget(resetButton);
+ h_layout->addWidget(changeKeyButton);
+
+ connect(textKey, SIGNAL(textChanged(const QString&)),
+ this, SLOT(searchOnText()));
+ connect(intKey, SIGNAL(valueChanged(int)),
+ this, SLOT(searchOnText()));
+ connect(dateKey, SIGNAL(valueChanged(const QDate&)),
+ this, SLOT(searchOnText()));
+ connect(timeKey, SIGNAL(valueChanged(const QTime&)),
+ this, SLOT(searchOnText()));
+}
+
+/*!
+ Destructs the widget
+*/
+TVBrowseKeyEntry::~TVBrowseKeyEntry()
+{
+}
+
+/*!
+ Changes which key the user intends to search on
+
+ \param id_param the index of the key future searches should be base on
+*/
+void TVBrowseKeyEntry::changeKeySlot(int id_param)
+{
+ if(ts) {
+ emit sortChanged(id_param);
+ ws->raiseWidget(ts->kRep->getKeyType(ts->current_column));
+ }
+}
+
+/*!
+ Opens the change key menu
+*/
+void TVBrowseKeyEntry::changeKeyMenuSlot()
+{
+ if(ts)
+ keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
+}
+
+
+void TVBrowseKeyEntry::setTableState(TableState *t) {
+ ts = t;
+}
+
+void TVBrowseKeyEntry::rebuildKeys() {
+ int i;
+ if (!ts) return;
+ if (!ts->kRep) return;
+
+ /* clear the old */
+ keyMenu->clear();
+
+ KeyListIterator it(*ts->kRep);
+
+ for (i = 0; i < ts->kRep->getNumFields(); i++) {
+ keyMenu->insertItem(it.current()->name(), this,
+ SLOT(changeKeySlot(int)), 0, i);
+ keyMenu->setItemParameter(i, it.currentKey());
+ ++it;
+ }
+}
+
+void TVBrowseKeyEntry::reset()
+{
+ textKey->clear();
+ intKey->clear();
+ dateKey->clear();
+ timeKey->clear();
+
+ keyMenu->clear();
+}
+/*!
+ Searches on the current value of the key entry provided that the
+ current key is of type text WARNING, TODO fix memory leaks
+*/
+void TVBrowseKeyEntry::searchOnText()
+{
+ TVVariant sendkey;
+
+ if (!ts)
+ return;
+
+ switch(ts->kRep->getKeyType(ts->current_column)) {
+ case TVVariant::String:
+ sendkey = TVVariant(QString(textKey->text()));
+ break;
+ case TVVariant::Int: {
+ sendkey = TVVariant(intKey->value());
+ break;
+ }
+ case TVVariant::Time: {
+ sendkey = TVVariant(QTime(timeKey->time()));
+ break;
+ }
+ case TVVariant::Date: {
+ sendkey = TVVariant(QDate(dateKey->date()));
+ break;
+ }
+ case TVVariant::Invalid:
+ break;
+ default:
+ qWarning("TVBrowseKeyEntry::searchOnText() "
+ "cannot work out data type");
+ return;
+ }
+ emit searchOnKey(ts->current_column, sendkey);
+}
+
+/*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, TVVariant)
+
+ This signal indicates that a search on key index currentKeyId should be
+ done searching for the value v.
+*/
diff --git a/noncore/apps/tableviewer/ui/browsekeyentry.h b/noncore/apps/tableviewer/ui/browsekeyentry.h
new file mode 100644
index 0000000..220bf6a
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/browsekeyentry.h
@@ -0,0 +1,75 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef BrowseKeyEntry_H
+#define BrowseKeyEntry_H
+
+#include <qwidget.h>
+#include "../db/common.h"
+
+/* Forward class declarations */
+class QWidgetStack;
+class QToolButton;
+class QPushButton;
+class QLineEdit;
+class DateEdit;
+class TimeEdit;
+class IntEdit;
+class QPopupMenu;
+class QHBox;
+
+class TVBrowseKeyEntry: public QWidget
+{
+ Q_OBJECT
+public:
+ TVBrowseKeyEntry( QWidget *parent = 0,
+ const char *name = 0, WFlags f = 0 );
+ ~TVBrowseKeyEntry();
+
+ void setTableState(TableState *t);
+ void rebuildKeys();
+ void reset();
+
+signals:
+ void searchOnKey(int keyIndex, TVVariant keyData);
+ void sortChanged(int i);
+
+private slots:
+ void changeKeySlot(int);
+ void changeKeyMenuSlot();
+ void searchOnText();
+
+private:
+ QPushButton *resetButton;
+ QToolButton *changeKeyButton;
+ QPopupMenu *keyMenu;
+ int totalKeys;
+ TableState *ts;
+
+ /* each type of possible data entry will be put on the stack */
+ QWidgetStack *ws;
+
+ /* include widgets for each type of data entry you need here. */
+ QLineEdit *textKey;
+ IntEdit *intKey;
+ DateEdit *dateKey;
+ TimeEdit *timeKey;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/commonwidgets.cpp b/noncore/apps/tableviewer/ui/commonwidgets.cpp
new file mode 100644
index 0000000..0b4f3c2
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/commonwidgets.cpp
@@ -0,0 +1,209 @@
+/**********************************************************************
+** 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 <datebookmonth.h>
+#include <qpopupmenu.h>
+#include <qspinbox.h>
+#include "commonwidgets.h"
+
+DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
+ : 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 )
+ : 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 )
+ : 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/commonwidgets.h b/noncore/apps/tableviewer/ui/commonwidgets.h
new file mode 100644
index 0000000..2a9691f
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/commonwidgets.h
@@ -0,0 +1,98 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef Dateedit_H
+#define Dateedit_H
+
+#include <qwidget.h>
+#include <qdatetime.h>
+
+/* inherited classes */
+#include <qtoolbutton.h>
+#include <qspinbox.h>
+
+class DateBookMonth;
+class QComboBox;
+
+class DateEdit : public QToolButton
+{
+ Q_OBJECT
+
+public:
+ DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
+ ~DateEdit();
+
+ QDate date() const;
+ void setDate(QDate);
+
+ QSizePolicy sizePolicy() const;
+signals:
+ void valueChanged(const QDate &);
+
+public slots:
+ void clear();
+private slots:
+ void subValueChanged();
+
+private:
+ DateBookMonth *dateSelector;
+};
+
+class TimeEdit : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
+ ~TimeEdit();
+
+ QTime time() const;
+ void setTime(QTime);
+
+ QSizePolicy sizePolicy() const;
+signals:
+ void valueChanged(const QTime &);
+
+public slots:
+ void clear();
+private slots:
+ void subValueChanged();
+
+private:
+ QSpinBox *secondKey;
+ QSpinBox *minuteKey;
+ QSpinBox *hourKey;
+ QComboBox *ampm;
+};
+
+/* more for consistency than need */
+class IntEdit : public QSpinBox
+{
+ Q_OBJECT
+
+public:
+ IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
+ ~IntEdit();
+
+ int value();
+
+public slots:
+ void clear();
+};
+#endif
diff --git a/noncore/apps/tableviewer/ui/filterkeyentry.cpp b/noncore/apps/tableviewer/ui/filterkeyentry.cpp
new file mode 100644
index 0000000..d108fbd
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/filterkeyentry.cpp
@@ -0,0 +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 "filterkeyentry.h"
+#include "commonwidgets.h"
+
+#include <qwidgetstack.h>
+#include <qcombobox.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qsizepolicy.h>
+#include <qdatetime.h>
+#include <qhbox.h>
+
+TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f)
+ : QWidget(parent, name, f)
+{
+ int stack_elem = 0;
+
+ layout = new QHBoxLayout(this, 0);
+ layout->setSpacing(0);
+ layout->setMargin(0);
+
+ textEntry = new QHBox(this, 0);
+ textEntry->setSpacing(0);
+ textEntry->setMargin(0);
+
+ intEntry = new QHBox(this, 0);
+ intEntry->setSpacing(0);
+ intEntry->setMargin(0);
+
+ timeEntry = new QHBox(this, 0);
+ timeEntry->setSpacing(0);
+ timeEntry->setMargin(0);
+
+ dateEntry = new QHBox(this, 0);
+ dateEntry->setSpacing(0);
+ dateEntry->setMargin(0);
+
+ textCombo = new QComboBox(textEntry, 0);
+ textKey = new QLineEdit(textEntry, 0);
+
+ /* Build the text combo list */
+ textCombo->insertItem("less than");
+ textCombo->insertItem("more than");
+ textCombo->insertItem("equal to");
+ textCombo->insertItem("containing");
+ textCombo->insertItem("starting with");
+ textCombo->insertItem("ending with");
+
+ intCombo = new QComboBox(intEntry, 0);
+ intKey = new IntEdit(intEntry, 0);
+
+ /* Build the int combo list */
+ intCombo->insertItem("less than");
+ intCombo->insertItem("more than");
+ intCombo->insertItem("equal to");
+
+ timeCombo = new QComboBox(timeEntry, 0);
+ timeKey = new TimeEdit(timeEntry, 0);
+
+ /* Build the time combo list */
+ timeCombo->insertItem("less than");
+ timeCombo->insertItem("more than");
+ timeCombo->insertItem("equal to");
+
+ dateCombo = new QComboBox(dateEntry, 0);
+ dateKey = new DateEdit(dateEntry, 0);
+
+ /* Build the date combo list */
+ dateCombo->insertItem("less than");
+ dateCombo->insertItem("more than");
+ dateCombo->insertItem("equal to");
+
+ ts = 0;
+
+ ws = new QWidgetStack(this, 0);
+ ws->setMargin(0);
+ ws->addWidget(textEntry, TVVariant::String);
+ ws->addWidget(intEntry, TVVariant::Int);
+ ws->addWidget(timeEntry, TVVariant::Time);
+ ws->addWidget(dateEntry, TVVariant::Date);
+
+ /* connect the signals down */
+ connect(textKey, SIGNAL(textChanged(const QString&)),
+ this, SIGNAL(valueChanged()));
+ connect(intKey, SIGNAL(valueChanged(int)),
+ this, SIGNAL(valueChanged()));
+ connect(dateKey, SIGNAL(valueChanged(const QDate&)),
+ this, SIGNAL(valueChanged()));
+ connect(timeKey, SIGNAL(valueChanged(const QTime&)),
+ this, SIGNAL(valueChanged()));
+
+ connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
+ connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
+ connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
+ connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
+
+ ws->raiseWidget(TVVariant::String);
+ layout->addWidget(ws);
+
+ current_type = TVVariant::String;
+}
+
+/*!
+ Destructs the widget
+*/
+TVFilterKeyEntry::~TVFilterKeyEntry()
+{
+}
+
+void TVFilterKeyEntry::setKey(int i)
+{
+
+ if (!ts) return;
+ if (!ts->kRep) return;
+
+ /* set up to raise appropriate widget set */
+ if (current_type != ts->kRep->getKeyType(i)) {
+ current_type = ts->kRep->getKeyType(i);
+ ws->raiseWidget(current_type);
+ }
+}
+
+void TVFilterKeyEntry::setTableState(TableState *t) {
+ int i;
+ ts = t;
+ if(!t) return;
+ if (!t->kRep)
+ return;
+ if (t->kRep->getNumFields() < 1)
+ return;
+ setKey(0);
+ /* set up the the menu stuff.. */
+}
+
+CmpType TVFilterKeyEntry::getCompareType()
+{
+
+ switch(current_type) {
+ case TVVariant::String: {
+ CmpType k = (CmpType) textCombo->currentItem();
+ return k;
+ }
+ case TVVariant::Int: {
+ CmpType k = (CmpType) intCombo->currentItem();
+ return k;
+ }
+ case TVVariant::Time: {
+ CmpType k = (CmpType) timeCombo->currentItem();
+ return k;
+ }
+ case TVVariant::Date: {
+ CmpType k = (CmpType) dateCombo->currentItem();
+ return k;
+ }
+ default:
+ break;
+ }
+ return ct_equal;
+}
+
+/* MUST return a valid pointer */
+TVVariant TVFilterKeyEntry::getCompareValue()
+{
+ TVVariant sendkey;
+ int tmp;
+
+ switch(current_type) {
+ case TVVariant::String:
+ sendkey = TVVariant(QString(textKey->text()));
+ break;
+ case TVVariant::Int: {
+ sendkey = TVVariant(intKey->value());
+ break;
+ }
+ case TVVariant::Time: {
+ sendkey = TVVariant(QTime(timeKey->time()));
+ break;
+ }
+ case TVVariant::Date: {
+ sendkey = TVVariant(QDate(dateKey->date()));
+ break;
+ }
+ default: {
+ sendkey = TVVariant(0);
+ qWarning("TVFilterKeyEntry::getCompareValue() "
+ "cannot work out data type");
+ }
+ }
+ return sendkey;
+}
diff --git a/noncore/apps/tableviewer/ui/filterkeyentry.h b/noncore/apps/tableviewer/ui/filterkeyentry.h
new file mode 100644
index 0000000..260e250
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/filterkeyentry.h
@@ -0,0 +1,96 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef FilterKeyEntry_H
+#define FilterKeyEntry_H
+
+#include <qwidget.h>
+#include <qhbox.h>
+#include <qlayout.h>
+#include "../db/common.h"
+
+/* Forward class declarations */
+class QWidgetStack;
+class QToolButton;
+class QLineEdit;
+class DateEdit;
+class TimeEdit;
+class IntEdit;
+class QPopupMenu;
+class QComboBox;
+
+typedef enum _CmpType {
+ ct_less = 0,
+ ct_more,
+ ct_equal,
+ ct_contains,
+ ct_startswith,
+ ct_endswith
+} CmpType;
+
+
+class TVFilterKeyEntry: public QWidget
+{
+ Q_OBJECT
+public:
+ TVFilterKeyEntry( QWidget *parent = 0,
+ const char *name = 0, WFlags f = 0 );
+ ~TVFilterKeyEntry();
+
+ void setTableState(TableState *t);
+ void setKey(int i);
+
+ CmpType getCompareType();
+ TVVariant getCompareValue();
+
+signals:
+ void valueChanged();
+
+private:
+ /* include widgets for each type of data entry you need here. */
+ QLineEdit *textKey;
+ QComboBox *textCombo;
+ QHBox *textEntry;
+
+ IntEdit *intKey;
+ QComboBox *intCombo;
+ QHBox *intEntry;
+
+ TimeEdit *timeKey;
+ QComboBox *timeCombo;
+ QHBox *timeEntry;
+
+ DateEdit *dateKey;
+ QComboBox *dateCombo;
+ QHBox *dateEntry;
+
+ TableState *ts;
+
+ /* each type of possible data entry will be put on the stack */
+ QWidgetStack *ws;
+
+ /* This allows for the inherited functions dealing with prefered size
+ * etc to simply get the information from the layout.
+ */
+ QHBoxLayout *layout;
+
+ TVVariant::KeyType current_type;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/tvbrowseview.cpp b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
new file mode 100644
index 0000000..f6da7b1
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvbrowseview.cpp
@@ -0,0 +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)
+{
+ 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/tvbrowseview.h b/noncore/apps/tableviewer/ui/tvbrowseview.h
new file mode 100644
index 0000000..1daff1c
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvbrowseview.h
@@ -0,0 +1,55 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef Tvbrowseview_H
+#define Tvbrowseview_H
+
+#include "../db/common.h"
+#include <qwidget.h>
+
+class QTextBrowser;
+class TVBrowseKeyEntry;
+
+class TVBrowseView : public QWidget
+{
+ Q_OBJECT
+
+signals:
+ void searchOnKey(int keyIndex, TVVariant keyValue);
+ void sortChanged(int);
+
+public:
+ TVBrowseView(TableState *t, QWidget* parent = 0,
+ const char* name = 0, WFlags fl = 0);
+ ~TVBrowseView();
+
+ /* Access Methods */
+ void setDisplayText(const DataElem *);
+ void rebuildKeys();
+ void rebuildData();
+ void reset();
+
+private:
+ TableState *ts;
+
+ QTextBrowser* textViewDisplay;
+ TVBrowseKeyEntry *keyEntry;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/tveditview.cpp b/noncore/apps/tableviewer/ui/tveditview.cpp
new file mode 100644
index 0000000..ba2bd06
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tveditview.cpp
@@ -0,0 +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)
+{
+ 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/tveditview.h b/noncore/apps/tableviewer/ui/tveditview.h
new file mode 100644
index 0000000..94c51d9
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tveditview.h
@@ -0,0 +1,62 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+
+#ifndef Tveditview_H
+#define Tveditview_H
+
+#include <qwidget.h>
+#include <qlist.h>
+#include <qdialog.h>
+#include <qmap.h>
+#include "../db/common.h"
+
+class QGrid;
+class QSignalMapper;
+class QCheckBox;
+
+class TVEditView : public QDialog
+{
+ Q_OBJECT
+
+public:
+ TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
+ const char* name = 0, WFlags fl = 0);
+ ~TVEditView();
+
+ static bool openEditItemDialog(TableState *s, DataElem *d, QWidget *parent);
+
+protected slots:
+ void toggleEnabled(int);
+
+protected:
+
+ void setData(TableState *s, DataElem *d);
+
+ QGrid *editDisplay;
+ QList<QWidget> edits;
+ QList<QCheckBox> buttons;
+ QSignalMapper *toggles;
+
+ QMap<int,int> keyIds;
+
+ int num_edits;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/tvfilterview.cpp b/noncore/apps/tableviewer/ui/tvfilterview.cpp
new file mode 100644
index 0000000..72d39d6
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvfilterview.cpp
@@ -0,0 +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)
+{
+ 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/tvfilterview.h b/noncore/apps/tableviewer/ui/tvfilterview.h
new file mode 100644
index 0000000..5de87b9
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvfilterview.h
@@ -0,0 +1,88 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef Tvfilterview_H
+#define Tvfilterview_H
+
+#include "filterkeyentry.h"
+#include "../db/common.h"
+#include <qlist.h>
+#include <qmap.h>
+#include <qdialog.h>
+
+class QListViewItem;
+class QPushButton;
+class QListView;
+class TVFilterKeyEntry;
+
+class TVFilterView : public QDialog
+{
+ Q_OBJECT
+
+signals:
+ void editView();
+ void listView();
+ void browseView();
+ void loadFile();
+
+protected slots:
+ void newTerm();
+ void deleteTerm();
+ void clearTerms();
+ void updateTerm();
+ void setTerm(QListViewItem *);
+
+public:
+ TVFilterView(TableState *t, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
+ ~TVFilterView();
+
+ /* Access Methods */
+ void rebuildKeys();
+ void rebuildData();
+ void reset();
+
+ bool passesFilter(DataElem *d);
+ bool filterActive() const; /* return true if and only if filtering is on */
+
+ QListView* display;
+ QPushButton* newFilterButton;
+ QPushButton* deleteFilterButton;
+ QPushButton* clearFilterButton;
+ QComboBox* keyNameCombo;
+
+ TVFilterKeyEntry* keyEntry;
+private:
+
+ typedef struct _FilterTerm {
+ int keyIndex;
+ CmpType ct;
+ TVVariant value;
+ QListViewItem *view;
+ } FilterTerm;
+
+ QList<FilterTerm> terms;
+ FilterTerm *current;
+ bool do_filter;
+
+ TableState *ts;
+
+ QMap<int, int> keyIds;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit.cpp b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
new file mode 100644
index 0000000..fb7b7fe
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit.cpp
@@ -0,0 +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)
+{
+ 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/tvkeyedit.h b/noncore/apps/tableviewer/ui/tvkeyedit.h
new file mode 100644
index 0000000..5e80b66
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit.h
@@ -0,0 +1,56 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+#ifndef Tvkeyedit_H
+#define Tvkeyedit_H
+
+#include "tvkeyedit_gen.h"
+#include "../db/common.h"
+
+class TVKeyEdit : public TVKeyEdit_gen
+{
+ Q_OBJECT
+
+signals:
+ void listView();
+ void browseView();
+
+protected slots:
+ void newTerm();
+ void deleteTerm();
+ void clearTerms();
+ void updateTerm(int);
+ void updateTerm(const QString &);
+ void setTerm(QListViewItem *);
+
+public:
+ TVKeyEdit(TableState *ts, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
+ ~TVKeyEdit();
+
+
+ static KeyList *openEditKeysDialog(TableState *ts, QWidget *parent);
+
+private:
+
+ TableState *ts;
+ int num_keys;
+ KeyList working_state;
+};
+
+#endif
diff --git a/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui b/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui
new file mode 100644
index 0000000..5c19d06
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvkeyedit_gen.ui
@@ -0,0 +1,239 @@
+<!DOCTYPE UI><UI>
+<class>TVKeyEdit_gen</class>
+<comment>Dialog for editing the keys and key types</comment>
+<author>Ian Walters</author>
+<forward>class QListViewItem;</forward>
+<widget>
+ <class>QDialog</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TVKeyEdit_gen</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>194</width>
+ <height>418</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>TableViewer - Edit Keys</string>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>0</number>
+ </property>
+ <widget>
+ <class>QListView</class>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Key Name</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>false</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>false</bool>
+ </property>
+ </column>
+ <column>
+ <property>
+ <name>text</name>
+ <string>Key Type</string>
+ </property>
+ <property>
+ <name>clickable</name>
+ <bool>false</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>false</bool>
+ </property>
+ </column>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>display</cstring>
+ </property>
+ </widget>
+ <widget>
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout4</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <spacer>
+ <property>
+ <name>name</name>
+ <cstring>Spacer2</cstring>
+ </property>
+ <property stdset="1">
+ <name>orientation</name>
+ <enum>Horizontal</enum>
+ </property>
+ <property stdset="1">
+ <name>sizeType</name>
+ <enum>Expanding</enum>
+ </property>
+ <property>
+ <name>sizeHint</name>
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>newKeyButton</cstring>
+ </property>
+ <property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>50</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>New</string>
+ </property>
+ </widget>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>deleteKeyButton</cstring>
+ </property>
+ <property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>50</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Delete</string>
+ </property>
+ </widget>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>clearKeysButton</cstring>
+ </property>
+ <property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>60</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Clear All</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget>
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout3</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QLineEdit</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>keyNameEdit</cstring>
+ </property>
+ </widget>
+ <widget>
+ <class>QComboBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>keyTypeEdit</cstring>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+</widget>
+<connections>
+ <connection>
+ <sender>newKeyButton</sender>
+ <signal>clicked()</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>newTerm()</slot>
+ </connection>
+ <connection>
+ <sender>deleteKeyButton</sender>
+ <signal>clicked()</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>deleteTerm()</slot>
+ </connection>
+ <connection>
+ <sender>clearKeysButton</sender>
+ <signal>clicked()</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>clearTerms()</slot>
+ </connection>
+ <connection>
+ <sender>display</sender>
+ <signal>selectionChanged(QListViewItem*)</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>setTerm(QListViewItem *)</slot>
+ </connection>
+ <connection>
+ <sender>keyNameEdit</sender>
+ <signal>textChanged(const QString&amp;)</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>updateTerm(const QString &amp;)</slot>
+ </connection>
+ <connection>
+ <sender>keyTypeEdit</sender>
+ <signal>activated(int)</signal>
+ <receiver>TVKeyEdit_gen</receiver>
+ <slot>updateTerm(int)</slot>
+ </connection>
+ <slot access="protected">clearTerms()</slot>
+ <slot access="protected">deleteTerm()</slot>
+ <slot access="protected">newTerm()</slot>
+ <slot access="public">new_slot()</slot>
+ <slot access="protected">setTerm(QListViewItem *)</slot>
+ <slot access="protected">updateTerm(int)</slot>
+ <slot access="protected">updateTerm(const QString &amp;)</slot>
+</connections>
+</UI>
diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp
new file mode 100644
index 0000000..82d67c6
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvlistview.cpp
@@ -0,0 +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)
+{
+ 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();
+}
diff --git a/noncore/apps/tableviewer/ui/tvlistview.h b/noncore/apps/tableviewer/ui/tvlistview.h
new file mode 100644
index 0000000..26bc299
--- a/dev/null
+++ b/noncore/apps/tableviewer/ui/tvlistview.h
@@ -0,0 +1,92 @@
+/**********************************************************************
+** 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.
+**
+**********************************************************************/
+
+#ifndef Tvlistview_H
+#define Tvlistview_H
+
+#include "../db/common.h"
+#include <qlistview.h>
+#include <qmap.h>
+
+class QListViewItemIterator;
+
+class TVListViewPrivate : public QListView
+{
+ Q_OBJECT
+
+signals:
+ void sortChanged(int i);
+
+public:
+ TVListViewPrivate( QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
+
+ void setColumnWidth(int c, int w);
+ void setSorting(int i, bool increasing=true);
+};
+
+class TVListView : public QWidget
+{
+ Q_OBJECT
+
+signals:
+ void loadFile();
+ void browseView();
+ void filterView();
+ void editView();
+
+protected slots:
+ void setSorting(int);
+ void setCurrent(QListViewItem *);
+
+public:
+ TVListView(TableState *t, QWidget* parent = 0,
+ const char* name = 0, WFlags fl = 0);
+ ~TVListView();
+
+ /* to be used for setting up the list */
+ void addItem(DataElem *);
+ void removeItem(); // remove from list, not from program
+ void clearItems();
+
+ /* DBStore clone functions */
+ void first();
+ void last();
+ void next();
+ void previous();
+
+ void rebuildKeys();
+ void rebuildData();
+ void reset();
+
+ DataElem *getCurrentData();
+
+ void findItem(int i, TVVariant v);
+
+protected:
+ QListViewItemIterator *it;
+ TableState *ts;
+
+ TVListViewPrivate *listViewDisplay;
+
+ QMap<int, int> keyIds;
+
+};
+
+#endif