26 #include <QAbstractItemView>
27 #include <QApplication>
28 #include <QFocusEvent>
39 const QString& propertyName,
41 QWidget(parent), elementName(elementName), propertyName(propertyName)
43 layout =
new QHBoxLayout;
45 layout->setSpacing(0);
47 const std::string file =
49 QSettings settings(QString(file.c_str()), QSettings::NativeFormat);
50 valueList = settings.value(elementName +
"/" + propertyName).toStringList();
54 combo->setEditable(
true);
55 combo->setAutoCompletion(
true);
56 combo->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive);
57 combo->addItems(valueList);
59 readOnlyLineEdit =
new QLineEdit();
60 readOnlyLineEdit->setReadOnly(
true);
61 readOnlyLineEdit->setVisible(
false);
63 checkbox =
new QCheckBox(
nullptr);
64 checkbox->setToolTip(
"If checked, this property will be written into the config file");
65 checkbox->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
67 setFocusPolicy(Qt::StrongFocus);
68 setAttribute(Qt::WA_InputMethodEnabled);
75 connect(checkbox, SIGNAL(stateChanged(
int)),
this, SLOT(slotEnabledChanged(
int)));
78 layout->addWidget(checkbox);
79 layout->addWidget(combo);
80 layout->addWidget(readOnlyLineEdit);
82 this->setLayout(layout);
90 fixComboboxValues =
true;
101 auto changed =
enabled != checkbox->isChecked();
112 checkbox->setDisabled(readOnly);
114 combo->setVisible(not readOnly);
115 readOnlyLineEdit->setVisible(readOnly);
121 auto changed =
value != combo->currentText();
122 bool enabledState = checkbox->isChecked();
124 combo->setCurrentText(
value);
125 readOnlyLineEdit->setText(
value);
127 if (checkbox->isChecked() != enabledState)
140 valueList.push_front(combo->currentText());
141 valueList.removeDuplicates();
142 if (!fixComboboxValues)
146 combo->addItems(valueList);
150 const std::string file =
152 QSettings settings(QString(file.c_str()), QSettings::NativeFormat);
153 settings.setValue(elementName +
"/" + propertyName, QVariant(valueList));
157 OptionalEdit::slotEnabledChanged(
int value)
165 QWidget::focusInEvent(e);
171 QWidget::focusOutEvent(e);
189 if (event->reason() != Qt::FocusReason::PopupFocusReason)
197 QComboBox::focusOutEvent(event);