#include #include #include #include #include #include #include #include #include "enum.bactypes.h" #include "enum.properties.h" #include "MultStateList.h" MultStateList::MultStateList(QWidget *parent, int db_id, QString label, QGridLayout *layout, int row, int col) : Field(parent, db_id, STATE_TEXT, BT_CHR_STR, label) { if(label != QString()) { QPushButton *btn = new QPushButton("Edit State List..."); connect(btn, SIGNAL(clicked()), this, SLOT(drawWindow())); this->input = btn; } else this->input = NULL; if(layout) { layout->addWidget(this->label, row, col, Qt::AlignRight); layout->addWidget(this->input, row, col + 1, Qt::AlignLeft); } this->value = QVariant(); PAWindow = new QDialog(parent); for(int i = 0; i < 16; ++i) { checkBoxes[i] = new QCheckBox(); switch(BacType) { case BT_BOOL: comboBoxes[i] = new QComboBox(PAWindow); comboBoxes[i]->addItem("Inactive"); comboBoxes[i]->addItem("Active"); comboBoxes[i]->setCurrentIndex(0); comboBoxes[i]->setDisabled(true); break; default: editBoxes[i] = new QLineEdit("0", PAWindow); editBoxes[i]->setDisabled(true); } } QGridLayout *PALayout = new QGridLayout(PAWindow); QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, PAWindow); QString pNames[] = { tr("Manual Life Safety:"), tr("Auto Life Safety:"), tr("Priority 3:"), tr("Priority 4:"), tr("Critical Equipment:"), tr("Minimum On/Off:"), tr("Priority 7:"), tr("Manual Operator:"), tr("Priority 9:"), tr("Priority 10:"), tr("Priority 11:"), tr("Priority 12:"), tr("Priority 13:"), tr("Priority 14:"), tr("Priority 15:"), tr("Priority 16:") }; for(int i = 0; i < 16; ++i) { QLabel *label = new QLabel(pNames[i]); PALayout->addWidget(label, i % 8, 4 * (i / 8), Qt::AlignRight); PALayout->addWidget(checkBoxes[i], i % 8, 4 * (i / 8) + 1, Qt::AlignCenter); switch(BacType) { case BT_BOOL: connect(checkBoxes[i], SIGNAL(toggled(bool)), comboBoxes[i], SLOT(setEnabled(bool))); PALayout->addWidget(comboBoxes[i], i % 8, 4 * (i / 8) + 2, Qt::AlignLeft); break; default: connect(checkBoxes[i], SIGNAL(toggled(bool)), editBoxes[i], SLOT(setEnabled(bool))); PALayout->addWidget(editBoxes[i], i % 8, 4 * (i / 8) + 2, Qt::AlignLeft); break; } } for(int i = 0; i < 8; ++i) PALayout->addItem(new QSpacerItem(70, 20), i, 3); PALayout->addWidget(buttons, 8, 0, 1, 7, Qt::AlignCenter); connect(buttons, SIGNAL(accepted()), this, SLOT(saveValues())); connect(buttons, SIGNAL(accepted()), PAWindow, SLOT(accept())); connect(buttons, SIGNAL(rejected()), PAWindow, SLOT(reject())); PAWindow->setWindowTitle("Edit Priority Array"); } void MultStateList::drawWindow() { PAWindow->exec(); } void MultStateList::saveValues() { QString rv; for(int i = 0; i < 16; ++i) { switch(BacType) { case BT_BOOL: if(comboBoxes[i]->isEnabled()) rv += QString::number(comboBoxes[i]->currentIndex()); break; default: if(editBoxes[i]->isEnabled()) rv += editBoxes[i]->text(); break; } rv += ';'; } qDebug() << rv; SetValue(rv); // this might not need to be here, but is very useful for debugging } void MultStateList::SetValue(QVariant value) { this->value = value; QStringList list = value.toString().split(";"); switch(BacType) { case BT_BOOL: for(int i = 0; i < list.size() - 1; ++i) { if(list[i].length()) { comboBoxes[i]->setCurrentIndex(list[i].toInt()); comboBoxes[i]->setEnabled(true); checkBoxes[i]->setCheckState(Qt::Checked); } else { comboBoxes[i]->setCurrentIndex(0); comboBoxes[i]->setEnabled(false); } } break; default: for(int i = 0; i < list.size(); ++i) { if(list[i].length()) { editBoxes[i]->setText(list[i]); editBoxes[i]->setEnabled(true); checkBoxes[i]->setCheckState(Qt::Checked); } else { editBoxes[i]->setText("0"); editBoxes[i]->setEnabled(false); } } break; } }