filter in inspector

This commit is contained in:
Christophe Alexandre 2008-04-29 12:53:59 +00:00
parent 357e9b4961
commit a5bc1de1fa
2 changed files with 23 additions and 5 deletions

View File

@ -1,3 +1,4 @@
#include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QTableView> #include <QTableView>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -19,14 +20,15 @@ HInspectorWidget::HInspectorWidget(QWidget* parent):
slotsView->setSelectionBehavior(QAbstractItemView::SelectRows); slotsView->setSelectionBehavior(QAbstractItemView::SelectRows);
slotsView->setSortingEnabled(true); slotsView->setSortingEnabled(true);
QVBoxLayout* inspectorLayout = new QVBoxLayout(); QGridLayout* inspectorLayout = new QGridLayout();
inspectorLayout->addWidget(slotsView); inspectorLayout->addWidget(slotsView, 0, 0, 1, 2);
filterPatternLineEdit = new QLineEdit(this); filterPatternLineEdit = new QLineEdit(this);
inspectorLayout->addWidget(filterPatternLineEdit); QLabel* filterPatternLabel = new QLabel(tr("&Filter pattern:"), this);
filterPatternLabel->setBuddy(filterPatternLineEdit);
inspectorLayout->addWidget(filterPatternLabel, 1, 0);
inspectorLayout->addWidget(filterPatternLineEdit, 1, 1);
QGroupBox* inspectorGroupBox = new QGroupBox(tr("Hurricane inspector"), this); QGroupBox* inspectorGroupBox = new QGroupBox(tr("Hurricane inspector"), this);
inspectorGroupBox->setLayout(inspectorLayout); inspectorGroupBox->setLayout(inspectorLayout);
@ -35,6 +37,9 @@ HInspectorWidget::HInspectorWidget(QWidget* parent):
mainLayout->addWidget(inspectorGroupBox); mainLayout->addWidget(inspectorGroupBox);
setLayout(mainLayout); setLayout(mainLayout);
connect(filterPatternLineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(textFilterChanged()));
setWindowTitle(tr("Inspector")); setWindowTitle(tr("Inspector"));
resize(1000, 500); resize(1000, 500);
} }
@ -53,7 +58,9 @@ void HInspectorWidget::internalSetRecord(Record* record) {
} else { } else {
RecordModel* recordModel = new RecordModel(record, this); RecordModel* recordModel = new RecordModel(record, this);
sortModel = new QSortFilterProxyModel(this); sortModel = new QSortFilterProxyModel(this);
sortModel->setDynamicSortFilter(true);
sortModel->setSourceModel(recordModel); sortModel->setSourceModel(recordModel);
sortModel->setFilterKeyColumn(1);
filterProxyModels[record] = sortModel; filterProxyModels[record] = sortModel;
} }
slotsView->setModel(sortModel); slotsView->setModel(sortModel);
@ -91,3 +98,11 @@ void HInspectorWidget::keyPressEvent(QKeyEvent *event) {
event->ignore(); event->ignore();
} }
} }
void HInspectorWidget::textFilterChanged() {
QRegExp regExp(filterPatternLineEdit->text());
QSortFilterProxyModel* sortModel =
static_cast<QSortFilterProxyModel*>(slotsView->model());
sortModel->setFilterRegExp(regExp);
}

View File

@ -18,6 +18,9 @@ class HInspectorWidget : public QWidget {
HInspectorWidget(QWidget* parent=0); HInspectorWidget(QWidget* parent=0);
void setRecord(Record* record); void setRecord(Record* record);
private slots:
void textFilterChanged();
protected: protected:
void keyPressEvent(QKeyEvent * event); void keyPressEvent(QKeyEvent * event);