SpikeStream Application Library  0.2
ConnectionGroupTableView.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "ConnectionGroupDialog.h"
00003 #include "ConnectionGroupTableView.h"
00004 #include "SpikeStreamException.h"
00005 #include "ViewParametersDialog.h"
00006 using namespace spikestream;
00007 
00008 //Qt includes
00009 #include <QDebug>
00010 #include <QHeaderView>
00011 
00013 ConnectionGroupTableView::ConnectionGroupTableView(QWidget* parent, ConnectionGroupModel* model) : QTableView(parent) {
00014         //Set up the view
00015         this->horizontalHeader()->setClickable(true);
00016         setShowGrid(false);
00017         setSelectionMode(QAbstractItemView::NoSelection);
00018         connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex)));
00019         connect(this->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int)));
00020         connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(tableDoubleClicked(QModelIndex)));
00021 
00022         //Set the model for this view and show it
00023         this->connectionGroupModel = model;
00024         setModel(model);
00025         show();
00026         resizeHeaders();
00027 }
00028 
00029 
00031 ConnectionGroupTableView::~ConnectionGroupTableView(){
00032 }
00033 
00034 
00035 /*--------------------------------------------------------*/
00036 /*-------             PUBLIC METHODS               -------*/
00037 /*--------------------------------------------------------*/
00038 
00041 void ConnectionGroupTableView::resizeHeaders(){
00042         QHeaderView* hHeader = horizontalHeader();
00043         hHeader->setMinimumSectionSize(10);
00044         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::VIS_COL), 20);//Visibility icon
00045         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::ID_COL), 50);//ID
00046         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::DESC_COL), 300);//Description
00047         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::SIZE_COL), 100);//Size
00048         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::FROM_NEUR_ID_COL), 100);//From neuron group
00049         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::T0_NEUR_ID_COL), 100);//To neuron group
00050         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::SYNAPSE_TYPE_COL), 100);//Synapse type
00051         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::SELECT_COL), 20);//Select
00052         hHeader->resizeSection(hHeader->logicalIndex(ConnectionGroupModel::PARAM_COL), 70);//Parameters
00053         hHeader->setDefaultAlignment(Qt::AlignLeft);
00054 }
00055 
00056 
00057 /*--------------------------------------------------------*/
00058 /*-------             PRIVATE SLOTS                -------*/
00059 /*--------------------------------------------------------*/
00060 
00062 void ConnectionGroupTableView::headerClicked(int column){
00063         if(column == ConnectionGroupModel::SELECT_COL)
00064                 connectionGroupModel->selectAllOrNone();
00065         else if(column == ConnectionGroupModel::VIS_COL)
00066                 connectionGroupModel->showAllOrNone();
00067 }
00068 
00069 
00071 void ConnectionGroupTableView::tableClicked(QModelIndex index){
00072         if(index.column() == ConnectionGroupModel::PARAM_COL){
00073                 try{
00074                         ViewParametersDialog dlg(connectionGroupModel->getParameters(index.row()), this);
00075                         dlg.exec();
00076                 }
00077                 catch(SpikeStreamException& ex){
00078                         qCritical()<<ex.getMessage();
00079                 }
00080                 return;
00081         }
00082         else{
00083                 model()->setData(index, 0);
00084         }
00085 }
00086 
00087 
00088 
00091 void ConnectionGroupTableView::tableDoubleClicked(QModelIndex index){
00092         if(index.column() == ConnectionGroupModel::DESC_COL){
00093                 try{
00094                         ConnectionGroupDialog* dialog = new ConnectionGroupDialog(connectionGroupModel->getInfo(index), this);
00095                         if(dialog->exec() == QDialog::Accepted){
00096                                 connectionGroupModel->reload();
00097                         }
00098                         delete dialog;
00099                 }
00100                 catch(SpikeStreamException& ex){
00101                         qCritical()<<ex.getMessage();
00102                 }
00103         }
00104 }
00105 
 All Classes Files Functions Variables Typedefs Friends Defines