kpilot

listItems.cc

Go to the documentation of this file.
00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 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., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 
00033 #include <qstring.h>
00034 #include <qlistbox.h>
00035 #include <qlistview.h>
00036 
00037 
00038 #ifndef _KPILOT_LISTITEMS_H
00039 #include "listItems.h"
00040 #endif
00041 
00042 #ifdef DEBUG
00043 /* static */ int PilotListItem::crt = 0;
00044 /* static */ int PilotListItem::del = 0;
00045 /* static */ int PilotListItem::count = 0;
00046 
00047 /* static */ void PilotListItem::counts()
00048 {
00049     FUNCTIONSETUP;
00050     DEBUGKPILOT << fname
00051         << ": created=" << crt << " deletions=" << del << endl;
00052 }
00053 #endif
00054 
00055 PilotListItem::PilotListItem(const QString & text,
00056     recordid_t pilotid, void *r) :
00057     QListBoxText(text),
00058     fid(pilotid),
00059     fr(r)
00060 {
00061     // FUNCTIONSETUP;
00062 #ifdef DEBUG
00063     crt++;
00064     count++;
00065     if (!(count & 0xff))
00066         counts();
00067 #endif
00068 }
00069 
00070 PilotListItem::~PilotListItem()
00071 {
00072     // FUNCTIONSETUP;
00073 #ifdef DEBUG
00074     del++;
00075     count++;
00076     if (!(count & 0xff))
00077         counts();
00078 #endif
00079 }
00080 
00081 
00082 
00083 
00084 #ifdef DEBUG
00085 /* static */ int PilotCheckListItem::crt = 0;
00086 /* static */ int PilotCheckListItem::del = 0;
00087 /* static */ int PilotCheckListItem::count = 0;
00088 
00089 /* static */ void PilotCheckListItem::counts()
00090 {
00091     FUNCTIONSETUP;
00092     DEBUGKPILOT << fname
00093         << ": created=" << crt << " deletions=" << del << endl;
00094 }
00095 #endif
00096 
00097 PilotCheckListItem::PilotCheckListItem(QListView * parent, const QString & text, recordid_t pilotid, void *r) :
00098     QCheckListItem(parent, text, QCheckListItem::CheckBox),
00099     fid(pilotid),
00100     fr(r)
00101 {
00102     // FUNCTIONSETUP;
00103 #ifdef DEBUG
00104     crt++;
00105     count++;
00106     if (!(count & 0xff))
00107         counts();
00108 #endif
00109 }
00110 
00111 PilotCheckListItem::~PilotCheckListItem()
00112 {
00113     // FUNCTIONSETUP;
00114 #ifdef DEBUG
00115     del++;
00116     count++;
00117     if (!(count & 0xff))
00118         counts();
00119 #endif
00120 }
00121 
00122 void PilotCheckListItem::stateChange ( bool on)
00123 {
00124     // FUNCTIONSETUP;
00125     QCheckListItem::stateChange(on);
00126 
00127 }
00128 
00129 
00130 
00131 
00132 #ifdef DEBUG
00133 /* static */ int PilotListViewItem::crt = 0;
00134 /* static */ int PilotListViewItem::del = 0;
00135 /* static */ int PilotListViewItem::count = 0;
00136 
00137 /* static */ void PilotListViewItem::counts()
00138 {
00139     FUNCTIONSETUP;
00140     DEBUGKPILOT << fname
00141         << ": created=" << crt << " deletions=" << del << endl;
00142 }
00143 #endif
00144 
00145 PilotListViewItem::PilotListViewItem( QListView * parent,
00146     QString label1, QString label2, QString label3, QString label4,
00147     recordid_t pilotid, void *r):
00148     QListViewItem(parent, label1, label2, label3, label4,
00149         QString::null, QString::null, QString::null, QString::null),
00150     fid(pilotid),
00151     fr(r),
00152     d(new PilotListViewItemData)
00153 {
00154     // FUNCTIONSETUP;
00155     if (d) d->valCol=-1;
00156 #ifdef DEBUG
00157     crt++;
00158     count++;
00159     if (!(count & 0xff))
00160         counts();
00161 #endif
00162 }
00163 
00164 PilotListViewItem::~PilotListViewItem()
00165 {
00166     // FUNCTIONSETUP;
00167 #ifdef DEBUG
00168     del++;
00169     count++;
00170     if (!(count & 0xff))
00171         counts();
00172 #endif
00173 }
00174 void PilotListViewItem::setNumericCol(int col, bool numeric)
00175 {
00176     // FUNCTIONSETUP;
00177     if (numeric)
00178     {
00179         if (!numericCols.contains(col))
00180             numericCols.append(col);
00181     }
00182     else
00183     {
00184         if (numericCols.contains(col))
00185             numericCols.remove(col);
00186     }
00187 }
00188 
00189 unsigned long PilotListViewItem::colValue(int col, bool *ok) const
00190 {
00191 //  FUNCTIONSETUP;
00192 /*  if (!d)
00193     {
00194         d=new PilotListViewItemData;
00195         d->valCol=-1;
00196     }*/
00197     if (d->valCol!=col)
00198     {
00199         // Use true for ascending for now...
00200         d->val=key(col, true).toULong(&d->valOk);
00201         d->valCol=col;
00202     }
00203     if (ok) (*ok)=d->valOk;
00204     return d->val;
00205 }
00206 
00207 int PilotListViewItem::compare( QListViewItem *i, int col, bool ascending ) const
00208 {
00209 //  FUNCTIONSETUP;
00210     PilotListViewItem*item=dynamic_cast<PilotListViewItem*>(i);
00211 /*#ifdef DEBUG
00212     DEBUGKPILOT<<"Item of dyn cast: "<<item<<endl;
00213 #endif*/
00214     if (item && numericCols.contains(col))
00215     {
00216 /*#ifdef DEBUG
00217     DEBUGKPILOT<<"Comparing: col "<<col<<", Ascending: "<<ascending<<endl;
00218 #endif*/
00219         bool ok1, ok2;
00221         unsigned long l1=colValue(col, &ok1);
00222         unsigned long l2=item->colValue(col, &ok2);
00223 /*#ifdef DEBUG
00224     DEBUGKPILOT<<"l1="<<l1<<"(ok: "<<ok1<<"), l2="<<l2<<"(ok: "<<ok2<<")"<<endl;
00225 #endif*/
00226         if (ok1 && ok2)
00227         {
00228             // Returns -1 if this item is less than i, 0 if they are
00229             // equal and 1 if this item is greater than i.
00230             int res=0;
00231             if (l1<l2) res=-1;
00232             else if (l1>l2) res=1;
00233             //else res=0;
00234 /*#ifdef DEBUG
00235     DEBUGKPILOT<<"RESULT="<<res<<endl;
00236 #endif*/
00237             return res;
00238         }
00239     }
00240     return QListViewItem::compare(i, col, ascending);
00241 }
00242