SpikeStream Application Library  0.2
AnalysesModel.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "Globals.h"
00003 #include "NetworkDisplay.h"
00004 #include "AnalysesModel.h"
00005 #include "SpikeStreamException.h"
00006 using namespace spikestream;
00007 
00008 //Qt includes
00009 #include <QDebug>
00010 #include <QIcon>
00011 
00012 
00014 AnalysesModel::AnalysesModel(unsigned int analysisType) : QAbstractTableModel(){
00015         this->analysisType = analysisType;
00016         reload();
00017 }
00018 
00019 
00021 AnalysesModel::~AnalysesModel(){
00022 }
00023 
00024 
00025 /*------------------------------------------------------------*/
00026 /*------               PUBLIC METHODS                   ------*/
00027 /*------------------------------------------------------------*/
00028 
00030 int AnalysesModel::columnCount(const QModelIndex&) const{
00031     return numCols;
00032 }
00033 
00034 
00037 QVariant AnalysesModel::data(const QModelIndex & index, int role) const{
00038     //Return invalid index if index is invalid
00039     if (!index.isValid())
00040         return QVariant();
00041 
00042     //Check rows and columns are in range
00043     if (index.row() < 0 || index.row() >= rowCount() || index.column() < 0 || index.column() >= columnCount())
00044         return QVariant();
00045 
00046     //Return appropriate data
00047     if (role == Qt::DisplayRole){
00048         if(index.column() == idCol)
00049             return analysisInfoList[index.row()].getID();
00050         if(index.column() == netIDCol)
00051             return analysisInfoList[index.row()].getNetworkID();
00052         if(index.column() == archIDCol)
00053             return analysisInfoList[index.row()].getArchiveID();
00054         if(index.column() == timeCol)
00055             return analysisInfoList[index.row()].getStartDateTime();
00056         if(index.column() == descCol)
00057             return analysisInfoList[index.row()].getDescription();
00058         if(index.column() == typeCol)
00059             return analysisInfoList[index.row()].getAnalyisType();
00060     }
00061 
00062     if (role == Qt::DecorationRole){
00063         if(index.column() == paramCol){
00064             return QIcon(Globals::getSpikeStreamRoot() + "/images/view_parameters.xpm");
00065         }
00066     }
00067 
00068     if(role == Qt::CheckStateRole){
00069         if(index.column() == selectCol ){
00070             if(selectionMap.contains(index.row()))
00071                 return Qt::Checked;
00072             return Qt::Unchecked;
00073         }
00074     }
00075 
00076     //If we have reached this point ignore request
00077     return QVariant();
00078 }
00079 
00080 
00082 QList<AnalysisInfo> AnalysesModel::getSelectedAnalyses(){
00083     QList<AnalysisInfo> tmpList;
00084     for(int i=0; i<analysisInfoList.size(); ++i){
00085         if(selectionMap.contains(i))
00086             tmpList.append(analysisInfoList.at(i));
00087     }
00088     return tmpList;
00089 }
00090 
00091 
00093 bool AnalysesModel::setData(const QModelIndex& index, const QVariant&, int) {
00094     if (!index.isValid() || index.row() < 0 || index.row() >= rowCount())
00095         return false;
00096 
00097     //Change selection of archive
00098     if(index.column() == selectCol){
00099         //Toggle selection of this row
00100         if(selectionMap.contains(index.row()))
00101             selectionMap.remove(index.row());
00102         else
00103             selectionMap[index.row()] = true;
00104 
00105         //Emit signal that data has changed and return true to indicate data set succesfully.
00106         emit dataChanged(index, index);
00107         return true;
00108     }
00109 
00110     //If we have reached this point no data has been set
00111     return false;
00112 }
00113 
00114 
00116 QVariant AnalysesModel::headerData(int section, Qt::Orientation orientation, int role) const{
00117     if (role != Qt::DisplayRole)
00118         return QVariant();
00119 
00120     if (orientation == Qt::Horizontal){
00121         if(section == selectCol)
00122             return "";
00123         if(section == idCol)
00124             return "ID";
00125         if(section == netIDCol)
00126             return "Network";
00127         if(section == archIDCol)
00128             return "Archive";
00129         if(section == timeCol)
00130             return "Time";
00131         if(section == descCol)
00132             return "Description";
00133         if(section == paramCol)
00134             return "Parameters";
00135         if(section == typeCol)
00136             return "Type";
00137     }
00138 
00139     return QVariant();
00140 
00141 }
00142 
00143 
00145 void AnalysesModel::reload(){
00146     if(!Globals::networkLoaded() || !Globals::archiveLoaded())
00147         throw SpikeStreamException("This dialog should not be invokable when network or archive is not loaded.");
00148 
00149         analysisInfoList = Globals::getAnalysisDao()->getAnalysesInfo(Globals::getNetwork()->getID(), Globals::getArchive()->getID(), analysisType);
00150     selectionMap.clear();
00151 }
00152 
00153 
00155 int AnalysesModel::rowCount(const QModelIndex&) const{
00156     return analysisInfoList.size();
00157 }
00158 
00159 
00160 
 All Classes Files Functions Variables Typedefs Friends Defines