Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
addprocdialog.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "addprocdialog.h"
4 
6 #include "marlin/CMProcessor.h"
7 #include <memory>
8 
9 using namespace std;
10 
11 APDialog::APDialog( MarlinSteerCheck* msc, QWidget *parent, Qt::WFlags f) : QDialog(parent,f), _msc(msc)
12 {
13  _parent = qobject_cast<QMainWindow *>(parent);
14 
15  connect(this, SIGNAL(editProcessor(int)), _parent, SLOT(editAProcessor(int)));
16 
17  mainLayout = new QVBoxLayout;
18 
19  //Processor Description
20  procLabel = new QLabel;
21  procLabel->setWordWrap(true);
22 
23  QVBoxLayout *descLO = new QVBoxLayout;
24  descLO->addWidget( procLabel );
25 
26  QGroupBox *descGB = new QGroupBox(tr("Processor Description "), this);
27  descGB->setLayout( descLO );
28  descGB->setMinimumHeight( 80 );
29 
30  //Processor Type
31  cb = new QComboBox;
33 
34  for( ssMap::const_iterator p=procTypes.begin(); p != procTypes.end(); p++ ){
35  if( (p->first =="AIDAProcessor" && _msc->existsProcessor("AIDAProcessor")==1 ) || !_msc->getMProcs()->isInstalled( p->first ) ){
36  continue;
37  }
38  cb->addItem((*p).first.c_str());
39  }
40 
41  connect(cb, SIGNAL(highlighted(const QString&)), this, SLOT(changeLabel(const QString&)));
42 
43  QVBoxLayout *typeLO = new QVBoxLayout;
44  typeLO->addWidget( descGB );
45  typeLO->addWidget( cb );
46 
47  QGroupBox *typeGB = new QGroupBox(tr("Processor Type "), this);
48  typeGB->setLayout( typeLO );
49 
50 
51  //Processor Name
52  le = new QLineEdit;
53 
54  QVBoxLayout *nameLO = new QVBoxLayout;
55  nameLO->addWidget( le );
56 
57  QGroupBox *nameGB = new QGroupBox(tr("Processor Name "), this);
58  nameGB->setLayout( nameLO );
59 
60  //Buttons
61  QPushButton *okButton = new QPushButton(tr("OK"));
62  QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
63 
64  okButton->setAutoDefault(true);
65 
66  connect(okButton, SIGNAL(clicked()), this, SLOT(addProcessor()));
67  connect(this, SIGNAL(apply()), this, SLOT(accept()));
68  connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
69 
70  QHBoxLayout *buttonsLO = new QHBoxLayout;
71  buttonsLO->addWidget( okButton );
72  buttonsLO->addWidget( cancelButton );
73 
74  QWidget *buttonsWG = new QWidget(this);
75  buttonsWG->setLayout( buttonsLO );
76 
77 
78  mainLayout->addWidget(typeGB);
79  mainLayout->addWidget(nameGB);
80  mainLayout->addWidget(buttonsWG);
81 
82  setLayout(mainLayout);
83 
84  changeLabel( cb->currentText() );
85 
86  setWindowTitle(tr("Add New Processor"));
87 }
88 
89 void APDialog::changeLabel(const QString& text){
90 
91  //set the label with the processor description
92  if(procTypes.find(text.toStdString()) != procTypes.end()){
93  procLabel->setText(procTypes[text.toStdString()].c_str());
94  QString name="My";
95  name+=text;
96  le->setText(name);
97  }
98 }
99 
101 
102  if( le->displayText().isEmpty() ){
103  QMessageBox::warning(this, tr("Add New Processor"),
104  tr("You cannot add a processor without name!!\nType a name in the appropriate edit box...") );
105  return;
106  }
107 
108  int existsProc = _msc->existsProcessor(cb->currentText().toStdString(), le->displayText().toStdString() );
109 
110  if( !existsProc ){
111  //add new processor
112  _msc->addProcessor( ACTIVE, le->displayText().toStdString(), cb->currentText().toStdString() , std::shared_ptr<StringParameters>() );
113 
114  //edit processor
115  emit( editProcessor( (int)_msc->getAProcs().size()-1 ));
116 
117  //aply changes
118  emit( apply() );
119  }
120  else{
121  QString error;
122  if( existsProc == 1 ){
123  error+="An active";
124  }
125  else{
126  error+="An inactive";
127  }
128  error+=" processor with the same name & type already exists...\nPlease choose another name";
129 
130  QMessageBox::warning(this, tr("Add New Processor"), error );
131  }
132 }
APDialog(const APDialog &)=default
this class is a Marlin Steering File consistency check Tool.
ssMap getProcDesc()
returns a map with the processor descriptions
Definition: CMProcessor.h:34
bool isInstalled(const std::string &type)
returns true if the processor with the given type is installed
Definition: CMProcessor.cc:85
QLabel * procLabel
Definition: addprocdialog.h:48
T end(T...args)
MarlinSteerCheck * _msc
Definition: addprocdialog.h:52
ssMap procTypes
Definition: addprocdialog.h:45
void editProcessor(int)
void addProcessor()
QVBoxLayout * mainLayout
Definition: addprocdialog.h:50
void addProcessor(bool status, const std::string &name, const std::string &type, std::shared_ptr< StringParameters > p)
Add a new processor.
void changeLabel(const QString &text)
void apply()
CMProcessor * getMProcs()
Returns the Marlin Processors.
T find(T...args)
T size(T...args)
T begin(T...args)
QMainWindow * _parent
Definition: addprocdialog.h:46
QComboBox * cb
Definition: addprocdialog.h:47
ProcVec & getAProcs()
Returns the Active Processors.
#define ACTIVE
Definition: CCProcessor.h:10
QLineEdit * le
Definition: addprocdialog.h:49
int existsProcessor(const std::string &type, const std::string &name="")
Check if a processor of the given type with the given name already exists Returns 0 if the processor ...