SpikeStream Application Library
0.2
|
00001 //SpikeStream includes 00002 #include "SpikeStreamException.h" 00003 #include "SynapseParametersEditDialog.h" 00004 #include "SynapseParametersView.h" 00005 using namespace spikestream; 00006 00007 //Qt includes 00008 #include <QDebug> 00009 #include <QHeaderView> 00010 00012 SynapseParametersView::SynapseParametersView(QWidget* parent, SynapseParametersModel* 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 SynapseParametersView::~SynapseParametersView(){ 00032 } 00033 00034 00035 /*----------------------------------------------------------*/ 00036 /*----- PRIVATE SLOTS -----*/ 00037 /*----------------------------------------------------------*/ 00038 00041 void SynapseParametersView::resizeHeaders(){ 00042 QHeaderView* hHeader = horizontalHeader(); 00043 hHeader->setMinimumSectionSize(10); 00044 hHeader->resizeSection(hHeader->logicalIndex(0), 100);//Description 00045 QList<ParameterInfo> conParams = model->getParameterInfoList(); 00046 for(int i=0; i<conParams.size(); ++i){ 00047 int tmpParamLength = 10+conParams.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(conParams.size() + 1), 50);//Edit button 00055 hHeader->setDefaultAlignment(Qt::AlignLeft); 00056 } 00057 00058 00060 void SynapseParametersView::tableClicked(QModelIndex index){ 00061 if(index.column() != model->getParameterInfoList().size() + 1) 00062 return; 00063 try{ 00064 SynapseParametersEditDialog dialog(model->getConnectionGroupInfo(index.row()), model->getParameterInfoList(), model->getParameterValues(index.row()), this); 00065 if(dialog.exec() == QDialog::Accepted) 00066 model->reload(); 00067 } 00068 catch(SpikeStreamException& ex){ 00069 qCritical()<<ex.getMessage(); 00070 } 00071 } 00072