invocationdialog.cpp
1 /*
2  name: tools/editor/invocationdialog.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 "invocationdialog.h"
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32 #include <QLabel>
33 
34 #include <QRadioButton>
35 #include <QButtonGroup>
36 #include <QPushButton>
37 
38 #include <iostream>
39 
40 #include <arcs/arcsfactory.h>
41 #include "stringlistvalidator.h"
42 #include <QMessageBox>
43 
44 InvocationDialog::InvocationDialog(QString portName, QWidget *parent) :
45  QDialog(parent)
46 {
47  prepareDialog();
48 
49  QString paramLiteralType = portName.section('(',1,1).section(')',0,0).section(',',0,0);
50 
51 
52  QString actualType = ARCSFactory::getInstance()->getInternalType(paramLiteralType);
53 
54  if (actualType.isEmpty())
55  cbType->setCurrentIndex(cbType->findText("void"));
56  else
57  cbType->setCurrentIndex(cbType->findText(actualType));
58 
59 
60 }
61 
62 
63 void InvocationDialog::prepareDialog()
64 {
65  QVBoxLayout* vlayout;
66  setLayout(vlayout = new QVBoxLayout(this));
67 
68  layout()->addWidget(new QLabel("Select an invocation type"));
69  layout()->addWidget(cbType = new QComboBox(this));
70  layout()->addWidget(new QLabel("Invoke at:"));
71 
72  QRadioButton* rbPre;
73  QRadioButton* rbPost;
74  QRadioButton* rbCleanup;
75 
76  bgType = new QButtonGroup(this);
77  layout()->addWidget(rbPre = new QRadioButton("Pre-connection",this));
78  layout()->addWidget(rbPost = new QRadioButton("Post-connection",this));
79  layout()->addWidget(rbCleanup = new QRadioButton("Cleanup stage",this));
80 
81  bgType->addButton(rbPre,GraphicsInvocationItem::Pre);
82  bgType->addButton(rbPost,GraphicsInvocationItem::Post);
83  bgType->addButton(rbCleanup,GraphicsInvocationItem::Cleanup);
84  rbPre->setChecked(true);
85 
86  layout()->addWidget(new QLabel("Invocation value:"));
87  layout()->addWidget(teValue = new QTextEdit(this));
88 
89 
90  QHBoxLayout* hlayout = new QHBoxLayout(this);
91  vlayout->addLayout(hlayout);
92 
93  QPushButton* ok = new QPushButton("Ok",this);
94  QPushButton* cancel = new QPushButton("Cancel",this);
95 
96  connect(ok,SIGNAL(clicked()),SLOT(accept()));
97  connect(cancel,SIGNAL(clicked()),SLOT(reject()));
98 
99 
100  hlayout->addWidget(ok);
101  hlayout->addWidget(cancel);
102 
103  // we should fill in the comboBox
104  QStringList arcsTypes = ARCSFactory::getInstance()->getTypeNames();
105  arcsTypes.sort();
106  cbType->addItems(arcsTypes);
107  cbType->setEditable(true);
108  cbType->setValidator(new StringListValidator(arcsTypes,this));
109 }
110 
111 
112 
113 void InvocationDialog::accept()
114 {
115  // cbType returns the type
116  // teValue returns the value
117 
118  // first we must check, if type != void, that the value is a valid one
119 
120  if (cbType->currentText() != "void")
121  {
122  QVariant var = ARCSFactory::getInstance()->dataDeserialize(cbType->currentText(),teValue->toPlainText());
123  if (ARCSFactory::getInstance()->getVariantType(var) != cbType->currentText())
124  {
125  QMessageBox::critical(this,"Type parsing error",
126  "Parsing the text \""+teValue->toPlainText()+"\" to perform an invocation of type \""+
127  cbType->currentText()+"\" has failed.",QMessageBox::Ok,QMessageBox::NoButton);
128  return;
129  }
130  }
131 
132 
133  QDialog::accept();
134 }
QString getVariantType(QVariant var)
Returns the type of a QVariant.
QString getInternalType(QString s)
static ARCSFactory * getInstance()
Returns the instance of the singleton ARCSFactory.
QVariant dataDeserialize(QString type, QString representation)
Deserialize data from their string representation.
QStringList getTypeNames()
Returns the names of the types currently stored.
Definition: arcsfactory.h:79