unitlistpage.h

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Michael Zugaro                                  *
00003  *   michael.zugaro@college-de-france.fr                                   *
00004  *   Copyright (C) 2004 by Lynn Hazan                                      *
00005  *   lynn.hazan@myrealbox.com                                              *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 #ifndef UNITLISTPAGE_H
00023 #define UNITLISTPAGE_H
00024 
00025 //include files for the application
00026 #include <unitlistlayout.h>
00027 
00028 // include files for QT
00029 #include <qwidget.h>
00030 #include <qtable.h>
00031 #include <qpushbutton.h>
00032 #include <qmap.h>
00033 #include <qregexp.h>
00034 #include <qheader.h> 
00035 #include <qmemarray.h> 
00036 #include <qlineedit.h>
00037 
00038 // include files for KDE
00039 
00040 
00041 //General C++ include files
00042 #include <iostream>
00043 using namespace std;
00044 
00045 
00050 class UnitListPage : public UnitListLayout
00051 {
00052         Q_OBJECT
00053 
00054         public:
00056                 UnitListPage(QWidget* parent = 0, const char *name = 0);
00058                 ~UnitListPage();
00062                 void setUnits(const QMap<int, QValueList<QString> >& units);
00066                 void getUnits(QMap<int, QValueList<QString> >& units)const;
00070                 inline void setNbUnits(int nbUnits)
00071                 {
00072                         this->nbUnits = nbUnits;
00073                         for(int i =0; i<unitTable->numRows();++i) unitTable->removeRow(i);
00074                         unitTable->setNumRows(nbUnits);
00075                 }; 
00077                 inline bool isModified()const{return modified;};
00078         
00079         protected:
00084                 bool eventFilter(QObject* object,QEvent* event);
00085         
00086         public slots:
00088                 inline void addUnit()
00089                 {  
00090                         if(isIncorrect) return;
00091                         modified = true;
00092                         unitTable->insertRows(unitTable->numRows());
00093                         //Use of the the 3 parameter constructor to be qt 3.1 compatible
00094                         for(int i=0;i<6;++i)
00095                         {
00096                                 QTableItem* item = new QTableItem(unitTable,QTableItem::WhenCurrent,"");
00097                                 item->setWordWrap(true);
00098                                 unitTable->setItem(unitTable->numRows() - 1,i,item);
00099                         }
00100                 };
00102                 void removeUnit();
00104                 inline void currentChanged()
00105                 { 
00106                         if(isIncorrect)
00107                         { 
00108                                 unitTable->selectRow(incorrectRow);
00109                                 unitTable->setCurrentCell(incorrectRow,incorrectColumn);
00110                         }
00111                 };
00113                 inline void unitChanged(int row,int column)
00114                 {
00115                         QString unit = unitTable->text(row,column); 
00116                         //the group and cluster entries should only contain digits
00117                         //the I.D. entry should only contain digits and '.'
00118                         if((column==0||column==1)&&(unit.contains(QRegExp("[^\\d]"))!=0)||(column==4&&(unit.contains(QRegExp("[^\\d.]"))!=0)))
00119                         {
00120                                 isIncorrect = true;
00121                                 incorrectRow = row;
00122                                 incorrectColumn = column;
00123 /*                              unitTable->selectRow(row);
00124                                 unitTable->setCurrentCell(row,column);*/
00125                         }
00126                         else
00127                         { 
00128                                 isIncorrect = false;
00129                                 unitTable->adjustRow(row);
00130                         }
00131                 };
00133                 inline void propertyModified(){modified = true;};
00135                 inline void resetModificationStatus(){modified = false;};
00136    
00137         private:
00138 
00139                 int     nbUnits; 
00140                 bool    isIncorrect;
00141                 int     incorrectRow,incorrectColumn;
00142                 bool    modified;
00143 };
00144 
00145 
00146 
00147 #endif

Generated on Sat Sep 15 16:04:45 2007 for ndmanager.kdevelop by  doxygen 1.5.1