summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/ui/browsekeyentry.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tableviewer/ui/browsekeyentry.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/tableviewer/ui/browsekeyentry.cpp206
1 files changed, 206 insertions, 0 deletions
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*/