summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/ui
Unidiff
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 @@
1moc_*
2Makefile
3tvbrowseview_gen.h
4tvfilterview_gen.h
5tvkeyedit_gen.h
6tvbrowseview_gen.cpp
7tvfilterview_gen.cpp
8tvkeyedit_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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "browsekeyentry.h"
21#include "commonwidgets.h"
22
23#include <qtoolbutton.h>
24#include <qwidgetstack.h>
25#include <qlayout.h>
26#include <qlineedit.h>
27#include <qpushbutton.h>
28#include <qpopupmenu.h>
29#include <qhbox.h>
30#include <qdatetime.h>
31
32#include <qheader.h>
33// For qWarning(const char *)
34
35/*!
36 \class TVBrowseKeyEntry
37 \brief a Widget used enter keys into the TVBrowseViewWidget
38
39 The TVBrowseKeyEntry Widget provides the facility to enter
40 various key types to be search on in the table. The key can be changed
41 and the entry field will update to the correct sort of widget appropriately
42*/
43
44/*!
45 Constructs the widget
46*/
47TVBrowseKeyEntry::TVBrowseKeyEntry(QWidget *parent, const char *name, WFlags f)
48 : QWidget(parent, name, f)
49{
50 QHBoxLayout *h_layout = new QHBoxLayout(this);
51
52 textKey = new QLineEdit(this, 0);
53 intKey = new IntEdit(this, 0);
54 dateKey = new DateEdit(this, 0);
55 timeKey = new TimeEdit(this, 0);
56
57 resetButton = new QPushButton(this, "reset");
58 resetButton->setMinimumSize(QSize(50, 0));
59 resetButton->setText(tr("Reset"));
60
61 changeKeyButton = new QToolButton(this, "changekey");
62 // TODO The icon stuff.
63 changeKeyButton->setText(tr("key"));
64
65 totalKeys = 0;
66 ts = 0;
67 keyMenu = new QPopupMenu(this, "keymenu");
68
69 ws = new QWidgetStack(this, 0);
70 ws->addWidget(textKey, TVVariant::String);
71 ws->addWidget(intKey, TVVariant::Int);
72 ws->addWidget(timeKey, TVVariant::Time);
73 ws->addWidget(dateKey, TVVariant::Date);
74
75 ws->raiseWidget(TVVariant::String);
76
77 // TODO connect slots and signals....
78 connect(changeKeyButton, SIGNAL(clicked()),
79 this, SLOT(changeKeyMenuSlot()));
80
81 connect(resetButton, SIGNAL(clicked()),
82 textKey, SLOT(clear()));
83 connect(resetButton, SIGNAL(clicked()),
84 intKey, SLOT(clear()));
85 connect(resetButton, SIGNAL(clicked()),
86 dateKey, SLOT(clear()));
87 connect(resetButton, SIGNAL(clicked()),
88 timeKey, SLOT(clear()));
89
90 h_layout->addWidget(ws);
91 h_layout->addWidget(resetButton);
92 h_layout->addWidget(changeKeyButton);
93
94 connect(textKey, SIGNAL(textChanged(const QString&)),
95 this, SLOT(searchOnText()));
96 connect(intKey, SIGNAL(valueChanged(int)),
97 this, SLOT(searchOnText()));
98 connect(dateKey, SIGNAL(valueChanged(const QDate&)),
99 this, SLOT(searchOnText()));
100 connect(timeKey, SIGNAL(valueChanged(const QTime&)),
101 this, SLOT(searchOnText()));
102}
103
104/*!
105 Destructs the widget
106*/
107TVBrowseKeyEntry::~TVBrowseKeyEntry()
108{
109}
110
111/*!
112 Changes which key the user intends to search on
113
114 \param id_param the index of the key future searches should be base on
115*/
116void TVBrowseKeyEntry::changeKeySlot(int id_param)
117{
118 if(ts) {
119 emit sortChanged(id_param);
120 ws->raiseWidget(ts->kRep->getKeyType(ts->current_column));
121 }
122}
123
124/*!
125 Opens the change key menu
126*/
127void TVBrowseKeyEntry::changeKeyMenuSlot()
128{
129 if(ts)
130 keyMenu->exec(changeKeyButton->mapToGlobal(QPoint(0,0)));
131}
132
133
134void TVBrowseKeyEntry::setTableState(TableState *t) {
135 ts = t;
136}
137
138void TVBrowseKeyEntry::rebuildKeys() {
139 int i;
140 if (!ts) return;
141 if (!ts->kRep) return;
142
143 /* clear the old */
144 keyMenu->clear();
145
146 KeyListIterator it(*ts->kRep);
147
148 for (i = 0; i < ts->kRep->getNumFields(); i++) {
149 keyMenu->insertItem(it.current()->name(), this,
150 SLOT(changeKeySlot(int)), 0, i);
151 keyMenu->setItemParameter(i, it.currentKey());
152 ++it;
153 }
154}
155
156void TVBrowseKeyEntry::reset()
157{
158 textKey->clear();
159 intKey->clear();
160 dateKey->clear();
161 timeKey->clear();
162
163 keyMenu->clear();
164}
165/*!
166 Searches on the current value of the key entry provided that the
167 current key is of type text WARNING, TODO fix memory leaks
168*/
169void TVBrowseKeyEntry::searchOnText()
170{
171 TVVariant sendkey;
172
173 if (!ts)
174 return;
175
176 switch(ts->kRep->getKeyType(ts->current_column)) {
177 case TVVariant::String:
178 sendkey = TVVariant(QString(textKey->text()));
179 break;
180 case TVVariant::Int: {
181 sendkey = TVVariant(intKey->value());
182 break;
183 }
184 case TVVariant::Time: {
185 sendkey = TVVariant(QTime(timeKey->time()));
186 break;
187 }
188 case TVVariant::Date: {
189 sendkey = TVVariant(QDate(dateKey->date()));
190 break;
191 }
192 case TVVariant::Invalid:
193 break;
194 default:
195 qWarning("TVBrowseKeyEntry::searchOnText() "
196 "cannot work out data type");
197 return;
198 }
199 emit searchOnKey(ts->current_column, sendkey);
200}
201
202/*! \fn void TVBrowseKeyEntry::searchOnKey(int currentKeyId, TVVariant)
203
204 This signal indicates that a search on key index currentKeyId should be
205 done searching for the value v.
206*/
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef BrowseKeyEntry_H
21#define BrowseKeyEntry_H
22
23#include <qwidget.h>
24#include "../db/common.h"
25
26/* Forward class declarations */
27class QWidgetStack;
28class QToolButton;
29class QPushButton;
30class QLineEdit;
31class DateEdit;
32class TimeEdit;
33class IntEdit;
34class QPopupMenu;
35class QHBox;
36
37class TVBrowseKeyEntry: public QWidget
38{
39 Q_OBJECT
40public:
41 TVBrowseKeyEntry( QWidget *parent = 0,
42 const char *name = 0, WFlags f = 0 );
43 ~TVBrowseKeyEntry();
44
45 void setTableState(TableState *t);
46 void rebuildKeys();
47 void reset();
48
49signals:
50 void searchOnKey(int keyIndex, TVVariant keyData);
51 void sortChanged(int i);
52
53private slots:
54 void changeKeySlot(int);
55 void changeKeyMenuSlot();
56 void searchOnText();
57
58private:
59 QPushButton *resetButton;
60 QToolButton *changeKeyButton;
61 QPopupMenu *keyMenu;
62 int totalKeys;
63 TableState *ts;
64
65 /* each type of possible data entry will be put on the stack */
66 QWidgetStack *ws;
67
68 /* include widgets for each type of data entry you need here. */
69 QLineEdit *textKey;
70 IntEdit *intKey;
71 DateEdit *dateKey;
72 TimeEdit *timeKey;
73};
74
75#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qlineedit.h>
22#include <qlayout.h>
23#include <qlabel.h>
24#include <qcombobox.h>
25#include <datebookmonth.h>
26#include <qpopupmenu.h>
27#include <qspinbox.h>
28#include "commonwidgets.h"
29
30DateEdit::DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
31 : QToolButton(parent, name)
32{
33 QPopupMenu *m1 = new QPopupMenu(this);
34 dateSelector = new DateBookMonth(m1, 0, TRUE);
35 m1->insertItem(dateSelector);
36 setPopup(m1);
37 setPopupDelay(0);
38
39 connect(dateSelector, SIGNAL(dateClicked(int, int, int)),
40 this, SLOT(subValueChanged()));
41
42 setText(dateSelector->selectedDate().toString());
43}
44
45
46DateEdit::~DateEdit() {}
47
48QDate DateEdit::date() const
49{
50 return dateSelector->selectedDate();
51}
52
53void DateEdit::setDate(QDate d)
54{
55 dateSelector->setDate(d.year(), d.month(), d.day());
56 setText(d.toString());
57}
58
59QSizePolicy DateEdit::sizePolicy() const
60{
61 QSizePolicy sp;
62 sp.setHorData(QToolButton::sizePolicy().horData());
63 sp.setVerData(QSizePolicy::Fixed);
64
65 return sp;
66}
67
68void DateEdit::clear()
69{
70 QDate today = QDate::currentDate();
71
72 dateSelector->setDate(today.year(), today.month(), today.day());
73 setText(today.toString());
74}
75
76void DateEdit::subValueChanged()
77{
78 QDate current = dateSelector->selectedDate();
79
80 setText(current.toString());
81 emit valueChanged(current);
82}
83
84TimeEdit::TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
85 : QWidget(parent, name, f)
86{
87 QHBoxLayout *layout = new QHBoxLayout(this, 0);
88
89 layout->addWidget(hourKey = new QSpinBox(1, 12, 1, this));
90 hourKey->setWrapping(true);
91 hourKey->setMinimumWidth(30);
92 hourKey->setMaximumWidth(35);
93
94 layout->addWidget(new QLabel(" : ", this));
95 layout->addWidget(minuteKey = new QSpinBox(0, 59, 1, this));
96 minuteKey->setWrapping(true);
97 minuteKey->setMinimumWidth(30);
98 minuteKey->setMaximumWidth(35);
99
100 layout->addWidget(new QLabel(" : ", this));
101 layout->addWidget(secondKey = new QSpinBox(0, 59, 1, this, 0));
102 secondKey->setWrapping(true);
103 secondKey->setMinimumWidth(30);
104 secondKey->setMaximumWidth(35);
105
106 layout->addWidget(ampm = new QComboBox(this));
107 ampm->insertItem("AM");
108 ampm->insertItem("PM");
109
110 layout->addStretch(-1);
111
112 clear();
113
114 connect(secondKey, SIGNAL(valueChanged(const QString&)),
115 this, SLOT(subValueChanged()));
116 connect(minuteKey, SIGNAL(valueChanged(const QString&)),
117 this, SLOT(subValueChanged()));
118 connect(hourKey, SIGNAL(valueChanged(const QString&)),
119 this, SLOT(subValueChanged()));
120 connect(ampm, SIGNAL(activated(int)),
121 this, SLOT(subValueChanged()));
122}
123
124
125TimeEdit::~TimeEdit() {}
126
127QTime TimeEdit::time() const
128{
129 int s,m,h;
130
131 s = secondKey->text().toInt();
132 m = minuteKey->text().toInt();
133 h = hourKey->text().toInt();
134
135 if(ampm->currentItem() == 1) {
136 /* pm */
137 h = h + 12;
138 }
139 /* hour now ranges 1->24 */
140
141 if (h == 12)
142 h = 0;
143 if (h == 24)
144 h = 12;
145
146 if(QTime::isValid(h, m, s))
147 return QTime(h, m, s);
148 return QTime(0, 0, 0);
149}
150
151void TimeEdit::setTime(QTime t)
152{
153 int h = t.hour();
154 secondKey->setValue(t.second());
155 minuteKey->setValue(t.minute());
156
157 /* h 0..23 */
158 if (h > 11) {
159 h -= 12;
160 ampm->setCurrentItem(1);
161 } else {
162 ampm->setCurrentItem(0);
163 }
164
165 if (h == 0) h = 12;
166 hourKey->setValue(h);
167}
168
169QSizePolicy TimeEdit::sizePolicy() const
170{
171 QSizePolicy sp;
172 sp.setHorData(QSizePolicy::Preferred);
173 sp.setVerData(QSizePolicy::Fixed);
174
175 return sp;
176}
177
178void TimeEdit::clear()
179{
180 secondKey->setValue(0);
181 minuteKey->setValue(0);
182 hourKey->setValue(12);
183
184 ampm->setCurrentItem(0);
185}
186
187void TimeEdit::subValueChanged()
188{
189 emit valueChanged(time());
190}
191
192IntEdit::IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 )
193 : QSpinBox(INT_MIN, INT_MAX, 1, parent, name)
194{
195 setValue(0);
196}
197
198
199IntEdit::~IntEdit() {}
200
201int IntEdit::value()
202{
203 return cleanText().toInt();
204}
205
206void IntEdit::clear()
207{
208 setValue(0);
209}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Dateedit_H
21#define Dateedit_H
22
23#include <qwidget.h>
24#include <qdatetime.h>
25
26/* inherited classes */
27#include <qtoolbutton.h>
28#include <qspinbox.h>
29
30class DateBookMonth;
31class QComboBox;
32
33class DateEdit : public QToolButton
34{
35 Q_OBJECT
36
37public:
38 DateEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
39 ~DateEdit();
40
41 QDate date() const;
42 void setDate(QDate);
43
44 QSizePolicy sizePolicy() const;
45signals:
46 void valueChanged(const QDate &);
47
48public slots:
49 void clear();
50private slots:
51 void subValueChanged();
52
53private:
54 DateBookMonth *dateSelector;
55};
56
57class TimeEdit : public QWidget
58{
59 Q_OBJECT
60
61public:
62 TimeEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
63 ~TimeEdit();
64
65 QTime time() const;
66 void setTime(QTime);
67
68 QSizePolicy sizePolicy() const;
69signals:
70 void valueChanged(const QTime &);
71
72public slots:
73 void clear();
74private slots:
75 void subValueChanged();
76
77private:
78 QSpinBox *secondKey;
79 QSpinBox *minuteKey;
80 QSpinBox *hourKey;
81 QComboBox *ampm;
82};
83
84/* more for consistency than need */
85class IntEdit : public QSpinBox
86{
87 Q_OBJECT
88
89public:
90 IntEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
91 ~IntEdit();
92
93 int value();
94
95public slots:
96 void clear();
97};
98#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "filterkeyentry.h"
21#include "commonwidgets.h"
22
23#include <qwidgetstack.h>
24#include <qcombobox.h>
25#include <qlayout.h>
26#include <qlineedit.h>
27#include <qsizepolicy.h>
28#include <qdatetime.h>
29#include <qhbox.h>
30
31TVFilterKeyEntry::TVFilterKeyEntry(QWidget *parent, const char *name, WFlags f)
32 : QWidget(parent, name, f)
33{
34 int stack_elem = 0;
35
36 layout = new QHBoxLayout(this, 0);
37 layout->setSpacing(0);
38 layout->setMargin(0);
39
40 textEntry = new QHBox(this, 0);
41 textEntry->setSpacing(0);
42 textEntry->setMargin(0);
43
44 intEntry = new QHBox(this, 0);
45 intEntry->setSpacing(0);
46 intEntry->setMargin(0);
47
48 timeEntry = new QHBox(this, 0);
49 timeEntry->setSpacing(0);
50 timeEntry->setMargin(0);
51
52 dateEntry = new QHBox(this, 0);
53 dateEntry->setSpacing(0);
54 dateEntry->setMargin(0);
55
56 textCombo = new QComboBox(textEntry, 0);
57 textKey = new QLineEdit(textEntry, 0);
58
59 /* Build the text combo list */
60 textCombo->insertItem("less than");
61 textCombo->insertItem("more than");
62 textCombo->insertItem("equal to");
63 textCombo->insertItem("containing");
64 textCombo->insertItem("starting with");
65 textCombo->insertItem("ending with");
66
67 intCombo = new QComboBox(intEntry, 0);
68 intKey = new IntEdit(intEntry, 0);
69
70 /* Build the int combo list */
71 intCombo->insertItem("less than");
72 intCombo->insertItem("more than");
73 intCombo->insertItem("equal to");
74
75 timeCombo = new QComboBox(timeEntry, 0);
76 timeKey = new TimeEdit(timeEntry, 0);
77
78 /* Build the time combo list */
79 timeCombo->insertItem("less than");
80 timeCombo->insertItem("more than");
81 timeCombo->insertItem("equal to");
82
83 dateCombo = new QComboBox(dateEntry, 0);
84 dateKey = new DateEdit(dateEntry, 0);
85
86 /* Build the date combo list */
87 dateCombo->insertItem("less than");
88 dateCombo->insertItem("more than");
89 dateCombo->insertItem("equal to");
90
91 ts = 0;
92
93 ws = new QWidgetStack(this, 0);
94 ws->setMargin(0);
95 ws->addWidget(textEntry, TVVariant::String);
96 ws->addWidget(intEntry, TVVariant::Int);
97 ws->addWidget(timeEntry, TVVariant::Time);
98 ws->addWidget(dateEntry, TVVariant::Date);
99
100 /* connect the signals down */
101 connect(textKey, SIGNAL(textChanged(const QString&)),
102 this, SIGNAL(valueChanged()));
103 connect(intKey, SIGNAL(valueChanged(int)),
104 this, SIGNAL(valueChanged()));
105 connect(dateKey, SIGNAL(valueChanged(const QDate&)),
106 this, SIGNAL(valueChanged()));
107 connect(timeKey, SIGNAL(valueChanged(const QTime&)),
108 this, SIGNAL(valueChanged()));
109
110 connect(intCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
111 connect(textCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
112 connect(timeCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
113 connect(dateCombo, SIGNAL(activated(int)), this, SIGNAL(valueChanged()));
114
115 ws->raiseWidget(TVVariant::String);
116 layout->addWidget(ws);
117
118 current_type = TVVariant::String;
119}
120
121/*!
122 Destructs the widget
123*/
124TVFilterKeyEntry::~TVFilterKeyEntry()
125{
126}
127
128void TVFilterKeyEntry::setKey(int i)
129{
130
131 if (!ts) return;
132 if (!ts->kRep) return;
133
134 /* set up to raise appropriate widget set */
135 if (current_type != ts->kRep->getKeyType(i)) {
136 current_type = ts->kRep->getKeyType(i);
137 ws->raiseWidget(current_type);
138 }
139}
140
141void TVFilterKeyEntry::setTableState(TableState *t) {
142 int i;
143 ts = t;
144 if(!t) return;
145 if (!t->kRep)
146 return;
147 if (t->kRep->getNumFields() < 1)
148 return;
149 setKey(0);
150 /* set up the the menu stuff.. */
151}
152
153CmpType TVFilterKeyEntry::getCompareType()
154{
155
156 switch(current_type) {
157 case TVVariant::String: {
158 CmpType k = (CmpType) textCombo->currentItem();
159 return k;
160 }
161 case TVVariant::Int: {
162 CmpType k = (CmpType) intCombo->currentItem();
163 return k;
164 }
165 case TVVariant::Time: {
166 CmpType k = (CmpType) timeCombo->currentItem();
167 return k;
168 }
169 case TVVariant::Date: {
170 CmpType k = (CmpType) dateCombo->currentItem();
171 return k;
172 }
173 default:
174 break;
175 }
176 return ct_equal;
177}
178
179/* MUST return a valid pointer */
180TVVariant TVFilterKeyEntry::getCompareValue()
181{
182 TVVariant sendkey;
183 int tmp;
184
185 switch(current_type) {
186 case TVVariant::String:
187 sendkey = TVVariant(QString(textKey->text()));
188 break;
189 case TVVariant::Int: {
190 sendkey = TVVariant(intKey->value());
191 break;
192 }
193 case TVVariant::Time: {
194 sendkey = TVVariant(QTime(timeKey->time()));
195 break;
196 }
197 case TVVariant::Date: {
198 sendkey = TVVariant(QDate(dateKey->date()));
199 break;
200 }
201 default: {
202 sendkey = TVVariant(0);
203 qWarning("TVFilterKeyEntry::getCompareValue() "
204 "cannot work out data type");
205 }
206 }
207 return sendkey;
208}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef FilterKeyEntry_H
21#define FilterKeyEntry_H
22
23#include <qwidget.h>
24#include <qhbox.h>
25#include <qlayout.h>
26#include "../db/common.h"
27
28/* Forward class declarations */
29class QWidgetStack;
30class QToolButton;
31class QLineEdit;
32class DateEdit;
33class TimeEdit;
34class IntEdit;
35class QPopupMenu;
36class QComboBox;
37
38typedef enum _CmpType {
39 ct_less = 0,
40 ct_more,
41 ct_equal,
42 ct_contains,
43 ct_startswith,
44 ct_endswith
45} CmpType;
46
47
48class TVFilterKeyEntry: public QWidget
49{
50 Q_OBJECT
51public:
52 TVFilterKeyEntry( QWidget *parent = 0,
53 const char *name = 0, WFlags f = 0 );
54 ~TVFilterKeyEntry();
55
56 void setTableState(TableState *t);
57 void setKey(int i);
58
59 CmpType getCompareType();
60 TVVariant getCompareValue();
61
62signals:
63 void valueChanged();
64
65private:
66 /* include widgets for each type of data entry you need here. */
67 QLineEdit *textKey;
68 QComboBox *textCombo;
69 QHBox *textEntry;
70
71 IntEdit *intKey;
72 QComboBox *intCombo;
73 QHBox *intEntry;
74
75 TimeEdit *timeKey;
76 QComboBox *timeCombo;
77 QHBox *timeEntry;
78
79 DateEdit *dateKey;
80 QComboBox *dateCombo;
81 QHBox *dateEntry;
82
83 TableState *ts;
84
85 /* each type of possible data entry will be put on the stack */
86 QWidgetStack *ws;
87
88 /* This allows for the inherited functions dealing with prefered size
89 * etc to simply get the information from the layout.
90 */
91 QHBoxLayout *layout;
92
93 TVVariant::KeyType current_type;
94};
95
96#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvbrowseview.h"
21#include "browsekeyentry.h"
22#include <qtoolbutton.h>
23#include <qtextview.h>
24#include <qtextbrowser.h>
25#include <qlayout.h>
26
27/*!
28 \class TVBrowseView
29 \brief The widget describing how to draw the browse view user interface
30
31 This widget allows for the user to browse through the table, one element
32 at a time, or search on a single key. Its main goal is to show a
33 single element in a readable format and make it easy for the user to
34 rapidly find specific elements in the table.
35*/
36
37/*!
38 Constructs a new TVBrowseView widget
39*/
40TVBrowseView::TVBrowseView(TableState *t, QWidget* parent = 0, const char *name = 0,
41 WFlags fl =0)
42{
43 if (!name)
44 setName("BrowseView");
45
46 setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding, 0, 0, sizePolicy().hasHeightForWidth() ) );
47 QVBoxLayout *vlayout = new QVBoxLayout(this);
48 textViewDisplay = new QTextBrowser(this, "textViewDisplay");
49 vlayout->addWidget( textViewDisplay );
50
51 keyEntry = new TVBrowseKeyEntry(this, "keyEntry");
52 vlayout->addWidget( keyEntry );
53
54 /* connect the signals down */
55
56 connect(keyEntry, SIGNAL(searchOnKey(int, TVVariant)),
57 this, SIGNAL(searchOnKey(int, TVVariant)));
58 connect(keyEntry, SIGNAL(sortChanged(int)),
59 this, SIGNAL(sortChanged(int)));
60
61 ts = t;
62 keyEntry->setTableState(t);
63}
64
65/*!
66 Destroys the TVBrowseView widget
67*/
68TVBrowseView::~TVBrowseView()
69{
70}
71
72void TVBrowseView::rebuildData()
73{
74 if(!ts)
75 return;
76 if(!ts->current_elem) {
77 /* also disable buttons */
78 textViewDisplay->setText("");
79 return;
80 }
81
82 setDisplayText(ts->current_elem);
83}
84
85/* Reset to initial state */
86void TVBrowseView::reset()
87{
88 textViewDisplay->setText("");
89 keyEntry->reset();
90}
91
92/*!
93 sets the data element to be displayed to element
94*/
95void TVBrowseView::setDisplayText(const DataElem *element)
96{
97 QString rep = "";
98
99 KeyListIterator it(*ts->kRep);
100
101 while (it.current()) {
102 if (element->hasValidValue(it.currentKey())) {
103 if(it.currentKey() == ts->current_column) {
104 rep += "<A name=\"ckey\"></A><B><FONT COLOR=#FF0000>"
105 + it.current()->name()
106 + ":</FONT></B> ";
107 } else {
108 rep += "<B>" + it.current()->name() + ":</B> ";
109 }
110 rep += element->toQString(it.currentKey()) + "<BR>";
111 }
112 ++it;
113 }
114
115 textViewDisplay->setText(rep);
116 textViewDisplay->scrollToAnchor("ckey");
117}
118
119void TVBrowseView::rebuildKeys()
120{
121 keyEntry->rebuildKeys();
122}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvbrowseview_H
21#define Tvbrowseview_H
22
23#include "../db/common.h"
24#include <qwidget.h>
25
26class QTextBrowser;
27class TVBrowseKeyEntry;
28
29class TVBrowseView : public QWidget
30{
31 Q_OBJECT
32
33signals:
34 void searchOnKey(int keyIndex, TVVariant keyValue);
35 void sortChanged(int);
36
37public:
38 TVBrowseView(TableState *t, QWidget* parent = 0,
39 const char* name = 0, WFlags fl = 0);
40 ~TVBrowseView();
41
42 /* Access Methods */
43 void setDisplayText(const DataElem *);
44 void rebuildKeys();
45 void rebuildData();
46 void reset();
47
48private:
49 TableState *ts;
50
51 QTextBrowser* textViewDisplay;
52 TVBrowseKeyEntry *keyEntry;
53};
54
55#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22/* The edit view widget. For each key in the DB display an
23 * appropriate edit box, and a 'key' button to change that particular
24 * key information (delete or edit).
25 *
26 * Bottem line should be a 'new key' button. Should be able to scroll
27 * in both directions.
28 */
29
30#include "tveditview.h"
31#include "commonwidgets.h"
32
33#include <qlayout.h>
34#include <qgrid.h>
35#include <qvbox.h>
36#include <qlineedit.h>
37#include <qcheckbox.h>
38#include <qlist.h>
39#include <qlabel.h>
40#include <qscrollview.h>
41#include <qsignalmapper.h>
42
43TVEditView::TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
44 const char *name = 0, WFlags fl =0) : QDialog(parent, name, true, fl)
45{
46 if (!name)
47 setName("TVEditView");
48
49 QVBoxLayout *layout = new QVBoxLayout(this, 0); /* only so that will resize
50 correctly in other
51 widgets */
52
53 toggles = new QSignalMapper(this);
54 QScrollView *sv = new QScrollView(this, 0);
55 sv->setResizePolicy(QScrollView::AutoOneFit);
56
57 layout->addWidget(sv);
58
59 editDisplay = new QGrid(3, sv, 0);
60 editDisplay->setSpacing(3);
61 sv->addChild(editDisplay);
62
63 connect(toggles, SIGNAL(mapped(int)), this, SLOT(toggleEnabled(int)));
64
65 setData(s, d);
66#ifdef Q_WS_QWS
67 showMaximized();
68#endif
69}
70
71TVEditView::~TVEditView()
72{
73}
74
75/*! set up the widgets in the grid, Set up initial values */
76void TVEditView::setData(TableState *t, DataElem *d)
77{
78
79 /* TODO need to somehow clear old children... a delete of each
80 * child? */
81 keyIds.clear();
82
83 KeyListIterator it(*t->kRep);
84
85 int i = 0;
86 while(it.current()) {
87 if (t->kRep->validIndex(it.currentKey())) {
88 new QLabel(it.current()->name(), editDisplay);
89 keyIds.insert(i, it.currentKey());
90 if (d->hasValidValue(it.currentKey())) {
91 switch(it.current()->type()) {
92 case TVVariant::String: {
93 QLineEdit *edit = new QLineEdit(editDisplay, 0);
94 edit->setText(d->getField(it.currentKey()).toString());
95 edits.append(edit);
96 break;
97 }
98 case TVVariant::Int: {
99 IntEdit *edit = new IntEdit(editDisplay, 0);
100 edit->setValue(d->getField(it.currentKey()).toInt());
101 edits.append(edit);
102 break;
103 }
104 case TVVariant::Time: {
105 TimeEdit *edit = new TimeEdit(editDisplay, 0);
106 edit->setTime(d->getField(it.currentKey()).toTime());
107 edits.append(edit);
108 break;
109 }
110 case TVVariant::Date: {
111 DateEdit *edit = new DateEdit(editDisplay, 0);
112 edit->setDate(d->getField(it.currentKey()).toDate());
113 edits.append(edit);
114 break;
115 }
116 default:
117 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
118 }
119 QCheckBox *tb = new QCheckBox(editDisplay);
120 tb->setChecked(TRUE);
121 toggles->setMapping(tb, i);
122 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
123 buttons.append(tb);
124 } else {
125 /* No valid value.. set to null */
126 switch(it.current()->type()) {
127 case TVVariant::String: {
128 QLineEdit *edit = new QLineEdit(editDisplay, 0);
129 edit->setEnabled(false);
130 edits.append(edit);
131 break;
132 }
133 case TVVariant::Int: {
134 IntEdit *edit = new IntEdit(editDisplay, 0);
135 edit->setEnabled(false);
136 edits.append(edit);
137 break;
138 }
139 case TVVariant::Time: {
140 TimeEdit *edit = new TimeEdit(editDisplay, 0);
141 edit->setEnabled(false);
142 edits.append(edit);
143 break;
144 }
145 case TVVariant::Date: {
146 DateEdit *edit = new DateEdit(editDisplay, 0);
147 edit->setEnabled(false);
148 edits.append(edit);
149 break;
150 }
151 default:
152 edits.append(new QLabel("<B><I>Uknown key type</I></B>", editDisplay));
153 }
154 QCheckBox *tb = new QCheckBox(editDisplay);
155 tb->setChecked(FALSE);
156 toggles->setMapping(tb, i);
157 connect(tb, SIGNAL(clicked()), toggles, SLOT(map()));
158 buttons.append(tb);
159 }
160 i++;
161 }
162 ++it;
163 }
164 num_edits = i;
165}
166
167void TVEditView::toggleEnabled(int i) {
168
169 if(edits.at(i)->isEnabled()) {
170 edits.at(i)->setEnabled(false);
171 buttons.at(i)->setChecked(FALSE);
172 } else {
173 edits.at(i)->setEnabled(true);
174 buttons.at(i)->setChecked(TRUE);
175 }
176}
177
178bool TVEditView::openEditItemDialog(TableState *ts, DataElem *d,
179 QWidget *parent)
180{
181 int i;
182 int keyId;
183
184 if(!ts) return 0;
185 if(!d) return 0;
186 if(!ts->kRep) return 0;
187
188 TVEditView *dlg = new TVEditView(ts, d, parent);
189
190 if (dlg->exec() == QDialog::Accepted ) {
191 /* update the element, basically for each
192 edits, if isEnabled, set Value, else unsetField */
193
194 for(i = 0; i < dlg->num_edits; i++) {
195 keyId = dlg->keyIds[i];
196 if(dlg->edits.at(i)->isEnabled()) {
197 switch(d->getFieldType(keyId)) {
198 case TVVariant::String: {
199 TVVariant value = TVVariant(
200 ((QLineEdit *)dlg->edits.at(i))->text());
201 d->setField(keyId, value);
202 break;
203 }
204 case TVVariant::Int: {
205 TVVariant value = TVVariant(
206 ((IntEdit *)dlg->edits.at(i))->value());
207 d->setField(keyId, value);
208 break;
209 }
210 case TVVariant::Time: {
211 TVVariant value = TVVariant(
212 ((TimeEdit *)dlg->edits.at(i))->time());
213 d->setField(keyId, value);
214 break;
215 }
216 case TVVariant::Date: {
217 TVVariant value = TVVariant(
218 ((DateEdit *)dlg->edits.at(i))->date());
219 d->setField(keyId, value);
220 break;
221 }
222 default:
223 break;
224 }
225 } else {
226 /* unset the field */
227 d->unsetField(keyId);
228 }
229 }
230 delete dlg;
231 return TRUE;
232 }
233
234 return FALSE;
235}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef Tveditview_H
22#define Tveditview_H
23
24#include <qwidget.h>
25#include <qlist.h>
26#include <qdialog.h>
27#include <qmap.h>
28#include "../db/common.h"
29
30class QGrid;
31class QSignalMapper;
32class QCheckBox;
33
34class TVEditView : public QDialog
35{
36 Q_OBJECT
37
38public:
39 TVEditView(TableState *s, DataElem *d, QWidget* parent = 0,
40 const char* name = 0, WFlags fl = 0);
41 ~TVEditView();
42
43 static bool openEditItemDialog(TableState *s, DataElem *d, QWidget *parent);
44
45protected slots:
46 void toggleEnabled(int);
47
48protected:
49
50 void setData(TableState *s, DataElem *d);
51
52 QGrid *editDisplay;
53 QList<QWidget> edits;
54 QList<QCheckBox> buttons;
55 QSignalMapper *toggles;
56
57 QMap<int,int> keyIds;
58
59 int num_edits;
60};
61
62#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvfilterview.h"
21#include <qtoolbutton.h>
22#include <qcombobox.h>
23#include <qlistview.h>
24#include <qlayout.h>
25#include <qheader.h>
26#include <qpushbutton.h>
27#include <qlabel.h>
28
29TVFilterView::TVFilterView(TableState *t, QWidget* parent = 0,
30 const char *name = 0, WFlags fl =0) : QDialog(parent, name, TRUE, fl)
31{
32 if ( !name )
33 setName( "Filter View" );
34
35 QVBoxLayout *vlayout = new QVBoxLayout(this);
36
37 display = new QListView(this, "display");
38 display->addColumn("Key");
39 display->addColumn("Constraint");
40 display->addColumn("Value");
41 display->header()->setClickEnabled(FALSE);
42 display->header()->setResizeEnabled(FALSE);
43
44 vlayout->addWidget(display);
45
46 QHBoxLayout *hlayout = new QHBoxLayout;
47 hlayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
48
49 newFilterButton = new QPushButton(this, "new Filter");
50 newFilterButton->setMaximumSize(QSize(50, 32767));
51 newFilterButton->setText("New");
52 hlayout->addWidget(newFilterButton);
53
54 deleteFilterButton = new QPushButton(this, "delete Filter");
55 deleteFilterButton->setMaximumSize(QSize(50, 32767));
56 deleteFilterButton->setText("Delete");
57 hlayout->addWidget(deleteFilterButton);
58
59 clearFilterButton = new QPushButton(this, "delete Filter");
60 clearFilterButton->setMaximumSize(QSize(60, 32767));
61 clearFilterButton->setText("Clear All");
62 hlayout->addWidget(clearFilterButton);
63
64 vlayout->addLayout(hlayout);
65
66 QHBoxLayout *hlayout2 = new QHBoxLayout;
67
68 keyNameCombo = new QComboBox(FALSE, this, "key name");
69 keyNameCombo->setEnabled(FALSE);
70 hlayout2->addWidget(keyNameCombo);
71
72 QLabel *label = new QLabel(this);
73 label->setText("has value");
74 hlayout2->addWidget(label);
75
76 keyEntry = new TVFilterKeyEntry(this, "key entry");
77 keyEntry->setEnabled(FALSE);
78
79 vlayout->addLayout(hlayout2);
80 vlayout->addWidget(keyEntry);
81
82 connect(newFilterButton, SIGNAL( clicked() ), this, SLOT( newTerm() ));
83 connect(deleteFilterButton, SIGNAL( clicked() ), this, SLOT( deleteTerm()));
84 connect(clearFilterButton, SIGNAL( clicked() ), this, SLOT( clearTerms()));
85
86 connect(keyEntry, SIGNAL(valueChanged()), this, SLOT( updateTerm() ));
87 connect(keyNameCombo, SIGNAL(activated(int)), this, SLOT( updateTerm() ));
88
89 connect(display, SIGNAL(selectionChanged(QListViewItem*)), this,
90 SLOT(setTerm(QListViewItem *)));
91
92 ts = t;
93 current = 0;
94 terms.setAutoDelete(true);
95 do_filter = false;
96
97#ifdef Q_WS_QWS
98 showMaximized();
99#endif
100}
101
102/*!
103 Destroys the TVFilterView widget
104*/
105TVFilterView::~TVFilterView()
106{
107}
108
109void TVFilterView::rebuildData()
110{
111}
112
113void TVFilterView::reset()
114{
115 keyNameCombo->clear();
116 keyIds.clear();
117}
118
119void TVFilterView::rebuildKeys()
120{
121 int i;
122
123 if (!ts) return;
124 if(!ts->kRep) return;
125 keyEntry->setTableState(ts);
126
127 /* set up the list of keys that can be compared on */
128 keyNameCombo->clear();
129 KeyListIterator it(*ts->kRep);
130
131 i = 0;
132 while(it.current()) {
133 if(ts->kRep->validIndex(it.currentKey())) {
134 keyNameCombo->insertItem(it.current()->name());
135 keyIds.insert(i, it.currentKey());
136 ++i;
137 }
138 ++it;
139 }
140}
141
142bool TVFilterView::passesFilter(DataElem *d) {
143 if (!filterActive()) return true;
144
145
146 FilterTerm *t;
147
148 for (t = terms.first(); t != 0; t = terms.next() ) {
149 /* check against filter */
150 switch(t->ct) {
151 case ct_less:
152 if (!d->lessThan(t->keyIndex, t->value))
153 return false;
154 break;
155 case ct_more:
156 if (!d->moreThan(t->keyIndex, t->value))
157 return false;
158 break;
159 case ct_equal:
160 if (!d->equalTo(t->keyIndex, t->value))
161 return false;
162 break;
163 case ct_contains:
164 if (!d->contains(t->keyIndex, t->value))
165 return false;
166 break;
167 case ct_startswith:
168 if (!d->startsWith(t->keyIndex, t->value))
169 return false;
170 break;
171 case ct_endswith:
172 if (!d->endsWith(t->keyIndex, t->value))
173 return false;
174 break;
175 default:
176 qWarning("TVFilterView::passesFilter() "
177 "unrecognized filter type");
178 return false;
179 }
180 }
181 return true;
182}
183
184bool TVFilterView::filterActive() const
185{
186 /* when button operated, also check the do_filter value
187 return do_filter;
188 */
189 if (terms.isEmpty())
190 return false;
191 return true;
192}
193
194/* SLOTS */
195void TVFilterView::newTerm()
196{
197 if (!ts) return;
198
199 FilterTerm *term = new FilterTerm;
200 current = term;
201
202 term->view = 0;
203
204 updateTerm();
205
206 display->setSelected(term->view, true);
207 terms.append(term);
208
209 keyEntry->setEnabled(true);
210 keyNameCombo->setEnabled(true);
211}
212
213void TVFilterView::updateTerm()
214{
215 FilterTerm *term;
216 /* Read the widget values (keyname, compare type, value)
217 * and build the lists */
218 if (!ts) return;
219 if (!current) return;
220
221 QString keyString;
222 QString cmpString;
223 QString vString;
224
225 term = current;
226
227 /* create new list item, set initial values, enable widgets */
228 term->keyIndex = keyIds[keyNameCombo->currentItem()];
229 keyEntry->setKey(term->keyIndex); /* so the next two items make sense */
230 term->ct = keyEntry->getCompareType(),
231 term->value = keyEntry->getCompareValue();
232
233 keyString = keyNameCombo->currentText();
234
235 switch(term->ct) {
236 case ct_less:
237 cmpString = " less than ";
238 break;
239 case ct_more:
240 cmpString = " more than ";
241 break;
242 case ct_equal:
243 cmpString = " equal to ";
244 break;
245 case ct_contains:
246 cmpString = " containing ";
247 break;
248 case ct_startswith:
249 cmpString = " starting with ";
250 break;
251 case ct_endswith:
252 cmpString = " ending with ";
253 break;
254 default:
255 cmpString = " ERROR ";
256 }
257
258 vString = term->value.toString();
259
260 /* remove old view */
261 if (term->view)
262 delete(term->view);
263 term->view = new QListViewItem(display, 0, keyString, cmpString, vString);
264 display->setSelected(term->view, true);
265}
266
267/* deletes current term */
268void TVFilterView::deleteTerm()
269{
270 if(!current) return;
271 if (current->view)
272 delete(current->view);
273
274 terms.removeRef(current);
275
276 current = terms.first();
277
278 if(terms.isEmpty()) {
279 keyEntry->setEnabled(false);
280 keyNameCombo->setEnabled(false);
281 }
282}
283
284/* clears all terminations */
285void TVFilterView::clearTerms()
286{
287 while(current)
288 deleteTerm();
289}
290
291void TVFilterView::setTerm(QListViewItem *target)
292{
293 /* Iterate through the list to find item with view=target..
294 * set as current, delete */
295 FilterTerm *term = current;
296
297 for (current = terms.first(); current != 0; current = terms.next() )
298 if (current->view == target)
299 break;
300
301 if (!current) {
302 current = term;
303 }
304}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvfilterview_H
21#define Tvfilterview_H
22
23#include "filterkeyentry.h"
24#include "../db/common.h"
25#include <qlist.h>
26#include <qmap.h>
27#include <qdialog.h>
28
29class QListViewItem;
30class QPushButton;
31class QListView;
32class TVFilterKeyEntry;
33
34class TVFilterView : public QDialog
35{
36 Q_OBJECT
37
38signals:
39 void editView();
40 void listView();
41 void browseView();
42 void loadFile();
43
44protected slots:
45 void newTerm();
46 void deleteTerm();
47 void clearTerms();
48 void updateTerm();
49 void setTerm(QListViewItem *);
50
51public:
52 TVFilterView(TableState *t, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
53 ~TVFilterView();
54
55 /* Access Methods */
56 void rebuildKeys();
57 void rebuildData();
58 void reset();
59
60 bool passesFilter(DataElem *d);
61 bool filterActive() const; /* return true if and only if filtering is on */
62
63 QListView* display;
64 QPushButton* newFilterButton;
65 QPushButton* deleteFilterButton;
66 QPushButton* clearFilterButton;
67 QComboBox* keyNameCombo;
68
69 TVFilterKeyEntry* keyEntry;
70private:
71
72 typedef struct _FilterTerm {
73 int keyIndex;
74 CmpType ct;
75 TVVariant value;
76 QListViewItem *view;
77 } FilterTerm;
78
79 QList<FilterTerm> terms;
80 FilterTerm *current;
81 bool do_filter;
82
83 TableState *ts;
84
85 QMap<int, int> keyIds;
86};
87
88#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvkeyedit.h"
21#include <qtoolbutton.h>
22#include <qlineedit.h>
23#include <qcombobox.h>
24#include <qlistview.h>
25#include <qmessagebox.h>
26#include <stdlib.h>
27#include <qpushbutton.h>
28
29/* QList view item... ?? that can store and update the values that I will
30 * be changing */
31
32class TVKEListViewItem : public QListViewItem
33{
34public:
35 TVKEListViewItem(QString n, TVVariant::KeyType kt, int p, QListView *parent) :
36 QListViewItem(parent)
37 {
38 name = n;
39 keyType = kt;
40 position = p;
41 }
42
43 QString text(int i) const
44 {
45 if(i) {
46 return TVVariant::typeToName(keyType);
47 }
48 return name;
49 }
50
51 /* always sort by key index, ignore i */
52 QString key(int, bool) const
53 {
54 return QString().sprintf("%08d", position);
55 }
56
57 void setText(int i, const QString &)
58 {
59 ;
60 }
61
62 QString getName() const
63 {
64 return name;
65 }
66
67 void setName(QString n)
68 {
69 name = n;
70 repaint();
71 }
72
73 TVVariant::KeyType getKeyType() const
74 {
75 return keyType;
76 }
77
78 void setKeyType(TVVariant::KeyType k)
79 {
80 keyType = k;
81 repaint();
82 }
83
84 inline int getPos() const
85 {
86 return position;
87 }
88
89private:
90 QString name;
91 TVVariant::KeyType keyType;
92 int position;
93};
94
95TVKeyEdit::TVKeyEdit(TableState *t, QWidget* parent = 0, const char *name = 0,
96 WFlags fl = 0) : TVKeyEdit_gen(parent, name, true, fl)
97{
98 int i;
99 ts = t;
100
101 if(!ts) return;
102 if(!ts->kRep) return;
103
104 working_state = *ts->kRep;
105
106 i = 1;
107 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
108 i++;
109 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
110 i++;
111 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
112 i++;
113 keyTypeEdit->insertItem(TVVariant::typeToName((TVVariant::KeyType)i));
114
115 KeyListIterator it(*ts->kRep);
116 while(it.current()) {
117 if(t->kRep->validIndex(it.currentKey())) {
118 new TVKEListViewItem(it.current()->name(),
119 it.current()->type(),
120 it.currentKey(),
121 display);
122 }
123 ++it;
124 }
125 num_keys = ts->kRep->getNumFields();
126 if(display->childCount() > 0) {
127 display->setCurrentItem(display->firstChild());
128 setTerm(display->currentItem());
129 } else {
130 deleteKeyButton->setEnabled(FALSE);
131 clearKeysButton->setEnabled(FALSE);
132 keyNameEdit->setEnabled(FALSE);
133 keyTypeEdit->setEnabled(FALSE);
134 }
135
136 display->setSorting(0);
137#ifdef Q_WS_QWS
138 showMaximized();
139#endif
140}
141
142/*!
143 Destroys the TVKeyEdit widget
144*/
145TVKeyEdit::~TVKeyEdit()
146{
147}
148
149/* SLOTS */
150void TVKeyEdit::newTerm()
151{
152 /* new item, make current Item */
153 int i;
154
155 i = working_state.addKey("<New Key>", TVVariant::String);
156 //working_state.setNewFlag(i, TRUE);
157 TVKEListViewItem *nItem = new TVKEListViewItem("<New Key>",
158 TVVariant::String,
159 i,
160 display);
161 display->setCurrentItem(nItem);
162 setTerm(nItem);
163
164 num_keys++;
165 if(display->childCount() == 1) {
166 deleteKeyButton->setEnabled(TRUE);
167 clearKeysButton->setEnabled(TRUE);
168 keyNameEdit->setEnabled(TRUE);
169 keyTypeEdit->setEnabled(TRUE);
170 }
171}
172
173void TVKeyEdit::updateTerm(const QString &newName)
174{
175 /* TODO if name matches a deleted term, prompt for
176 renewing old data instead */
177 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
178 if(i) {
179 i->setName(newName);
180 working_state.setKeyName(i->getPos(), newName);
181 }
182}
183
184void TVKeyEdit::updateTerm(int t)
185{
186 /* t is an index to a combo in a menu, NOT a type */
187 t++; /* menu counts from 0, types count from 1 */
188 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
189 if (i) {
190 i->setKeyType((TVVariant::KeyType)t);
191 working_state.setKeyType(i->getPos(), (TVVariant::KeyType)t);
192 }
193}
194
195/* deletes current term
196 * really just marks key as deleted so is now invalid.
197 * the actual delete will happen when data is 'cleaned'
198 * or when file is saved.
199 */
200
201void TVKeyEdit::deleteTerm()
202{
203 TVKEListViewItem *i = (TVKEListViewItem *)display->currentItem();
204 if (i) {
205 working_state.setDeleteFlag(i->getPos(), TRUE);
206 delete i;
207 }
208 if(!display->childCount()) {
209 /* disable the delete and clear buttons, etc */
210 deleteKeyButton->setEnabled(FALSE);
211 clearKeysButton->setEnabled(FALSE);
212 keyNameEdit->setEnabled(FALSE);
213 keyTypeEdit->setEnabled(FALSE);
214 }
215}
216
217/* clears all terminations */
218void TVKeyEdit::clearTerms()
219{
220 /* should pop up a warning */
221 if (QMessageBox::warning(this, "Delete all keys",
222 "Are you sure you want to\ndelete all the keys?",
223 "Yes", "No") == 0)
224 {
225 while(display->currentItem())
226 deleteTerm();
227 }
228}
229
230void TVKeyEdit::setTerm(QListViewItem *target)
231{
232 /* need to update the widgets to show keys values */
233 keyNameEdit->setText(((TVKEListViewItem *)target)->getName());
234 int t = (int)(((TVKEListViewItem *)target)->getKeyType());
235 t--;
236 keyTypeEdit->setCurrentItem(t);
237}
238
239KeyList* TVKeyEdit::openEditKeysDialog(TableState *t, QWidget *parent = 0)
240{
241 if(!t)
242 return 0;
243 if(!t->kRep)
244 return 0;
245
246 TVKeyEdit *dlg = new TVKeyEdit(t, parent);
247
248 if ((dlg->exec() == QDialog::Accepted) &&
249 (dlg->working_state != *t->kRep))
250 {
251 return (new KeyList(dlg->working_state));
252 }
253 return 0;
254}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef Tvkeyedit_H
21#define Tvkeyedit_H
22
23#include "tvkeyedit_gen.h"
24#include "../db/common.h"
25
26class TVKeyEdit : public TVKeyEdit_gen
27{
28 Q_OBJECT
29
30signals:
31 void listView();
32 void browseView();
33
34protected slots:
35 void newTerm();
36 void deleteTerm();
37 void clearTerms();
38 void updateTerm(int);
39 void updateTerm(const QString &);
40 void setTerm(QListViewItem *);
41
42public:
43 TVKeyEdit(TableState *ts, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
44 ~TVKeyEdit();
45
46
47 static KeyList *openEditKeysDialog(TableState *ts, QWidget *parent);
48
49private:
50
51 TableState *ts;
52 int num_keys;
53 KeyList working_state;
54};
55
56#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 @@
1<!DOCTYPE UI><UI>
2<class>TVKeyEdit_gen</class>
3<comment>Dialog for editing the keys and key types</comment>
4<author>Ian Walters</author>
5<forward>class QListViewItem;</forward>
6<widget>
7 <class>QDialog</class>
8 <property stdset="1">
9 <name>name</name>
10 <cstring>TVKeyEdit_gen</cstring>
11 </property>
12 <property stdset="1">
13 <name>geometry</name>
14 <rect>
15 <x>0</x>
16 <y>0</y>
17 <width>194</width>
18 <height>418</height>
19 </rect>
20 </property>
21 <property stdset="1">
22 <name>caption</name>
23 <string>TableViewer - Edit Keys</string>
24 </property>
25 <vbox>
26 <property stdset="1">
27 <name>margin</name>
28 <number>0</number>
29 </property>
30 <property stdset="1">
31 <name>spacing</name>
32 <number>0</number>
33 </property>
34 <widget>
35 <class>QListView</class>
36 <column>
37 <property>
38 <name>text</name>
39 <string>Key Name</string>
40 </property>
41 <property>
42 <name>clickable</name>
43 <bool>false</bool>
44 </property>
45 <property>
46 <name>resizeable</name>
47 <bool>false</bool>
48 </property>
49 </column>
50 <column>
51 <property>
52 <name>text</name>
53 <string>Key Type</string>
54 </property>
55 <property>
56 <name>clickable</name>
57 <bool>false</bool>
58 </property>
59 <property>
60 <name>resizeable</name>
61 <bool>false</bool>
62 </property>
63 </column>
64 <property stdset="1">
65 <name>name</name>
66 <cstring>display</cstring>
67 </property>
68 </widget>
69 <widget>
70 <class>QLayoutWidget</class>
71 <property stdset="1">
72 <name>name</name>
73 <cstring>Layout4</cstring>
74 </property>
75 <hbox>
76 <property stdset="1">
77 <name>margin</name>
78 <number>0</number>
79 </property>
80 <property stdset="1">
81 <name>spacing</name>
82 <number>6</number>
83 </property>
84 <spacer>
85 <property>
86 <name>name</name>
87 <cstring>Spacer2</cstring>
88 </property>
89 <property stdset="1">
90 <name>orientation</name>
91 <enum>Horizontal</enum>
92 </property>
93 <property stdset="1">
94 <name>sizeType</name>
95 <enum>Expanding</enum>
96 </property>
97 <property>
98 <name>sizeHint</name>
99 <size>
100 <width>20</width>
101 <height>20</height>
102 </size>
103 </property>
104 </spacer>
105 <widget>
106 <class>QPushButton</class>
107 <property stdset="1">
108 <name>name</name>
109 <cstring>newKeyButton</cstring>
110 </property>
111 <property stdset="1">
112 <name>maximumSize</name>
113 <size>
114 <width>50</width>
115 <height>32767</height>
116 </size>
117 </property>
118 <property stdset="1">
119 <name>text</name>
120 <string>New</string>
121 </property>
122 </widget>
123 <widget>
124 <class>QPushButton</class>
125 <property stdset="1">
126 <name>name</name>
127 <cstring>deleteKeyButton</cstring>
128 </property>
129 <property stdset="1">
130 <name>maximumSize</name>
131 <size>
132 <width>50</width>
133 <height>32767</height>
134 </size>
135 </property>
136 <property stdset="1">
137 <name>text</name>
138 <string>Delete</string>
139 </property>
140 </widget>
141 <widget>
142 <class>QPushButton</class>
143 <property stdset="1">
144 <name>name</name>
145 <cstring>clearKeysButton</cstring>
146 </property>
147 <property stdset="1">
148 <name>maximumSize</name>
149 <size>
150 <width>60</width>
151 <height>32767</height>
152 </size>
153 </property>
154 <property stdset="1">
155 <name>text</name>
156 <string>Clear All</string>
157 </property>
158 </widget>
159 </hbox>
160 </widget>
161 <widget>
162 <class>QLayoutWidget</class>
163 <property stdset="1">
164 <name>name</name>
165 <cstring>Layout3</cstring>
166 </property>
167 <hbox>
168 <property stdset="1">
169 <name>margin</name>
170 <number>0</number>
171 </property>
172 <property stdset="1">
173 <name>spacing</name>
174 <number>6</number>
175 </property>
176 <widget>
177 <class>QLineEdit</class>
178 <property stdset="1">
179 <name>name</name>
180 <cstring>keyNameEdit</cstring>
181 </property>
182 </widget>
183 <widget>
184 <class>QComboBox</class>
185 <property stdset="1">
186 <name>name</name>
187 <cstring>keyTypeEdit</cstring>
188 </property>
189 </widget>
190 </hbox>
191 </widget>
192 </vbox>
193</widget>
194<connections>
195 <connection>
196 <sender>newKeyButton</sender>
197 <signal>clicked()</signal>
198 <receiver>TVKeyEdit_gen</receiver>
199 <slot>newTerm()</slot>
200 </connection>
201 <connection>
202 <sender>deleteKeyButton</sender>
203 <signal>clicked()</signal>
204 <receiver>TVKeyEdit_gen</receiver>
205 <slot>deleteTerm()</slot>
206 </connection>
207 <connection>
208 <sender>clearKeysButton</sender>
209 <signal>clicked()</signal>
210 <receiver>TVKeyEdit_gen</receiver>
211 <slot>clearTerms()</slot>
212 </connection>
213 <connection>
214 <sender>display</sender>
215 <signal>selectionChanged(QListViewItem*)</signal>
216 <receiver>TVKeyEdit_gen</receiver>
217 <slot>setTerm(QListViewItem *)</slot>
218 </connection>
219 <connection>
220 <sender>keyNameEdit</sender>
221 <signal>textChanged(const QString&amp;)</signal>
222 <receiver>TVKeyEdit_gen</receiver>
223 <slot>updateTerm(const QString &amp;)</slot>
224 </connection>
225 <connection>
226 <sender>keyTypeEdit</sender>
227 <signal>activated(int)</signal>
228 <receiver>TVKeyEdit_gen</receiver>
229 <slot>updateTerm(int)</slot>
230 </connection>
231 <slot access="protected">clearTerms()</slot>
232 <slot access="protected">deleteTerm()</slot>
233 <slot access="protected">newTerm()</slot>
234 <slot access="public">new_slot()</slot>
235 <slot access="protected">setTerm(QListViewItem *)</slot>
236 <slot access="protected">updateTerm(int)</slot>
237 <slot access="protected">updateTerm(const QString &amp;)</slot>
238</connections>
239</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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "tvlistview.h"
21#include "../db/common.h"
22#include <qtoolbutton.h>
23#include <qlistview.h>
24#include <qlayout.h>
25
26void TVListViewPrivate::setColumnWidth(int column, int width)
27{
28 if(width > 70) width = 70;
29 QListView::setColumnWidth(column, width);
30}
31
32void TVListViewPrivate::setSorting(int column, bool increasing)
33{
34 emit sortChanged(column);
35 QListView::setSorting(column, increasing);
36}
37
38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
39 WFlags fl) : QListView(parent, name, fl) {
40 ;
41}
42
43class TVListViewItem : public QListViewItem
44{
45public:
46
47 TVListViewItem(QListView *parent, DataElem *d);
48 ~TVListViewItem();
49
50 QString text(int i) const
51 {
52 return data_reference->toQString(i);
53 }
54
55 /* Do nothing... all data for this item should be generated */
56 void setText(int i, const QString &)
57 {
58 ;
59 }
60 QString key(int i, bool a) const
61 {
62 return data_reference->toSortableQString(i);
63 }
64
65 void setDataElem(DataElem *d)
66 {
67 data_reference = d;
68 }
69
70 DataElem *getDataElem() {
71 return data_reference;
72 }
73private:
74 DataElem *data_reference;
75};
76
77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
78 : QListViewItem(parent)
79{
80 data_reference = d;
81}
82
83TVListViewItem::~TVListViewItem()
84{
85 data_reference = 0;
86}
87
88TVListView::TVListView(TableState *t, QWidget* parent = 0,
89 const char *name = 0, WFlags fl =0) : QWidget(parent, name, fl)
90{
91 if (!name)
92 setName("TVListView");
93
94 // the next two lines need to be rationalized.
95 resize(318,457);
96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
98 setCaption(tr("List View"));
99
100 QVBoxLayout *layout = new QVBoxLayout(this);
101 layout->setSpacing(0);
102 layout->setMargin(0);
103
104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
105 layout->addWidget(listViewDisplay);
106
107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this,
108 SLOT(setCurrent(QListViewItem *)));
109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
110 SLOT(setSorting(int)));
111
112 listViewDisplay->setShowSortIndicator(true);
113
114 it = new QListViewItemIterator(listViewDisplay);
115 ts = t;
116}
117
118TVListView::~TVListView()
119{
120}
121
122void TVListView::addItem(DataElem *d)
123{
124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
125
126 delete it;
127 it = new QListViewItemIterator(i);
128}
129
130/* remove current (it) item */
131void TVListView::removeItem()
132{
133 QListViewItemIterator other(*it);
134
135 QListViewItemIterator tmp = *it;
136 (*it)++;
137 if (!it->current()) {
138 *it = tmp;
139 (*it)--;
140 if (!it->current()) {
141 delete it;
142 it = 0;
143 }
144 }
145
146 delete other.current();
147}
148
149void TVListView::clearItems()
150{
151 /* This is ok since the destructor for TVListItem does not know about
152 the data_reference pointer.. and hence will leave it alone */
153 listViewDisplay->clear();
154 delete it;
155 it = new QListViewItemIterator(listViewDisplay);
156}
157
158void TVListView::first()
159{
160 delete it;
161 it = new QListViewItemIterator(listViewDisplay);
162}
163
164void TVListView::last()
165{
166 qWarning("TVListView::last not yet implemented");
167}
168
169void TVListView::next()
170{
171 QListViewItemIterator tmp = *it;
172 (*it)++;
173 if (!it->current()) {
174 *it = tmp;
175 }
176}
177
178void TVListView::previous()
179{
180 QListViewItemIterator tmp = *it;
181 (*it)--;
182 if (!it->current()) {
183 *it = tmp;
184 }
185}
186
187DataElem *TVListView::getCurrentData() {
188 if (it->current()) {
189 return ((TVListViewItem *)it->current())->getDataElem();
190 }
191 return NULL;
192}
193
194/*! Now to implement the closest match function */
195void TVListView::findItem(int keyId, TVVariant value)
196{
197 QListViewItem *i;
198 TVListViewItem *best_so_far = NULL;
199 /* start at the beginning... go through till find the closest elem */
200 i = listViewDisplay->firstChild();
201 while (i) {
202 /* search stuff */
203 if(best_so_far) {
204 if (DataElem::closer(
205 ((TVListViewItem *)i)->getDataElem(),
206 best_so_far->getDataElem(), value, keyId))
207 best_so_far = (TVListViewItem *)i;
208 } else {
209 if (DataElem::closer(
210 ((TVListViewItem *)i)->getDataElem(),
211 NULL, value, keyId))
212 best_so_far = (TVListViewItem *)i;
213 }
214
215 i = i->itemBelow();
216 }
217 if (best_so_far) {
218 /* set best_so_far to current element */
219 delete it;
220 it = new QListViewItemIterator(best_so_far);
221 }
222}
223
224void TVListView::rebuildKeys()
225{
226 int i;
227 if(!ts) return;
228 if(!ts->kRep) return;
229
230 i = listViewDisplay->columns();
231
232 while(i > 0)
233 listViewDisplay->removeColumn(--i);
234
235 KeyListIterator kit(*ts->kRep);
236 i = 0;
237 while(kit.current()) {
238 if(!kit.current()->delFlag()) {
239 listViewDisplay->addColumn(kit.current()->name());
240 keyIds.insert(i, kit.currentKey());
241 ++i;
242 }
243 ++kit;
244 }
245}
246
247
248void TVListView::setSorting(int column)
249{
250 /* Without table state can't do anything */
251 if (ts == 0)
252 return;
253 if (keyIds[column] != ts->current_column) {
254 ts->current_column = keyIds[column];
255 }
256}
257
258void TVListView::rebuildData() {
259 int i;
260 QMap<int, int>::Iterator kit;
261 /* Need to set sort order */
262 if(!ts)
263 return;
264
265 /* revers lookup the column */
266 i = -1;
267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) {
268 if (kit.data() == ts->current_column) {
269 i = kit.key();
270 break;
271 }
272 }
273 if (i == -1)
274 return;
275
276 listViewDisplay->setSorting(i);
277 listViewDisplay->sort();
278
279 /* reset current element */
280 listViewDisplay->setCurrentItem(it->current());
281 listViewDisplay->setSelected(it->current(), true);
282 listViewDisplay->ensureItemVisible(it->current());
283}
284
285void TVListView::reset()
286{
287 int i;
288 listViewDisplay->clear();
289
290 i = listViewDisplay->columns();
291 while (i > 0)
292 listViewDisplay->removeColumn(--i);
293
294 keyIds.clear();
295}
296
297void TVListView::setCurrent(QListViewItem *i)
298{
299 /* cast */
300 TVListViewItem *t = (TVListViewItem *)i;
301
302 if(!t) {
303 /* set current to null */
304 ts->current_elem = 0;
305 return;
306 }
307
308 ts->current_elem = t->getDataElem();
309 /* now also set up the iterator */
310
311 delete it;
312 it = new QListViewItemIterator(i);
313
314 //emit browseView();
315}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#ifndef Tvlistview_H
22#define Tvlistview_H
23
24#include "../db/common.h"
25#include <qlistview.h>
26#include <qmap.h>
27
28class QListViewItemIterator;
29
30class TVListViewPrivate : public QListView
31{
32 Q_OBJECT
33
34signals:
35 void sortChanged(int i);
36
37public:
38 TVListViewPrivate( QWidget *parent = 0, const char *name = 0, WFlags fl = 0);
39
40 void setColumnWidth(int c, int w);
41 void setSorting(int i, bool increasing=true);
42};
43
44class TVListView : public QWidget
45{
46 Q_OBJECT
47
48signals:
49 void loadFile();
50 void browseView();
51 void filterView();
52 void editView();
53
54protected slots:
55 void setSorting(int);
56 void setCurrent(QListViewItem *);
57
58public:
59 TVListView(TableState *t, QWidget* parent = 0,
60 const char* name = 0, WFlags fl = 0);
61 ~TVListView();
62
63 /* to be used for setting up the list */
64 void addItem(DataElem *);
65 void removeItem(); // remove from list, not from program
66 void clearItems();
67
68 /* DBStore clone functions */
69 void first();
70 void last();
71 void next();
72 void previous();
73
74 void rebuildKeys();
75 void rebuildData();
76 void reset();
77
78 DataElem *getCurrentData();
79
80 void findItem(int i, TVVariant v);
81
82protected:
83 QListViewItemIterator *it;
84 TableState *ts;
85
86 TVListViewPrivate *listViewDisplay;
87
88 QMap<int, int> keyIds;
89
90};
91
92#endif