summaryrefslogtreecommitdiff
path: root/noncore/apps/tableviewer/ui/tvlistview.cpp
Unidiff
Diffstat (limited to 'noncore/apps/tableviewer/ui/tvlistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/tableviewer/ui/tvlistview.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/apps/tableviewer/ui/tvlistview.cpp b/noncore/apps/tableviewer/ui/tvlistview.cpp
index b25e813..b10ff1d 100644
--- a/noncore/apps/tableviewer/ui/tvlistview.cpp
+++ b/noncore/apps/tableviewer/ui/tvlistview.cpp
@@ -1,300 +1,300 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "tvlistview.h" 20#include "tvlistview.h"
21#include "../db/common.h" 21#include "../db/common.h"
22#include <qtoolbutton.h> 22#include <qtoolbutton.h>
23#include <qlistview.h> 23#include <qlistview.h>
24#include <qlayout.h> 24#include <qlayout.h>
25 25
26void TVListViewPrivate::setColumnWidth(int column, int width) 26void TVListViewPrivate::setColumnWidth(int column, int width)
27{ 27{
28 if(width > 70) width = 70; 28 if(width > 70) width = 70;
29 QListView::setColumnWidth(column, width); 29 QListView::setColumnWidth(column, width);
30} 30}
31 31
32void TVListViewPrivate::setSorting(int column, bool increasing) 32void TVListViewPrivate::setSorting(int column, bool increasing)
33{ 33{
34 emit sortChanged(column); 34 emit sortChanged(column);
35 QListView::setSorting(column, increasing); 35 QListView::setSorting(column, increasing);
36} 36}
37 37
38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name, 38TVListViewPrivate::TVListViewPrivate(QWidget *parent, const char* name,
39 WFlags fl) : QListView(parent, name, fl) { 39 WFlags fl) : QListView(parent, name, fl) {
40 ; 40 ;
41} 41}
42 42
43class TVListViewItem : public QListViewItem 43class TVListViewItem : public QListViewItem
44{ 44{
45public: 45public:
46 46
47 TVListViewItem(QListView *parent, DataElem *d); 47 TVListViewItem(QListView *parent, DataElem *d);
48 ~TVListViewItem(); 48 ~TVListViewItem();
49 49
50 QString text(int i) const 50 QString text(int i) const
51 { 51 {
52 return data_reference->toQString(i); 52 return data_reference->toQString(i);
53 } 53 }
54 54
55 /* Do nothing... all data for this item should be generated */ 55 /* Do nothing... all data for this item should be generated */
56 void setText(int i, const QString &) 56 void setText(int i, const QString &)
57 { 57 {
58 ; 58 ;
59 } 59 }
60 QString key(int i, bool a) const 60 QString key(int i, bool a) const
61 { 61 {
62 return data_reference->toSortableQString(i); 62 return data_reference->toSortableQString(i);
63 } 63 }
64 64
65 void setDataElem(DataElem *d) 65 void setDataElem(DataElem *d)
66 { 66 {
67 data_reference = d; 67 data_reference = d;
68 } 68 }
69 69
70 DataElem *getDataElem() { 70 DataElem *getDataElem() {
71 return data_reference; 71 return data_reference;
72 } 72 }
73private: 73private:
74 DataElem *data_reference; 74 DataElem *data_reference;
75}; 75};
76 76
77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d) 77TVListViewItem::TVListViewItem(QListView *parent, DataElem *d)
78 : QListViewItem(parent) 78 : QListViewItem(parent)
79{ 79{
80 data_reference = d; 80 data_reference = d;
81} 81}
82 82
83TVListViewItem::~TVListViewItem() 83TVListViewItem::~TVListViewItem()
84{ 84{
85 data_reference = 0; 85 data_reference = 0;
86} 86}
87 87
88TVListView::TVListView(TableState *t, QWidget* parent, 88TVListView::TVListView(TableState *t, QWidget* parent,
89 const char *name, WFlags fl ) : QWidget(parent, name, fl) 89 const char *name, WFlags fl ) : QWidget(parent, name, fl)
90{ 90{
91 if (!name) 91 if (!name)
92 setName("TVListView"); 92 setName("TVListView");
93 93
94 // the next two lines need to be rationalized. 94 // the next two lines need to be rationalized.
95 resize(318,457); 95 resize(318,457);
96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, 96 setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth())); 97 (QSizePolicy::SizeType)7, sizePolicy().hasHeightForWidth()));
98 setCaption(tr("List View")); 98 setCaption(tr("List View"));
99 99
100 QVBoxLayout *layout = new QVBoxLayout(this); 100 QVBoxLayout *layout = new QVBoxLayout(this);
101 layout->setSpacing(0); 101 layout->setSpacing(0);
102 layout->setMargin(0); 102 layout->setMargin(0);
103 103
104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay"); 104 listViewDisplay = new TVListViewPrivate(this, "listViewDisplay");
105 layout->addWidget(listViewDisplay); 105 layout->addWidget(listViewDisplay);
106 106
107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem *)), this, 107 connect(listViewDisplay, SIGNAL(currentChanged(QListViewItem*)), this,
108 SLOT(setCurrent(QListViewItem *))); 108 SLOT(setCurrent(QListViewItem*)));
109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this, 109 connect(listViewDisplay, SIGNAL(sortChanged(int)), this,
110 SLOT(setSorting(int))); 110 SLOT(setSorting(int)));
111 111
112 listViewDisplay->setShowSortIndicator(true); 112 listViewDisplay->setShowSortIndicator(true);
113 113
114 it = new QListViewItemIterator(listViewDisplay); 114 it = new QListViewItemIterator(listViewDisplay);
115 ts = t; 115 ts = t;
116} 116}
117 117
118TVListView::~TVListView() 118TVListView::~TVListView()
119{ 119{
120} 120}
121 121
122void TVListView::addItem(DataElem *d) 122void TVListView::addItem(DataElem *d)
123{ 123{
124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d); 124 TVListViewItem *i = new TVListViewItem(listViewDisplay, d);
125 125
126 delete it; 126 delete it;
127 it = new QListViewItemIterator(i); 127 it = new QListViewItemIterator(i);
128} 128}
129 129
130/* remove current (it) item */ 130/* remove current (it) item */
131void TVListView::removeItem() 131void TVListView::removeItem()
132{ 132{
133 QListViewItemIterator other(*it); 133 QListViewItemIterator other(*it);
134 134
135 QListViewItemIterator tmp = *it; 135 QListViewItemIterator tmp = *it;
136 (*it)++; 136 (*it)++;
137 if (!it->current()) { 137 if (!it->current()) {
138 *it = tmp; 138 *it = tmp;
139 (*it)--; 139 (*it)--;
140 if (!it->current()) { 140 if (!it->current()) {
141 delete it; 141 delete it;
142 it = 0; 142 it = 0;
143 } 143 }
144 } 144 }
145 145
146 delete other.current(); 146 delete other.current();
147} 147}
148 148
149void TVListView::clearItems() 149void TVListView::clearItems()
150{ 150{
151 /* This is ok since the destructor for TVListItem does not know about 151 /* This is ok since the destructor for TVListItem does not know about
152 the data_reference pointer.. and hence will leave it alone */ 152 the data_reference pointer.. and hence will leave it alone */
153 listViewDisplay->clear(); 153 listViewDisplay->clear();
154 delete it; 154 delete it;
155 it = new QListViewItemIterator(listViewDisplay); 155 it = new QListViewItemIterator(listViewDisplay);
156} 156}
157 157
158void TVListView::first() 158void TVListView::first()
159{ 159{
160 delete it; 160 delete it;
161 it = new QListViewItemIterator(listViewDisplay); 161 it = new QListViewItemIterator(listViewDisplay);
162} 162}
163 163
164void TVListView::last() 164void TVListView::last()
165{ 165{
166 qWarning("TVListView::last not yet implemented"); 166 qWarning("TVListView::last not yet implemented");
167} 167}
168 168
169void TVListView::next() 169void TVListView::next()
170{ 170{
171 QListViewItemIterator tmp = *it; 171 QListViewItemIterator tmp = *it;
172 (*it)++; 172 (*it)++;
173 if (!it->current()) { 173 if (!it->current()) {
174 *it = tmp; 174 *it = tmp;
175 } 175 }
176} 176}
177 177
178void TVListView::previous() 178void TVListView::previous()
179{ 179{
180 QListViewItemIterator tmp = *it; 180 QListViewItemIterator tmp = *it;
181 (*it)--; 181 (*it)--;
182 if (!it->current()) { 182 if (!it->current()) {
183 *it = tmp; 183 *it = tmp;
184 } 184 }
185} 185}
186 186
187DataElem *TVListView::getCurrentData() { 187DataElem *TVListView::getCurrentData() {
188 if (it->current()) { 188 if (it->current()) {
189 return ((TVListViewItem *)it->current())->getDataElem(); 189 return ((TVListViewItem *)it->current())->getDataElem();
190 } 190 }
191 return NULL; 191 return NULL;
192} 192}
193 193
194/*! Now to implement the closest match function */ 194/*! Now to implement the closest match function */
195void TVListView::findItem(int keyId, TVVariant value) 195void TVListView::findItem(int keyId, TVVariant value)
196{ 196{
197 QListViewItem *i; 197 QListViewItem *i;
198 TVListViewItem *best_so_far = NULL; 198 TVListViewItem *best_so_far = NULL;
199 /* start at the beginning... go through till find the closest elem */ 199 /* start at the beginning... go through till find the closest elem */
200 i = listViewDisplay->firstChild(); 200 i = listViewDisplay->firstChild();
201 while (i) { 201 while (i) {
202 /* search stuff */ 202 /* search stuff */
203 if(best_so_far) { 203 if(best_so_far) {
204 if (DataElem::closer( 204 if (DataElem::closer(
205 ((TVListViewItem *)i)->getDataElem(), 205 ((TVListViewItem *)i)->getDataElem(),
206 best_so_far->getDataElem(), value, keyId)) 206 best_so_far->getDataElem(), value, keyId))
207 best_so_far = (TVListViewItem *)i; 207 best_so_far = (TVListViewItem *)i;
208 } else { 208 } else {
209 if (DataElem::closer( 209 if (DataElem::closer(
210 ((TVListViewItem *)i)->getDataElem(), 210 ((TVListViewItem *)i)->getDataElem(),
211 NULL, value, keyId)) 211 NULL, value, keyId))
212 best_so_far = (TVListViewItem *)i; 212 best_so_far = (TVListViewItem *)i;
213 } 213 }
214 214
215 i = i->itemBelow(); 215 i = i->itemBelow();
216 } 216 }
217 if (best_so_far) { 217 if (best_so_far) {
218 /* set best_so_far to current element */ 218 /* set best_so_far to current element */
219 delete it; 219 delete it;
220 it = new QListViewItemIterator(best_so_far); 220 it = new QListViewItemIterator(best_so_far);
221 } 221 }
222} 222}
223 223
224void TVListView::rebuildKeys() 224void TVListView::rebuildKeys()
225{ 225{
226 int i; 226 int i;
227 if(!ts) return; 227 if(!ts) return;
228 if(!ts->kRep) return; 228 if(!ts->kRep) return;
229 229
230 i = listViewDisplay->columns(); 230 i = listViewDisplay->columns();
231 231
232 while(i > 0) 232 while(i > 0)
233 listViewDisplay->removeColumn(--i); 233 listViewDisplay->removeColumn(--i);
234 234
235 KeyListIterator kit(*ts->kRep); 235 KeyListIterator kit(*ts->kRep);
236 i = 0; 236 i = 0;
237 while(kit.current()) { 237 while(kit.current()) {
238 if(!kit.current()->delFlag()) { 238 if(!kit.current()->delFlag()) {
239 listViewDisplay->addColumn(kit.current()->name()); 239 listViewDisplay->addColumn(kit.current()->name());
240 keyIds.insert(i, kit.currentKey()); 240 keyIds.insert(i, kit.currentKey());
241 ++i; 241 ++i;
242 } 242 }
243 ++kit; 243 ++kit;
244 } 244 }
245} 245}
246 246
247 247
248void TVListView::setSorting(int column) 248void TVListView::setSorting(int column)
249{ 249{
250 /* Without table state can't do anything */ 250 /* Without table state can't do anything */
251 if (ts == 0) 251 if (ts == 0)
252 return; 252 return;
253 if (keyIds[column] != ts->current_column) { 253 if (keyIds[column] != ts->current_column) {
254 ts->current_column = keyIds[column]; 254 ts->current_column = keyIds[column];
255 } 255 }
256} 256}
257 257
258void TVListView::rebuildData() { 258void TVListView::rebuildData() {
259 int i; 259 int i;
260 QMap<int, int>::Iterator kit; 260 QMap<int, int>::Iterator kit;
261 /* Need to set sort order */ 261 /* Need to set sort order */
262 if(!ts) 262 if(!ts)
263 return; 263 return;
264 264
265 /* revers lookup the column */ 265 /* revers lookup the column */
266 i = -1; 266 i = -1;
267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) { 267 for(kit = keyIds.begin(); kit != keyIds.end(); ++kit) {
268 if (kit.data() == ts->current_column) { 268 if (kit.data() == ts->current_column) {
269 i = kit.key(); 269 i = kit.key();
270 break; 270 break;
271 } 271 }
272 } 272 }
273 if (i == -1) 273 if (i == -1)
274 return; 274 return;
275 275
276 listViewDisplay->setSorting(i); 276 listViewDisplay->setSorting(i);
277 listViewDisplay->sort(); 277 listViewDisplay->sort();
278 278
279 /* reset current element */ 279 /* reset current element */
280 listViewDisplay->setCurrentItem(it->current()); 280 listViewDisplay->setCurrentItem(it->current());
281 listViewDisplay->setSelected(it->current(), true); 281 listViewDisplay->setSelected(it->current(), true);
282 listViewDisplay->ensureItemVisible(it->current()); 282 listViewDisplay->ensureItemVisible(it->current());
283} 283}
284 284
285void TVListView::reset() 285void TVListView::reset()
286{ 286{
287 int i; 287 int i;
288 listViewDisplay->clear(); 288 listViewDisplay->clear();
289 289
290 i = listViewDisplay->columns(); 290 i = listViewDisplay->columns();
291 while (i > 0) 291 while (i > 0)
292 listViewDisplay->removeColumn(--i); 292 listViewDisplay->removeColumn(--i);
293 293
294 keyIds.clear(); 294 keyIds.clear();
295} 295}
296 296
297void TVListView::setCurrent(QListViewItem *i) 297void TVListView::setCurrent(QListViewItem *i)
298{ 298{
299 /* cast */ 299 /* cast */
300 TVListViewItem *t = (TVListViewItem *)i; 300 TVListViewItem *t = (TVListViewItem *)i;