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/tveditview.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/apps/tableviewer/ui/tveditview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/ui/tveditview.cpp | 235 |
1 files changed, 235 insertions, 0 deletions
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 | |||
43 | TVEditView::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 | |||
71 | TVEditView::~TVEditView() | ||
72 | { | ||
73 | } | ||
74 | |||
75 | /*! set up the widgets in the grid, Set up initial values */ | ||
76 | void 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 | |||
167 | void 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 | |||
178 | bool 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 | } | ||