Skip to content

Commit

Permalink
added SearchProxyModel to context widget
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Sep 26, 2023
1 parent c2c561c commit e07e625
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "gui/graph_widget/contexts/graph_context.h"
#include "gui/searchbar/search_proxy_model.h"

#include <QRegularExpression>
#include <QSortFilterProxyModel>
Expand All @@ -36,7 +37,7 @@ namespace hal
* @ingroup utility_widgets-context
* @brief A proxy model to filter the ContextTableModel by a given string.
*/
class ContextTableProxyModel : public QSortFilterProxyModel
class ContextTableProxyModel : public SearchProxyModel
{
Q_OBJECT

Expand Down Expand Up @@ -67,6 +68,7 @@ namespace hal
* @param filter_text - The new filter string.
*/
void handleFilterTextChanged(const QString& filter_text);
void startSearch(QString text, int options) override;

protected:

Expand Down
1 change: 1 addition & 0 deletions plugins/gui/include/gui/module_model/module_proxy_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "gui/gui_utils/sort.h"


#include <QSortFilterProxyModel>

namespace hal
Expand Down
4 changes: 2 additions & 2 deletions plugins/gui/include/gui/searchbar/search_proxy_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ namespace hal
Q_OBJECT

public:
SearchProxyModel();
SearchProxyModel(QObject* parent = nullptr);

public Q_SLOTS:
void startSearch(QString text, int options);
virtual void startSearch(QString text, int options) = 0;
private:
SearchOptions* opts;
};
Expand Down
18 changes: 9 additions & 9 deletions plugins/gui/include/gui/searchbar/searchbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ namespace hal
Q_PROPERTY(QString searchIconStyle READ searchIconStyle WRITE setSearchIconStyle)
Q_PROPERTY(QString clearIcon READ clearIcon WRITE setClearIcon)
Q_PROPERTY(QString clearIconStyle READ clearIconStyle WRITE setClearIconStyle)
Q_PROPERTY(QString caseSensitivityIcon READ caseSensitivityIcon WRITE setCaseSensitivityIcon)
/*Q_PROPERTY(QString caseSensitivityIcon READ caseSensitivityIcon WRITE setCaseSensitivityIcon)
Q_PROPERTY(QString caseSensitivityIconStyle READ caseSensitivityIconStyle WRITE setCaseSensitivityIconStyle)
Q_PROPERTY(QString exactMatchIcon READ exactMatchIcon WRITE setExactMatchIcon)
Q_PROPERTY(QString exactMatchIconStyle READ exactMatchIconStyle WRITE setExactMatchIconStyle)
Q_PROPERTY(QString exactMatchIconStyle READ exactMatchIconStyle WRITE setExactMatchIconStyle)*/

public:
/**
Expand All @@ -70,10 +70,10 @@ namespace hal
QString searchIconStyle() const;
QString clearIcon() const;
QString clearIconStyle() const;
QString caseSensitivityIcon() const;
/*QString caseSensitivityIcon() const;
QString caseSensitivityIconStyle() const;
QString exactMatchIcon() const;
QString exactMatchIconStyle() const;
QString exactMatchIconStyle() const;*/
///@}

/// @name Q_PROPERTY WRITE Functions
Expand All @@ -82,10 +82,10 @@ namespace hal
void setSearchIconStyle(const QString& style);
void setClearIcon(const QString& icon);
void setClearIconStyle(const QString& style);
void setCaseSensitivityIcon(const QString& icon);
/*void setCaseSensitivityIcon(const QString& icon);
void setCaseSensitivityIconStyle(const QString& style);
void setExactMatchIcon(const QString& icon);
void setExactMatchIconStyle(const QString& style);
void setExactMatchIconStyle(const QString& style);*/
///@}

/**
Expand Down Expand Up @@ -217,18 +217,18 @@ namespace hal

QToolButton* mDownButton;
QToolButton* mUpButton;
QToolButton* mCaseSensitiveButton;
//QToolButton* mCaseSensitiveButton;
QToolButton* mSearchOptionsButton;
QToolButton* mClearButton;

QString mSearchIcon;
QString mSearchIconStyle;
QString mClearIcon;
QString mClearIconStyle;
QString mCaseSensitivityIcon;
/*QString mCaseSensitivityIcon;
QString mCaseSensitivityIconStyle;
QString mExactMatchIcon;
QString mExactMatchIconStyle;
QString mExactMatchIconStyle;*/

// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ namespace hal
connect(mContextTableModel, &ContextTableModel::rowsRemoved, this, &ContextManagerWidget::handleDataChanged);
connect(mContextTableModel, &ContextTableModel::rowsInserted, this, &ContextManagerWidget::handleDataChanged);

