summaryrefslogtreecommitdiffstats
path: root/kpilot/listItems.cpp
blob: 7db37cc890a8f97f101a5b4d70d3a4092142359b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/* KPilot
**
** Copyright (C) 1998-2001 by Dan Pilone
** Copyright (C) 2003 by Reinhold Kainhofer
**
** Program description
*/

/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/

#include "options.h"


#include <tqstring.h>
#include <tqlistbox.h>
#include <tqlistview.h>


#ifndef _KPILOT_LISTITEMS_H
#include "listItems.h"
#endif

#ifdef DEBUG
/* static */ int PilotListItem::crt = 0;
/* static */ int PilotListItem::del = 0;
/* static */ int PilotListItem::count = 0;

/* static */ void PilotListItem::counts()
{
	FUNCTIONSETUP;
	DEBUGKPILOT << fname
		<< ": created=" << crt << " deletions=" << del << endl;
}
#endif

PilotListItem::PilotListItem(const TQString & text,
	recordid_t pilotid, void *r) :
	TQListBoxText(text),
	fid(pilotid),
	fr(r)
{
	// FUNCTIONSETUP;
#ifdef DEBUG
	crt++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}

PilotListItem::~PilotListItem()
{
	// FUNCTIONSETUP;
#ifdef DEBUG
	del++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}




#ifdef DEBUG
/* static */ int PilotCheckListItem::crt = 0;
/* static */ int PilotCheckListItem::del = 0;
/* static */ int PilotCheckListItem::count = 0;

/* static */ void PilotCheckListItem::counts()
{
	FUNCTIONSETUP;
	DEBUGKPILOT << fname
		<< ": created=" << crt << " deletions=" << del << endl;
}
#endif

PilotCheckListItem::PilotCheckListItem(TQListView * parent, const TQString & text, recordid_t pilotid, void *r) :
	TQCheckListItem(parent, text, TQCheckListItem::CheckBox),
	fid(pilotid),
	fr(r)
{
	// FUNCTIONSETUP;
#ifdef DEBUG
	crt++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}

PilotCheckListItem::~PilotCheckListItem()
{
	// FUNCTIONSETUP;
#ifdef DEBUG
	del++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}

void PilotCheckListItem::stateChange ( bool on)
{
	// FUNCTIONSETUP;
	TQCheckListItem::stateChange(on);

}




#ifdef DEBUG
/* static */ int PilotListViewItem::crt = 0;
/* static */ int PilotListViewItem::del = 0;
/* static */ int PilotListViewItem::count = 0;

/* static */ void PilotListViewItem::counts()
{
	FUNCTIONSETUP;
	DEBUGKPILOT << fname
		<< ": created=" << crt << " deletions=" << del << endl;
}
#endif

PilotListViewItem::PilotListViewItem( TQListView * parent,
	TQString label1, TQString label2, TQString label3, TQString label4,
	recordid_t pilotid, void *r):
	TQListViewItem(parent, label1, label2, label3, label4,
		TQString(), TQString(), TQString(), TQString()),
	fid(pilotid),
	fr(r),
	d(new PilotListViewItemData)
{
	// FUNCTIONSETUP;
	if (d) d->valCol=-1;
#ifdef DEBUG
	crt++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}

PilotListViewItem::~PilotListViewItem()
{
	// FUNCTIONSETUP;
#ifdef DEBUG
	del++;
	count++;
	if (!(count & 0xff))
		counts();
#endif
}
void PilotListViewItem::setNumericCol(int col, bool numeric)
{
	// FUNCTIONSETUP;
	if (numeric)
	{
		if (!numericCols.contains(col))
			numericCols.append(col);
	}
	else
	{
		if (numericCols.contains(col))
			numericCols.remove(col);
	}
}

unsigned long PilotListViewItem::colValue(int col, bool *ok) const
{
//	FUNCTIONSETUP;
/*	if (!d)
	{
		d=new PilotListViewItemData;
		d->valCol=-1;
	}*/
	if (d->valCol!=col)
	{
		// Use true for ascending for now...
		d->val=key(col, true).toULong(&d->valOk);
		d->valCol=col;
	}
	if (ok) (*ok)=d->valOk;
	return d->val;
}

int PilotListViewItem::compare( TQListViewItem *i, int col, bool ascending ) const
{
// 	FUNCTIONSETUP;
	PilotListViewItem*item=dynamic_cast<PilotListViewItem*>(i);
/*#ifdef DEBUG
	DEBUGKPILOT<<"Item of dyn cast: "<<item<<endl;
#endif*/
	if (item && numericCols.contains(col))
	{
/*#ifdef DEBUG
	DEBUGKPILOT<<"Comparing: col "<<col<<", Ascending: "<<ascending<<endl;
#endif*/
		bool ok1, ok2;
		/// Do the toULong call just once if the sorting column changed:
		unsigned long l1=colValue(col, &ok1);
		unsigned long l2=item->colValue(col, &ok2);
/*#ifdef DEBUG
	DEBUGKPILOT<<"l1="<<l1<<"(ok: "<<ok1<<"), l2="<<l2<<"(ok: "<<ok2<<")"<<endl;
#endif*/
		if (ok1 && ok2)
		{
			// Returns -1 if this item is less than i, 0 if they are
			// equal and 1 if this item is greater than i.
			int res=0;
			if (l1<l2) res=-1;
			else if (l1>l2) res=1;
			//else res=0;
/*#ifdef DEBUG
	DEBUGKPILOT<<"RESULT="<<res<<endl;
#endif*/
			return res;
		}
	}
	return TQListViewItem::compare(i, col, ascending);
}