CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
canrawsender_p.h
Go to the documentation of this file.
1#ifndef CANRAWSENDER_P_H
2#define CANRAWSENDER_P_H
3
4#include "canrawsender.h"
5#include "gui/crsgui.h"
6#include "newlinemanager.h"
7#include <QJsonObject>
8#include <QtGui/QStandardItemModel>
9#include <context.h>
10#include <memory>
11#include <nlmfactory.h>
12
13namespace Ui {
15}
16
19class CanRawSenderPrivate : public QObject {
20 Q_OBJECT
21
22public:
28 : _ctx(std::move(ctx))
29 , _ui(_ctx.get<CRSGuiInterface>())
31 , _simulationState(false)
32 , _columnsOrder({ "Id", "Data", "Remote", "Loop", "Interval", "" })
33 , q_ptr(q)
34 {
35 // NOTE: Implementation must be kept here. Otherwise VS2015 fails to link.
36 initProps();
37
38 _tvModel.setHorizontalHeaderLabels(_columnsOrder);
39
40 _ui.initTableView(_tvModel);
41
42 _ui.setAddCbk(std::bind(&CanRawSenderPrivate::addNewItem, this));
43 _ui.setRemoveCbk(std::bind(&CanRawSenderPrivate::removeRowsSelectedByMouse, this));
44
45 _ui.setDockUndockCbk([this] {
46 docked = !docked;
48 });
49 }
50
52 virtual ~CanRawSenderPrivate() = default;
53
56 void setSimulationState(bool state);
57
60 void saveSettings(QJsonObject& json) const;
61
64 int getLineCount() const;
65
69 bool restoreConfiguration(const QJsonObject& json);
70
74
75private:
78 void writeColumnsOrder(QJsonObject& json) const;
79
82 void writeSortingRules(QJsonObject& json) const;
83
86 bool columnAdopt(QJsonObject const& json);
87
90 bool sortingAdopt(QJsonObject const& json);
91
94 bool contentAdopt(QJsonObject const& json);
95
97 void initProps()
98 {
99 for (const auto& p: _supportedProps)
100 {
102 }
103 }
104
105private slots:
107 void removeRowsSelectedByMouse();
108
110 void addNewItem();
111
112public:
116 bool docked{ true };
117 std::map<QString, QVariant> _props;
118
119private:
120 std::vector<std::unique_ptr<NewLineManager>> _lines;
121 QStandardItemModel _tvModel;
122 bool _simulationState;
123 int _currentIndex;
124 QStringList _columnsOrder;
125 CanRawSender* q_ptr;
126
127 const QString _nameProperty = "name";
128
129 // workaround for clang 3.5
131
132 // clang-format off
134 std::make_tuple(_nameProperty, QVariant::String, true, cf(nullptr))
135 };
136 // clang-format on
137};
138
139#endif // CANRAWSENDER_P_H
Definition canrawsender.h:13
void mainWidgetDockToggled(QWidget *widget) override
This class is responsible for manage can raw sender window.
Definition canrawsender_p.h:19
bool restoreConfiguration(const QJsonObject &json)
Used to restore rawsender configurations.
Definition canrawsender_p.cpp:252
CRSGuiInterface & _ui
Definition canrawsender_p.h:114
int getLineCount() const
This method returns actual number of lines in table.
Definition canrawsender_p.cpp:31
void saveSettings(QJsonObject &json) const
This method writes to json format actual can raw sender window properties.
Definition canrawsender_p.cpp:14
bool docked
Definition canrawsender_p.h:116
NLMFactoryInterface & _nlmFactory
Definition canrawsender_p.h:115
void setSimulationState(bool state)
This method propagates the system simulator state.
Definition canrawsender_p.cpp:6
CanRawSenderCtx _ctx
Definition canrawsender_p.h:113
ComponentInterface::ComponentProperties getSupportedProperties() const
Used to get list of properties supported by component.
Definition canrawsender_p.cpp:65
virtual ~CanRawSenderPrivate()=default
destructor
std::map< QString, QVariant > _props
Definition canrawsender_p.h:117
CanRawSenderPrivate(CanRawSender *q, CanRawSenderCtx &&ctx=CanRawSenderCtx(new CRSGui, new NLMFactory))
constructor
Definition canrawsender_p.h:27
Context< CRSGuiInterface, NLMFactoryInterface > CanRawSenderCtx
Definition context.h:45
Definition canrawsender_p.h:13
Definition crsgui.h:12
Definition crsguiinterface.h:12
virtual QWidget * mainWidget()=0
virtual void initTableView(QAbstractItemModel &_tvModel)=0
virtual void setAddCbk(const add_t &cb)=0
virtual void setRemoveCbk(const remove_t &cb)=0
virtual void setDockUndockCbk(const dockUndock_t &cb)=0
std::vector< ComponentProperty > ComponentProperties
Definition componentinterface.h:66
std::function< QWidget *(void)> CustomEditFieldCbk
Definition componentinterface.h:64
static constexpr const QString & propertyName(const ComponentProperty &p)
Definition componentinterface.h:69
Definition nlmfactory.h:9
Definition nlmfactoryinterface.h:8