CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
cansignaldataguiimpl.h
Go to the documentation of this file.
1#ifndef CANSIGNALDATAGUIIMPL_H
2#define CANSIGNALDATAGUIIMPL_H
3
5#include "searchmodel.h"
6#include "ui_cansignaldata.h"
7#include <QButtonGroup>
8#include <QItemDelegate>
9#include <QItemEditorFactory>
10#include <QStyledItemDelegate>
11#include <QWidget>
12#include <log.h>
13
14class IntervalLE : public QLineEdit {
15public:
16 IntervalLE(uint32_t, QWidget* parent)
17 : QLineEdit(parent)
18 {
19 QRegExp qRegExp("[0-9]*");
20 auto v = new QRegExpValidator(qRegExp, this);
21 setValidator(v);
22 }
23};
24
25class ValueLE : public QLineEdit {
26public:
27 ValueLE(uint32_t len, QWidget* parent)
28 : QLineEdit(parent)
29 {
30 QRegExp qRegExp("[0-9A-Fa-f]{" + QString::number(len * 2) + "}");
31 auto v = new QRegExpValidator(qRegExp, this);
32 setValidator(v);
33 setPlaceholderText(QString(" %1 hex digits expected").arg(len*2));
34 }
35};
36
37template <typename T> class DbFieldDelegate : public QStyledItemDelegate {
38public:
39 DbFieldDelegate(QAbstractItemModel* model, QObject* parent = nullptr)
40 : QStyledItemDelegate(parent)
41 , _model(model)
42 {
43 }
44
45 virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const override
46 {
47 uint32_t dlc = _model->data(_model->index(index.row(), 2)).toUInt();
48
49 return new T(dlc, parent);
50 }
51
52private:
53 QAbstractItemModel* _model;
54};
55
58 : _ui(new Ui::CanSignalDataPrivate)
59 , _widget(new QWidget)
60 {
61 _ui->setupUi(_widget);
62 _widget->setMinimumSize(_ui->tv->minimumSize());
63
64 QButtonGroup* bg = new QButtonGroup(_widget);
65 bg->addButton(_ui->pbMsg);
66 bg->addButton(_ui->pbSig);
67
68 _ui->tv->setEditTriggers(QAbstractItemView::AllEditTriggers);
69 }
70
71 virtual void setDockUndockCbk(const dockUndock_t& cb) override
72 {
73 QObject::connect(_ui->pbDockUndock, &QPushButton::toggled, cb);
74 }
75
76 virtual void setMsgViewCbk(const msgView_t& cb) override
77 {
78 QObject::connect(_ui->pbMsg, &QPushButton::toggled, cb);
79 }
80
81 virtual void setMsgSettingsUpdatedCbk(const msgSettingsUpdated_t& cb) override
82 {
83 _msgSettingsUpdatedCbk = cb;
84 }
85
86 virtual QWidget* mainWidget() override
87 {
88 return _widget;
89 }
90
91 virtual void setMsgView(QAbstractItemModel& tvModel) override
92 {
93 if (_settingsState.size() > 0) {
94 _ui->tv->horizontalHeader()->restoreState(_settingsState);
95 }
96
97 _ui->tv->setModel(&tvModel);
98 _ui->tv->horizontalHeader()->setSectionsMovable(true);
99 _ui->tv->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
100 _ui->tv->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
101 _ui->tv->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Stretch);
102 _ui->tv->horizontalHeader()->setSectionResizeMode(5, QHeaderView::Stretch);
103 _ui->tv->setColumnHidden(0, false);
104
105 _settingsState = _ui->tv->horizontalHeader()->saveState();
106
107 _cycleDelegate = new DbFieldDelegate<IntervalLE>(&tvModel, _ui->tv);
108 _ui->tv->setItemDelegateForColumn(4, _cycleDelegate);
109 QObject::connect(_cycleDelegate, &QAbstractItemDelegate::closeEditor,
111
112 _initValDelegate = new DbFieldDelegate<ValueLE>(&tvModel, _ui->tv);
113 _ui->tv->setItemDelegateForColumn(5, _initValDelegate);
114 QObject::connect(_initValDelegate, &QAbstractItemDelegate::closeEditor,
116 }
117
119 {
120 if (_msgSettingsUpdatedCbk) {
121 _msgSettingsUpdatedCbk();
122 }
123 }
124
125 virtual void setSigView(QAbstractItemModel& tvModel) override
126 {
127 if (_tableState.size() > 0) {
128 _ui->tv->horizontalHeader()->restoreState(_tableState);
129 }
130
131 _ui->tv->setModel(&tvModel);
132 _ui->tv->horizontalHeader()->setSectionsMovable(true);
133 _ui->tv->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Interactive);
134 _ui->tv->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
135 _ui->tv->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
136 _ui->tv->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
137 _ui->tv->horizontalHeader()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
138 _ui->tv->horizontalHeader()->setSectionResizeMode(5, QHeaderView::ResizeToContents);
139 _ui->tv->horizontalHeader()->setSectionResizeMode(6, QHeaderView::ResizeToContents);
140
141 _tableState = _ui->tv->horizontalHeader()->saveState();
142 }
143
144 void initSearch(SearchModel& model) override
145 {
146 QObject::connect(_ui->searchLine, &QLineEdit::textChanged, &model, &SearchModel::updateFilter);
147 }
148
149private:
150 Ui::CanSignalDataPrivate* _ui;
151 QWidget* _widget;
152 QByteArray _settingsState;
153 QByteArray _tableState;
154 DbFieldDelegate<IntervalLE>* _cycleDelegate;
155 DbFieldDelegate<ValueLE>* _initValDelegate;
156 msgSettingsUpdated_t _msgSettingsUpdatedCbk{ nullptr };
157};
158
159#endif // CANSIGNALDATAGUIIMPL_H
Definition cansignaldata_p.h:14
Definition cansignaldataguiimpl.h:37
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override
Definition cansignaldataguiimpl.h:45
DbFieldDelegate(QAbstractItemModel *model, QObject *parent=nullptr)
Definition cansignaldataguiimpl.h:39
Definition cansignaldataguiimpl.h:14
IntervalLE(uint32_t, QWidget *parent)
Definition cansignaldataguiimpl.h:16
Definition searchmodel.h:6
void updateFilter(const QString &filter)
Definition searchmodel.cpp:56
Definition cansignaldataguiimpl.h:25
ValueLE(uint32_t len, QWidget *parent)
Definition cansignaldataguiimpl.h:27
Definition canrawsender_p.h:13
Definition cansignaldataguiimpl.h:56
virtual void setDockUndockCbk(const dockUndock_t &cb) override
Definition cansignaldataguiimpl.h:71
CanSignalDataGuiImpl()
Definition cansignaldataguiimpl.h:57
virtual void setMsgViewCbk(const msgView_t &cb) override
Definition cansignaldataguiimpl.h:76
void initSearch(SearchModel &model) override
Definition cansignaldataguiimpl.h:144
virtual void setMsgSettingsUpdatedCbk(const msgSettingsUpdated_t &cb) override
Definition cansignaldataguiimpl.h:81
virtual void setSigView(QAbstractItemModel &tvModel) override
Definition cansignaldataguiimpl.h:125
void msgSettingUpdated()
Definition cansignaldataguiimpl.h:118
virtual void setMsgView(QAbstractItemModel &tvModel) override
Definition cansignaldataguiimpl.h:91
virtual QWidget * mainWidget() override
Definition cansignaldataguiimpl.h:86
Definition cansignaldataguiint.h:11
std::function< void()> msgSettingsUpdated_t
Definition cansignaldataguiint.h:14
std::function< void()> msgView_t
Definition cansignaldataguiint.h:12
std::function< void()> dockUndock_t
Definition cansignaldataguiint.h:13