author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/apps/tableviewer/ui/filterkeyentry.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/apps/tableviewer/ui/filterkeyentry.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/ui/filterkeyentry.cpp | 208 |
1 files changed, 208 insertions, 0 deletions
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 | |||
31 | TVFilterKeyEntry::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 | */ | ||
124 | TVFilterKeyEntry::~TVFilterKeyEntry() | ||
125 | { | ||
126 | } | ||
127 | |||
128 | void 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 | |||
141 | void 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 | |||
153 | CmpType 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 */ | ||
180 | TVVariant 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 | } | ||