anatomypage.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Lynn Hazan                                      *
00003  *   lynn.hazan@myrealbox.com                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef ANATOMYPAGE_H
00021 #define ANATOMYPAGE_H
00022 
00023 //include files for the application
00024 #include <anatomylayout.h>
00025 
00026 // include files for QT
00027 #include <qwidget.h>
00028 #include <qtable.h>
00029 #include <qpushbutton.h>
00030 #include <qmap.h>
00031 #include <qregexp.h>
00032 #include <qheader.h> 
00033 #include <qmemarray.h> 
00034 #include <qlineedit.h>
00035 
00036 // include files for KDE
00037 
00038 
00039 //General C++ include files
00040 #include <iostream>
00041 using namespace std;
00042 
00043 
00048 class AnatomyPage : public AnatomyLayout
00049 {
00050 Q_OBJECT
00051 public:
00053   AnatomyPage(QWidget* parent = 0, const char *name = 0);
00055  ~AnatomyPage();
00056 
00060  void setAttributes(const QMap<QString, QMap<int,QString> >& attributes); 
00061  
00065  void getAttributes(QMap<QString, QMap<int,QString> >& attributesMap)const;
00066  
00070  void setGroups(const QMap<int, QValueList<int> >& groups);
00071  
00075  void getGroups(QMap<int, QValueList<int> >& groups)const;
00076  
00080  inline void setNbChannels(int nbChannels){
00081   this->nbChannels = nbChannels;
00082   for(int i =0; i<attributesTable->numRows();++i) attributesTable->removeRow(i);
00083   attributesTable->setNumRows(nbChannels);
00084  }; 
00085  
00087  inline bool isModified()const{return modified;};
00088 
00089 protected:
00094  bool eventFilter(QObject* object,QEvent* event);
00095  
00096 public slots:
00098  inline void addGroup(){  
00099   if(isIncorrectRow) return;
00100   modified = true;
00101   groupTable->insertRows(groupTable->numRows());
00102   //Use of the the 3 parameter constructor to be qt 3.1 compatible
00103   QTableItem* item = new QTableItem(groupTable,QTableItem::WhenCurrent,"");
00104   item->setWordWrap(true);
00105   groupTable->setItem(groupTable->numRows() - 1,0,item);
00106  };
00107  
00109  void removeGroup();
00110  
00112  inline void slotValidate(){ 
00113   modified = true;
00114   if(isIncorrectRow){ 
00115    groupTable->selectRow(incorrectRow);
00116    groupTable->setCurrentCell(incorrectRow,0);
00117   }
00118  };
00119  
00121  inline void groupChanged(int row,int column){
00122   modified = true;
00123   QString group = groupTable->text(row,column); 
00124 
00125   if(isIncorrectRow){
00126     QWidget* widget = groupTable->cellWidget(incorrectRow,0);
00127     QString incorrectGroup;
00128     if(widget != 0 && widget->isA("QLineEdit")) incorrectGroup = static_cast<QLineEdit*>(widget)->text();
00129     else if(widget == 0) incorrectGroup = groupTable->item(incorrectRow,0)->text();
00130     if(incorrectGroup.contains(QRegExp("[^\\d\\s]")) != 0){
00131      groupTable->selectRow(incorrectRow);
00132      groupTable->setCurrentCell(incorrectRow,0); 
00133      return;
00134     } 
00135    }
00136    
00137    isIncorrectRow = false;
00138    incorrectRow = 0;
00139    groupTable->adjustRow(row);   
00140    
00141   //the group entry should only contain digits and whitespaces
00142   if(group.contains(QRegExp("[^\\d\\s]")) != 0){
00143    isIncorrectRow = true;
00144    incorrectRow = row;
00145    groupTable->selectRow(incorrectRow);
00146    groupTable->setCurrentCell(incorrectRow,0);
00147   }   
00148  };
00149  
00151  inline void attributeChanged(int row,int column){
00152   modified = true;
00153   //hard coded that the skip attribut is an int, later it can be made more dynamic
00154   QHeader* header = attributesTable->horizontalHeader();
00155   QString attributName = header->label(column);
00156   if(attributName == "Skip"){
00157    bool ok;
00158    QString attribut = attributesTable->text(row,column);
00159    attribut.toInt(&ok);
00160    if(ok) attributesTable->adjustRow(row);
00161    else {
00162     attributesTable->selectRow(row);
00163     attributesTable->setCurrentCell(row,column);
00164    }
00165   }
00166   else attributesTable->adjustRow(row);
00167  };
00168  
00170   inline void propertyModified(){modified = true;};
00171 
00173  inline void resetModificationStatus(){modified = false;};
00174    
00175 private:
00176  int nbChannels; 
00177  bool isIncorrectRow;
00178  int incorrectRow;
00179  bool modified;
00180 };
00181 
00182 
00183 
00184 #endif

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