1 /*****************************************************************************
2  *                                                                           *
3  *  Elmer, A Finite Element Software for Multiphysical Problems              *
4  *                                                                           *
5  *  Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland    *
6  *                                                                           *
7  *  This program is free software; you can redistribute it and/or            *
8  *  modify it under the terms of the GNU General Public License              *
9  *  as published by the Free Software Foundation; either version 2           *
10  *  of the License, or (at your option) any later version.                   *
11  *                                                                           *
12  *  This program is distributed in the hope that it will be useful,          *
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
15  *  GNU General Public License for more details.                             *
16  *                                                                           *
17  *  You should have received a copy of the GNU General Public License        *
18  *  along with this program (in file fem/GPL-2); if not, write to the        *
19  *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,         *
20  *  Boston, MA 02110-1301, USA.                                              *
21  *                                                                           *
22  *****************************************************************************/
23 
24 /*****************************************************************************
25  *                                                                           *
26  *  ElmerGUI dynamiceditor                                                   *
27  *                                                                           *
28  *****************************************************************************
29  *                                                                           *
30  *  Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back                   *
31  *  Email:   Juha.Ruokolainen@csc.fi                                         *
32  *  Web:     http://www.csc.fi/elmer                                         *
33  *  Address: CSC - IT Center for Science Ltd.                                 *
34  *           Keilaranta 14                                                   *
35  *           02101 Espoo, Finland                                            *
36  *                                                                           *
37  *  Original Date: 15 Mar 2008                                               *
38  *                                                                           *
39  *****************************************************************************/
40 
41 #include <QtGui>
42 #include <iostream>
43 #include "dynamiceditor.h"
44 
45 using namespace std;
46 
DynLineEdit(QWidget * parent)47 DynLineEdit::DynLineEdit(QWidget *parent) : QWidget(parent)
48 {
49    name = "";
50    label = NULL;
51    frame  = NULL;
52    layout = NULL;
53    textEdit = NULL;
54    closeButton = NULL;
55    lineEdit = new QLineEdit;
56 }
57 
~DynLineEdit()58 DynLineEdit::~DynLineEdit()
59 {
60 }
61 
DynamicEditor(QWidget * parent)62 DynamicEditor::DynamicEditor(QWidget *parent)
63   : QWidget(parent)
64 {
65   newIcon = QIcon(":/icons/document-new.png");
66   addIcon = QIcon(":/icons/list-add.png");
67   okIcon = QIcon(":/icons/dialog-ok-apply.png");
68   removeIcon = QIcon(":/icons/list-remove.png");
69   setWindowFlags(Qt::Window);
70 
71   menuAction = NULL;
72   ID = -1;
73   touched = false;
74 
75   setWindowIcon(QIcon(":/icons/Mesh3D.png"));
76 }
77 
78 //----------------------------------------------------------------------------
~DynamicEditor()79 DynamicEditor::~DynamicEditor()
80 {
81 }
82 
83 //----------------------------------------------------------------------------
setupTabs(QDomDocument * elmerDefs,const QString & Section,int ID)84 void DynamicEditor::setupTabs(QDomDocument *elmerDefs, const QString &Section, int ID)
85 {
86   // Clear:
87   //-------
88   this->ID = ID;
89 
90   hash.clear();
91 
92   QLayout *layout = this->layout();
93   if(layout != NULL) {
94     QLayoutItem *item;
95     while((item = layout->takeAt(0)) != 0)
96       delete item;
97     if(tabWidget != NULL) {
98       tabWidget->clear();
99       delete tabWidget;
100     }
101     delete layout;
102   }
103 
104   // Get root element of elmerDefs:
105   //-------------------------------
106   root = elmerDefs->documentElement();
107 
108   tabWidget = new QTabWidget;
109   //tabWidget->setTabShape(QTabWidget::Triangular);
110   tabWidget->setUsesScrollButtons(true);
111   tabWidget->setElideMode(Qt::ElideNone);
112   all_stuff = root.firstChildElement("ALL");
113   element = root.firstChildElement("PDE");
114 
115   tabs = 0;
116 
117   while(!element.isNull()) {
118 
119     name = element.firstChildElement("Name");
120 
121     QGridLayout *grid = new QGridLayout;
122 
123     int params = 0;
124 
125     for( int iter=0; iter<2; iter++ )
126     {
127       if ( iter==0 ) {
128         if ( name.text().trimmed() == "General" ) continue;
129         section = all_stuff.firstChildElement(Section);
130       } else  {
131         section = element.firstChildElement(Section);
132       }
133 
134       param = section.firstChildElement("Parameter");
135 
136       // ML: Added argument "Parameter" for nextSiblingElement(), 5. August 2010:
137       for( ; !param.isNull(); param=param.nextSiblingElement("Parameter"), params++ ) {
138 
139         // label
140         QString widget_type = param.attribute("Widget","Edit");
141         QString widget_enabled = param.attribute("Enabled","True");
142         QString widget_visible = param.attribute("Visible","True");
143         QString paramType = param.firstChildElement("Type").text().trimmed();
144         QString labelName = param.firstChildElement("Name").text().trimmed();
145         QString sifName   = param.firstChildElement("SifName").text().trimmed();
146         if ( sifName == "" ) sifName = labelName;
147         QString paramDefault = param.firstChildElement("DefaultValue").text().trimmed();
148         QString whatis    = param.firstChildElement("Whatis").text().trimmed();
149         QString statusTip = param.firstChildElement("StatusTip").text().trimmed();
150         QString fullName  = "/"+name.text().trimmed()+"/"+Section+"/"+labelName+"/"+QString::number(ID);
151         h.widget = NULL;
152 
153         if ( widget_type == "Edit" ) {
154           DynLineEdit *edit = new DynLineEdit;
155           h.widget = edit->lineEdit;
156           edit->lineEdit->setText(paramDefault);
157           edit->name = fullName;
158           connect(edit->lineEdit, SIGNAL(returnPressed()),
159 		  edit, SLOT(editSlot()));
160           connect(edit->lineEdit, SIGNAL(textChanged(QString)),
161 		  this, SLOT(textChangedSlot(QString)));
162 
163         } else if (widget_type == "TextEdit") {
164 	  QTextEdit *textEdit = new QTextEdit;
165 	  // set height to 5..8 lines of current font:
166 	  QFont currentFont = textEdit->currentFont();
167 	  QFontMetrics fontMetrics(currentFont);
168 	  int fontHeight = fontMetrics.height();
169 	  textEdit->setMinimumHeight(5*fontHeight);
170 	  textEdit->setMaximumHeight(8*fontHeight);
171 	  h.widget = textEdit;
172 
173 	} else if ( widget_type == "Combo" ) {
174           QComboBox *combo = new QComboBox;
175           h.widget = combo;
176 
177           // combo->setObjectName(labelName);  // removed 30. sept. 2008, ML
178           int count = 0, active=0;
179 
180           QDomElement item = param.firstChildElement("Item");
181           for( ; !item.isNull(); item=item.nextSiblingElement("Item") ) {
182             QString itemType = item.attribute( "Type", "" );
183             if ( itemType == "Active" ) active=count;
184             QDomElement itemName = item.firstChildElement("Name");
185             combo->insertItem(count++,itemName.text().trimmed() );
186           }
187           combo->setCurrentIndex(active);
188           // connect(combo, SIGNAL(activated(QString)), this, SLOT(comboSlot(QString)));
189 	  connect(combo, SIGNAL(currentIndexChanged(QString)), this, SLOT(comboSlot(QString)));
190 
191         } else if ( widget_type == "CheckBox" ) {
192           QCheckBox *l = new QCheckBox;
193           h.widget = l;
194 
195           l->setText("");
196           l->setChecked(false);
197           if ( paramDefault == "True" ) l->setChecked(true);
198           connect(l, SIGNAL(stateChanged(int)), this, SLOT(lSlot(int)));
199 
200         } else if ( widget_type == "Label" ) {
201           QLabel *label = new QLabel;
202           QFont font;
203           font.setBold(true);
204           font.setUnderline(true);
205           label->setFont(font);
206           label->setText(labelName);
207           h.widget = label;
208         }
209 
210         if ( h.widget ) {
211           h.widget->setWhatsThis(whatis);
212           h.widget->setStatusTip(statusTip);
213           h.widget->setProperty( "dom address",fullName);
214           h.elem = param;
215 
216           if ( widget_enabled == "False" ) h.widget->setEnabled(false);
217 
218 	  if(widget_type != "TextEdit") h.widget->setFixedHeight(18);
219 
220 	  if(widget_type == "TextEdit") {
221             QLabel *textEditLabel = new QLabel;
222             textEditLabel->setText(labelName);
223             h.label = textEditLabel;
224 	    grid->addWidget(h.widget, params, 0, 1, 2);
225 
226             if ( widget_visible == "False" ) {
227               h.label->hide();
228               h.widget->hide();
229             }
230 
231 	  } else if ( widget_type != "Label" ) {
232             QLabel *label = new QLabel;
233             label->setText(labelName);
234             h.label = label;
235             grid->addWidget(h.label,  params, 0);
236             grid->addWidget(h.widget, params, 1);
237 
238             if ( widget_visible == "False" ) {
239               h.label->hide();
240               h.widget->hide();
241             }
242           } else {
243             h.label = NULL;
244             grid->addWidget(h.widget, params, 0);
245           }
246           hash[fullName] = h;
247         }
248       }
249     }
250 
251     // add a dummy widget in the left bottom corner:
252     QWidget *dummyWidget = new QWidget;
253     grid->addWidget(dummyWidget, params, 0);
254     grid->setRowStretch(params, 1);
255 
256     // put the grid in a widget:
257     QWidget *frmWidget = new QWidget;
258     frmWidget->setLayout(grid);
259 
260     // set up the scroll area:
261     QScrollArea *src = new QScrollArea;
262     src->setWidget(frmWidget);
263     src->setMinimumHeight(300);
264     src->setWidgetResizable(true);
265 
266     // add the scroll area to the tab:
267     if (params>0)
268       tabWidget->addTab(src, name.text().trimmed());
269 
270     tabs++;
271     element = element.nextSiblingElement("PDE"); // ML: Added "PDE" 5. August 2010
272   }
273 
274   // Buttons:
275   //----------
276   QLabel *lbl = new QLabel;
277   lbl->setText("Name:");
278 
279   nameEdit  = new QLineEdit;
280   nameEdit->setText(Section + " " + QString::number(ID+1));
281 
282   applyButton = new QPushButton(tr("&Add"));
283   applyButton->setIcon(addIcon);
284   connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
285 
286   discardButton = new QPushButton(tr("&Remove"));
287   discardButton->setIcon(removeIcon);
288   connect(discardButton, SIGNAL(clicked()), this, SLOT(discardButtonClicked()));
289 
290   okButton = new QPushButton(tr("&OK"));
291   okButton->setIcon(okIcon);
292   connect(okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
293 
294   newButton = new QPushButton(tr("&New"));
295   newButton->setIcon(newIcon);
296   connect(newButton, SIGNAL(clicked()), this, SLOT(newButtonClicked()));
297 
298   QHBoxLayout *nameLayout = new QHBoxLayout;
299   nameLayout->addWidget(lbl);
300   nameLayout->addWidget(nameEdit);
301 
302   QHBoxLayout *buttonLayout = new QHBoxLayout;
303   buttonLayout->addWidget(newButton);
304   buttonLayout->addWidget(applyButton);
305   buttonLayout->addWidget(okButton);
306   buttonLayout->addWidget(discardButton);
307 
308   QHBoxLayout *spareButtonLayout = new QHBoxLayout;
309   spareButton = new QPushButton(tr("SpareButton"));;
310   spareButton->setVisible(false);
311   spareButtonLayout->addWidget(spareButton);
312   connect(spareButton, SIGNAL(clicked()), this, SLOT(spareButtonClicked()));
313 
314   spareScroll = new QScrollArea;
315   spareScroll->hide();
316 
317   // Main layout:
318   //-------------
319   QVBoxLayout *mainLayout = new QVBoxLayout;
320   mainLayout->addWidget(tabWidget);
321   mainLayout->addWidget(spareScroll);
322   mainLayout->addLayout(spareButtonLayout);
323   mainLayout->addLayout(nameLayout);
324   mainLayout->addLayout(buttonLayout);
325   setLayout(mainLayout);
326 
327   // Window title:
328   //---------------
329   setWindowTitle(Section);
330 }
331 
332 //----------------------------------------------------------------------------
editSlot()333 void DynLineEdit::editSlot()
334 {
335   QLineEdit *q =  lineEdit;
336   QString s = q->text();
337 #if WITH_QT5
338   cout << string(s.toLatin1()) << endl;
339 #else
340   cout << string(s.toAscii()) << endl;
341 #endif
342 
343   if ( frame ) {
344     frame->show();
345     frame->raise();
346     return;
347   }
348 
349   textEdit = new QTextEdit;
350   textEdit->setLineWrapMode(QTextEdit::NoWrap);
351 
352   s.replace( ';', '\n' );
353   textEdit->append(s);
354 
355   closeButton = new QPushButton(tr("&Close"));
356   connect(closeButton, SIGNAL(clicked()), this, SLOT(lineEditClose()));
357 
358   label = new QLabel;
359   label->setText(name);
360 
361   layout = new QVBoxLayout;
362   layout->addWidget(label);
363   layout->addWidget(textEdit);
364   layout->addWidget(closeButton);
365 
366   frame = new QFrame;
367   frame->setLayout(layout);
368   frame->show();
369   frame->setWindowTitle(name);
370 }
371 
372 //----------------------------------------------------------------------------
lineEditClose()373 void DynLineEdit::lineEditClose()
374 {
375   QString q = textEdit->toPlainText();
376 
377   //q.replace( '\n', ';' );
378 
379   lineEdit->setText(q);
380 
381   frame->close();
382 
383   name = "";
384 
385   delete label;
386   label = NULL;
387 
388   delete textEdit;
389   textEdit = NULL;
390 
391   delete closeButton;
392   closeButton = NULL;
393 
394   delete layout;
395   layout = NULL;
396 
397   delete frame;
398   frame = NULL;
399 }
400 
401 //----------------------------------------------------------------------------
lSlot(int state)402 void DynamicEditor::lSlot(int state)
403 {
404   QDomElement param;
405   QString q = QObject::sender()->property("dom address").toString();
406 
407   int ind = q.lastIndexOf( '/', -1);
408   QString ID = q.mid(ind,-1);
409 
410   param = hash[q].elem.firstChildElement("Activate");
411   for( ;!param.isNull(); param=param.nextSiblingElement("Activate") ) {
412     q = param.text().trimmed() + ID;
413     hash[q].widget->setEnabled(state);
414     QString widget_visible = hash[q].elem.attribute("Visible","Unknown");
415     if ( state == false && widget_visible != "Unknown" ) {
416       hash[q].label->hide(); hash[q].widget->hide();
417     } else {
418       hash[q].label->show(); hash[q].widget->show();
419     }
420   }
421 
422   param = hash[q].elem.firstChildElement("Deactivate");
423   for( ;!param.isNull(); param=param.nextSiblingElement("Deactivate") ) {
424     q = param.text().trimmed() + ID;
425     hash[q].widget->setEnabled(!state);
426     QString widget_visible = hash[q].elem.attribute("Visible","Unknown");
427     if ( state == true && widget_visible != "Unknown" ) {
428       hash[q].label->hide(); hash[q].widget->hide();
429     } else {
430       hash[q].label->show(); hash[q].widget->show();
431     }
432   }
433 }
434 
435 //----------------------------------------------------------------------------
textChangedSlot(QString text)436 void DynamicEditor::textChangedSlot(QString text)
437 {
438   QDomElement param;
439   QString q = QObject::sender()->property("dom address").toString();
440 
441   int ind = q.lastIndexOf( '/', -1);
442   QString ID = q.mid(ind,-1);
443 
444   param = hash[q].elem.firstChildElement("Activate");
445   for( ;!param.isNull(); param=param.nextSiblingElement("Activate") ) {
446     q = param.text().trimmed() + ID;
447     QString widget_visible = hash[q].elem.attribute("Visible","Uknown");
448 
449     if ( text != "" ) {
450       hash[q].widget->setEnabled(true);
451       hash[q].widget->show();
452       hash[q].label->show();
453     } else {
454       hash[q].widget->setEnabled(false);
455       if ( widget_visible != "Unknown" ) {
456         hash[q].label->hide();
457         hash[q].widget->hide();
458       }
459     }
460   }
461 }
462 
463 //----------------------------------------------------------------------------
comboSlot(QString select)464 void DynamicEditor::comboSlot(QString select)
465 {
466   QString q = QObject::sender()->property("dom address").toString();
467   QDomElement item;
468 
469   int ind = q.lastIndexOf( '/', -1);
470   QString ID = q.mid(ind,-1);
471 
472   item = hash[q].elem.firstChildElement("Item");
473   for( ;!item.isNull(); item=item.nextSiblingElement("Item") ) {
474     QDomElement itemName = item.firstChildElement("Name");
475     if ( itemName.text().trimmed() != select ) {
476       QDomElement activ;
477 
478       activ = item.firstChildElement("Activate");
479       for( ;!activ.isNull(); activ=activ.nextSiblingElement("Activate") ) {
480         QString s=activ.text().trimmed() + ID;
481         hash_entry_t h = hash[s];
482 
483         QString widget_enabled = h.elem.attribute("Enabled","True");
484         QString widget_visible = h.elem.attribute("Visible","Unknown");
485 
486         h.widget->setEnabled(false);
487         if ( widget_visible != "Unknown" ) {
488           h.label->hide(); h.widget->hide();
489         }
490       }
491     }
492   }
493 
494   item = hash[q].elem.firstChildElement("Item");
495   for( ;!item.isNull(); item=item.nextSiblingElement("Item") ) {
496     QDomElement itemName = item.firstChildElement("Name");
497     if ( itemName.text().trimmed() == select ) {
498       QDomElement activ;
499       activ = item.firstChildElement("Activate");
500       for( ;!activ.isNull(); activ=activ.nextSiblingElement("Activate") ) {
501         QString s=activ.text().trimmed() + ID;
502         hash_entry_t h = hash[s];
503         h.widget->setEnabled(true);
504         h.label->show(); h.widget->show();
505       }
506     }
507   }
508   // this->show();  // Removed 30. sept. 2008, ML
509 }
510 
511 
512 //----------------------------------------------------------------------------
minimumSizeHint() const513 QSize DynamicEditor::minimumSizeHint() const
514 {
515   return QSize(128, 128);
516 }
517 
518 //----------------------------------------------------------------------------
sizeHint() const519 QSize DynamicEditor::sizeHint() const
520 {
521   return QSize(400, 500);
522 }
523 
524 //----------------------------------------------------------------------------
spareButtonClicked()525 void DynamicEditor::spareButtonClicked()
526 {
527   emit(dynamicEditorSpareButtonClicked(tabWidget->currentIndex(), ID));
528 }
529 
530 //----------------------------------------------------------------------------
applyButtonClicked()531 void DynamicEditor::applyButtonClicked()
532 {
533 
534   cout << "Dynamic editor: apply-button clicked" << endl;
535   cout.flush();
536 
537   touched = true;
538 
539   emit(dynamicEditorReady(MAT_APPLY, ID));
540 }
541 
542 
543 //----------------------------------------------------------------------------
discardButtonClicked()544 void DynamicEditor::discardButtonClicked()
545 {
546 
547   cout << "Dynamic editor: Remove-button clicked" << endl;
548   cout.flush();
549 
550   touched = false;
551 
552   emit(dynamicEditorReady(MAT_DELETE, ID));
553 }
554 
555 //----------------------------------------------------------------------------
okButtonClicked()556 void DynamicEditor::okButtonClicked()
557 {
558 
559   // cout << "Dynamic editor: ok-button clicked" << endl;
560   // cout.flush();
561 
562   touched = false;
563 
564   emit(dynamicEditorReady(MAT_OK, ID));
565 }
566 
567 //----------------------------------------------------------------------------
newButtonClicked()568 void DynamicEditor::newButtonClicked()
569 {
570   cout << "Dynamic editor: next-button clicked" << endl;
571   cout.flush();
572 
573   touched = false;
574 
575   emit(dynamicEditorReady(MAT_NEW, ID));
576 }
577 
578 //----------------------------------------------------------------------------
dumpHash(QDomDocument * projectDoc,QDomElement * item)579 void DynamicEditor::dumpHash(QDomDocument *projectDoc, QDomElement *item)
580 {
581   for(int j = 0; j < this->hash.count(); j++) {
582     QString key = this->hash.keys().at(j);
583     hash_entry_t value = this->hash.values().at(j);
584     QDomElement elem = value.elem;
585     QWidget *widget = value.widget;
586 
587     QDomElement itemWidget = projectDoc->createElement("widget");
588     item->appendChild(itemWidget);
589 
590     QDomElement itemKey = projectDoc->createElement("key");
591     QDomText itemKeyValue = projectDoc->createTextNode(key);
592     itemKey.appendChild(itemKeyValue);
593     itemWidget.appendChild(itemKey);
594 
595     if(elem.attribute("Widget") == "CheckBox") {
596       QCheckBox *checkBox = (QCheckBox*)widget;
597       QDomElement itemCheckBox = projectDoc->createElement("value");
598       QDomText itemCheckBoxValue = projectDoc->createTextNode(QString::number(checkBox->isChecked()));
599       itemCheckBox.appendChild(itemCheckBoxValue);
600       itemWidget.appendChild(itemCheckBox);
601       itemWidget.setAttribute("type", "CheckBox");
602 
603     } else if(elem.attribute("Widget") == "Edit") {
604       QLineEdit *lineEdit = (QLineEdit*)widget;
605       QDomElement itemLineEdit = projectDoc->createElement("value");
606       QDomText itemLineEditValue = projectDoc->createTextNode(lineEdit->text().trimmed());
607       itemLineEdit.appendChild(itemLineEditValue);
608       itemWidget.appendChild(itemLineEdit);
609       itemWidget.setAttribute("type", "Edit");
610 
611     } else if(elem.attribute("Widget") == "TextEdit") {
612       QTextEdit *textEdit = (QTextEdit*)widget;
613       QDomElement itemTextEdit = projectDoc->createElement("value");
614       QDomText itemTextEditValue = projectDoc->createTextNode(textEdit->toPlainText());
615       itemTextEdit.appendChild(itemTextEditValue);
616       itemWidget.appendChild(itemTextEdit);
617       itemWidget.setAttribute("type", "TextEdit");
618 
619     } else if(elem.attribute("Widget") == "Combo") {
620       QComboBox *comboBox = (QComboBox*)widget;
621       QDomElement itemComboBox = projectDoc->createElement("value");
622       QDomText itemComboBoxValue = projectDoc->createTextNode(comboBox->currentText().trimmed());
623       itemComboBox.appendChild(itemComboBoxValue);
624       itemWidget.appendChild(itemComboBox);
625       itemWidget.setAttribute("type", "Combo");
626 
627     } else if(elem.attribute("Widget") == "Label") {
628       QLabel *label = (QLabel*)widget;
629       QDomElement itemLabel = projectDoc->createElement("value");
630       QDomText itemLabelValue = projectDoc->createTextNode(label->text().trimmed());
631       itemLabel.appendChild(itemLabelValue);
632       itemWidget.appendChild(itemLabel);
633       itemWidget.setAttribute("type", "Label");
634     }
635   }
636 }
637 
populateHash(QDomElement * item)638 void DynamicEditor::populateHash(QDomElement *item)
639 {
640   QDomElement widget = item->firstChildElement("widget");
641 
642   // ML: Added argument "widget" for nextSiblingElement(), 5. August 2010:
643   for(; !widget.isNull(); widget = widget.nextSiblingElement("widget")) {
644     QString type = widget.attribute("type").trimmed();
645     QString key = widget.firstChildElement("key").text().trimmed();
646     QString value = widget.firstChildElement("value").text().trimmed();
647 
648     if(value.isEmpty())
649       continue;
650 
651     QStringList splittedKey = key.split("/");
652 
653     // Compare with current hash:
654     //----------------------------
655     bool match_found = false;
656     for(int j = 0; j < this->hash.count(); j++) {
657       QString hashkey = this->hash.keys().at(j);
658       QStringList splittedHashKey = hashkey.split("/");
659       hash_entry_t hashvalue = this->hash.values().at(j);
660       QWidget *widget = hashvalue.widget;
661       QDomElement elem = hashvalue.elem;
662 
663       if((splittedKey.at(1) == splittedHashKey.at(1)) &&
664 	 (splittedKey.at(2) == splittedHashKey.at(2)) &&
665 	 (splittedKey.at(3) == splittedHashKey.at(3))) {
666 
667 	match_found = true;
668 
669 	if(elem.attribute("Widget") == "CheckBox") {
670 	  if(type != "CheckBox")
671 	    cout << "Load project: type mismatch with checkBox" << endl;
672 	  QCheckBox *checkBox = (QCheckBox*)widget;
673 	  if(value.toInt() == 1)
674 	    checkBox->setChecked(true);
675 	  else
676 	    checkBox->setChecked(false);
677 
678 	} else if(elem.attribute("Widget") == "Edit") {
679 	  if(type != "Edit")
680 	    cout << "Load project: type mismatch with lineEdit" << endl;
681 	  QLineEdit *lineEdit = (QLineEdit*)widget;
682 	  lineEdit->setText(value);
683 
684 	} else if(elem.attribute("Widget") == "TextEdit") {
685 	  if(type != "TextEdit")
686 	    cout << "Load project: type mismatch with textEdit" << endl;
687 	  QTextEdit *textEdit = (QTextEdit*)widget;
688 	  textEdit->clear();
689 	  textEdit->append(value);
690 
691 	} else if(elem.attribute("Widget") == "Combo") {
692 	  if(type != "Combo")
693 	    cout << "Load project: type mismatch with comboBox" << endl;
694 	  QComboBox *comboBox = (QComboBox*)widget;
695 	  for(int k = 0; k < comboBox->count(); k++) {
696 	    QString current = comboBox->itemText(k).trimmed();
697 	    if(current == value.trimmed())
698 	      comboBox->setCurrentIndex(k);
699 	  }
700 	}
701       }
702     }
703 
704     if(!match_found) {
705 #if WITH_QT5
706       cout << "Error: Unable to set menu entry: key: " << key.toLatin1().data() << endl;
707 #else
708       cout << "Error: Unable to set menu entry: key: " << key.toAscii().data() << endl;
709 #endif
710       cout.flush();
711     }
712   }
713 }
714