Skip to content

Commit

Permalink
Add context menu to save current search as filter (#253)
Browse files Browse the repository at this point in the history
One of the features discussed in:
#243
  • Loading branch information
twardakm authored Mar 31, 2021
1 parent 9bf68ff commit 1c8ad2b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/ui/include/crawlerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class CrawlerWidget : public QSplitter,
void followModeChanged( bool follow );
// Sent up when the current line number is updated
void updateLineNumber( LineNumber line );
// Sent up when user wants to save new predefined filter from current search
void saveCurrentSearchAsPredefinedFilter( QString newFilter );

// "auto-refresh" check has been changed
void searchRefreshChanged( bool isRefreshing );
Expand Down Expand Up @@ -212,6 +214,9 @@ class CrawlerWidget : public QSplitter,
// Clear the search items
void clearSearchItems();

// Save current search as predefined filter
void saveAsPredefinedFilter();

// Search Context Menu
void showSearchContextMenu();

Expand Down
6 changes: 5 additions & 1 deletion src/ui/include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MainWindow : public QMainWindow {
void openClipboard();
void openUrl();
void editHighlighters();
void editPredefinedFilters();
void editPredefinedFilters( QString newFilter = "" );
void options();
void about();
void aboutQt();
Expand All @@ -138,6 +138,10 @@ class MainWindow : public QMainWindow {
// Must be passed as the internal (starts at 0) line number.
void lineNumberHandler( LineNumber line );

// Save current search in line edit as predefined filter.
// Opens dialog with new entry.
void newPredefinedFilterHandler( QString newFilter );

// Instructs the widget to update the loading progress gauge
void updateLoadingProgress( int progress );
// Instructs the widget to display the 'normal' status bar,
Expand Down
3 changes: 2 additions & 1 deletion src/ui/include/predefinedfiltersdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PredefinedFiltersDialog : public QDialog, public Ui::PredefinedFiltersDial
Q_OBJECT

public:
explicit PredefinedFiltersDialog( QWidget* parent = nullptr );
explicit PredefinedFiltersDialog( QWidget* parent = nullptr, QString newFilter = "" );

private slots:
void addFilter() const;
Expand All @@ -64,6 +64,7 @@ class PredefinedFiltersDialog : public QDialog, public Ui::PredefinedFiltersDial
void optionsChanged();

private:
void addFilterFromSearchLine( QString newFilter ) const;
void populateFiltersTable() const;
void saveSettings();
void readFiltersTable();
Expand Down
12 changes: 12 additions & 0 deletions src/ui/src/crawlerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ void CrawlerWidget::clearSearchItems()
searchLineCompleter->setModel( new QStringListModel( empty_history, searchLineCompleter ) );
}

void CrawlerWidget::saveAsPredefinedFilter()
{
const auto currentText = searchLineEdit->currentText();

emit saveCurrentSearchAsPredefinedFilter( currentText );
}

void CrawlerWidget::showSearchContextMenu()
{
if ( searchLineContextMenu )
Expand Down Expand Up @@ -891,8 +898,11 @@ void CrawlerWidget::setup()
searchLineEdit->setContentsMargins( 2, 2, 2, 2 );

QAction* clearSearchItemsAction = new QAction( "Clear All Items", this );
QAction* saveAsPredefinedFilterAction = new QAction( "Save as Filter", this );
searchLineContextMenu = searchLineEdit->lineEdit()->createStandardContextMenu();
searchLineContextMenu->addSeparator();
searchLineContextMenu->addAction( saveAsPredefinedFilterAction );
searchLineContextMenu->addSeparator();
searchLineContextMenu->addAction( clearSearchItemsAction );
searchLineEdit->setContextMenuPolicy( Qt::CustomContextMenu );

Expand Down Expand Up @@ -960,6 +970,8 @@ void CrawlerWidget::setup()

connect( searchLineEdit, &QWidget::customContextMenuRequested, this,
&CrawlerWidget::showSearchContextMenu );
connect( saveAsPredefinedFilterAction, &QAction::triggered, this,
&CrawlerWidget::saveAsPredefinedFilter );
connect( clearSearchItemsAction, &QAction::triggered, this, &CrawlerWidget::clearSearchItems );
connect( searchButton, &QToolButton::clicked, this, &CrawlerWidget::startNewSearch );
connect( stopButton, &QToolButton::clicked, this, &CrawlerWidget::stopSearch );
Expand Down
11 changes: 9 additions & 2 deletions src/ui/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ MainWindow::MainWindow( WindowSession session )
SLOT( changeFollowMode( bool ) ) );
signalMux_.connect( SIGNAL( updateLineNumber( LineNumber ) ), this,
SLOT( lineNumberHandler( LineNumber ) ) );
signalMux_.connect( SIGNAL( saveCurrentSearchAsPredefinedFilter( QString ) ), this,
SLOT( newPredefinedFilterHandler( QString ) ) );

// Register for progress status bar
signalMux_.connect( SIGNAL( loadingProgressed( int ) ), this,
Expand Down Expand Up @@ -893,9 +895,9 @@ void MainWindow::editHighlighters()
}

// Opens dialog to configure predefined filters
void MainWindow::editPredefinedFilters()
void MainWindow::editPredefinedFilters( QString newFilter )
{
PredefinedFiltersDialog dialog( this );
PredefinedFiltersDialog dialog( this, newFilter );

signalMux_.connect( &dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() ) );

Expand Down Expand Up @@ -1040,6 +1042,11 @@ void MainWindow::lineNumberHandler( LineNumber line )
}
}

