SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "NeuronGroupDialog.h" 00003 #include "NeuronGroupTableView.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 NeuronGroupTableView::NeuronGroupTableView(QWidget* parent, NeuronGroupModel* model) : QTableView(parent) { 00014 //Set up the view 00015 setShowGrid(false); 00016 setSelectionMode(QAbstractItemView::NoSelection); 00017 connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex))); 00018 connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(tableDoubleClicked(QModelIndex))); 00019 00020 //Header click events 00021 this->horizontalHeader()->setClickable(true); 00022 connect(this->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(headerClicked(int))); 00023 00024 //Set the model for this view and show it 00025 this->neuronGroupModel = model; 00026 setModel(model); 00027 show(); 00028 resizeHeaders(); 00029 } 00030 00031 00033 NeuronGroupTableView::~NeuronGroupTableView(){ 00034 } 00035 00036 00037 /*--------------------------------------------------------*/ 00038 /*------- PUBLIC METHODS -------*/ 00039 /*--------------------------------------------------------*/ 00040 00043 void NeuronGroupTableView::resizeHeaders(){ 00044 QHeaderView* hHeader = horizontalHeader(); 00045 hHeader->setMinimumSectionSize(10); 00046 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::VIS_COL), 20);//Visibility icon 00047 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::ZOOM_COL), 20);//Zoom icon 00048 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::ID_COL), 50);//ID 00049 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::NAME_COL), 100);//Name 00050 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::DESC_COL), 300);//Description 00051 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::SIZE_COL), 100);//Size 00052 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::NEUR_TYPE_COL), 200);//Neuron type 00053 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::SELECT_COL), 20);//Selection 00054 hHeader->resizeSection(hHeader->logicalIndex(NeuronGroupModel::PARAM_COL), 70);//Parameters 00055 hHeader->setDefaultAlignment(Qt::AlignLeft); 00056 } 00057 00058 00059 /*--------------------------------------------------------*/ 00060 /*------- PRIVATE SLOTS -------*/ 00061 /*--------------------------------------------------------*/ 00062 00064 void NeuronGroupTableView::headerClicked(int column){ 00065 if(column == NeuronGroupModel::SELECT_COL) 00066 neuronGroupModel->selectAllOrNone(); 00067 else if(column == NeuronGroupModel::VIS_COL) 00068 neuronGroupModel->showAllOrNone(); 00069 } 00070 00071 00073 void NeuronGroupTableView::tableClicked(QModelIndex index){ 00074 if(index.column() == NeuronGroupModel::PARAM_COL){ 00075 try{ 00076 ViewParametersDialog dlg(neuronGroupModel->getParameters(index.row()), this); 00077 dlg.exec(); 00078 } 00079 catch(SpikeStreamException& ex){ 00080 qCritical()<<ex.getMessage(); 00081 } 00082 return; 00083 } 00084 else{ 00085 model()->setData(index, 0); 00086 } 00087 } 00088 00089 00092 void NeuronGroupTableView::tableDoubleClicked(QModelIndex index){ 00093 if(index.column() == NeuronGroupModel::DESC_COL || index.column() == NeuronGroupModel::NAME_COL){ 00094 try{ 00095 NeuronGroupDialog* dialog = new NeuronGroupDialog(neuronGroupModel->getInfo(index), this); 00096 if(dialog->exec() == QDialog::Accepted){ 00097 neuronGroupModel->reload(); 00098 } 00099 delete dialog; 00100 } 00101 catch(SpikeStreamException& ex){ 00102 qCritical()<<ex.getMessage(); 00103 } 00104 } 00105 } 00106