| 114 | } |
| 115 | |
| 116 | QWidget *PreferencesHelper::addPreferenceEditValidation(Preferences *p, QString id, QString title, QString description, |
| 117 | std::function<bool(const QString &)> validator, QObject *parent) |
| 118 | { |
| 119 | QWidget *widget = new QWidget(); |
| 120 | QHBoxLayout *layout = new QHBoxLayout(); |
| 121 | layout->setMargin(0); |
| 122 | layout->setSpacing(0); |
| 123 | layout->setMargin(0); |
| 124 | widget->setLayout(layout); |
| 125 | |
| 126 | QWidget *infoBtn = setupDescriptionButton(id, description, parent); |
| 127 | |
| 128 | QString pref1Val = p->get(id).toString(); |
| 129 | QLineEdit *pref = new QLineEdit(); |
| 130 | pref->setText(pref1Val); |
| 131 | parent->connect(pref, &QLineEdit::returnPressed, parent, [p, id, validator, pref]() { |
| 132 | QString prefText = pref->text(); |
| 133 | bool valid = false; |
| 134 | if(validator) { |
| 135 | valid = validator(prefText); |
| 136 | } |
| 137 | |
| 138 | if(valid) { |
| 139 | p->set(id, prefText); |
| 140 | } else { |
| 141 | pref->setText(p->get(id).toString()); |
| 142 | } |
| 143 | }); |
| 144 | |
| 145 | QLabel *label = new QLabel(title); |
| 146 | p->initDescription(id, title, description); |
| 147 | |
| 148 | QSpacerItem *space = new QSpacerItem(20, 20, QSizePolicy::Preferred, QSizePolicy::Preferred); |
| 149 | |
| 150 | layout->addWidget(infoBtn); |
| 151 | layout->addWidget(label, 1); |
| 152 | layout->addSpacerItem(space); |
| 153 | layout->addWidget(pref, 1); |
| 154 | return widget; |
| 155 | } |
| 156 | |
| 157 | QWidget *PreferencesHelper::addPreferenceComboList(Preferences *p, QString id, QString title, QString description, |
| 158 | QList<QPair<QString, QVariant>> options, QObject *parent) |
nothing calls this directly
no test coverage detected