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
@@ -11,194 +11,194 @@
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(