Skip to content

Commit

Permalink
use regexp for column filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
sunderme committed Nov 7, 2022
1 parent 036698c commit 7f04064
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ void MainWindow::setupGUI()
leFilterText = new QLineEdit;
connect(leFilterText,&QLineEdit::textEdited,this,&MainWindow::filterTextChanged);
hLayout2->addWidget(leFilterText);
btRegExp=new QToolButton;
btRegExp->setCheckable(true);
btRegExp->setText(".*");
//btRegExp->setIcon(QIcon(":/icons/view-filter.svg"));
connect(btRegExp,&QAbstractButton::toggled,this,&MainWindow::regexToggled);
hLayout2->addWidget(btRegExp);
hLayout2->addSpacing(1);
mainLayout->addLayout(hLayout2);
mainLayout->addWidget(tableWidget,3);
Expand Down Expand Up @@ -1092,6 +1098,15 @@ void MainWindow::filterToggled(bool checked)
filterTextChanged(leFilterText->text());
}
}
/*!
* \brief use regexp as filter text
* \param checked
*/
void MainWindow::regexToggled(bool )
{
// filter columns
filterTextChanged(leFilterText->text());
}
/*!
* \brief filter to only columns which are checked on header
* \param checked
Expand Down Expand Up @@ -1133,9 +1148,16 @@ void MainWindow::filterTextChanged(const QString &text)
if(!btFilter->isChecked()){
btFilter->setChecked(true);
}
bool useRegex=btRegExp->isChecked();
if(btFilter->isChecked()){
for(int i=0;i<m_columns.size();++i){
if(m_columns.value(i).contains(text, Qt::CaseInsensitive)){
bool show=false;
if(useRegex){
show=m_columns.value(i).contains(QRegularExpression(text));
}else{
show=m_columns.value(i).contains(text, Qt::CaseInsensitive);
}
if(show){
tableWidget->showColumn(i);
}else{
tableWidget->hideColumn(i);
Expand Down
3 changes: 2 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class MainWindow : public QMainWindow
void populateRecentFiles();
void populateRecentTemplates();
void filterToggled(bool checked);
void regexToggled(bool checked);
void filterCheckedToggled(bool checked);
void filterPlotToggled(bool checked);
void filterTextChanged(const QString &text);
Expand Down Expand Up @@ -122,7 +123,7 @@ class MainWindow : public QMainWindow
QListWidget *lstSweeps;
QListWidget *lstData;

QToolButton *btFilter,*btFilterPlot,*btFilterChecked;
QToolButton *btFilter,*btFilterPlot,*btFilterChecked,*btRegExp;
QLineEdit *leFilterText;

QString m_fileName;
Expand Down

0 comments on commit 7f04064

Please sign in to comment.