SpikeStream Application Library  0.2
NeuronParametersView.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "NeuronParametersEditDialog.h"
00003 #include "NeuronParametersView.h"
00004 using namespace spikestream;
00005 
00006 //Qt includes
00007 #include <QDebug>
00008 #include <QHeaderView>
00009 
00010 
00012 NeuronParametersView::NeuronParametersView(QWidget* parent, NeuronParametersModel* model) : QTableView(parent) {
00013         this->model = model;
00014 
00015         //Set up the view
00016         setShowGrid(false);
00017         setSelectionMode(QAbstractItemView::NoSelection);
00018         connect(this, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex)));
00019 
00020         //Set the model for this view and show it
00021         setModel(model);
00022         show();
00023         resizeHeaders();
00024 
00025         //Listen for resize events
00026         connect(model, SIGNAL(modelReset()), this, SLOT(resizeHeaders()));
00027 }
00028 
00029 
00031 NeuronParametersView::~NeuronParametersView(){
00032 }
00033 
00034 
00035 /*----------------------------------------------------------*/
00036 /*-----                 PRIVATE SLOTS                  -----*/
00037 /*----------------------------------------------------------*/
00038 
00041 void NeuronParametersView::resizeHeaders(){
00042         QHeaderView* hHeader = horizontalHeader();
00043         hHeader->setMinimumSectionSize(10);
00044         hHeader->resizeSection(hHeader->logicalIndex(0), 100);//Description
00045         QList<ParameterInfo> neuronParams = model->getParameterInfoList();
00046         for(int i=0; i<neuronParams.size(); ++i){
00047                 int tmpParamLength = 10+neuronParams.at(i).getName().length() * 10;
00048                 if(tmpParamLength < 40)
00049                         tmpParamLength = 40;
00050                 hHeader->resizeSection(hHeader->logicalIndex(i+1), tmpParamLength);//Parameter name
00051         }
00052 
00053         //Icon
00054         hHeader->resizeSection(hHeader->logicalIndex(neuronParams.size() + 1), 50);//Edit button
00055         hHeader->setDefaultAlignment(Qt::AlignLeft);
00056 }
00057 
00058 
00060 void NeuronParametersView::tableClicked(QModelIndex index){
00061         if(index.column() != model->getParameterInfoList().size() + 1)
00062                 return;
00063 
00064         NeuronParametersEditDialog dialog(model->getNeuronGroupInfo(index.row()), model->getParameterInfoList(), model->getParameterValues(index.row()), this);
00065         if(dialog.exec() == QDialog::Accepted)
00066                 model->reload();
00067 }
00068 
 All Classes Files Functions Variables Typedefs Friends Defines