Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

SIG_IndividualListItem.cpp

00001 #include "SIGEL_MasterGUI/SIG_IndividualListItem.h"
00002 
00003 #include <qpixmap.h>
00004 
00005 #include <cstdlib>
00006 
00007 namespace SIGEL_MasterGUI
00008 {
00009 
00010 SIG_IndividualListItem::SIG_IndividualListItem( QListView *parent )
00011   : QListViewItem( parent )
00012 {
00013   QString sigelRoot( std::getenv( "SIGEL_ROOT" ) );
00014   setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/individualSmall.xpm" ) );
00015 };
00016 
00017 SIG_IndividualListItem::SIG_IndividualListItem( QListView *parent, int poolPosition, SIGEL_GP::SIG_GPIndividual *theIndividual )
00018   : QListViewItem( parent ), poolPosition( poolPosition), theIndividual( theIndividual ) 
00019 {
00020   QString sigelRoot( std::getenv( "SIGEL_ROOT" ) );
00021   if( theIndividual )
00022     {
00023       QString name = theIndividual->getName();
00024       setText(0, name ); // has to be theIndividual->getName()
00025       QString fitness = QString::number( theIndividual->getFitness() );
00026       setText(1, fitness );
00027       QString age = QString::number( theIndividual->getAge() );
00028       setText(2, age );
00029       setPixmap( 0, QPixmap( sigelRoot + "/pixmaps/individualSmall.xpm" ) );
00030       this->theIndividual = theIndividual;
00031       this->poolPosition = theIndividual->getPoolPos();
00032     }
00033 };
00034 
00035 SIG_IndividualListItem::~SIG_IndividualListItem()
00036 {
00037   
00038 };
00039 QString SIG_IndividualListItem::key(int column, bool ascending) const
00040 {
00041   int const zeros = 15;
00042   switch(column)
00043     {
00044     case 0:
00045       {
00046         QString result;
00047         int length = this->text(0).length();
00048         int difference = zeros - length;
00049         for( int i=0; i < difference; i++ )
00050           result.prepend("0");
00051         result.append(this->text(0));
00052         return result;
00053       }
00054       break;
00055     case 1:
00056       {
00057         QString result;
00058         int positionOfPoint = this->text(1).find( "." );
00059         if( positionOfPoint != -1 )
00060           {
00061             for( int i=0; i < zeros - positionOfPoint; i++ )
00062               result.prepend("0");
00063           }
00064         else
00065           {
00066             for( int i=0; i < zeros - this->text(1).length(); i++ )
00067               result.prepend("0");
00068           }
00069         result.append(this->text(1));
00070         return result;
00071       }
00072       break;
00073     case 2:
00074       {
00075         QString result;
00076         int length = this->text(2).length();
00077         int difference = zeros - length;
00078         for( int i=0; i < difference; i++ )
00079           result.prepend("0");
00080         result.append(this->text(2));
00081         return result;
00082       }
00083       break;
00084     }
00085   return QString::null;
00086 };
00087 
00088 void SIG_IndividualListItem::setTo( SIGEL_GP::SIG_GPIndividual *theIndividual )
00089 {
00090   if( theIndividual )
00091     {
00092       QString name = theIndividual->getName();
00093       setText(0, name ); // has to be theIndividual->getName()
00094       QString fitness = QString::number( theIndividual->getFitness() );
00095       setText(1, fitness );
00096       QString age = QString::number( theIndividual->getAge() );
00097       setText(2, age );
00098       //  setPixmap( 0, QPixmap( "./pixmaps/individualSmall.xpm" ) );
00099       this->theIndividual = theIndividual;
00100       this->poolPosition = theIndividual->getPoolPos();
00101     }
00102 };
00103 
00104 }

Generated at Mon Sep 3 01:32:25 2001 for PG 368 - SIGEL by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000