diff --git a/plugins/gui/include/gui/searchbar/searchbar.h b/plugins/gui/include/gui/searchbar/searchbar.h index 3e5b392ad88..48feed568c6 100644 --- a/plugins/gui/include/gui/searchbar/searchbar.h +++ b/plugins/gui/include/gui/searchbar/searchbar.h @@ -218,7 +218,7 @@ namespace hal QToolButton* mDownButton; QToolButton* mUpButton; QToolButton* mCaseSensitiveButton; - QToolButton* mExactMatchButton; + QToolButton* mSearchOptionsButton; QToolButton* mClearButton; QString mSearchIcon; @@ -236,5 +236,6 @@ namespace hal SearchOptions* mCurrentOptions; bool mIncrementalSearch; + int mMinCharsToStartIncSearch; }; } diff --git a/plugins/gui/include/gui/searchbar/searchoptions_dialog.h b/plugins/gui/include/gui/searchbar/searchoptions_dialog.h index 67ee3619c19..fbc868eada0 100644 --- a/plugins/gui/include/gui/searchbar/searchoptions_dialog.h +++ b/plugins/gui/include/gui/searchbar/searchoptions_dialog.h @@ -33,6 +33,7 @@ #include #include #include +#include namespace hal { @@ -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); @@ -63,7 +66,9 @@ namespace hal QComboBox* mInputBox; QLineEdit* mLineEdit; QComboBox* mColumnBox; + QLabel* mSpinBoxLabel; QCheckBox* mIncrementalSearchBox; + QSpinBox* mSpinBox; QCheckBox* mExactMatchBox; QCheckBox* mCaseSensitiveBox; QCheckBox* mRegExBox; @@ -71,5 +76,6 @@ namespace hal QPushButton* mSearchBtn; QPushButton* mCloseBtn; + }; } diff --git a/plugins/gui/src/searchbar/searchbar.cpp b/plugins/gui/src/searchbar/searchbar.cpp index d147821a7e1..62c73111a24 100644 --- a/plugins/gui/src/searchbar/searchbar.cpp +++ b/plugins/gui/src/searchbar/searchbar.cpp @@ -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); @@ -38,7 +38,7 @@ 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); @@ -46,17 +46,7 @@ namespace hal 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)); @@ -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); } @@ -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); @@ -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()); } @@ -241,7 +236,7 @@ namespace hal bool Searchbar::exactMatchChecked() { - return mExactMatchButton->isChecked(); + return mSearchOptionsButton->isChecked(); } bool Searchbar::caseSensitiveChecked() @@ -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()); } } diff --git a/plugins/gui/src/searchbar/searchoptions_dialog.cpp b/plugins/gui/src/searchbar/searchoptions_dialog.cpp index 1fd66f57683..c3d81024b76 100644 --- a/plugins/gui/src/searchbar/searchoptions_dialog.cpp +++ b/plugins/gui/src/searchbar/searchoptions_dialog.cpp @@ -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"); @@ -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); @@ -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); + } @@ -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 @@ -78,4 +86,14 @@ namespace hal return mSearchText; } + + int SearchOptionsDialog::getMinIncSearchValue() + { + return mSpinBox->value(); + } + bool SearchOptionsDialog::getIncrementalSearch() + { + return mIncrementalSearchBox->isChecked(); + } + }