editcomponentwidget.cpp
1 /*
2  name: tools/editor/editcomponentwidget.cpp
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #include "editcomponentwidget.h"
30 
31 #include <QVBoxLayout>
32 #include <QTextEdit>
33 #include <QLabel>
34 #include <QPushButton>
35 #include <QMessageBox>
36 #include <arcs/arcslog.h>
37 #include <QMenu>
38 
40  QWidget(parent)
41 {
43 
44  setWindowTitle("Component:" + aac->getProperty("id").toString());
45 
46  this->setLayout(new QVBoxLayout());
47 
48  component = aac;
49  componentText = new QTextEdit(this);
50  componentText->setAcceptRichText(false);
51  layout()->addWidget(new QLabel("Textual representation"));
52  layout()->addWidget(componentText);
53 
54  componentText->setText(aac->toString());
55  componentRepresentation = aac->toString();
56 
57  validateButton = new QPushButton("Apply to component",this);
58  layout()->addWidget(validateButton);
59 
60  connect(validateButton,SIGNAL(clicked()),this,SLOT(validate()));
61  this->addActions(componentText->createStandardContextMenu()->actions());
62 }
63 
64 
65 void EditComponentWidget::validate()
66 {
67 
68  ARCSLog::getInstance()->startCapture();
69 
70  if ( component->parseString(componentText->toPlainText()))
71  {
72  QMessageBox::information(this,"Component content validation","The component textual representation has been validated.",QMessageBox::Ok);
73  componentRepresentation = componentText->toPlainText();
74  }
75  else
76  {
77  QMessageBox::critical(this,"Component content validation","The component textual representation is not valid thus we are using the old one.");
78  component->parseString(componentRepresentation);
79  componentText->setText(componentRepresentation);
80  }
81 
82  emit sendLog(ARCSLog::getInstance()->endCapture());
83 }
84 
virtual QString toString()=0
Defines a basic seralization mechanism.
QVariant getProperty(QString name)
Gets a meta-property from this component.
Class handling the generic description of a component.
static ARCSLog * getInstance()
returns the only instance of the logging system that is available
Definition: arcslog.cpp:188
EditComponentWidget(ARCSAbstractComponent *aac, QWidget *parent=0)
virtual bool parseString(QString s)=0
Defines a basic seralization mechanism.