EComboBox usability patch
This commit is contained in:
@@ -67,6 +67,10 @@ EComboBox::EComboBox(QWidget * parent)
|
||||
header->setParent(iv->header());
|
||||
connect(filter, &CLineEdit::textChanged, this, [this](const QString & text) { EComboBox::filterChanged(text, false); });
|
||||
connect(model(), &EModel::layoutChanged, this, &EComboBox::rowsChanged);
|
||||
connect(filter, &QLineEdit::returnPressed, this, [this]() {
|
||||
if (rows_visible != 1) return;
|
||||
setCurrentIndex(first_index.row());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +88,7 @@ void EComboBox::showPopup() {
|
||||
QRect r = iv->header()->rect();
|
||||
header->setGeometry(r.x(), r.y(), r.width(), r.height() - 1);
|
||||
filter->setFocus();
|
||||
filter->selectAll();
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +114,7 @@ void EComboBox::filterChanged(const QString & text, bool first) {
|
||||
iv->hide();
|
||||
QModelIndex pi = iv->rootIndex();
|
||||
int row_count = iv->model()->rowCount();
|
||||
rows_visible = 0;
|
||||
if (text.isEmpty()) {
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
iv->setRowHidden(i, pi, false);
|
||||
@@ -124,15 +130,18 @@ void EComboBox::filterChanged(const QString & text, bool first) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
iv->setRowHidden(i,
|
||||
pi,
|
||||
!iv->model()->index(i, 0, pi).data().toString().contains(
|
||||
bool hidden = !iv->model()->index(i, 0, pi).data().toString().contains(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QRegExp(text, Qt::CaseInsensitive)
|
||||
QRegExp(text, Qt::CaseInsensitive)
|
||||
#else
|
||||
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
||||
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
||||
#endif
|
||||
));
|
||||
);
|
||||
if (!hidden) {
|
||||
if (rows_visible == 0) first_index = iv->model()->index(i, 0);
|
||||
++rows_visible;
|
||||
}
|
||||
iv->setRowHidden(i, pi, hidden);
|
||||
iv->model()->setData(iv->model()->index(i, 0), iv->model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole);
|
||||
}
|
||||
iv->show();
|
||||
|
||||
@@ -55,6 +55,8 @@ private:
|
||||
QLabel * icon;
|
||||
CLineEdit * filter;
|
||||
QFont nfont, ifont;
|
||||
QModelIndex first_index;
|
||||
int rows_visible = 0;
|
||||
};
|
||||
|
||||
#endif // ECOMBOBOX_H
|
||||
|
||||
Reference in New Issue
Block a user