23 #include "comboboxex.h" 27 ComboBoxEx::ComboBoxEx(QComboBox &comboBox)
32 QStringList ComboBoxEx::allItems()
const 35 for (
int i = 0; i < box.count(); ++i)
37 items << box.itemText(i);
42 bool ComboBoxEx::caseInsensitiveLessThan(
const QString &s1,
const QString &s2)
44 return s1.toLower() < s2.toLower();
49 return removeItem(box.currentText());
54 int idx = box.findText(item);
64 void ComboBoxEx::setCurrentOrAddNewAndSelect(
const QString &item)
66 int idx = box.findText(item);
69 box.setCurrentIndex(idx);
73 box.insertItem(0, item);
74 box.setCurrentIndex(0);
76 box.lineEdit()->selectAll();
79 void ComboBoxEx::setItemsSorted(QStringList items)
81 qSort(items.begin(), items.end(), caseInsensitiveLessThan);
83 foreach (
const QString& item, items)
85 if (box.findText(item) < 0)
bool removeCurrentItem()
Removes currently selected item.
bool removeItem(const QString &item)
Removes item that matches specified one.