portdialog.cpp
1 /*
2  name: tools/editor/portdialog.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 "portdialog.h"
30 
31 #include <QVBoxLayout>
32 #include <QHBoxLayout>
33 #include <QLabel>
34 #include <QLineEdit>
35 #include <QListWidget>
36 #include <QCompleter>
37 #include <QPushButton>
38 
39 #include <QMessageBox>
40 
41 #include <iostream>
42 
43 PortDialog::PortDialog(ARCSAbstractComponent *aac, bool slt, QWidget *parent) : QDialog(parent)
44 {
45 
46  QVBoxLayout* vlayout;
47  setLayout(vlayout = new QVBoxLayout(this));
48 
49  QString portTypeName ;
50 
51  if (slt)
52  {
53  portList = aac->getSlots();
54  portTypeName = "slot";
55  }
56  else
57  {
58  portList = aac->getSignals();
59  portTypeName = "signal";
60  }
61 
62  layout()->addWidget(new QLabel("Please pick a "+portTypeName + " name."));
63  portNameEdit = new QLineEdit(this);
64  portNameEdit->setCompleter(new QCompleter(portList));
65  layout()->addWidget(portNameEdit);
66 
67  QListWidget* portListView = new QListWidget(this);
68  portListView->insertItems(0,portList);
69 
70  layout()->addWidget(portListView);
71  connect(portListView,SIGNAL(currentTextChanged(QString)),portNameEdit,SLOT(setText(QString)));
72 
73  QHBoxLayout* hlayout = new QHBoxLayout(this);
74 // std::cout << "kaboom" <<std::endl;
75 
76  vlayout->addLayout(hlayout);
77  QPushButton* ok = new QPushButton("Ok",this);
78  QPushButton* cancel = new QPushButton("Cancel",this);
79 
80  connect(ok,SIGNAL(clicked()),SLOT(accept()));
81  connect(cancel,SIGNAL(clicked()),SLOT(reject()));
82 
83 
84  hlayout->addWidget(ok);
85  hlayout->addWidget(cancel);
86 }
87 
88 
89 void PortDialog::accept()
90 {
91  if (portList.contains(portNameEdit->text()))
92  {
93  QDialog::accept();
94  return ;
95  }
96 
97  QMessageBox::critical(this,"Invalid method name","Please provide a valid method name");
98 }
virtual QStringList getSlots()=0
Returns the names of the available slots.
Class handling the generic description of a component.
virtual QStringList getSignals()=0
Returns the names of the availables signals.