23 #include "comboboxex.h" 27 ComboBoxEx::ComboBoxEx(QComboBox &comboBox)
32 QStringList ComboBoxEx::allItems()
const 35 for (
int i = 0; i < box.count(); ++i)
36 items << box.itemText(i);
40 bool ComboBoxEx::caseInsensitiveLessThan(
const QString &s1,
const QString &s2)
42 return s1.toLower() < s2.toLower();
47 return removeItem(box.currentText());
52 int idx = box.findText(item);
62 void ComboBoxEx::setCurrentOrAddNewAndSelect(
const QString &item)
64 int idx = box.findText(item);
66 box.setCurrentIndex(idx);
69 box.insertItem(0, item);
70 box.setCurrentIndex(0);
72 box.lineEdit()->selectAll();
75 void ComboBoxEx::setItemsSorted(QStringList items)
77 std::sort(items.begin(), items.end(), caseInsensitiveLessThan);
79 for (
const QString &item : items)
81 if (box.findText(item) < 0)
bool removeCurrentItem()
Removes currently selected item.
bool removeItem(const QString &item)
Removes item that matches specified one.