Marlin  01.17.01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
icoldelegate.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 "icoldelegate.h"
7 
8 IColDelegate::IColDelegate(CCProcessor* p, MarlinSteerCheck* msc, const QString& name, const QString& type, QObject *parent) : QItemDelegate(parent){
9  _name=name.toStdString();
10  _type=type.toStdString();
11  _parent = qobject_cast<QTableWidget *>(parent);
12  _p=p;
13  _msc=msc;
14 }
15 
16 QWidget *IColDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex &index) const
17 {
18  if( index.column() == 0 ){
19  QComboBox *comboBox = new QComboBox(parent);
20 
21  sSet colsSet=_msc->getColsSet( _type, _name, _p );
22 
23  for( sSet::const_iterator p=colsSet.begin(); p != colsSet.end(); p++ ){
24  comboBox->addItem((*p).c_str());
25  }
26  comboBox->setEditable(true);
27  comboBox->setAutoCompletion(true);
28 
29  return comboBox;
30  }
31  return NULL;
32 }
33 
34 void IColDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
35 {
36  QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
37  if (!comboBox) return;
38 
39  int pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly);
40  if( pos != -1){
41  comboBox->setCurrentIndex(pos);
42  }
43  else{
44  comboBox->addItem(index.model()->data(index).toString());
45  pos = comboBox->findText(index.model()->data(index).toString(), Qt::MatchExactly);
46  comboBox->setCurrentIndex(pos);
47  }
48  if( _p->isActive() ){
49  //set background color
50  _parent->currentItem()->setBackgroundColor( _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ?
51  QColor(184,16,0,180) : QColor(32,140,64,180) );
52 
53  //set background color from (combobox)
54  QPalette pal = comboBox->palette();
55  pal.setColor(QPalette::Base, _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ?
56  QColor(164,32,16) : QColor(32,140,64) );
57  pal.setColor(QPalette::Text, QColor(255,255,255) );
58  comboBox->setPalette(pal);
59  }
60 }
61 
62 void IColDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
63 {
64  QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
65  if (!comboBox) return;
66 
67  model->setData(index, comboBox->currentText());
68 
69  //update the processor
70  _p->getCols( INPUT, _name )[ index.row() ]->setValue( comboBox->currentText().toStdString() );
72 
73  if( _p->isActive() ){
74  //set background color
75  _parent->currentItem()->setBackgroundColor( _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ?
76  QColor(184,16,0,180) : QColor(32,140,64,180) );
77 
78  //set background color from (combobox)
79  QPalette pal = comboBox->palette();
80  pal.setColor(QPalette::Base, _p->isErrorCol( _type, comboBox->currentText().toStdString() ) ?
81  QColor(164,32,16) : QColor(32,140,64) );
82  pal.setColor(QPalette::Text, QColor(255,255,255) );
83  comboBox->setPalette(pal);
84  }
85 }
86 
88 
89  //update the table
90  int row = _parent->rowCount();
91  _parent->setRowCount(row + 1);
92 
93  QTableWidgetItem *item0 = new QTableWidgetItem( _msc->getColsSet( _type, _name, _p ).size() != 0 ?
94  (* _msc->getColsSet( _type, _name, _p ).begin()).c_str() : "No_Suitable_Collection_Found" );
95 
96  //update the processor
97  _p->addCol( INPUT, _name, _type, _msc->getColsSet( _type, _name, _p ).size() != 0 ?
98  (* _msc->getColsSet( _type, _name, _p ).begin()).c_str() : "No_Suitable_Collection_Found" );
100 
101  if( _p->isActive() ){
102  //set background color
103  item0->setBackgroundColor( _p->isErrorCol( _type, item0->text().toStdString() ) ?
104  QColor(184,16,0,180) : QColor(32,140,64,180) );
105  }
106  _parent->setItem(row, 0, item0);
107  _parent->setCurrentItem(item0);
108 }
109 
111 
112  int row = _parent->currentRow();
113  if( row >= 0 && row < _parent->rowCount() ){
114 
115  //update the table
116  _parent->removeRow( row );
117 
118  //update the processor
119  _p->remCol( INPUT, _name, row );
120  }
121 }
QTableWidget * _parent
Definition: icoldelegate.h:42
std::string _name
Definition: icoldelegate.h:38
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
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
T end(T...args)
void remCol(const std::string &iotype, const std::string &name, unsigned int index)
Removes collection of the given iotype ( INPUT / OUTPUT ) with the given name at the given index...
Definition: CCProcessor.cc:327
CCProcessor * _p
Definition: icoldelegate.h:40
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
handles information about marlin processors and their collections needed by MarlinSteerCheck ...
Definition: CCProcessor.h:39
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...
IColDelegate(const IColDelegate &)=default
std::string _type
Definition: icoldelegate.h:39
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.
void addCol(const std::string &iotype, const std::string &name, const std::string &type, const std::string &value)
Adds a collection of the given iotype ( INPUT / OUTPUT ) with the given name, type and value...
Definition: CCProcessor.cc:290
void remCollection()
T size(T...args)
MarlinSteerCheck * _msc
Definition: icoldelegate.h:41
T begin(T...args)
void addCollection()
void setEditorData(QWidget *editor, const QModelIndex &index) const
#define INPUT
Definition: CCProcessor.h:15
bool isActive()
Returns true if the processor is active.
Definition: CCProcessor.h:68