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