| 52 | } |
| 53 | |
| 54 | void TemplateOptionsPage::load(const SourceFileTemplate& fileTemplate, TemplateRenderer* renderer) |
| 55 | { |
| 56 | // TODO: keep any old changed values, as it comes by surprise to have them lost |
| 57 | // when going back and forward |
| 58 | |
| 59 | // clear anything as there is on reentering the page |
| 60 | d->entries.clear(); |
| 61 | d->controls.clear(); |
| 62 | // clear any old option group boxes & the base layout |
| 63 | d->firstEditWidget = nullptr; |
| 64 | qDeleteAll(d->groupBoxes); |
| 65 | d->groupBoxes.clear(); |
| 66 | delete layout(); |
| 67 | |
| 68 | auto* layout = new QVBoxLayout(); |
| 69 | layout->setContentsMargins(0, 0, 0, 0); |
| 70 | |
| 71 | const auto customOptions = fileTemplate.customOptions(renderer); |
| 72 | d->groupBoxes.reserve(customOptions.size()); |
| 73 | d->entries.reserve(customOptions.size()); |
| 74 | for (const auto& optionGroup : customOptions) { |
| 75 | auto* box = new QGroupBox(this); |
| 76 | d->groupBoxes.append(box); |
| 77 | |
| 78 | box->setTitle(optionGroup.name); |
| 79 | |
| 80 | auto* formLayout = new QFormLayout; |
| 81 | |
| 82 | d->entries << optionGroup.options; |
| 83 | for (const auto& entry : optionGroup.options) { |
| 84 | QWidget* control = nullptr; |
| 85 | const QString type = entry.type; |
| 86 | if (type == QLatin1String("String")) |
| 87 | { |
| 88 | control = new QLineEdit(entry.value.toString(), box); |
| 89 | } |
| 90 | else if (type == QLatin1String("Enum")) |
| 91 | { |
| 92 | auto input = new QComboBox(box); |
| 93 | input->addItems(entry.values); |
| 94 | input->setCurrentText(entry.value.toString()); |
| 95 | control = input; |
| 96 | } |
| 97 | else if (type == QLatin1String("Int")) |
| 98 | { |
| 99 | auto input = new QSpinBox(box); |
| 100 | input->setValue(entry.value.toInt()); |
| 101 | if (!entry.minValue.isEmpty()) |
| 102 | { |
| 103 | input->setMinimum(entry.minValue.toInt()); |
| 104 | } |
| 105 | if (!entry.maxValue.isEmpty()) |
| 106 | { |
| 107 | input->setMaximum(entry.maxValue.toInt()); |
| 108 | } |
| 109 | control = input; |
| 110 | } |
| 111 | else if (type == QLatin1String("Bool")) |
no test coverage detected