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

Use qset in channel filter #363

Merged
merged 18 commits into from
Nov 9, 2023
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
2 changes: 2 additions & 0 deletions libshvvisu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_library(libshvvisu
images/images.qrc
src/logview/dataviewwidget.cpp
src/logview/dlgloginspector.cpp
src/logview/logmodel.cpp
src/logview/logsortfilterproxymodel.cpp
Expand Down Expand Up @@ -28,6 +29,7 @@ add_library(libshvvisu
src/timeline/sample.cpp
src/widgets/timezonecombobox.cpp

include/shv/visu/logview/dataviewwidget.h
include/shv/visu/logview/dlgloginspector.h
include/shv/visu/logview/logsortfilterproxymodel.h
include/shv/visu/logview/logmodel.h
Expand Down
1 change: 1 addition & 0 deletions libshvvisu/images/filter-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions libshvvisu/images/filter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions libshvvisu/images/images.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="shv/visu/images">
<file>filter.svg</file>
<file>filter-off.svg</file>
<file>pencil.svg</file>
<file>clock.svg</file>
<file>ok.svg</file>
Expand Down
33 changes: 33 additions & 0 deletions libshvvisu/include/shv/visu/logview/dataviewwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include <QWidget>
#include <shv/visu/timeline/graph.h>

namespace shv {
namespace visu {
namespace logview {

namespace Ui {
class DataViewWidget;
}

class DataViewWidget : public QWidget
{
Q_OBJECT

public:
explicit DataViewWidget(QWidget *parent = nullptr);
~DataViewWidget();

void init(const QString &site_path, timeline::Graph *graph);

private:
void onShowChannelFilterClicked();

timeline::Graph *m_graph = nullptr;
QString m_sitePath;

Ui::DataViewWidget *ui;
};

}}}
9 changes: 0 additions & 9 deletions libshvvisu/include/shv/visu/logview/dlgloginspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog
void setTimeZone(const QTimeZone &tz);
#endif

void applyFilters(const QStringList &channel_paths);
void onChannelsFilterClicked();
void onGraphChannelFilterChanged();

void initVisualSettingSelector(const QString &shv_path);
void onSaveViewClicked();
void onDeleteViewClicked();
void onViewSelected(int index);
void setView(const QString &name);

private:
Ui::DlgLogInspector *ui;

Expand All @@ -79,7 +71,6 @@ class SHVVISU_DECL_EXPORT DlgLogInspector : public QDialog
shv::visu::timeline::GraphModel *m_graphModel = nullptr;
shv::visu::timeline::Graph *m_graph = nullptr;
shv::visu::timeline::GraphWidget *m_graphWidget = nullptr;
shv::visu::timeline::ChannelFilterDialog *m_channelFilterDialog = nullptr;
};

}}}
5 changes: 3 additions & 2 deletions libshvvisu/include/shv/visu/logview/logsortfilterproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../timeline/fulltextfilter.h"

#include <QSortFilterProxyModel>
#include <optional>

