Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nparamvecset.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "nparamvecset.h"
4 #include "nparamvecsetd.h"
5 
6 using namespace std;
7 
8 //constructor
10  MarlinSteerCheck* msc,
11  CCProcessor* p,
12  QTableWidget *parent,
13  QDialog *dialog
14  ):
15  _msc(msc),
16  _p(p),
17  _parent(parent),
18  _dialog(dialog)
19 {
20  valTable = new QTableWidget;
21 
22  valTable->verticalHeader()->hide();
23  valTable->setSelectionMode(QAbstractItemView::NoSelection);
24  valTable->setEditTriggers(QAbstractItemView::AllEditTriggers);
25 
26  QPushButton *addButton = new QPushButton(tr("Add"));
27  QPushButton *remButton = new QPushButton(tr("Rem"));
28 
29  addButton->setAutoDefault( false );
30  remButton->setAutoDefault( false );
31 
32  addButton->setToolTip(tr("Add New Row"));
33  remButton->setToolTip(tr("Remove Selected Row"));
34 
35  connect(addButton, SIGNAL(clicked()), this, SLOT(addValSet()));
36  connect(remButton, SIGNAL(clicked()), this, SLOT(remValSet()));
37 
38  QVBoxLayout *buttonsLO = new QVBoxLayout;
39  buttonsLO->addWidget(addButton);
40  buttonsLO->addWidget(remButton);
41 
42  QWidget *buttons = new QWidget;
43  buttons->setLayout(buttonsLO);
44 
45  //layout
46  QGridLayout *layout = new QGridLayout;
47  layout->addWidget( valTable, 0, 0 );
48  layout->addWidget( buttons, 0, 1, Qt::AlignTop | Qt::AlignRight );
49 
50  //group box
51  QGroupBox *groupBox = new QGroupBox(tr("Edit Parameter Values"));
52  groupBox->setLayout(layout);
53  groupBox->setMinimumWidth(550);
54  groupBox->setMaximumHeight(600);
55 
56  mainLayout = new QVBoxLayout;
57  mainLayout->addWidget( groupBox );
58 
59  setLayout( mainLayout );
60  this->hide();
61 }
62 
64  string _key = _parent->item(_parent->currentRow(), 0)->text().toStdString();
65  string _val = _parent->item(_parent->currentRow(), 1)->text().toStdString();
66  int _ssize = _msc->getMProcs()->getParamSetSize(_p->getType(), _key);
67 
68  valTable->setColumnCount(0);
69  valTable->setRowCount(0);
70  if( _ssize != 0 ){
71  this->show();
72 
73  valTable->setColumnCount(_ssize);
74 
75  for( int i=0; i<_ssize; i++ ){
76  valTable->horizontalHeader()->resizeSection(i, 90);
77  }
78 
79 
80  //initialize table
81  StringVec tokens;
82  _msc->getMProcs()->tokenize( _val, tokens );
83 
84  if(( tokens.size() % _ssize ) != 0 ){
85  cerr << "Parameter [" << _key << "] from processor [" << _p->getName() << "] [" << _p->getType() <<
86  "]... Has an error: Number of parameters do not fit for the Set Size specified!!\n";
87  }
88 
89  for( unsigned int i=0; i<tokens.size()/_ssize; i++ ){
90  int row = valTable->rowCount();
91  valTable->setRowCount(row + 1);
92  for( int j=0; j<_ssize; j++ ){
93  QTableWidgetItem *item = new QTableWidgetItem( tokens[ (i*_ssize)+j ].c_str() );
94 
95  item->setToolTip( QString( _msc->getMProcs()->getParamD( _p->getType(), _key ).c_str() ));
96  valTable->setItem(row, j, item);
97  }
98  }
99 
100  //delegate
102  valTable->setItemDelegate(d);
103  }
104  else{
105  this->hide();
106  }
107 }
108 
110 
111  string _key = _parent->item(_parent->currentRow(), 0)->text().toStdString();
112  int _ssize = _msc->getMProcs()->getParamSetSize(_p->getType(), _key);
113 
114  int row = valTable->rowCount();
115  valTable->setRowCount(row + 1);
116 
117  StringVec newVals;
118 
119  for( int i=0; i<_ssize; i++ ){
120  QTableWidgetItem *item = new QTableWidgetItem( "0" );
121  valTable->setItem(row, i, item);
122  newVals.push_back("0");
123  }
124 
125  _p->getParameters()->add( _key, newVals );
126 }
127 
129 
130  if(valTable->currentRow() != -1 ){
131 
132  string _key = _parent->item(_parent->currentRow(), 0)->text().toStdString();
133  int _ssize = _msc->getMProcs()->getParamSetSize(_p->getType(), _key);
134 
135  StringVec vals, newVals;
136  string text;
137  _p->getParameters()->getStringVals( _key, vals );
138 
139  //if it is the last parameter being removed just deactivate the optional parameter
140  if( (int)vals.size() == _ssize && _msc->getMProcs()->isParamOpt(_p->getType(), _key) ){
141  _p->setOptionalParam( _key, true );
142  _parent->item(_parent->currentRow(), 2)->setCheckState( Qt::Unchecked );
143  return;
144  }
145  //prevent the last parameter to be removed
146  if( (int)vals.size() == _ssize && !_msc->getMProcs()->isParamOpt(_p->getType(), _key) ){
147  return;
148  }
149 
150  int ret = QMessageBox::warning(this, tr("Remove Row"),
151  tr("Do you want to delete the entire row?"),
152  QMessageBox::Yes | QMessageBox::Default,
153  QMessageBox::No);
154 
155  if( ret == QMessageBox::No ){
156  return;
157  }
158 
159  for( int i=0; i<(int)vals.size(); i++ ){
160  if( i < (valTable->currentRow()*_ssize) || i > ((valTable->currentRow()*_ssize)+(_ssize-1)) ){
161  newVals.push_back(vals[i]);
162  text+=vals[i];
163  text+=" ";
164  }
165  }
166 
167  _p->getParameters()->erase( _key );
168  _p->getParameters()->add( _key, newVals );
169 
170  _parent->item(_parent->currentRow(), 1)->setText( text.c_str() );
171  updateTable();
172  }
173 }
this class is a Marlin Steering File consistency check Tool.
void updateTable()
CCProcessor * _p
Definition: nparamvecset.h:49
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
Definition: CCProcessor.h:39
const std::string getParamD(const std::string &type, const std::string &key)
returns the description of the parameter with the given key for the processor with the given type ...
Definition: CMProcessor.cc:165
T push_back(T...args)
void setOptionalParam(const std::string &key, bool optional=true)
Sets a parameter as optional (if optional=true parameter is written out as a comment) ...
Definition: CCProcessor.cc:446
QVBoxLayout * mainLayout
Definition: nparamvecset.h:54
NParamVecSet(const NParamVecSet &)=default
const std::string & getType()
Returns the Type of the processor.
Definition: CCProcessor.h:77
const std::string & getName()
Returns the Name of the processor.
Definition: CCProcessor.h:74
CMProcessor * getMProcs()
Returns the Marlin Processors.
void tokenize(const std::string str, StringVec &tokens, const std::string &delimiters=" ")
Definition: CMProcessor.cc:212
T size(T...args)
T c_str(T...args)
int getParamSetSize(const std::string &type, const std::string &key)
returns the set_size of the parameter with the given key for the processor with the given type ...
Definition: CMProcessor.cc:181
bool isParamOpt(const std::string &type, const std::string &key)
returns true if the parameter with the given key for the processor with the given type is optional ...
Definition: CMProcessor.cc:189
QTableWidget * valTable
Definition: nparamvecset.h:51
MarlinSteerCheck * _msc
Definition: nparamvecset.h:48
std::shared_ptr< StringParameters > getParameters()
Returns the string parameters for this processor.
Definition: CCProcessor.h:103
QTableWidget * _parent
Definition: nparamvecset.h:50