#include #include "NewDialog.h" #include "object/enum.objtypes.h" // Slots void CreateNewDialog::TypeChanged() { objType = TypeSelect->itemData(TypeSelect->currentIndex()).toInt(); if(!bNameChanged) { NameSelect->setText(TypeSelect->currentText() + " " + QString::number(NumObjects[objType] + 1)); NumSelect->setText(QString::number(NumObjects[objType] + 1)); } objName = NameSelect->text(); } void CreateNewDialog::NumChanged() { objNum = NumSelect->text().toInt(); if(!bNameChanged && objNum > NumObjects[objType]) NameSelect->setText(TypeSelect->currentText() + " " + QString::number(objNum)); objName = NameSelect->text(); } void CreateNewDialog::NameChanged() { objName = NameSelect->text(); bNameChanged = true; } void CreateNewDialog::CancelClicked() { reject(); } void CreateNewDialog::OKClicked() { if(objNum > NumObjects[objType]) accept(); else QMessageBox::critical(this, tr("Invalid Number"), tr("Invalid Instance ID."), QMessageBox::Ok); } // Constructor CreateNewDialog::CreateNewDialog(QWidget *workspace, int NumObjects[]) : QDialog(workspace) { QGridLayout *layout = new QGridLayout(); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, workspace); this->NumObjects = NumObjects; objNum = NumObjects[0] + 1; objType = OBJ_AN_INPUT; objName = "Analog Input " + QString::number(objNum); TypeSelect = new QComboBox(); NumSelect = new QLineEdit(QString::number(objNum)); NameSelect = new QLineEdit(objName); TypeSelect->addItem(tr("Analog Input"), 0); TypeSelect->addItem(tr("Analog Output"), 1); TypeSelect->addItem(tr("Analog Value"), 2); TypeSelect->addItem(tr("Binary Input"), 3); TypeSelect->addItem(tr("Binary Output"), 4); TypeSelect->addItem(tr("Binary Value"), 5); TypeSelect->addItem(tr("Calendar"), 6); TypeSelect->addItem(tr("Command"), 7); TypeSelect->addItem(tr("Event"), 9); TypeSelect->addItem(tr("Event Class"), 15); TypeSelect->addItem(tr("File"), 10); TypeSelect->addItem(tr("Group"), 11); TypeSelect->addItem(tr("Loop"), 12); TypeSelect->addItem(tr("Mult Input"), 13); TypeSelect->addItem(tr("Mult Output"), 14); TypeSelect->addItem(tr("Mult Variable"), 19); TypeSelect->addItem(tr("Program"), 16); TypeSelect->addItem(tr("Schedule"), 17); TypeSelect->addItem(tr("Averaging"), 18); TypeSelect->addItem(tr("Safety Point"), 21); TypeSelect->addItem(tr("Safety Zone"), 22); TypeSelect->addItem(tr("Trend Log"), 20); QLabel *TypeLabel = new QLabel(tr("Type:")); QLabel *NumLabel = new QLabel(tr("Instance:")); QLabel *NameLabel = new QLabel(tr("Name:")); NumSelect->setValidator(new QIntValidator(1, 65536, NULL)); connect(TypeSelect, SIGNAL(currentIndexChanged(int)), this, SLOT(TypeChanged())); connect(NumSelect, SIGNAL(textChanged(QString)), this, SLOT(NumChanged())); connect(NameSelect, SIGNAL(textEdited(QString)), this, SLOT(NameChanged())); connect(buttons, SIGNAL(accepted()), this, SLOT(OKClicked())); connect(buttons, SIGNAL(rejected()), this, SLOT(CancelClicked())); bNameChanged = false; layout->addWidget(TypeLabel, 0, 0); layout->addWidget(TypeSelect, 0, 1); layout->addWidget(NumLabel, 1, 0); layout->addWidget(NumSelect, 1, 1); layout->addWidget(NameLabel, 2, 0); layout->addWidget(NameSelect, 2, 1); layout->addWidget(buttons, 3, 0, 1, 2); this->setWindowTitle("New Object"); this->setLayout(layout); }