/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
#include "CApp.h"
//-------------------------------------- init -----------------------------------------------------------
void DlgAllergie::init()
{if (G_pCApp->m_pCMedicaBase==0) G_pCApp->m_pCMedicaBase = new CMedicaBase;
 if (G_pCApp->m_pCMedicaBase==0)     return;

 pushButton_AddToChoix_1->setPixmap(QPixmap( Theme::getIconNext()
                                    .pixmap(QIconSet::Automatic,TRUE,QIconSet::On)));
 pushButtonRemoveFromChoix->setPixmap(QPixmap( Theme::getIconPrevious()
                                      .pixmap(QIconSet::Automatic,TRUE,QIconSet::On)));
 setIcon( Theme::getIconVidal().pixmap(QIconSet::Automatic,TRUE,QIconSet::On));

 //long nb = G_pCApp->m_pCMedicaBase->Datasemp_GetSubstanceList(listView_Sbce,  "a" );
 //textLabelStatut->setText(QString::number(nb) + tr(" substances trouvée(s)"));
 lineEditNom_textChanged( "a" );
}

//-------------------------------------- lineEditNom_textChanged -------------------------------------------------------
void DlgAllergie::lineEditNom_textChanged( const QString &qtext )
{long nb = G_pCApp->m_pCMedicaBase->Datasemp_GetSubstanceList(listView_Sbce,  qtext );

 if (nb>1)
     textLabelStatut->setText(QString::number(nb) + tr(" substances trouvées"));
 else if (nb==1)
     textLabelStatut->setText(tr("Une substance trouvée"));
 else
     textLabelStatut->setText(tr("Aucune substance trouvée"));
 lineEditNom->setFocus ();
}

//-------------------------------------- listView_Sbce_clicked -------------------------------------------------------
void DlgAllergie::listView_Sbce_clicked( QListViewItem * )
{//pushButton_AddToChoix_1_clicked();
}

//-------------------------------------- pushButton_AddToChoix_1_clicked -------------------------------------------------------
void DlgAllergie::pushButton_AddToChoix_1_clicked()
{if (listView_Sbce->childCount () ==-1)     return;   // si liste vide cassos
 QListViewItem *qlistViewItem = listView_Sbce->currentItem();
 if (qlistViewItem==0)                      return;   // si pas d'element courant

 QListViewItem *find = listView_Choix->findItem( qlistViewItem->text(0), 0 );
 if (find != 0) delete find;                                    // si existe deja l'effacer

 QListViewItem element = new QListViewItem( listView_Choix,                                        // inserer dans la liste de choix
                                            qlistViewItem->text(0),                                // libelle
                                            qlistViewItem->text(1)                                 // code
	                                  );
 lineEditNom->setFocus ();
}

//-------------------------------------- listView_Choix_clicked -------------------------------------------------------
void DlgAllergie::listView_Choix_clicked( QListViewItem * )
{
    // pushButtonRemoveFromChoix_pressed();
}

//-------------------------------------- pushButtonRemoveFromChoix_pressed -------------------------------------------------------
void DlgAllergie::pushButtonRemoveFromChoix_pressed()
{if (listView_Choix->childCount () ==-1)     return;   // si liste vide cassos
 QListViewItem *qlistViewItem = listView_Choix->currentItem();
 if (qlistViewItem==0)                       return;   // si pas d'element courant

 delete qlistViewItem;                                 // si existe deja l'effacer
 lineEditNom->setFocus ();
}

//-------------------------------------- pushButtonOK_clicked -------------------------------------------------------
void DlgAllergie::pushButtonOK_clicked()
{accept();
}






