SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "Globals.h" 00003 #include "GlobalVariables.h" 00004 #include "NetworkDisplay.h" 00005 #include "NetworkDao.h" 00006 #include "ConnectionsModel.h" 00007 using namespace spikestream; 00008 00009 //Qt includes 00010 #include <QDebug> 00011 #include <QIcon> 00012 00013 00015 ConnectionsModel::ConnectionsModel() : QAbstractTableModel(){ 00016 connect(Globals::getEventRouter(), SIGNAL(visibleConnectionsChangedSignal()), this, SLOT(visibleConnectionsChanged()), Qt::QueuedConnection); 00017 connect(Globals::getEventRouter(), SIGNAL(weightsChangedSignal()), this, SLOT(visibleConnectionsChanged()), Qt::QueuedConnection); 00018 } 00019 00020 00022 ConnectionsModel::~ConnectionsModel(){ 00023 } 00024 00025 00026 /*----------------------------------------------------------*/ 00027 /*----- PUBLIC METHODS -----*/ 00028 /*----------------------------------------------------------*/ 00029 00031 int ConnectionsModel::columnCount(const QModelIndex&) const{ 00032 return numCols; 00033 } 00034 00035 00038 QVariant ConnectionsModel::data(const QModelIndex & index, int role) const{ 00039 //Return invalid index if index is invalid or no network loaded 00040 if (!index.isValid()) 00041 return QVariant(); 00042 if(!Globals::networkLoaded()) 00043 return QVariant(); 00044 00045 //Check rows and columns are in range 00046 if (index.row() < 0 || index.row() >= rowCount() || index.column() < 0 || index.column() >= columnCount()) 00047 return QVariant(); 00048 00049 //Return appropriate data 00050 if (role == Qt::DisplayRole){ 00051 //Get pointer to the appropriate Connection class 00052 QList<Connection*>& tmpConList = Globals::getNetworkDisplay()->getVisibleConnectionsList(); 00053 Connection* tmpConnection = tmpConList[index.row()]; 00054 00055 if(index.column() == idCol) 00056 return tmpConnection->getID(); 00057 if(index.column() == fromIDCol) 00058 return tmpConnection->getFromNeuronID(); 00059 if(index.column() == toIDCol) 00060 return tmpConnection->getToNeuronID(); 00061 if(index.column() == delayCol) 00062 return tmpConnection->getDelay(); 00063 if(index.column() == weightCol) 00064 return tmpConnection->getWeight(); 00065 if(index.column() == tmpWeightCol) 00066 return tmpConnection->getTempWeight(); 00067 } 00068 00069 00070 //If we have reached this point ignore request 00071 return QVariant(); 00072 } 00073 00074 00076 QVariant ConnectionsModel::headerData(int section, Qt::Orientation orientation, int role) const{ 00077 if (role != Qt::DisplayRole) 00078 return QVariant(); 00079 00080 if (orientation == Qt::Horizontal){ 00081 if(section == idCol) 00082 return "ID"; 00083 if(section == fromIDCol) 00084 return "From"; 00085 if(section == toIDCol) 00086 return "To"; 00087 if(section == delayCol) 00088 return "Delay"; 00089 if(section == weightCol) 00090 return "Weight"; 00091 if(section == tmpWeightCol) 00092 return "Temp Weight"; 00093 } 00094 00095 return QVariant(); 00096 00097 } 00098 00099 00101 int ConnectionsModel::rowCount(const QModelIndex&) const{ 00102 return Globals::getNetworkDisplay()->getVisibleConnectionsList().size(); 00103 } 00104 00105 00107 void ConnectionsModel::visibleConnectionsChanged(){ 00108 reset(); 00109 } 00110 00111 00112 /*----------------------------------------------------------*/ 00113 /*----- PRIVATE METHODS -----*/ 00114 /*----------------------------------------------------------*/ 00115 00116