Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable filtering channels by localized path #542

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@ class SHVVISU_DECL_EXPORT LogSortFilterProxyModel : public QSortFilterProxyModel
explicit LogSortFilterProxyModel(QObject *parent = nullptr);

void setChannelFilter(const std::optional<timeline::ChannelFilter> &filter);
void setShvPathColumn(int column);
void setChannelFilterPathColumn(int column);
void setValueColumn(int column);
void setFulltextFilter(const shv::visu::timeline::FullTextFilter &filter);
void setFulltextFilterPathColumn(int column);

bool filterAcceptsRow(int source_rrow, const QModelIndex &source_parent) const override;

private:
std::optional<shv::visu::timeline::ChannelFilter> m_channelFilter;
shv::visu::timeline::FullTextFilter m_fulltextFilter;
int m_shvPathColumn = -1;
int m_channelFilterPathColumn = -1;
int m_fulltextFilterPathColumn = -1;
int m_valueColumn = -1;
};
}
3 changes: 2 additions & 1 deletion libshvvisu/src/logview/dlgloginspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ DlgLogInspector::DlgLogInspector(const QString &shv_path, QWidget *parent) :

m_logModel = new LogModel(this);
m_logSortFilterProxy = new shv::visu::logview::LogSortFilterProxyModel(this);
m_logSortFilterProxy->setShvPathColumn(LogModel::ColPath);
m_logSortFilterProxy->setChannelFilterPathColumn(LogModel::ColPath);
m_logSortFilterProxy->setFulltextFilterPathColumn(LogModel::ColPath);
m_logSortFilterProxy->setValueColumn(LogModel::ColValue);
m_logSortFilterProxy->setSourceModel(m_logModel);
ui->tblData->setModel(m_logSortFilterProxy);
Expand Down
35 changes: 21 additions & 14 deletions libshvvisu/src/logview/logsortfilterproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ void LogSortFilterProxyModel::setChannelFilter(const std::optional<shv::visu::ti
invalidateFilter();
}

void LogSortFilterProxyModel::setShvPathColumn(int column)
void LogSortFilterProxyModel::setChannelFilterPathColumn(int column)
{
m_shvPathColumn = column;
m_channelFilterPathColumn = column;
}

void LogSortFilterProxyModel::setValueColumn(int column)
Expand All @@ -33,6 +33,11 @@ void LogSortFilterProxyModel::setFulltextFilter(const timeline::FullTextFilter &
invalidateFilter();
}

void LogSortFilterProxyModel::setFulltextFilterPathColumn(int column)
{
m_fulltextFilterPathColumn = column;
}

bool startsWithPath(const QStringView &str, const QStringView &path)
{
if (path.empty())
Expand All @@ -52,21 +57,23 @@ bool LogSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex
{
bool is_row_accepted = true;

if (m_shvPathColumn >= 0) {
QModelIndex ix = sourceModel()->index(source_row, m_shvPathColumn, source_parent);
if (m_channelFilterPathColumn >= 0) {
QModelIndex ix = sourceModel()->index(source_row, m_channelFilterPathColumn, source_parent);
is_row_accepted = (m_channelFilter) ? m_channelFilter.value().isPathPermitted(sourceModel()->data(ix).toString()) : true;

if (is_row_accepted && !m_fulltextFilter.pattern().isEmpty()) {
bool is_fulltext_filter_matched = m_fulltextFilter.matches(sourceModel()->data(ix).toString());

if (m_valueColumn >= 0) {
ix = sourceModel()->index(source_row, m_valueColumn, source_parent);
is_fulltext_filter_matched = is_fulltext_filter_matched || m_fulltextFilter.matches(sourceModel()->data(ix).toString());
}
is_row_accepted = is_row_accepted && is_fulltext_filter_matched;
}
if (is_row_accepted && !m_fulltextFilter.pattern().isEmpty()) {
bool path_matches = true;
bool value_matches = true;
if (m_fulltextFilterPathColumn >= 0) {
QModelIndex ix = sourceModel()->index(source_row, m_fulltextFilterPathColumn, source_parent);
path_matches = m_fulltextFilter.matches(sourceModel()->data(ix).toString());
}
if (m_valueColumn >= 0) {
QModelIndex ix = sourceModel()->index(source_row, m_valueColumn, source_parent);
value_matches = m_fulltextFilter.matches(sourceModel()->data(ix).toString());
}
is_row_accepted = path_matches || value_matches;
}

return is_row_accepted;
}

Expand Down
Loading