kpilot Library API Documentation

listItems.cc

00001 /* listItem.cc          KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Modifications 2003 by Reinhold Kainhofer
00005 **
00006 ** Program description
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 ** MA 02111-1307, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 static const char *listitems_id =
00031     "$Id: listItems.cc,v 1.12 2003/06/19 21:58:04 kainhofe Exp $";
00032 
00033 #include "options.h"
00034 
00035 
00036 #include <qstring.h>
00037 #include <qlistbox.h>
00038 #include <qlistview.h>
00039 
00040 
00041 #ifndef _KPILOT_LISTITEMS_H
00042 #include "listItems.h"
00043 #endif
00044 
00045 #ifdef DEBUG
00046 /* static */ int PilotListItem::crt = 0;
00047 /* static */ int PilotListItem::del = 0;
00048 /* static */ int PilotListItem::count = 0;
00049 
00050 /* static */ void PilotListItem::counts()
00051 {
00052     FUNCTIONSETUP;
00053     DEBUGKPILOT << fname
00054         << ": created=" << crt << " deletions=" << del << endl;
00055 }
00056 #endif
00057 
00058 PilotListItem::PilotListItem(const QString & text,
00059     recordid_t pilotid, void *r) :
00060     QListBoxText(text),
00061     fid(pilotid),
00062     fr(r)
00063 {
00064     // FUNCTIONSETUP;
00065 #ifdef DEBUG
00066     crt++;
00067     count++;
00068     if (!(count & 0xff))
00069         counts();
00070 #endif
00071     (void) listitems_id;
00072 }
00073 
00074 PilotListItem::~PilotListItem()
00075 {
00076     // FUNCTIONSETUP;
00077 #ifdef DEBUG
00078     del++;
00079     count++;
00080     if (!(count & 0xff))
00081         counts();
00082 #endif
00083 }
00084 
00085 
00086 
00087 
00088 #ifdef DEBUG
00089 /* static */ int PilotCheckListItem::crt = 0;
00090 /* static */ int PilotCheckListItem::del = 0;
00091 /* static */ int PilotCheckListItem::count = 0;
00092 
00093 /* static */ void PilotCheckListItem::counts()
00094 {
00095     FUNCTIONSETUP;
00096     DEBUGKPILOT << fname
00097         << ": created=" << crt << " deletions=" << del << endl;
00098 }
00099 #endif
00100 
00101 PilotCheckListItem::PilotCheckListItem(QListView * parent, const QString & text, recordid_t pilotid, void *r) :
00102     QCheckListItem(parent, text, QCheckListItem::CheckBox),
00103     fid(pilotid),
00104     fr(r)
00105 {
00106     // FUNCTIONSETUP;
00107 #ifdef DEBUG
00108     crt++;
00109     count++;
00110     if (!(count & 0xff))
00111         counts();
00112 #endif
00113     (void) listitems_id;
00114 }
00115 
00116 PilotCheckListItem::~PilotCheckListItem()
00117 {
00118     // FUNCTIONSETUP;
00119 #ifdef DEBUG
00120     del++;
00121     count++;
00122     if (!(count & 0xff))
00123         counts();
00124 #endif
00125 }
00126 
00127 void PilotCheckListItem::stateChange ( bool on)
00128 {
00129     // FUNCTIONSETUP;
00130     QCheckListItem::stateChange(on);
00131 
00132 }
00133 
00134 
00135 
00136 
00137 #ifdef DEBUG
00138 /* static */ int PilotListViewItem::crt = 0;
00139 /* static */ int PilotListViewItem::del = 0;
00140 /* static */ int PilotListViewItem::count = 0;
00141 
00142 /* static */ void PilotListViewItem::counts()
00143 {
00144     FUNCTIONSETUP;
00145     DEBUGKPILOT << fname
00146         << ": created=" << crt << " deletions=" << del << endl;
00147 }
00148 #endif
00149 
00150 PilotListViewItem::PilotListViewItem( QListView * parent,
00151     QString label1, QString label2, QString label3, QString label4,
00152     recordid_t pilotid, void *r):
00153     QListViewItem(parent, label1, label2, label3, label4,
00154         QString::null, QString::null, QString::null, QString::null),
00155     fid(pilotid),
00156     fr(r),
00157     d(new PilotListViewItemData)
00158 {
00159     // FUNCTIONSETUP;
00160     if (d) d->valCol=-1;
00161 #ifdef DEBUG
00162     crt++;
00163     count++;
00164     if (!(count & 0xff))
00165         counts();
00166 #endif
00167     (void) listitems_id;
00168 }
00169 
00170 PilotListViewItem::~PilotListViewItem()
00171 {
00172     // FUNCTIONSETUP;
00173 #ifdef DEBUG
00174     del++;
00175     count++;
00176     if (!(count & 0xff))
00177         counts();
00178 #endif
00179 }
00180 void PilotListViewItem::setNumericCol(int col, bool numeric)
00181 {
00182     // FUNCTIONSETUP;
00183     if (numeric)
00184     {
00185         if (!numericCols.contains(col))
00186             numericCols.append(col);
00187     }
00188     else
00189     {
00190         if (numericCols.contains(col))
00191             numericCols.remove(col);
00192     }
00193 }
00194 
00195 unsigned long PilotListViewItem::colValue(int col, bool *ok) const
00196 {
00197 //  FUNCTIONSETUP;
00198 /*  if (!d)
00199     {
00200         d=new PilotListViewItemData;
00201         d->valCol=-1;
00202     }*/
00203     if (d->valCol!=col)
00204     {
00205         // Use true for ascending for now...
00206         d->val=key(col, true).toULong(&d->valOk);
00207         d->valCol=col;
00208     }
00209     if (ok) (*ok)=d->valOk;
00210     return d->val;
00211 }
00212 
00213 int PilotListViewItem::compare( QListViewItem *i, int col, bool ascending ) const
00214 {
00215 //  FUNCTIONSETUP;
00216     PilotListViewItem*item=dynamic_cast<PilotListViewItem*>(i);
00217 /*#ifdef DEBUG
00218     DEBUGKPILOT<<"Item of dyn cast: "<<item<<endl;
00219 #endif*/
00220     if (item && numericCols.contains(col))
00221     {
00222 /*#ifdef DEBUG
00223     DEBUGKPILOT<<"Comparing: col "<<col<<", Ascending: "<<ascending<<endl;
00224 #endif*/
00225         bool ok1, ok2;
00227         unsigned long l1=colValue(col, &ok1);
00228         unsigned long l2=item->colValue(col, &ok2);
00229 /*#ifdef DEBUG
00230     DEBUGKPILOT<<"l1="<<l1<<"(ok: "<<ok1<<"), l2="<<l2<<"(ok: "<<ok2<<")"<<endl;
00231 #endif*/
00232         if (ok1 && ok2)
00233         {
00234             // Returns -1 if this item is less than i, 0 if they are
00235             // equal and 1 if this item is greater than i.
00236             int res=0;
00237             if (l1<l2) res=-1;
00238             else if (l1>l2) res=1;
00239             //else res=0;
00240 /*#ifdef DEBUG
00241     DEBUGKPILOT<<"RESULT="<<res<<endl;
00242 #endif*/
00243             return res;
00244         }
00245     }
00246     return QListViewItem::compare(i, col, ascending);
00247 }
00248 
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:48 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003