65
ParamEditorDelegate::ParamEditorDelegate(QObject* parent)
66
: QItemDelegate(parent)
70
QWidget *ParamEditorDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& , const QModelIndex& index) const
72
Int type = index.sibling(index.row(),0).data(Qt::UserRole).toInt();
72
void OpenMSLineEdit::focusInEvent ( QFocusEvent * e )
74
//std::cerr << "got focus";
77
void OpenMSLineEdit::focusOutEvent ( QFocusEvent * e )
79
//std::cerr << "lost focus";
83
ParamEditorDelegate::ParamEditorDelegate(QObject * parent) :
88
QWidget * ParamEditorDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem &, const QModelIndex & index) const
90
Int type = index.sibling(index.row(), 0).data(Qt::UserRole).toInt();
74
92
// only create editor for first column (value column)
75
if(index.column()==1 && type!=ParamEditor::NODE)
77
QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
78
QString restrictions = index.sibling(index.row(),2).data(Qt::UserRole).toString();
79
QString value = index.sibling(index.row(),1).data(Qt::DisplayRole).toString();
80
if (dtype=="string" && restrictions!="") //Drop-down list for enums
82
QComboBox* editor = new QComboBox(parent);
85
list += restrictions.split(",");
86
editor->addItems(list);
87
connect(editor,SIGNAL(activated(int)),this, SLOT(commitAndCloseComboBox_()));
90
else if(dtype == "output file")
92
QLineEdit* editor = new QLineEdit(parent);
93
QString dir="";// = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
93
if (index.column() == 1 && type != ParamEditor::NODE)
95
has_uncommited_data_ = false; // by default all data is committed
97
QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
98
QString restrictions = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
99
QString value = index.sibling(index.row(), 1).data(Qt::DisplayRole).toString();
100
if (dtype == "string" && restrictions != "") //Drop-down list for enums
102
QComboBox * editor = new QComboBox(parent);
105
list += restrictions.split(",");
106
editor->addItems(list);
107
connect(editor, SIGNAL(activated(int)), this, SLOT(commitAndCloseComboBox_()));
110
else if (dtype == "output file")
112
QLineEdit * editor = new QLineEdit(parent);
113
QString dir = ""; // = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
94
114
if (File::isDirectory(value) || File::writable(value))
96
116
dir = File::absolutePath(value).toQString();
98
fileName_ = QFileDialog::getSaveFileName(editor,tr("Output File"),dir);
101
else if(dtype == "input file")
103
QLineEdit* editor = new QLineEdit(parent);
104
QString dir="";// = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
118
fileName_ = QFileDialog::getSaveFileName(editor, tr("Output File"), dir);
121
else if (dtype == "input file")
123
QLineEdit * editor = new QLineEdit(parent);
124
QString dir = ""; // = index.sibling(index.row(),0).data(Qt::DisplayRole).toString();
105
125
if (File::isDirectory(value) || File::exists(value))
107
127
dir = File::absolutePath(value).toQString();
109
fileName_ = QFileDialog::getOpenFileName(editor,tr("Input File"),dir);
112
else if(dtype =="string list" || dtype =="int list" || dtype=="double list" || dtype =="input file list" || dtype =="output file list" ) // for lists
114
QString str = "<"+ index.sibling(index.row(),0).data(Qt::DisplayRole).toString() + "> " +"(<" + dtype + ">)";
115
ListEditor *editor = new ListEditor(0,str);
116
editor->setTypeName(index.sibling(index.row(),0).data(Qt::DisplayRole).toString());
117
editor->setModal(true);
118
connect(editor,SIGNAL(accepted()),this, SLOT(commitAndCloseListEditor_()));
119
connect(editor,SIGNAL(rejected()),this, SLOT(closeListEditor_()));
122
else //LineEditor for rest
124
QLineEdit *editor = new QLineEdit(parent);
125
editor->setFocusPolicy(Qt::StrongFocus);
132
void ParamEditorDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
134
QString str = index.data(Qt::DisplayRole).toString();
129
fileName_ = QFileDialog::getOpenFileName(editor, tr("Input File"), dir);
132
else if (dtype == "string list" || dtype == "int list" || dtype == "double list" || dtype == "input file list" || dtype == "output file list") // for lists
134
QString str = "<" + index.sibling(index.row(), 0).data(Qt::DisplayRole).toString() + "> " + "(<" + dtype + ">)";
135
ListEditor * editor = new ListEditor(0, str);
136
editor->setTypeName(index.sibling(index.row(), 0).data(Qt::DisplayRole).toString());
137
editor->setModal(true);
138
connect(editor, SIGNAL(accepted()), this, SLOT(commitAndCloseListEditor_()));
139
connect(editor, SIGNAL(rejected()), this, SLOT(closeListEditor_()));
142
else //LineEditor for rest
144
OpenMSLineEdit * editor = new OpenMSLineEdit(parent);
145
editor->setFocusPolicy(Qt::StrongFocus);
146
connect(editor, SIGNAL(lostFocus()), this, SLOT(commitAndCloseLineEdit_()));
147
//std::cerr << "created ... \n";
148
has_uncommited_data_ = true;
155
void ParamEditorDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
157
QString str = index.data(Qt::DisplayRole).toString();
136
159
// only set editor data for first column (value column)
137
if(index.column()==1)
139
if(qobject_cast<QComboBox*>(editor)) //Drop-down list for enums
141
int index = static_cast<QComboBox*>(editor)->findText(str);
146
static_cast<QComboBox*>(editor)->setCurrentIndex(index);
148
else if(qobject_cast<QLineEdit*>(editor))// LineEdit for other values
150
QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
151
if(dtype == "output file" || dtype == "input file") /// for output/input file
153
if(!fileName_.isNull())
155
static_cast<QLineEdit*>(editor)->setText(fileName_);
160
if(str == "" && (dtype == "int" || dtype == "float"))
162
if (dtype == "int") static_cast<QLineEdit*>(editor)->setText("0");
163
else if (dtype == "float") static_cast<QLineEdit*>(editor)->setText("nan");
167
static_cast<QLineEdit*>(editor)->setText(str);
171
else // ListEditor for lists
174
list = str.mid(1,str.length()-2);
175
QString type = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
176
StringList rlist = StringList::create(list);
177
for(UInt i = 0; i < rlist.size(); ++i)
179
rlist[i] = rlist[i].trim();
181
if(type == "int list")
183
static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::INT);
185
else if(type == "double list")
187
static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::FLOAT);
189
else if(type == "string list")
191
static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::STRING);
193
else if(type == "input file list")
195
static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::INPUT_FILE);
197
else if(type == "output file list")
199
static_cast<ListEditor*>(editor)->setList(rlist,ListEditor::OUTPUT_FILE);
201
static_cast<ListEditor*>(editor)->setListRestrictions(index.sibling(index.row(),2).data(Qt::UserRole).toString());
206
void ParamEditorDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
208
QVariant present_value = index.data(Qt::DisplayRole);
211
bool new_list = false;
160
if (index.column() == 1)
162
if (qobject_cast<QComboBox *>(editor)) //Drop-down list for enums
164
int index = static_cast<QComboBox *>(editor)->findText(str);
169
static_cast<QComboBox *>(editor)->setCurrentIndex(index);
171
else if (qobject_cast<QLineEdit *>(editor)) // LineEdit for other values
173
QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
174
if (dtype == "output file" || dtype == "input file") /// for output/input file
176
if (!fileName_.isNull())
178
static_cast<QLineEdit *>(editor)->setText(fileName_);
183
if (str == "" && (dtype == "int" || dtype == "float"))
186
static_cast<QLineEdit *>(editor)->setText("0");
187
else if (dtype == "float")
188
static_cast<QLineEdit *>(editor)->setText("nan");
192
static_cast<QLineEdit *>(editor)->setText(str);
196
else // ListEditor for lists
199
list = str.mid(1, str.length() - 2);
200
QString type = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
201
StringList rlist = StringList::create(list);
202
for (UInt i = 0; i < rlist.size(); ++i)
204
rlist[i] = rlist[i].trim();
206
if (type == "int list")
208
static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::INT);
210
else if (type == "double list")
212
static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::FLOAT);
214
else if (type == "string list")
216
static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::STRING);
218
else if (type == "input file list")
220
static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::INPUT_FILE);
222
else if (type == "output file list")
224
static_cast<ListEditor *>(editor)->setList(rlist, ListEditor::OUTPUT_FILE);
226
static_cast<ListEditor *>(editor)->setListRestrictions(index.sibling(index.row(), 2).data(Qt::UserRole).toString());
231
void ParamEditorDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
233
QVariant present_value = index.data(Qt::DisplayRole);
236
bool new_list = false;
212
237
// only set model data for first column (value column)
213
if(index.column()==1)
216
if(qobject_cast<QComboBox*>(editor)) //Drop-down list for enums
218
new_value = QVariant(static_cast<QComboBox*>(editor)->currentText());
220
else if(qobject_cast<QLineEdit*>(editor))
222
QString dtype = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
223
if(dtype =="output file" || dtype == "input file")// input/outut file
226
new_value = QVariant(static_cast<QLineEdit*>(editor)->text());
229
else if(static_cast<QLineEdit*>(editor)->text() == "" && ((dtype == "int") || (dtype == "float"))) //numeric
231
if (dtype == "int") new_value = QVariant("0");
232
else if (dtype == "float") new_value = QVariant("nan");
236
new_value = QVariant(static_cast<QLineEdit*>(editor)->text());
241
list = static_cast<ListEditor*>(editor)->getList();
242
for(UInt i = 1; i < list.size(); ++i)
244
list[i] = "\n" + list[i] ;
248
//check if it matches the restrictions or is empty
249
if (new_value.toString()!="")
251
QString type = index.sibling(index.row(),2).data(Qt::DisplayRole).toString();
252
bool restrictions_met = true;
253
String restrictions = index.sibling(index.row(),2).data(Qt::UserRole).toString();
254
if (type=="int") //check if valid integer
257
new_value.toString().toLong(&ok);
260
QMessageBox::warning(0,"Invalid value",QString("Cannot convert '%1' to integer number!").arg(new_value.toString()) );
261
new_value = present_value;
264
vector<String> parts;
265
if (restrictions.split(' ',parts))
267
if (parts[0]!="" && new_value.toInt()<parts[0].toInt())
269
restrictions_met = false;
271
if (parts[1]!="" && new_value.toInt()>parts[1].toInt())
273
restrictions_met = false;
277
else if (type=="float") //check if valid float
280
new_value.toString().toDouble(&ok);
283
QMessageBox::warning(0,"Invalid value",QString("Cannot convert '%1' to floating point number!").arg(new_value.toString()) );
284
new_value = present_value;
287
vector<String> parts;
288
if (restrictions.split(' ',parts))
290
if (parts[0]!="" && new_value.toDouble()<parts[0].toDouble())
292
restrictions_met = false;
294
if (parts[1]!="" && new_value.toDouble()>parts[1].toDouble())
296
restrictions_met = false;
300
if(!restrictions_met)
302
QMessageBox::warning(0,"Invalid value",QString("Value restrictions not met: %1").arg(index.sibling(index.row(),3).data(Qt::DisplayRole).toString()) );
303
new_value = present_value;
312
new_value = QVariant(QString::fromStdString(ss.str()));
313
model->setData(index, new_value);
314
model->setData(index,QBrush(Qt::yellow),Qt::BackgroundRole);
320
if(new_value!=present_value)
322
model->setData(index, new_value);
323
model->setData(index,QBrush(Qt::yellow),Qt::BackgroundRole);
329
void ParamEditorDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& ) const
331
editor->setGeometry(option.rect);
334
bool ParamEditorDelegate::exists_(QString name, QModelIndex index) const
336
UInt current_index = 0;
337
while(index.parent().child(current_index,0).isValid())
340
current_index != (UInt)(index.row())
342
index.parent().child(current_index,0).data(Qt::DisplayRole).toString()==name
345
(index.data(Qt::UserRole).toInt()==0 && index.parent().child(current_index,0).data(Qt::UserRole).toInt()==0)
347
(index.data(Qt::UserRole).toInt()!=0 && index.parent().child(current_index,0).data(Qt::UserRole).toInt()!=0)
358
void ParamEditorDelegate::commitAndCloseListEditor_()
360
ListEditor* editor = qobject_cast<ListEditor*>(sender());
361
emit commitData(editor);
362
emit closeEditor(editor);
365
void ParamEditorDelegate::commitAndCloseComboBox_()
367
QComboBox* editor = qobject_cast<QComboBox*>(sender());
368
emit commitData(editor);
369
emit closeEditor(editor);
372
void ParamEditorDelegate::closeListEditor_()
374
ListEditor* editor = qobject_cast<ListEditor*>(sender());
375
emit closeEditor(editor);
378
///////////////////ParamTree/////////////////////////////////
380
ParamTree::ParamTree(QWidget* parent)
381
: QTreeWidget(parent)
385
void ParamTree::selectionChanged(const QItemSelection& s, const QItemSelection&)
389
emit selected(s.indexes().first());
393
bool ParamTree::edit(const QModelIndex& index, EditTrigger trigger, QEvent* event)
395
if (trigger == QAbstractItemView::EditKeyPressed)
397
return QAbstractItemView::edit(index.sibling(index.row(),1), trigger, event);
399
return QAbstractItemView::edit(index, trigger, event);
404
///////////////////ParamEditor/////////////////////////////////
406
ParamEditor::ParamEditor(QWidget* parent)
410
advanced_mode_(false)
413
tree_ = new Internal::ParamTree(this);
414
tree_->setMinimumSize(450,200);
415
tree_->setAllColumnsShowFocus(true);
416
tree_->setColumnCount(4);
238
if (index.column() == 1)
241
if (qobject_cast<QComboBox *>(editor)) //Drop-down list for enums
243
new_value = QVariant(static_cast<QComboBox *>(editor)->currentText());
245
else if (qobject_cast<QLineEdit *>(editor))
247
QString dtype = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
248
if (dtype == "output file" || dtype == "input file") // input/outut file
251
new_value = QVariant(static_cast<QLineEdit *>(editor)->text());
254
else if (static_cast<QLineEdit *>(editor)->text() == "" && ((dtype == "int") || (dtype == "float"))) //numeric
257
new_value = QVariant("0");
258
else if (dtype == "float")
259
new_value = QVariant("nan");
263
new_value = QVariant(static_cast<QLineEdit *>(editor)->text());
268
list = static_cast<ListEditor *>(editor)->getList();
269
for (UInt i = 1; i < list.size(); ++i)
271
list[i] = "\n" + list[i];
275
//check if it matches the restrictions or is empty
276
if (new_value.toString() != "")
278
QString type = index.sibling(index.row(), 2).data(Qt::DisplayRole).toString();
279
bool restrictions_met = true;
280
String restrictions = index.sibling(index.row(), 2).data(Qt::UserRole).toString();
281
if (type == "int") //check if valid integer
284
new_value.toString().toLong(&ok);
287
QMessageBox::warning(0, "Invalid value", QString("Cannot convert '%1' to integer number!").arg(new_value.toString()));
288
new_value = present_value;
291
vector<String> parts;
292
if (restrictions.split(' ', parts))
294
if (parts[0] != "" && new_value.toInt() < parts[0].toInt())
296
restrictions_met = false;
298
if (parts[1] != "" && new_value.toInt() > parts[1].toInt())
300
restrictions_met = false;
304
else if (type == "float") //check if valid float
307
new_value.toString().toDouble(&ok);
310
QMessageBox::warning(0, "Invalid value", QString("Cannot convert '%1' to floating point number!").arg(new_value.toString()));
311
new_value = present_value;
314
vector<String> parts;
315
if (restrictions.split(' ', parts))
317
if (parts[0] != "" && new_value.toDouble() < parts[0].toDouble())
319
restrictions_met = false;
321
if (parts[1] != "" && new_value.toDouble() > parts[1].toDouble())
323
restrictions_met = false;
327
if (!restrictions_met)
329
QMessageBox::warning(0, "Invalid value", QString("Value restrictions not met: %1").arg(index.sibling(index.row(), 3).data(Qt::DisplayRole).toString()));
330
new_value = present_value;
339
new_value = QVariant(QString::fromStdString(ss.str()));
340
model->setData(index, new_value);
341
model->setData(index, QBrush(Qt::yellow), Qt::BackgroundRole);
347
if (new_value != present_value)
349
model->setData(index, new_value);
350
model->setData(index, QBrush(Qt::yellow), Qt::BackgroundRole);
356
void ParamEditorDelegate::updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex &) const
358
editor->setGeometry(option.rect);
361
bool ParamEditorDelegate::exists_(QString name, QModelIndex index) const
363
UInt current_index = 0;
364
while (index.parent().child(current_index, 0).isValid())
367
current_index != (UInt)(index.row())
369
index.parent().child(current_index, 0).data(Qt::DisplayRole).toString() == name
372
(index.data(Qt::UserRole).toInt() == 0 && index.parent().child(current_index, 0).data(Qt::UserRole).toInt() == 0)
374
(index.data(Qt::UserRole).toInt() != 0 && index.parent().child(current_index, 0).data(Qt::UserRole).toInt() != 0)
385
void ParamEditorDelegate::commitAndCloseListEditor_()
387
ListEditor * editor = qobject_cast<ListEditor *>(sender());
388
emit commitData(editor);
389
emit closeEditor(editor);
391
void ParamEditorDelegate::commitAndCloseLineEdit_()
393
has_uncommited_data_ = false;
394
OpenMSLineEdit * editor = qobject_cast<OpenMSLineEdit *>(sender());
395
emit commitData(editor);
396
emit closeEditor(editor);
399
void ParamEditorDelegate::commitAndCloseComboBox_()
401
QComboBox * editor = qobject_cast<QComboBox *>(sender());
402
emit commitData(editor);
403
emit closeEditor(editor);
406
void ParamEditorDelegate::closeListEditor_()
408
ListEditor * editor = qobject_cast<ListEditor *>(sender());
409
emit closeEditor(editor);
412
bool ParamEditorDelegate::hasUncommittedData() const
414
return has_uncommited_data_;
417
///////////////////ParamTree/////////////////////////////////
419
ParamTree::ParamTree(QWidget * parent) :
424
void ParamTree::selectionChanged(const QItemSelection & s, const QItemSelection &)
428
emit selected(s.indexes().first());
432
bool ParamTree::edit(const QModelIndex & index, EditTrigger trigger, QEvent * event)
433
{ // allow F2 or double click on any column in the current row
434
if (trigger == QAbstractItemView::EditKeyPressed || trigger == QAbstractItemView::DoubleClicked)
435
{ // --> re-route to actual value column
436
return QAbstractItemView::edit(index.sibling(index.row(), 1), trigger, event);
438
return QAbstractItemView::edit(index, trigger, event);
443
///////////////////ParamEditor/////////////////////////////////
445
ParamEditor::ParamEditor(QWidget * parent) :
449
advanced_mode_(false)
452
tree_ = new Internal::ParamTree(this);
453
tree_->setMinimumSize(450, 200);
454
tree_->setAllColumnsShowFocus(true);
455
tree_->setColumnCount(4);
418
457
list << "parameter" << "value" << "type" << "restrictions";
419
tree_->setHeaderLabels(list);
420
dynamic_cast<QVBoxLayout*>(layout())->insertWidget(0,tree_,1);
421
tree_->setItemDelegate(new Internal::ParamEditorDelegate(tree_)); // the delegate from above is set
422
connect(tree_->itemDelegate(),SIGNAL(modified(bool)),this,SLOT(setModified(bool)));
423
connect(advanced_,SIGNAL(toggled(bool)),this,SLOT(toggleAdvancedMode(bool)));
424
connect(tree_,SIGNAL(selected(const QModelIndex&)),this,SLOT(showDocumentation(const QModelIndex&)));
427
void ParamEditor::showDocumentation(const QModelIndex& index)
429
doc_->setText(index.sibling(index.row(),1).data(Qt::UserRole).toString());
432
void ParamEditor::load(Param& param)
438
QTreeWidgetItem* parent=tree_->invisibleRootItem();
439
QTreeWidgetItem* item = NULL;
441
for(Param::ParamIterator it=param.begin();it!=param.end();++it)
443
//********handle opened/closed nodes********
444
const std::vector< Param::ParamIterator::TraceInfo >& trace = it.getTrace();
445
for(std::vector< Param::ParamIterator::TraceInfo >::const_iterator it2 = trace.begin(); it2!=trace.end(); ++it2)
447
if (it2->opened) //opened node
449
item = new QTreeWidgetItem(parent);
451
item->setText(0, it2->name.toQString());
458
tree_->setHeaderLabels(list);
459
dynamic_cast<QVBoxLayout *>(layout())->insertWidget(0, tree_, 1);
460
tree_->setItemDelegate(new Internal::ParamEditorDelegate(tree_)); // the delegate from above is set
461
connect(tree_->itemDelegate(), SIGNAL(modified(bool)), this, SLOT(setModified(bool)));
462
connect(advanced_, SIGNAL(toggled(bool)), this, SLOT(toggleAdvancedMode(bool)));
463
connect(tree_, SIGNAL(selected(const QModelIndex &)), this, SLOT(showDocumentation(const QModelIndex &)));
466
void ParamEditor::showDocumentation(const QModelIndex & index)
468
doc_->setText(index.sibling(index.row(), 1).data(Qt::UserRole).toString());
471
void ParamEditor::load(Param & param)
477
QTreeWidgetItem * parent = tree_->invisibleRootItem();
478
QTreeWidgetItem * item = NULL;
480
for (Param::ParamIterator it = param.begin(); it != param.end(); ++it)
482
//********handle opened/closed nodes********
483
const std::vector<Param::ParamIterator::TraceInfo> & trace = it.getTrace();
484
for (std::vector<Param::ParamIterator::TraceInfo>::const_iterator it2 = trace.begin(); it2 != trace.end(); ++it2)
486
if (it2->opened) //opened node
488
item = new QTreeWidgetItem(parent);
490
item->setText(0, it2->name.toQString());
452
491
item->setTextColor(0, Qt::darkGray); // color of nodes with children
455
item->setData(1,Qt::UserRole, it2->description.toQString());
457
item->setData(0,Qt::UserRole, NODE);
461
item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
465
item->setFlags( Qt::ItemIsEnabled );
471
parent=parent->parent();
472
if(parent==NULL) parent=tree_->invisibleRootItem();
476
//********handle item********
477
item = new QTreeWidgetItem(parent);
494
item->setData(1, Qt::UserRole, it2->description.toQString());
496
item->setData(0, Qt::UserRole, NODE);
500
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
504
item->setFlags(Qt::ItemIsEnabled);
510
parent = parent->parent();
512
parent = tree_->invisibleRootItem();
516
//********handle item********
517
item = new QTreeWidgetItem(parent);
479
519
// grey out non-editable columns (leaf nodes)
480
520
bool is_required = it->tags.find("required") != it->tags.end();
481
521
if (is_required) // special color for required parameters
483
item->setTextColor(0, QColor(255,140,0,255)); // orange
484
item->setTextColor(2, QColor(255,140,0,255));
485
item->setTextColor(3, QColor(255,140,0,255));
523
item->setTextColor(0, QColor(255, 140, 0, 255)); // orange
524
item->setTextColor(2, QColor(255, 140, 0, 255));
525
item->setTextColor(3, QColor(255, 140, 0, 255));
488
529
item->setTextColor(0, Qt::darkGray);
489
530
item->setTextColor(2, Qt::darkGray);
490
531
item->setTextColor(3, Qt::darkGray);
493
if (it->tags.count("advanced"))
495
item->setData(0,Qt::UserRole,ADVANCED_ITEM);
497
else //advanced parameter
499
item->setData(0,Qt::UserRole,NORMAL_ITEM);
502
item->setText(0, it->name.toQString());
504
if(it->value.valueType() == DataValue::STRING_LIST)
506
StringList string_list = it->value;
507
String list_string = String("[")+string_list.concatenate(",\n")+"]";
508
item->setText(1, list_string.toQString());
510
else if(it->value.valueType() == DataValue::INT_LIST)
512
IntList list = it->value;
513
StringList string_list;
514
for (Size i=0; i<list.size();++i)
516
string_list.push_back(list[i]);
518
String list_string = String("[")+string_list.concatenate(",\n")+"]";
519
item->setText(1, list_string.toQString());
521
else if(it->value.valueType() == DataValue::DOUBLE_LIST)
523
DoubleList list = it->value;
524
StringList string_list;
525
for (Size i=0; i<list.size();++i)
527
string_list.push_back(list[i]);
529
String list_string = String("[")+string_list.concatenate(",\n")+"]";
530
item->setText(1, list_string.toQString());
534
item->setText(1, String(it->value).toQString());
537
switch(it->value.valueType())
539
case DataValue::INT_VALUE:
540
item->setText(2, "int");
542
case DataValue::DOUBLE_VALUE:
543
item->setText(2, "float");
545
case DataValue::STRING_VALUE:
546
if(it->tags.count("input file"))
548
item->setText(2,"input file");
550
else if(it->tags.count("output file"))
552
item->setText(2,"output file");
556
item->setText(2,"string");
559
case DataValue::STRING_LIST:
560
if(it->tags.count("input file"))
562
item->setText(2,"input file list");
564
else if(it->tags.count("output file"))
566
item->setText(2,"output file list");
570
item->setText(2,"string list");
573
case DataValue::INT_LIST:
574
item->setText(2,"int list");
576
case DataValue::DOUBLE_LIST:
577
item->setText(2,"double list");
582
//restrictions (displayed and internal for easier parsing)
583
switch(it->value.valueType())
585
case DataValue::INT_VALUE:
586
case DataValue::INT_LIST:
588
String drest="", irest="";
589
bool min_set = (it->min_int!=-numeric_limits<Int>::max());
590
bool max_set = (it->max_int!=numeric_limits<Int>::max());
591
if (max_set || min_set)
595
drest += String("min: ") + it->min_int;
596
irest += it->min_int;
601
if (min_set && max_set) drest += " ";
602
drest += String("max: ") + it->max_int;
603
irest += it->max_int;
605
item->setText(3, drest.toQString());
607
item->setData(2,Qt::UserRole,irest.toQString());
610
case DataValue::DOUBLE_VALUE:
611
case DataValue::DOUBLE_LIST:
613
String drest="", irest="";
614
bool min_set = (it->min_float!=-numeric_limits<DoubleReal>::max());
615
bool max_set = (it->max_float!=numeric_limits<DoubleReal>::max());
616
if (max_set || min_set)
620
drest += String("min: ") + it->min_float;
621
irest += it->min_float;
626
if (min_set && max_set) drest += " ";
627
drest += String("max: ") + it->max_float;
628
irest += it->max_float;
630
item->setText(3, drest.toQString());
632
item->setData(2,Qt::UserRole,irest.toQString());
635
case DataValue::STRING_VALUE:
636
case DataValue::STRING_LIST:
639
if (it->valid_strings.size()!=0)
641
irest.concatenate(it->valid_strings.begin(),it->valid_strings.end(),",");
646
if (r_text.size() > 255)
647
{ // truncate restriction text, as some QT versions (4.6 & 4.7) will crash if text is too long
648
r_text = irest.prefix(251) + "...";
650
item->setText(3, r_text.toQString());
652
item->setData(2,Qt::UserRole,irest.toQString());
660
item->setData(1,Qt::UserRole,it->description.toQString());
664
item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
668
item->setFlags( Qt::ItemIsEnabled );
673
toggleAdvancedMode(advanced_mode_);
675
tree_->resizeColumnToContents(0);
676
tree_->resizeColumnToContents(1);
677
tree_->resizeColumnToContents(2);
678
tree_->resizeColumnToContents(3);
681
void ParamEditor::store()
685
QTreeWidgetItem* parent=tree_->invisibleRootItem();
688
for (Int i = 0; i < parent->childCount();++i)
690
map<String,String> section_descriptions;
691
storeRecursive_(parent->child(i),"", section_descriptions); //whole tree recursively
698
void ParamEditor::clear()
703
void ParamEditor::storeRecursive_(QTreeWidgetItem* child, String path,map<String,String>& section_descriptions)
707
@todo: why would we "recreate" (setting restrictions etc) the the param object from scratch?
708
updating everything that changed seems the better option, as
709
this is more robust against additions to Param
712
child->setData ( 1, Qt::BackgroundRole, QBrush(Qt::white));
716
path = child->text(0).toStdString();
720
path += String(":") + String(child->text(0).toStdString());
723
String description = child->data(1, Qt::UserRole).toString();
534
if (it->tags.count("advanced"))
536
item->setData(0, Qt::UserRole, ADVANCED_ITEM);
538
else //advanced parameter
540
item->setData(0, Qt::UserRole, NORMAL_ITEM);
543
item->setText(0, it->name.toQString());
545
if (it->value.valueType() == DataValue::STRING_LIST)
547
StringList string_list = it->value;
548
String list_string = String("[") + string_list.concatenate(",\n") + "]";
549
item->setText(1, list_string.toQString());
551
else if (it->value.valueType() == DataValue::INT_LIST)
553
IntList list = it->value;
554
StringList string_list;
555
for (Size i = 0; i < list.size(); ++i)
557
string_list.push_back(list[i]);
559
String list_string = String("[") + string_list.concatenate(",\n") + "]";
560
item->setText(1, list_string.toQString());
562
else if (it->value.valueType() == DataValue::DOUBLE_LIST)
564
DoubleList list = it->value;
565
StringList string_list;
566
for (Size i = 0; i < list.size(); ++i)
568
string_list.push_back(list[i]);
570
String list_string = String("[") + string_list.concatenate(",\n") + "]";
571
item->setText(1, list_string.toQString());
575
item->setText(1, String(it->value).toQString());
578
switch (it->value.valueType())
580
case DataValue::INT_VALUE:
581
item->setText(2, "int");
584
case DataValue::DOUBLE_VALUE:
585
item->setText(2, "float");
588
case DataValue::STRING_VALUE:
589
if (it->tags.count("input file"))
591
item->setText(2, "input file");
593
else if (it->tags.count("output file"))
595
item->setText(2, "output file");
599
item->setText(2, "string");
603
case DataValue::STRING_LIST:
604
if (it->tags.count("input file"))
606
item->setText(2, "input file list");
608
else if (it->tags.count("output file"))
610
item->setText(2, "output file list");
614
item->setText(2, "string list");
618
case DataValue::INT_LIST:
619
item->setText(2, "int list");
622
case DataValue::DOUBLE_LIST:
623
item->setText(2, "double list");
629
//restrictions (displayed and internal for easier parsing)
630
switch (it->value.valueType())
632
case DataValue::INT_VALUE:
633
case DataValue::INT_LIST:
635
String drest = "", irest = "";
636
bool min_set = (it->min_int != -numeric_limits<Int>::max());
637
bool max_set = (it->max_int != numeric_limits<Int>::max());
638
if (max_set || min_set)
642
drest += String("min: ") + it->min_int;
643
irest += it->min_int;
648
if (min_set && max_set)
650
drest += String("max: ") + it->max_int;
651
irest += it->max_int;
653
item->setText(3, drest.toQString());
655
item->setData(2, Qt::UserRole, irest.toQString());
659
case DataValue::DOUBLE_VALUE:
660
case DataValue::DOUBLE_LIST:
662
String drest = "", irest = "";
663
bool min_set = (it->min_float != -numeric_limits<DoubleReal>::max());
664
bool max_set = (it->max_float != numeric_limits<DoubleReal>::max());
665
if (max_set || min_set)
669
drest += String("min: ") + it->min_float;
670
irest += it->min_float;
675
if (min_set && max_set)
677
drest += String("max: ") + it->max_float;
678
irest += it->max_float;
680
item->setText(3, drest.toQString());
682
item->setData(2, Qt::UserRole, irest.toQString());
686
case DataValue::STRING_VALUE:
687
case DataValue::STRING_LIST:
690
if (it->valid_strings.size() != 0)
692
irest.concatenate(it->valid_strings.begin(), it->valid_strings.end(), ",");
696
String r_text = irest;
697
if (r_text.size() > 255) // truncate restriction text, as some QT versions (4.6 & 4.7) will crash if text is too long
699
r_text = irest.prefix(251) + "...";
701
item->setText(3, r_text.toQString());
703
item->setData(2, Qt::UserRole, irest.toQString());
712
item->setData(1, Qt::UserRole, it->description.toQString());
716
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
720
item->setFlags(Qt::ItemIsEnabled);
725
toggleAdvancedMode(advanced_mode_);
727
tree_->resizeColumnToContents(0);
728
tree_->resizeColumnToContents(1);
729
tree_->resizeColumnToContents(2);
730
tree_->resizeColumnToContents(3);
733
void ParamEditor::store()
735
//std::cerr << "store entered ...\n";
737
// store only if no line-edit is opened (in which case data is uncommitted and will not be saved)
738
// this applies only to INIFileEditor, where pressing Ctrl-s results in saving the current (but outdated) param
739
if (param_ != NULL &&
740
!static_cast<Internal::ParamEditorDelegate*>(this->tree_->itemDelegate())->hasUncommittedData())
742
//std::cerr << "and done!...\n";
743
QTreeWidgetItem * parent = tree_->invisibleRootItem();
746
for (Int i = 0; i < parent->childCount(); ++i)
748
map<String, String> section_descriptions;
749
storeRecursive_(parent->child(i), "", section_descriptions); //whole tree recursively
754
//else std::cerr << "store aborted!\n";
758
void ParamEditor::clear()
763
void ParamEditor::storeRecursive_(QTreeWidgetItem * child, String path, map<String, String> & section_descriptions)
767
@todo: why would we "recreate" (setting restrictions etc) the the param object from scratch?
768
updating everything that changed seems the better option, as
769
this is more robust against additions to Param
772
child->setData(1, Qt::BackgroundRole, QBrush(Qt::white));
776
path = child->text(0).toStdString();
780
path += String(":") + String(child->text(0).toStdString());
783
String description = child->data(1, Qt::UserRole).toString();
725
785
StringList tag_list;
727
{ // might throw ElementNotFound
786
try // might throw ElementNotFound
728
788
tag_list = param_->getTags(path);
732
if(child->text(2)=="") // node
734
if (description != "")
736
section_descriptions.insert(make_pair(path,description));
739
else //item + section descriptions
741
if(child->text(2)=="float")
743
param_->setValue(path,child->text(1).toDouble(),description,tag_list);
744
String restrictions = child->data(2, Qt::UserRole).toString();
745
vector<String> parts;
746
if (restrictions.split(' ',parts))
750
param_->setMinFloat(path,parts[0].toDouble());
754
param_->setMaxFloat(path,parts[1].toDouble());
758
else if(child->text(2)=="string")
760
param_->setValue(path, child->text(1).toStdString(),description,tag_list);
761
String restrictions = child->data(2, Qt::UserRole).toString();
764
std::vector<String> parts;
765
restrictions.split(',', parts);
766
param_->setValidStrings(path,parts);
769
else if(child->text(2) =="input file")
771
param_->setValue(path, child->text(1).toStdString(),description,tag_list);
772
String restrictions = child->data(2, Qt::UserRole).toString();
775
std::vector<String> parts;
776
restrictions.split(',', parts);
777
param_->setValidStrings(path,parts);
780
else if(child->text(2) =="output file")
782
param_->setValue(path, child->text(1).toStdString(),description,tag_list);
783
String restrictions = child->data(2, Qt::UserRole).toString();
786
std::vector<String> parts;
787
restrictions.split(',', parts);
788
param_->setValidStrings(path,parts);
791
else if(child->text(2)=="int")
793
param_->setValue(path, child->text(1).toInt(),description,tag_list);
794
String restrictions = child->data(2, Qt::UserRole).toString();
795
vector<String> parts;
796
if (restrictions.split(' ',parts))
800
param_->setMinInt(path,parts[0].toInt());
804
param_->setMaxInt(path,parts[1].toInt());
809
list = child->text(1).mid(1,child->text(1).length()-2);
810
StringList rlist = StringList::create(list);
811
for(UInt i = 0; i < rlist.size(); ++i)
813
rlist[i] = rlist[i].trim();
815
if(child->text(2)=="string list")
817
param_->setValue(path,rlist,description,tag_list);
818
String restrictions = child->data(2,Qt::UserRole).toString();
821
vector<String> parts;
822
restrictions.split(',',parts);
823
param_->setValidStrings(path,parts);
826
else if(child->text(2)=="input file list")
828
param_->setValue(path,rlist,description,tag_list);
829
String restrictions = child->data(2,Qt::UserRole).toString();
832
vector<String> parts;
833
restrictions.split(',',parts);
834
param_->setValidStrings(path,parts);
837
else if(child->text(2)=="output file list")
839
param_->setValue(path,rlist,description,tag_list);
840
String restrictions = child->data(2,Qt::UserRole).toString();
843
vector<String> parts;
844
restrictions.split(',',parts);
845
param_->setValidStrings(path,parts);
848
else if(child->text(2) =="double list")
850
param_->setValue(path,DoubleList::create(rlist),description,tag_list);
851
String restrictions = child->data(2,Qt::UserRole).toString();
852
vector<String> parts;
853
if(restrictions.split(' ',parts))
857
param_->setMinFloat(path,parts[0].toFloat());
861
param_->setMaxFloat(path,parts[1].toFloat());
865
else if(child->text(2) == "int list")
867
param_->setValue(path,IntList::create(rlist),description,tag_list);
868
String restrictions = child->data(2,Qt::UserRole).toString();
869
vector<String> parts;
870
if(restrictions.split(' ',parts))
874
param_->setMinInt(path,parts[0].toInt());
878
param_->setMaxInt(path,parts[1].toInt());
883
// set description node description if the prefix matches
884
for (map<String,String>::const_iterator it = section_descriptions.begin(); it!=section_descriptions.end(); ++it)
886
if (path.hasPrefix(it->first))
888
param_->setSectionDescription(it->first, it->second);
891
section_descriptions.clear();
894
for (Int i = 0; i < child->childCount();++i)
896
storeRecursive_(child->child(i),path,section_descriptions); //whole tree recursively
900
void ParamEditor::setModified(bool is_modified)
902
if (is_modified != modified_)
904
modified_ = is_modified;
905
emit modified(modified_);
909
bool ParamEditor::isModified() const
914
void ParamEditor::toggleAdvancedMode(bool advanced)
916
advanced_mode_ = advanced;
918
stack<QTreeWidgetItem*> stack, node_stack;
921
stack.push(tree_->invisibleRootItem());
922
while(!stack.empty())
924
QTreeWidgetItem* current = stack.top();
927
Int type = current->data(0,Qt::UserRole).toInt();
928
if (type!=NODE) //ITEM
930
if (advanced_mode_ && type==ADVANCED_ITEM) //advanced mode
932
current->setHidden(false);
934
else if (!advanced_mode_ && type==ADVANCED_ITEM) //Normal mode
936
current->setHidden(true);
941
for (Int i=0; i<current->childCount(); ++i)
943
stack.push(current->child(i));
948
current->setHidden(false); //show all nodes in advanced mode
952
node_stack.push(current); //store node pointers in normal mode
957
//hide sections that have no visible items in normal mode
958
while(!node_stack.empty())
960
QTreeWidgetItem* current = node_stack.top();
963
bool has_visible_children = false;
964
for (Int i=0; i<current->childCount(); ++i)
966
if (!current->child(i)->isHidden())
968
has_visible_children = true;
972
if (!has_visible_children)
974
current->setHidden(true);
979
tree_->resizeColumnToContents(0);
980
tree_->resizeColumnToContents(1);
981
tree_->resizeColumnToContents(2);
982
tree_->resizeColumnToContents(3);
794
if (child->text(2) == "") // node
796
if (description != "")
798
section_descriptions.insert(make_pair(path, description));
801
else //item + section descriptions
803
if (child->text(2) == "float")
805
param_->setValue(path, child->text(1).toDouble(), description, tag_list);
806
String restrictions = child->data(2, Qt::UserRole).toString();
807
vector<String> parts;
808
if (restrictions.split(' ', parts))
812
param_->setMinFloat(path, parts[0].toDouble());
816
param_->setMaxFloat(path, parts[1].toDouble());
820
else if (child->text(2) == "string")
822
param_->setValue(path, child->text(1).toStdString(), description, tag_list);
823
String restrictions = child->data(2, Qt::UserRole).toString();
824
if (restrictions != "")
826
std::vector<String> parts;
827
restrictions.split(',', parts);
828
param_->setValidStrings(path, parts);
831
else if (child->text(2) == "input file")
833
param_->setValue(path, child->text(1).toStdString(), description, tag_list);
834
String restrictions = child->data(2, Qt::UserRole).toString();
835
if (restrictions != "")
837
std::vector<String> parts;
838
restrictions.split(',', parts);
839
param_->setValidStrings(path, parts);
842
else if (child->text(2) == "output file")
844
param_->setValue(path, child->text(1).toStdString(), description, tag_list);
845
String restrictions = child->data(2, Qt::UserRole).toString();
846
if (restrictions != "")
848
std::vector<String> parts;
849
restrictions.split(',', parts);
850
param_->setValidStrings(path, parts);
853
else if (child->text(2) == "int")
855
param_->setValue(path, child->text(1).toInt(), description, tag_list);
856
String restrictions = child->data(2, Qt::UserRole).toString();
857
vector<String> parts;
858
if (restrictions.split(' ', parts))
862
param_->setMinInt(path, parts[0].toInt());
866
param_->setMaxInt(path, parts[1].toInt());
871
list = child->text(1).mid(1, child->text(1).length() - 2);
872
StringList rlist = StringList::create(list);
873
for (UInt i = 0; i < rlist.size(); ++i)
875
rlist[i] = rlist[i].trim();
877
if (child->text(2) == "string list")
879
param_->setValue(path, rlist, description, tag_list);
880
String restrictions = child->data(2, Qt::UserRole).toString();
881
if (restrictions != "")
883
vector<String> parts;
884
restrictions.split(',', parts);
885
param_->setValidStrings(path, parts);
888
else if (child->text(2) == "input file list")
890
param_->setValue(path, rlist, description, tag_list);
891
String restrictions = child->data(2, Qt::UserRole).toString();
892
if (restrictions != "")
894
vector<String> parts;
895
restrictions.split(',', parts);
896
param_->setValidStrings(path, parts);
899
else if (child->text(2) == "output file list")
901
param_->setValue(path, rlist, description, tag_list);
902
String restrictions = child->data(2, Qt::UserRole).toString();
903
if (restrictions != "")
905
vector<String> parts;
906
restrictions.split(',', parts);
907
param_->setValidStrings(path, parts);
910
else if (child->text(2) == "double list")
912
param_->setValue(path, DoubleList::create(rlist), description, tag_list);
913
String restrictions = child->data(2, Qt::UserRole).toString();
914
vector<String> parts;
915
if (restrictions.split(' ', parts))
919
param_->setMinFloat(path, parts[0].toFloat());
923
param_->setMaxFloat(path, parts[1].toFloat());
927
else if (child->text(2) == "int list")
929
param_->setValue(path, IntList::create(rlist), description, tag_list);
930
String restrictions = child->data(2, Qt::UserRole).toString();
931
vector<String> parts;
932
if (restrictions.split(' ', parts))
936
param_->setMinInt(path, parts[0].toInt());
940
param_->setMaxInt(path, parts[1].toInt());
945
// set description node description if the prefix matches
946
for (map<String, String>::const_iterator it = section_descriptions.begin(); it != section_descriptions.end(); ++it)
948
if (path.hasPrefix(it->first))
950
param_->setSectionDescription(it->first, it->second);
953
section_descriptions.clear();
956
for (Int i = 0; i < child->childCount(); ++i)
958
storeRecursive_(child->child(i), path, section_descriptions); //whole tree recursively
962
void ParamEditor::setModified(bool is_modified)
964
if (is_modified != modified_)
966
modified_ = is_modified;
967
emit modified(modified_);
971
bool ParamEditor::isModified() const
976
void ParamEditor::toggleAdvancedMode(bool advanced)
978
advanced_mode_ = advanced;
980
stack<QTreeWidgetItem *> stack, node_stack;
983
stack.push(tree_->invisibleRootItem());
984
while (!stack.empty())
986
QTreeWidgetItem * current = stack.top();
989
Int type = current->data(0, Qt::UserRole).toInt();
990
if (type != NODE) //ITEM
992
if (advanced_mode_ && type == ADVANCED_ITEM) //advanced mode
994
current->setHidden(false);
996
else if (!advanced_mode_ && type == ADVANCED_ITEM) //Normal mode
998
current->setHidden(true);
1003
for (Int i = 0; i < current->childCount(); ++i)
1005
stack.push(current->child(i));
1010
current->setHidden(false); //show all nodes in advanced mode
1014
node_stack.push(current); //store node pointers in normal mode
1019
//hide sections that have no visible items in normal mode
1020
while (!node_stack.empty())
1022
QTreeWidgetItem * current = node_stack.top();
1025
bool has_visible_children = false;
1026
for (Int i = 0; i < current->childCount(); ++i)
1028
if (!current->child(i)->isHidden())
1030
has_visible_children = true;
1034
if (!has_visible_children)
1036
current->setHidden(true);
1041
tree_->resizeColumnToContents(0);
1042
tree_->resizeColumnToContents(1);
1043
tree_->resizeColumnToContents(2);
1044
tree_->resizeColumnToContents(3);
985
1047
} // namespace OpenMS