Skip to content

Commit

Permalink
added to int and from int conversion for search options
Browse files Browse the repository at this point in the history
  • Loading branch information
neoneela committed Sep 22, 2023
1 parent e7c7486 commit 922b571
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
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,9 +34,9 @@ namespace hal
public:
SearchProxyModel();

void updateProxy(int options, QString text);
void startSearch(QString text, int options);
private:
SearchOptions opts;
SearchOptions* opts;
};
}

5 changes: 3 additions & 2 deletions plugins/gui/include/gui/searchbar/searchoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@

#pragma once
#include <QList>
//#include "searchoptions_dialog.h"

namespace hal
{
class SearchOptions
{
public:
SearchOptions(bool exactMatchCmb, bool caseSensitiveCmb, bool regExCmb, QList<int> cols);
SearchOptions();
SearchOptions(int code);

void setOptions(bool exactMatch, bool caseSensitive, bool regEx, QList<int> columns);
int toInt() const;
static int toInt(bool exactMatch, bool caseSensitive, bool regEx, QList<int> columns);
private:
bool mExactMatch;
bool mCaseSensitive;
Expand Down
2 changes: 2 additions & 0 deletions plugins/gui/include/gui/searchbar/searchoptions_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ namespace hal
*/
SearchOptionsDialog(QWidget *parent = nullptr);

Q_SIGNALS:
void startSearch(QString text, int options);

public Q_SLOTS:
void optionsChanged();
void emitStartSearch();

private:
SearchProxyModel* searchProxy;
Expand Down
9 changes: 5 additions & 4 deletions plugins/gui/src/searchbar/search_proxy_model.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "gui/searchbar/search_proxy_model.h"
#include <QDebug>

namespace hal {
SearchProxyModel::SearchProxyModel()
: opts(false, false, false, {})
{

opts = new SearchOptions();
}

void SearchProxyModel::updateProxy(int options, QString text)
void SearchProxyModel::startSearch(QString text, int options)
{
//opts.setOptions(exactMatch, caseSensitive, regEx, columns);
opts = new SearchOptions(options);
qInfo() << "startSearch emitted";
}
}
59 changes: 56 additions & 3 deletions plugins/gui/src/searchbar/searchoptions.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,65 @@
#include "gui/searchbar/searchoptions.h"
#include <QDebug>


namespace hal
{
SearchOptions::SearchOptions(bool exactMatchCmb, bool caseSensitiveCmb, bool regExCmb, QList<int> cols)
: mExactMatch(exactMatchCmb), mCaseSensitive(caseSensitiveCmb), mRegularExpression(regExCmb), mColumns(cols)
SearchOptions::SearchOptions()
{};

SearchOptions::SearchOptions(int code)
{
mExactMatch = code & 1;
mCaseSensitive = code & 2;
mRegularExpression = code & 4;
if (!(code & (1<<3))) //check if the first column is 0
{
for(int i = 4; i<32; i++)
{
if(code & (1<<i))
mColumns.append(i-4);
}
}

qInfo() << mExactMatch << mCaseSensitive << mRegularExpression << "; " << mColumns;
}

int SearchOptions::toInt() const
{
int prefix = 0;
int suffix = 0;
prefix += mExactMatch;
prefix += mCaseSensitive << 1;
prefix += mRegularExpression << 2;
if(mColumns.empty()) prefix += 1 << 3;
else
{
for(int i=0; i < mColumns.length(); i++)
{
suffix += 1<<mColumns[i];
}
}
suffix = suffix << 4;
return prefix + suffix;
}

int SearchOptions::toInt(bool exactMatch, bool caseSensitive, bool regEx, QList<int> columns)
{
//qInfo() << "constructor executed";
int prefix = 0;
int suffix = 0;
prefix += exactMatch;
prefix += caseSensitive << 1;
prefix += regEx << 2;
if(columns.empty()) prefix += 1 << 3;
else
{
for(int i=0; i < columns.length(); i++)
{
suffix += 1<<columns[i];
}
}
suffix = suffix << 4;
return prefix + suffix;
}

void SearchOptions::setOptions(bool exactMatch, bool caseSensitive, bool regEx, QList<int> columns)
Expand Down
15 changes: 12 additions & 3 deletions plugins/gui/src/searchbar/searchoptions_dialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "gui/searchbar/searchoptions_dialog.h"
#include <QDebug>

namespace hal
{
Expand Down Expand Up @@ -39,20 +40,28 @@ namespace hal

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

connect(mSearchBtn, &QPushButton::clicked, this, &SearchOptionsDialog::emitStartSearch);
//connect(this, &SearchOptionsDialog::emitStartSearch, searchProxy, &SearchProxyModel::startSearch);

connect(mIncrementalSearchBox, &QCheckBox::stateChanged, this, &SearchOptionsDialog::optionsChanged);
connect(mExactMatchBox, &QCheckBox::stateChanged, this, &SearchOptionsDialog::optionsChanged);
connect(mCaseSensitiveBox, &QCheckBox::stateChanged, this, &SearchOptionsDialog::optionsChanged);
connect(mRegExBox, &QCheckBox::stateChanged, this, &SearchOptionsDialog::optionsChanged);

}

void SearchOptionsDialog::startSearch(QString text, int options)
void SearchOptionsDialog::emitStartSearch()
{

qInfo() << "emitstartSearch";
/*TODO
replace searchProxy
*/
searchProxy->startSearch(searchText, SearchOptions::toInt(mExactMatchBox->isChecked(), mCaseSensitiveBox->isChecked(), mRegExBox->isChecked(), {}));
}

void SearchOptionsDialog::optionsChanged()
{
// searchProxy->updateProxy(mExactMatchBox->isChecked(), mCaseSensitiveBox->isChecked(), mRegExBox->isChecked(), {}, searchText);
// searchProxy->startSearch(12, "");
//searchProxy->updateProxy(mExactMatchBox->isChecked(), mCaseSensitiveBox->isChecked(), mRegExBox->isChecked(), {}, searchText);
}
}

0 comments on commit 922b571

Please sign in to comment.