Skip to content

Commit

Permalink
Added TODO's for signal slot communication between Searchbar and (Pro…
Browse files Browse the repository at this point in the history
…xy)-Widget
  • Loading branch information
joern274 committed Sep 25, 2023
1 parent b810358 commit db3f974
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
25 changes: 20 additions & 5 deletions plugins/gui/include/gui/searchbar/searchbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#pragma once

#include "gui/searchbar/searchoptions.h"
#include <QFrame>

class QLabel;
Expand Down Expand Up @@ -161,14 +162,26 @@ namespace hal
bool eventFilter(QObject *object, QEvent *event);

Q_SIGNALS:
/**
* Q_SIGNAL that is emitted whenever the search string (i.e. the string withing the Searchbar's QLineEdit)
/** TODO : remove textEdited signal
* textEdited should be handled internally
* If incremental search is switched off a new search will be issued if user presses Enter or clicks "Search" in Dialog
* If incremental search is switched on a new search will be issued if search text has sufficient length
*
*
*
* has been changed.
*
* @param text - The new search string
* @param text
*/
void textEdited(const QString& text);

/**
* Q_SIGNAL that is emitted whenever the Proxy should be updated or a new search should be issued
* @param text - The new search string
* @param searchOptions - Search options encoded as int (use SearchOptions(int) constructor to get settings)
*/
void triggerNewSearch(const QString& text, int searchOptions);

/**
* Q_SIGNAL that is emitted whenever the Return/Enter key has been pressed.
*/
Expand All @@ -179,9 +192,9 @@ namespace hal

public Q_SLOTS:
/**
* Emits textEdited with respect to mEmitTextWithFlags.
* Handle textEdited signal, might emit triggerNewSearch with respect to mEmitTextWithFlags.
*/
void emitTextEdited();
void handleTextEdited();

/**
* Handles Return/Enter key pressed. Emits the signal returnPressed.
Expand Down Expand Up @@ -220,5 +233,7 @@ namespace hal
// One can decide wether to receive the text (emitted by textEdited) with or without regex modifier
// If set to false, one has to manually implement 'Exact Match'/'Case Sensitive' functionality
bool mEmitTextWithFlags = true;

SearchOptions mCurrentOptions;
};
}
1 change: 1 addition & 0 deletions plugins/gui/include/gui/searchbar/searchoptions_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace hal
*/
SearchOptionsDialog(QWidget *parent = nullptr);
void emitOptions();
SearchOptions getOptions() const;

Q_SIGNALS:
void emitOptions(QString text, int options);
Expand Down
8 changes: 6 additions & 2 deletions plugins/gui/src/grouping_dialog/grouping_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ namespace hal {
addAction(mToggleSearchbar);

connect(mTabWidget, &QTabWidget::currentChanged, this, &GroupingDialog::handleCurrentTabChanged);
connect(mSearchbar, &Searchbar::textEdited, this, &GroupingDialog::filter);

// connect(mSearchbar, &Searchbar::textEdited, this, &GroupingDialog::filter);

// TODO: change parameter in filter() method
// connect(mSearchbar, &Searchbar::triggerNewSearch, this, &GroupingDialog::filter);
connect(mToggleSearchbar, &QAction::triggered, this, &GroupingDialog::handleToggleSearchbar);
connect(mButtonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
Expand All @@ -92,7 +96,7 @@ namespace hal {
}
}

void GroupingDialog::filter(const QString& text)
void GroupingDialog::filter(const QString& text) // TODO : add int parameter search options
{
static_cast<GroupingProxyModel*>(mGroupingTableView->model())->setFilterRegularExpression(text);
if (mLastUsed)
Expand Down
29 changes: 20 additions & 9 deletions plugins/gui/src/searchbar/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace hal

setFrameStyle(QFrame::NoFrame);

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

Expand Down Expand Up @@ -164,7 +164,7 @@ namespace hal
void Searchbar::clear()
{
mLineEdit->clear();
emitTextEdited();
handleTextEdited(); // TODO : check use cases . Must reset proxy filter when search string emptied.
}

void Searchbar::hideEvent(QHideEvent *)
Expand All @@ -174,8 +174,7 @@ namespace hal

void Searchbar::showEvent(QShowEvent *)
{
if (!mLineEdit->text().isEmpty())
emitTextEdited();
// ???
}

QString Searchbar::getCurrentText()
Expand Down Expand Up @@ -219,15 +218,21 @@ namespace hal
s->polish(mLineEdit);
}

void Searchbar::emitTextEdited()
void Searchbar::handleTextEdited()
{
repolish();
Q_EMIT textEdited(mEmitTextWithFlags ? getCurrentTextWithFlags() : getCurrentText());
// TODO : emit only if incremental search switched on and minimum number of characters entered in search field

// TODO : should emit triggerNewSearch()
// Q_EMIT textEdited(mEmitTextWithFlags ? getCurrentTextWithFlags() : getCurrentText());
}

void Searchbar::handleReturnPressed()
{
Q_EMIT returnPressed();
// Q_EMIT returnPressed();

// TODO : check if member variables present
Q_EMIT triggerNewSearch(mLineEdit->text(), mCurrentOptions.toInt());
}

void Searchbar::handleClearClicked()
Expand Down Expand Up @@ -276,6 +281,12 @@ namespace hal
void Searchbar::handleSearchOptionsDialog()
{
SearchOptionsDialog sd;
sd.exec();
if (sd.exec() == QDialog::Accepted)
{
mCurrentOptions = sd.getOptions();

QString txt ; // TODO : get modified text from sd
Q_EMIT triggerNewSearch(txt,mCurrentOptions.toInt());
}
}
}
8 changes: 8 additions & 0 deletions plugins/gui/src/searchbar/searchoptions_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ namespace hal

Q_EMIT emitOptions(searchText, options);
}

SearchOptions SearchOptionsDialog::getOptions() const
{
SearchOptions retval;
// TODO :: retval.setOptions()
return retval;
}

}

0 comments on commit db3f974

Please sign in to comment.