namespace shv {
namespace visu {
Expand All @@ -18,15 +19,15 @@ class SHVVISU_DECL_EXPORT LogSortFilterProxyModel : public QSortFilterProxyModel
public:
explicit LogSortFilterProxyModel(QObject *parent = nullptr);

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

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

private:
shv::visu::timeline::ChannelFilter m_channelFilter;
std::optional<shv::visu::timeline::ChannelFilter> m_channelFilter;
shv::visu::timeline::FullTextFilter m_fulltextFilter;
int m_shvPathColumn = -1;
int m_valueColumn = -1;
Expand Down
19 changes: 10 additions & 9 deletions libshvvisu/include/shv/visu/timeline/channelfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ class SHVVISU_DECL_EXPORT ChannelFilter
{
public:
ChannelFilter();
ChannelFilter(const QStringList &matching_paths);
ChannelFilter(const QSet<QString> &permitted_paths, const QString &name = {});

void addMatchingPath(const QString &shv_path);
void removeMatchingPath(const QString &shv_path);
void addPermittedPath(const QString &path);
void removePermittedPath(const QString &path);

QStringList matchingPaths() const;
void setMatchingPaths(const QStringList &paths);
QSet<QString> permittedPaths() const;
void setPermittedPaths(const QSet<QString> &paths);

bool isPathPermitted(const QString &path) const;
QString name();

bool isPathMatch(const QString &path) const;
bool isValid() const;
private:
QStringList m_matchingPaths;
bool m_isValid;
QString m_name;
QSet<QString> m_permittedPaths;
};

}
Expand Down
31 changes: 26 additions & 5 deletions libshvvisu/include/shv/visu/timeline/channelfilterdialog.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include "../shvvisuglobal.h"
#include <shv/visu/timeline/graph.h>

#include <QDialog>
#include <optional>

namespace shv {
namespace visu {
Expand All @@ -20,20 +22,29 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog
Q_OBJECT

public:
explicit ChannelFilterDialog(QWidget *parent = nullptr);
explicit ChannelFilterDialog(QWidget *parent, const QString &site_path, Graph *graph);
~ChannelFilterDialog();

void init(const QString &site_path, const QStringList &logged_paths);

QStringList selectedChannels();
void setSelectedChannels(const QStringList &channels);
std::optional<ChannelFilter> channelFilter();

private:
void applyTextFilter();
void reloadDataViewsCombobox();

void saveDataView();
void saveDataViewAs();
void discardUserChanges();
void deleteDataView();
void exportDataView();
void importDataView();

void refreshActions();

void setVisibleItemsCheckState(Qt::CheckState state);
void setVisibleItemsCheckState_helper(const QModelIndex &mi, Qt::CheckState state);
void loadChannelFilterFomGraph();

void onDataViewComboboxChanged(int index);
void onCustomContextMenuRequested(QPoint pos);

void onPbCheckItemsClicked();
Expand All @@ -43,9 +54,19 @@ class SHVVISU_DECL_EXPORT ChannelFilterDialog : public QDialog
void onChbFindRegexChanged(int state);

Ui::ChannelFilterDialog *ui;
shv::visu::timeline::Graph *m_graph = nullptr;
ChannelFilterModel *m_channelsFilterModel = nullptr;
ChannelFilterSortFilterProxyModel *m_channelsFilterProxyModel = nullptr;
QString m_sitePath;
QString m_recentSettingsDir;

QAction *m_saveViewAction = nullptr;
QAction *m_saveViewAsAction = nullptr;
QAction *m_revertViewAction = nullptr;
QAction *m_resetViewAction = nullptr;
QAction *m_deleteViewAction = nullptr;
QAction *m_exportViewAction = nullptr;
QAction *m_importViewAction = nullptr;
};

}
Expand Down
8 changes: 4 additions & 4 deletions libshvvisu/include/shv/visu/timeline/channelfiltermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel
ChannelFilterModel(QObject *parent = nullptr);
~ChannelFilterModel() Q_DECL_OVERRIDE;

void createNodes(const QStringList &channels);
void createNodes(const QSet<QString> &channels);

QStringList selectedChannels();
void setSelectedChannels(const QStringList &channels);
QSet<QString> permittedChannels();
void setPermittedChannels(const QSet<QString> &channels);
void setItemCheckState(const QModelIndex &mi, Qt::CheckState check_state);
void fixCheckBoxesIntegrity();
protected:
Expand All @@ -38,7 +38,7 @@ class SHVVISU_DECL_EXPORT ChannelFilterModel : public QStandardItemModel

void createNodesForPath(const QString &path);

void selectedChannels_helper(QStringList *channels, QStandardItem *it);
void selectedChannels_helper(QSet<QString> *channels, QStandardItem *it);
bool setData ( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void setChildItemsCheckedState(QStandardItem *it, Qt::CheckState check_state);
void fixChildItemsCheckBoxesIntegrity(QStandardItem *it);
Expand Down
33 changes: 18 additions & 15 deletions libshvvisu/include/shv/visu/timeline/graph.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#pragma once

#include <shv/visu/timeline/channelfilter.h>
#include <shv/visu/timeline/channelprobe.h>
#include <shv/visu/timeline/graphchannel.h>
#include <shv/visu/timeline/graphbuttonbox.h>
#include <shv/visu/timeline/sample.h>
#include <shv/visu/shvvisuglobal.h>
#include "channelfilter.h"
#include "channelprobe.h"
#include "graphchannel.h"
#include "graphbuttonbox.h"
#include "sample.h"
#include "../shvvisuglobal.h"

#include <shv/coreqt/utils.h>
#include <shv/core/exception.h>
#include <shv/core/utils/shvlogtypeinfo.h>

#include <optional>
#include <QObject>
#include <QVector>
#include <QVariantMap>
Expand Down Expand Up @@ -93,8 +94,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject

QString toJson() const;
static VisualSettings fromJson(const QString &json);
bool isValid() const;
QVector<Channel> channels;
QString name;
};

Graph(QObject *parent = nullptr);
Expand All @@ -111,12 +112,10 @@ class SHVVISU_DECL_EXPORT Graph : public QObject
#endif

void setSettingsUserName(const QString &user);

void reset();

enum class SortChannels { No = 0, Yes };
void createChannelsFromModel(SortChannels sorted = SortChannels::Yes);
void resetChannelsRanges();
bool isInitialView() const;

qsizetype channelCount() const;
void clearChannels();
Expand All @@ -128,10 +127,10 @@ class SHVVISU_DECL_EXPORT Graph : public QObject
QString channelName(qsizetype channel) const;

void showAllChannels();
QStringList channelPaths();
QSet<QString> channelPaths();
void hideFlatChannels();
const ChannelFilter& channelFilter() const;
void setChannelFilter(const ChannelFilter &filter);
const std::optional<ChannelFilter> &channelFilter() const;
void setChannelFilter(const std::optional<ChannelFilter> &filter);
void setChannelVisible(qsizetype channel_ix, bool is_visible);
void setChannelMaximized(qsizetype channel_ix, bool is_maximized);

Expand Down Expand Up @@ -226,14 +225,16 @@ class SHVVISU_DECL_EXPORT Graph : public QObject
static QString rectToString(const QRect &r);

VisualSettings visualSettings() const;
void setVisualSettings(const VisualSettings &settings);
void setVisualSettingsAndChannelFilter(const VisualSettings &settings);
void resizeChannelHeight(qsizetype ix, int delta_px);
void resizeVerticalHeaderWidth(int delta_px);

void saveVisualSettings(const QString &settings_id, const QString &name) const;
void deleteVisualSettings(const QString &settings_id, const QString &name) const;
QStringList savedVisualSettingsNames(const QString &settings_id) const;
void loadVisualSettings(const QString &settings_id, const QString &name);
QString loadedVisualSettingsId();
bool isChannelFilterValid() const;

protected:
void sanityXRangeZoom();
Expand Down Expand Up @@ -270,6 +271,8 @@ class SHVVISU_DECL_EXPORT Graph : public QObject
virtual void drawCurrentTime(QPainter *painter, int channel_ix);
void drawCurrentTimeMarker(QPainter *painter, time_t time);

virtual void applyCustomChannelStyle(GraphChannel *channel);

QVariantMap mergeMaps(const QVariantMap &base, const QVariantMap &overlay) const;
void makeXAxis();
void makeYAxis(qsizetype channel);
Expand All @@ -290,7 +293,7 @@ class SHVVISU_DECL_EXPORT Graph : public QObject

QVector<ChannelProbe*> m_channelProbes;
QVector<GraphChannel*> m_channels;
ChannelFilter m_channelFilter;
std::optional<ChannelFilter> m_channelFilter;

struct SHVVISU_DECL_EXPORT XAxis
{
Expand Down
53 changes: 53 additions & 0 deletions libshvvisu/src/logview/dataviewwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "ui_dataviewwidget.h"

#include <shv/visu/logview//dataviewwidget.h>
#include <shv/visu/timeline/graph.h>
#include <shv/visu/timeline/channelfilterdialog.h>

#include "shv/core/log.h"

namespace tl = shv::visu::timeline;

namespace shv::visu::logview {

DataViewWidget::DataViewWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DataViewWidget)
{
ui->setupUi(this);

connect(ui->pbShowChannelFilterDialog, &QToolButton::clicked, this, &DataViewWidget::onShowChannelFilterClicked);
}

DataViewWidget::~DataViewWidget()
{
delete ui;
}

void DataViewWidget::init(const QString &site_path, timeline::Graph *graph)
{
if (m_graph != nullptr) {
shvWarning() << "Dialog is allready initialized.";
return;
}

m_graph = graph;
m_sitePath = site_path;

connect(graph, &timeline::Graph::channelFilterChanged, this, [this](){
ui->pbShowChannelFilterDialog->setIcon(m_graph->isChannelFilterValid()? QIcon(QStringLiteral(":/shv/visu/images/filter.svg")): QIcon(QStringLiteral(":/shv/visu/images/filter-off.svg")));
});
}

void DataViewWidget::onShowChannelFilterClicked()
{
auto *channel_filter_dialog = new tl::ChannelFilterDialog(this, m_sitePath, m_graph);

if (channel_filter_dialog->exec() == QDialog::Accepted) {
m_graph->setChannelFilter(channel_filter_dialog->channelFilter());
}

channel_filter_dialog->deleteLater();
}

}
Loading