Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
icoltdelegate.cpp
Go to the documentation of this file.
1 #include <QtGui>
2 
3 #include "marlin/CCProcessor.h"
4 #include "marlin/CCCollection.h"
5 
6 #include "icoltdelegate.h"
7 
9  _parent = qobject_cast<QTableWidget *>(parent);
10  _p=p;
11  _msc=msc;
12 }
13 
14 QWidget *IColTDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const
15 {
16  QLineEdit *edit = new QLineEdit(parent);
17  QComboBox *comboBox = new QComboBox(parent);
18 
19  if( index.column() != 2 ){
20  edit->setReadOnly(true);
21  return edit;
22  }
23  else{
24  sSet colsSet=_msc->getColsSet( _parent->item(index.row(),1)->text().toStdString(),
25  _parent->item(index.row(),0)->text().toStdString() , _p );
26 
27  for( sSet::const_iterator p=colsSet.begin(); p != colsSet.end(); p++ ){
28  comboBox->addItem((*p).c_str());
29  }
30  comboBox->setEditable(true);
31  comboBox->setAutoCompletion(true);
32 
33  return comboBox;
34  }
35  return NULL;
36 }
37 
38 void IColTDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
39 {
40 
41  if( index.column() != 2 ){
42  QLineEdit *edit = qobject_cast<QLineEdit *>(editor);
43  edit->setText(index.model()->data(index).toString());
44  }
45  else{
46  QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
47  if (!comboBox) return;
48 
49  int pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly);
50  if( pos != -1){
51  comboBox->setCurrentIndex(pos);
52  }
53  else{
54  comboBox->addItem(index.model()->data(index).toString());
55  pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly);
56  comboBox->setCurrentIndex(pos);
57  }
58 
59  if(_p->isActive()){
60  //set background color
61  _parent->currentItem()->setBackgroundColor(
62  _p->isErrorCol( _parent->item(index.row(),1)->text().toStdString(), comboBox->currentText().toStdString() ) ?
63  QColor(184,16,0,180) : QColor(32,140,64,180) );
64 
65  //set background color (combobox)
66  QPalette pal = comboBox->palette();
67  pal.setColor(QPalette::Base,
68  _p->isErrorCol( _parent->item(index.row(),1)->text().toStdString(), comboBox->currentText().toStdString() ) ?
69  QColor(164,32,16) : QColor(32,140,64) );
70  pal.setColor(QPalette::Text, QColor(255,255,255) );
71  comboBox->setPalette(pal);
72  }
73  }
74 }
75 
76 void IColTDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
77 {
78  if( index.column() == 2 ){
79 
80  QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
81  if (!comboBox) return;
82 
83  model->setData(index, comboBox->currentText());
84 
85  //update the processor
86  _p->getCols( INPUT, _parent->item(index.row(),0)->text().toStdString() )[ 0 ]->setValue( comboBox->currentText().toStdString() );
88 
89  if(_p->isActive()){
90  //set background color
91  _parent->currentItem()->setBackgroundColor(
92  _p->isErrorCol( _parent->item(index.row(),1)->text().toStdString(), comboBox->currentText().toStdString() ) ?
93  QColor(184,16,0,180) : QColor(32,140,64,180) );
94 
95  //set background color from (combobox)
96  QPalette pal = comboBox->palette();
97  pal.setColor(QPalette::Base,
98  _p->isErrorCol( _parent->item(index.row(),1)->text().toStdString(), comboBox->currentText().toStdString() ) ?
99  QColor(164,32,16) : QColor(32,140,64) );
100  pal.setColor(QPalette::Text, QColor(255,255,255) );
101  comboBox->setPalette(pal);
102  }
103  }
104 }
105 
this class is a Marlin Steering File consistency check Tool.
bool isErrorCol(const std::string &type, const std::string &value)
Returns true if the given collection is in the unavailable or duplicate list of this processor...
Definition: CCProcessor.cc:381
QTableWidget * _parent
Definition: icoltdelegate.h:36
T end(T...args)
IColTDelegate(const IColTDelegate &)=default
void setEditorData(QWidget *editor, const QModelIndex &index) const
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
Definition: CCProcessor.h:39
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
sSet & getColsSet(const std::string &type, const std::string &name, CCProcessor *proc)
Returns a list of all available Collections for a given type, name and processor (to use in a ComboBo...
MarlinSteerCheck * _msc
Definition: icoltdelegate.h:35
ColVec & getCols(const std::string &iotype, const std::string &type_name="ALL_COLLECTIONS")
Returns collections of a given iotype ( INPUT, OUTPUT, UNAVAILABLE, DUPLICATE ) for a given name or t...
Definition: CCProcessor.cc:352
void consistencyCheck()
Performs a check at all active processors to search for unavailable collections.
T begin(T...args)
CCProcessor * _p
Definition: icoltdelegate.h:34
#define INPUT
Definition: CCProcessor.h:15
bool isActive()
Returns true if the processor is active.
Definition: CCProcessor.h:68