29 #include "newcomponentdialog.h"
35 #include <QListWidget>
36 #include <QPushButton>
37 #include <QMessageBox>
40 NewComponentDialog::NewComponentDialog(
ARCSContext* ctx, QWidget *parent) :
45 this->setLayout(
new QVBoxLayout());
47 componentType =
new QLineEdit(
this);
48 componentName =
new QLineEdit(
this);
49 layout()->addWidget(
new QLabel(
"Component types:"));
50 layout()->addWidget(componentType);
52 componentTypes =
new QListWidget(
this);
54 componentTypes->sortItems();
55 layout()->addWidget(componentTypes);
57 layout()->addWidget(
new QLabel(
"Component name"));
58 layout()->addWidget(componentName);
60 QHBoxLayout* buttonLayout =
new QHBoxLayout();
61 ((QBoxLayout*)layout())->addLayout(buttonLayout);
62 okButton =
new QPushButton(
"Ok");
63 cancelButton =
new QPushButton(
"Cancel");
64 buttonLayout->addWidget(okButton);
65 buttonLayout->addWidget(cancelButton);
68 cmpl->setCaseSensitivity(Qt::CaseInsensitive);
69 componentType->setCompleter(cmpl);
71 connect(okButton,SIGNAL(clicked()),
this,SLOT(verify()));
72 connect(cancelButton,SIGNAL(clicked()),
this,SLOT(reject()));
73 connect(componentType,SIGNAL(textChanged(QString)),
this,SLOT(setType(QString)));
74 connect(componentTypes,SIGNAL(currentTextChanged(QString)),componentType,SLOT(setText(QString)));
78 void NewComponentDialog::verify()
80 if (componentTypes->selectedItems().isEmpty())
82 QMessageBox::critical(
this,
"Missing type",
"Component type is missing",QMessageBox::Ok);
85 if (componentName->text().isEmpty() || context->
getComponent(componentName->text()) )
87 QMessageBox::critical(
this,
"Invalid name",
"Your component name is either empty or already taken by another one.",QMessageBox::Ok);
94 void NewComponentDialog::setType(QString s)
96 QList<QListWidgetItem*> results = componentTypes->findItems(s,Qt::MatchCaseSensitive);
98 if (!results.isEmpty())
100 componentTypes->scrollToItem(results[0]);
101 componentTypes->setCurrentItem(results[0]);
static ARCSFactory * getInstance()
Returns the instance of the singleton ARCSFactory.
ARCSAbstractComponent * getComponent(QString name)
Retrieves a component by its id.
This class manages components and constants in a given context.