Skip to content

Commit

Permalink
Changed position of the Searchbar filtericon
Browse files Browse the repository at this point in the history
Cleanup of searchbar.cpp
Implemented Spinbox for minimum chars required to start incremental search within searchoptions_dialog.cpp
  • Loading branch information
HerrKermet committed Sep 26, 2023
1 parent ea6d712 commit c2c561c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
3 changes: 2 additions & 1 deletion plugins/gui/include/gui/searchbar/searchbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ namespace hal
QToolButton* mDownButton;
QToolButton* mUpButton;
QToolButton* mCaseSensitiveButton;
QToolButton* mExactMatchButton;
QToolButton* mSearchOptionsButton;
QToolButton* mClearButton;

QString mSearchIcon;
Expand All @@ -236,5 +236,6 @@ namespace hal

SearchOptions* mCurrentOptions;
bool mIncrementalSearch;
int mMinCharsToStartIncSearch;
};
}
6 changes: 6 additions & 0 deletions plugins/gui/include/gui/searchbar/searchoptions_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QSpinBox>

namespace hal
{
Expand All @@ -49,6 +50,8 @@ namespace hal
void emitOptions();
SearchOptions* getOptions() const;
QString getText() const;
int getMinIncSearchValue();
bool getIncrementalSearch();

Q_SIGNALS:
void emitOptions(QString text, int options);
Expand All @@ -63,13 +66,16 @@ namespace hal
QComboBox* mInputBox;
QLineEdit* mLineEdit;
QComboBox* mColumnBox;
QLabel* mSpinBoxLabel;
QCheckBox* mIncrementalSearchBox;
QSpinBox* mSpinBox;
QCheckBox* mExactMatchBox;
QCheckBox* mCaseSensitiveBox;
QCheckBox* mRegExBox;
QLabel* mColumnLabel;
QPushButton* mSearchBtn;
QPushButton* mCloseBtn;


};
}
35 changes: 18 additions & 17 deletions plugins/gui/src/searchbar/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace hal
{
Searchbar::Searchbar(QWidget* parent)
: QFrame(parent), mLayout(new QHBoxLayout()), mSearchIconLabel(new QLabel()), mLineEdit(new QLineEdit()), mClearIconLabel(new QLabel()), mDownButton(new QToolButton()),
mUpButton(new QToolButton()), mCaseSensitiveButton(new QToolButton()), mExactMatchButton(new QToolButton()), mClearButton(new QToolButton())
mUpButton(new QToolButton()), mCaseSensitiveButton(new QToolButton()), mSearchOptionsButton(new QToolButton()), mClearButton(new QToolButton())
{
setLayout(mLayout);

Expand All @@ -38,25 +38,15 @@ namespace hal
//Placeholder icons get better ones
mDownButton->setIcon(QIcon(":/icons/arrow-down"));
mUpButton->setIcon(QIcon(":/icons/arrow-up"));
mExactMatchButton->setIcon(QIcon(":/icons/settings"));
mSearchOptionsButton->setIcon(QIcon(":/icons/settings"));

mSearchIconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
mLineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

mLayout->addWidget(mSearchIconLabel);
mLayout->addWidget(mLineEdit);

//mExactMatchButton->setText("==");
mExactMatchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
mExactMatchButton->setCheckable(true);
mExactMatchButton->setToolTip("Search Options");
mLayout->addWidget(mExactMatchButton);

/*mCaseSensitiveButton->setText("Aa");
mCaseSensitiveButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
mCaseSensitiveButton->setCheckable(true);
mCaseSensitiveButton->setToolTip("Case Sensitive");
mLayout->addWidget(mCaseSensitiveButton);*/

mClearButton->setIcon(gui_utility::getStyledSvgIcon(mClearIconStyle, mClearIcon));
mClearButton->setIconSize(QSize(10, 10));
Expand All @@ -65,15 +55,20 @@ namespace hal
mClearButton->setToolTip("Clear");
mLayout->addWidget(mClearButton);

mSearchOptionsButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
mSearchOptionsButton->setCheckable(true);
mSearchOptionsButton->setToolTip("Search Options");
mLayout->addWidget(mSearchOptionsButton);

setFrameStyle(QFrame::NoFrame);

connect(mLineEdit, &QLineEdit::textEdited, this, &Searchbar::handleTextEdited);
connect(mLineEdit, &QLineEdit::returnPressed, this, &Searchbar::handleReturnPressed);
connect(mCaseSensitiveButton, &QToolButton::clicked, this, &Searchbar::handleTextEdited);
//connect(mExactMatchButton, &QToolButton::clicked, this, &Searchbar::emitTextEdited);
//connect(mSearchOptionsButton, &QToolButton::clicked, this, &Searchbar::emitTextEdited);
connect(mClearButton, &QToolButton::clicked, this, &Searchbar::handleClearClicked);

connect(mExactMatchButton, &QToolButton::clicked, this, &Searchbar::handleSearchOptionsDialog);
connect(mSearchOptionsButton, &QToolButton::clicked, this, &Searchbar::handleSearchOptionsDialog);

setFocusProxy(mLineEdit);
}
Expand Down Expand Up @@ -194,7 +189,7 @@ namespace hal
QString textWithFlags;

textWithFlags.append(mCaseSensitiveButton->isChecked() ? "(?-i)" : "(?i)");
if (mExactMatchButton->isChecked())
if (mSearchOptionsButton->isChecked())
{
textWithFlags.append("^");
textWithFlags.append(text);
Expand Down Expand Up @@ -223,7 +218,7 @@ namespace hal
void Searchbar::handleTextEdited()
{
repolish();
if(mIncrementalSearch && mLineEdit->text().length()>=3)
if(mIncrementalSearch && mLineEdit->text().length() >= mMinCharsToStartIncSearch)
{
Q_EMIT triggerNewSearch(mLineEdit->text(), mCurrentOptions->toInt());
}
Expand All @@ -241,7 +236,7 @@ namespace hal

bool Searchbar::exactMatchChecked()
{
return mExactMatchButton->isChecked();
return mSearchOptionsButton->isChecked();
}

bool Searchbar::caseSensitiveChecked()
Expand Down Expand Up @@ -279,12 +274,18 @@ namespace hal

void Searchbar::handleSearchOptionsDialog()
{
//TODO discuss if previous options should be passed back to the dialog to build dialog from them.
// otherwise the use has to enter the same options again
SearchOptionsDialog sd;
if (sd.exec() == QDialog::Accepted)
{
mCurrentOptions = sd.getOptions();

QString txt = sd.getText(); // TODO : get modified text from sd
mIncrementalSearch = sd.getIncrementalSearch();
mMinCharsToStartIncSearch = sd.getMinIncSearchValue();

qInfo() << "Searchbar starts search with: " << txt << " " << mCurrentOptions->toInt() << " inc search: " << mIncrementalSearch << " " << mMinCharsToStartIncSearch;
Q_EMIT triggerNewSearch(txt, mCurrentOptions->toInt());
}
}
Expand Down
22 changes: 20 additions & 2 deletions plugins/gui/src/searchbar/searchoptions_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ namespace hal
mLineEdit = mInputBox->lineEdit();

mIncrementalSearchBox = new QCheckBox("Incremental search");
mSpinBoxLabel = new QLabel("start at: ");
mSpinBox = new QSpinBox();
mSpinBox->setMinimum(0);
mSpinBox->setMaximum(50);
mSpinBox->setSuffix(" chars");
mExactMatchBox = new QCheckBox("Exact match");
mExactMatchBox->setChecked(true);
mCaseSensitiveBox = new QCheckBox("Case sensitive");
mRegExBox = new QCheckBox("Regular expression");

Expand All @@ -30,6 +36,8 @@ namespace hal

mLayout->addWidget(mInputBox, 0, 0, 0, 3, Qt::AlignTop);
mLayout->addWidget(mIncrementalSearchBox, 1, 0);
mLayout->addWidget(mSpinBoxLabel, 1, 1, Qt::AlignRight);
mLayout->addWidget(mSpinBox, 1, 2, Qt::AlignLeft);
mLayout->addWidget(mExactMatchBox, 2, 0);
mLayout->addWidget(mCaseSensitiveBox, 3, 0);
mLayout->addWidget(mRegExBox, 4, 0);
Expand All @@ -39,13 +47,12 @@ namespace hal
mLayout->addWidget(mCloseBtn, 6, 3);

connect(mCloseBtn, &QPushButton::clicked, this, &SearchOptionsDialog::close);


connect(mSearchBtn, &QPushButton::clicked, this, &SearchOptionsDialog::emitStartSearch);

//TODO maybe delete this because edit triggers also the mSearchBtn signal as if it was clicked. Currently the emit search is emited twice while pressing Enter
// discuss with Joern
connect(mLineEdit, &QLineEdit::returnPressed, this, &SearchOptionsDialog::emitStartSearch);

}


Expand All @@ -64,6 +71,7 @@ namespace hal
qInfo() << "Emit search with string: " << mSearchText << " and options: " << options;

Q_EMIT emitOptions(mSearchText, options);
Q_EMIT accept();
}

SearchOptions* SearchOptionsDialog::getOptions() const
Expand All @@ -78,4 +86,14 @@ namespace hal
return mSearchText;
}


int SearchOptionsDialog::getMinIncSearchValue()
{
return mSpinBox->value();
}
bool SearchOptionsDialog::getIncrementalSearch()
{
return mIncrementalSearchBox->isChecked();
}

}

0 comments on commit c2c561c

Please sign in to comment.