void MainWindow::newPredefinedFilterHandler( QString newFilter )
{
editPredefinedFilters( newFilter );
}

void MainWindow::updateLoadingProgress( int progress )
{
LOG( logDEBUG ) << "Loading progress: " << progress;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/src/predefinedfilterscombobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PredefinedFiltersComboBox::PredefinedFiltersComboBox( QWidget* parent )
: QComboBox( parent )
, model_( new QStandardItemModel() )
{
setFocusPolicy( Qt::NoFocus );
setFocusPolicy( Qt::ClickFocus );
populatePredefinedFilters();
}

Expand Down
19 changes: 18 additions & 1 deletion src/ui/src/predefinedfiltersdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "log.h"
#include "predefinedfilters.h"

PredefinedFiltersDialog::PredefinedFiltersDialog( QWidget* parent )
PredefinedFiltersDialog::PredefinedFiltersDialog( QWidget* parent, QString newFilter )
: QDialog( parent )
{
setupUi( this );
Expand All @@ -73,6 +73,10 @@ PredefinedFiltersDialog::PredefinedFiltersDialog( QWidget* parent )
addFilterButton->setIcon( iconLoader.load( "icons8-plus-16" ) );
removeFilterButton->setIcon( iconLoader.load( "icons8-minus-16" ) );
} );

if ( newFilter != "" ) {
addFilterFromSearchLine( newFilter );
}
}

void PredefinedFiltersDialog::populateFiltersTable() const
Expand Down Expand Up @@ -129,6 +133,19 @@ void PredefinedFiltersDialog::addFilter() const
filtersTableWidget->setRowCount( filtersTableWidget->rowCount() + 1 );
}

void PredefinedFiltersDialog::addFilterFromSearchLine( QString newFilter ) const
{
addFilter();

const auto row = filtersTableWidget->rowCount() - 1;

filtersTableWidget->setItem( row, 1, new QTableWidgetItem( newFilter ) );
filtersTableWidget->setItem( row, 0, new QTableWidgetItem( "" ) );

filtersTableWidget->scrollToItem( filtersTableWidget->item( row, 0 ) );
filtersTableWidget->editItem( filtersTableWidget->item( row, 0 ) );
}

void PredefinedFiltersDialog::removeFilter() const
{
filtersTableWidget->removeRow( filtersTableWidget->currentRow() );
Expand Down

0 comments on commit 1c8ad2b

Please sign in to comment.