connect(mSearchbar, &Searchbar::textEdited, mContextTableProxyModel, &ContextTableProxyModel::handleFilterTextChanged);
//connect(mSearchbar, &Searchbar::textEdited, mContextTableProxyModel, &ContextTableProxyModel::handleFilterTextChanged);
connect(mSearchbar, &Searchbar::textEdited, this, &ContextManagerWidget::updateSearchIcon);

connect(mSearchbar, &Searchbar::triggerNewSearch, mContextTableProxyModel, &ContextTableProxyModel::startSearch);
}

void ContextManagerWidget::handleCreateContextClicked()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace hal
{
ContextTableProxyModel::ContextTableProxyModel(QObject* parent) : QSortFilterProxyModel(parent)
ContextTableProxyModel::ContextTableProxyModel(QObject* parent) : SearchProxyModel(parent)
{
mFilterExpression.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
}
Expand Down Expand Up @@ -36,9 +36,15 @@ namespace hal
return !(gui_utility::compare(gui_utility::mSortMechanism::natural, leftData.toString(), rightData.toString()));
}

void ContextTableProxyModel::handleFilterTextChanged(const QString& filter_text)
/*void ContextTableProxyModel::handleFilterTextChanged(const QString& filter_text)
{
mFilterExpression.setPattern(filter_text);
invalidateFilter();
}*/

void ContextTableProxyModel::startSearch(QString text, int options)
{
mFilterExpression.setPattern(text);
invalidateFilter();
}
}
1 change: 1 addition & 0 deletions plugins/gui/src/module_dialog/module_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace hal {
connect(mButtonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(mTreeView, &QTreeView::doubleClicked, this, &ModuleDialog::handleTreeDoubleClick);
connect(mTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ModuleDialog::handleTreeSelectionChanged);

}

void ModuleDialog::enableButtons()
Expand Down
2 changes: 1 addition & 1 deletion plugins/gui/src/searchbar/search_proxy_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <QDebug>

namespace hal {
SearchProxyModel::SearchProxyModel()
SearchProxyModel::SearchProxyModel(QObject* parent): QSortFilterProxyModel(parent)
{
opts = new SearchOptions();
}
Expand Down
22 changes: 10 additions & 12 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()), mSearchOptionsButton(new QToolButton()), mClearButton(new QToolButton())
mUpButton(new QToolButton()), /*mCaseSensitiveButton(new QToolButton()),*/ mSearchOptionsButton(new QToolButton()), mClearButton(new QToolButton())
{
setLayout(mLayout);

Expand Down Expand Up @@ -46,8 +46,6 @@ namespace hal
mLayout->addWidget(mSearchIconLabel);
mLayout->addWidget(mLineEdit);



mClearButton->setIcon(gui_utility::getStyledSvgIcon(mClearIconStyle, mClearIcon));
mClearButton->setIconSize(QSize(10, 10));
mClearButton->setFixedWidth(32);
Expand All @@ -64,7 +62,7 @@ namespace hal

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

Expand Down Expand Up @@ -93,7 +91,7 @@ namespace hal
return mClearIconStyle;
}

QString Searchbar::caseSensitivityIcon() const
/*QString Searchbar::caseSensitivityIcon() const
{
return mCaseSensitivityIcon;
}
Expand All @@ -111,7 +109,7 @@ namespace hal
QString Searchbar::exactMatchIconStyle() const
{
return mExactMatchIconStyle;
}
}*/

void Searchbar::setSearchIcon(const QString& icon)
{
Expand All @@ -133,7 +131,7 @@ namespace hal
mClearIconStyle = style;
}

void Searchbar::setCaseSensitivityIcon(const QString& icon)
/*void Searchbar::setCaseSensitivityIcon(const QString& icon)
{
mCaseSensitivityIcon = icon;
}
Expand All @@ -151,7 +149,7 @@ namespace hal
void Searchbar::setExactMatchIconStyle(const QString& style)
{
mExactMatchIconStyle = style;
}
}*/

void Searchbar::setPlaceholderText(const QString& text)
{
Expand Down Expand Up @@ -188,8 +186,8 @@ namespace hal
{
QString textWithFlags;

textWithFlags.append(mCaseSensitiveButton->isChecked() ? "(?-i)" : "(?i)");
if (mSearchOptionsButton->isChecked())
textWithFlags.append(caseSensitiveChecked() ? "(?-i)" : "(?i)");
if (exactMatchChecked())
{
textWithFlags.append("^");
textWithFlags.append(text);
Expand Down Expand Up @@ -236,12 +234,12 @@ namespace hal

bool Searchbar::exactMatchChecked()
{
return mSearchOptionsButton->isChecked();
return mCurrentOptions->toInt()&&1;
}

bool Searchbar::caseSensitiveChecked()
{
return mCaseSensitiveButton->isChecked();
return mCurrentOptions->toInt()&&2;
}

void Searchbar::setEmitTextWithFlags(bool emitTextWithFlags)
Expand Down

0 comments on commit e07e625

Please sign in to comment.