code format
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
#include "ecombobox.h"
|
||||
|
||||
#include "clineedit.h"
|
||||
#include "qabstractitemview.h"
|
||||
#include "qad_types.h"
|
||||
#include "qwidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHeaderView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTreeView>
|
||||
|
||||
|
||||
class EModel: public QStandardItemModel {
|
||||
@@ -18,6 +20,7 @@ public:
|
||||
setSupportedDragActions(Qt::MoveAction);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Qt::ItemFlags flags(const QModelIndex & index) const override {
|
||||
Qt::ItemFlags f = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
|
||||
@@ -25,20 +28,18 @@ protected:
|
||||
return f;
|
||||
}
|
||||
#if QT_VERSION >= 0x050000
|
||||
Qt::DropActions supportedDragActions() const override {return Qt::MoveAction;}
|
||||
Qt::DropActions supportedDropActions() const override {return Qt::MoveAction;}
|
||||
Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
|
||||
Qt::DropActions supportedDropActions() const override { return Qt::MoveAction; }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
EComboBox::EComboBox(QWidget * parent)
|
||||
: QComboBox(parent)
|
||||
, iv(new QTreeView(this))
|
||||
, header(new QWidget(this))
|
||||
, icon(new QLabel(this))
|
||||
, filter(new CLineEdit(this))
|
||||
{
|
||||
, filter(new CLineEdit(this)) {
|
||||
setView(iv);
|
||||
setModel(new EModel());
|
||||
iv->setTextElideMode(Qt::ElideMiddle);
|
||||
@@ -64,9 +65,7 @@ EComboBox::EComboBox(QWidget * parent)
|
||||
header->layout()->addWidget(icon);
|
||||
header->layout()->addWidget(filter);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -91,13 +90,12 @@ void EComboBox::showPopup() {
|
||||
void EComboBox::changeEvent(QEvent * e) {
|
||||
QComboBox::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
case QEvent::LanguageChange:
|
||||
#if QT_VERSION >= 0x040700
|
||||
filter->setPlaceholderText(tr("Filter"));
|
||||
filter->setPlaceholderText(tr("Filter"));
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +108,7 @@ void EComboBox::filterChanged(const QString & text, bool first) {
|
||||
}
|
||||
iv->hide();
|
||||
QModelIndex pi = iv->rootIndex();
|
||||
int row_count = iv->model()->rowCount();
|
||||
int row_count = iv->model()->rowCount();
|
||||
if (text.isEmpty()) {
|
||||
for (int i = 0; i < row_count; ++i) {
|
||||
iv->setRowHidden(i, pi, false);
|
||||
@@ -126,13 +124,15 @@ 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(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QRegExp(text, Qt::CaseInsensitive)
|
||||
#else
|
||||
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
||||
#endif
|
||||
));
|
||||
iv->setRowHidden(i,
|
||||
pi,
|
||||
!iv->model()->index(i, 0, pi).data().toString().contains(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
QRegExp(text, Qt::CaseInsensitive)
|
||||
#else
|
||||
QRegularExpression(text, QRegularExpression::CaseInsensitiveOption)
|
||||
#endif
|
||||
));
|
||||
iv->model()->setData(iv->model()->index(i, 0), iv->model()->index(i, 0, pi).data().toString(), Qt::ToolTipRole);
|
||||
}
|
||||
iv->show();
|
||||
|
||||
Reference in New Issue
Block a user