5#include <QtCore/QElapsedTimer>
6#include <QtCore/QJsonArray>
7#include <QtCore/QJsonObject>
8#include <QtGui/QStandardItemModel>
9#include <QtSerialBus/QCanBusFrame>
16const int32_t rowCountMax = 2000;
17const QString remoteFrameData =
"R";
26 :
_ctx(std::move(ctx))
29 , _columnsOrder({
"rowID",
"time",
"id",
"dir",
"len",
"data" })
34 _tvModel.setHorizontalHeaderLabels(_columnsOrder);
44 _ui.
setFilterCbk(std::bind(&CanRawViewPrivate::setFilter,
this, std::placeholders::_1));
73 QJsonArray viewModelsArray;
75 writeColumnsOrder(json);
79 void frameView(
const QCanBusFrame& frame,
const QString& direction)
82 cds_debug(
"send/received frame while simulation stopped");
86 auto payHex = frame.payload().toHex();
88 for (
int ii = payHex.size() - 2; ii >= 2; ii -= 2) {
89 payHex.insert(ii,
' ');
93 if (frame.hasExtendedFrameFormat()) {
97 QString frameID = QString(
"0x" + QString::number(frame.frameId(), 16).rightJustified(idPadding,
'0'));
98 QString time = QString::number((
_timer.elapsed() / 1000.0),
'f', 2);
100 if (QCanBusFrame::RemoteRequestFrame == frame.frameType()) {
102 data = remoteFrameData;
104 size = QString::number(frame.payload().size());
105 data = QString::fromUtf8(payHex.data(), payHex.size());
108 QList<QStandardItem*> list;
110 if (
_tvModel.rowCount() < rowCountMax) {
111 list.append(
new QStandardItem(QString::number(_rowID)));
112 list.append(
new QStandardItem(time));
113 list.append(
new QStandardItem(frameID));
114 list.append(
new QStandardItem(direction));
115 list.append(
new QStandardItem(size));
116 list.append(
new QStandardItem(data));
119 auto it = list.begin();
121 (*it++)->setText(QString::number(_rowID));
122 (*it++)->setText(time);
123 (*it++)->setText(frameID);
124 (*it++)->setText(direction);
125 (*it++)->setText(size);
126 (*it++)->setText(data);
131 quint32 fId = frame.frameId();
132 if (frame.hasExtendedFrameFormat()) {
138 if (direction ==
"RX") {
139 if (_uniqueRxMap.count(fId)) {
140 auto& row = _uniqueRxMap[fId];
142 std::get<0>(row)->setText(QString::number(_rowID));
143 std::get<1>(row)->setText(time);
144 std::get<2>(row)->setText(frameID);
145 std::get<3>(row)->setText(direction);
146 std::get<4>(row)->setText(size);
147 std::get<5>(row)->setText(data);
149 auto rowEl =
new QStandardItem(QString::number(_rowID));
150 auto timeEl =
new QStandardItem(time);
151 auto frameEl =
new QStandardItem(frameID);
152 auto dirEl =
new QStandardItem(direction);
153 auto sizeEl =
new QStandardItem(size);
154 auto dataEl =
new QStandardItem(data);
156 _tvModelUnique.appendRow({ rowEl, timeEl, frameEl, dirEl, sizeEl, dataEl });
157 _uniqueRxMap[fId] = std::make_tuple(rowEl, timeEl, frameEl, dirEl, sizeEl, dataEl);
159 }
else if (direction ==
"TX") {
160 if (_uniqueTxMap.count(fId)) {
161 auto& row = _uniqueTxMap[fId];
163 std::get<0>(row)->setText(QString::number(_rowID));
164 std::get<1>(row)->setText(time);
165 std::get<2>(row)->setText(frameID);
166 std::get<3>(row)->setText(direction);
167 std::get<4>(row)->setText(size);
168 std::get<5>(row)->setText(data);
170 auto rowEl =
new QStandardItem(QString::number(_rowID));
171 auto timeEl =
new QStandardItem(time);
172 auto frameEl =
new QStandardItem(frameID);
173 auto dirEl =
new QStandardItem(direction);
174 auto sizeEl =
new QStandardItem(size);
175 auto dataEl =
new QStandardItem(data);
177 _tvModelUnique.appendRow({ rowEl, timeEl, frameEl, dirEl, sizeEl, dataEl });
178 _uniqueTxMap[fId] = std::make_tuple(rowEl, timeEl, frameEl, dirEl, sizeEl, dataEl);
181 cds_warn(
"Invalid direction string: {}", direction.toStdString());
193 if (columnAdopt(json) ==
false) {
196 if (scrollingAdopt(json) ==
false) {
206 return _supportedProps;
210 void writeColumnsOrder(QJsonObject& json)
const
213 QJsonArray columnArray;
214 for (
const auto& column : _columnsOrder) {
216 QJsonObject columnProper;
219 columnProper[
"name"] = column;
220 columnProper[
"vIdx"] = vIdx;
221 columnArray.append(columnProper);
225 json[
"viewColumns"] = std::move(columnArray);
245 bool scrollingAdopt(QJsonObject
const& json)
247 auto scrolling = json.find(
"scrolling");
248 if (scrolling == json.end()) {
253 if (scrolling.value().type() != QJsonValue::Bool) {
254 cds_error(
"Scrolling format is different than bool");
257 auto frozen = json[
"scrolling"].toBool();
262 cds_info(
"Scrolling was restored correctly");
266 bool columnAdopt(QJsonObject
const& json)
268 auto columnIter = json.find(
"viewColumns");
269 if (columnIter == json.end()) {
274 if (columnIter.value().type() != QJsonValue::Array) {
275 cds_error(
"Columns format is different than array");
279 auto colArray = json[
"viewColumns"].toArray();
280 if (colArray.size() != 5) {
281 cds_error(
"Columns array size must be 5 not {}", std::to_string(colArray.size()));
289 bool operator<(
const ref& rhs)
const
291 return vIdxConf < rhs.vIdxConf;
294 std::vector<ref> refContener;
297 for (
const auto& column : _columnsOrder) {
300 for (; jj < colArray.size(); ++jj) {
303 if (colArray[jj].isObject() ==
false) {
304 cds_error(
"Columns description is not an object.");
307 auto colObj = colArray[jj].toObject();
308 if (colObj.contains(
"name") ==
false) {
309 cds_error(
"Columns description does not contain name field.");
312 if (colObj[
"name"].isString() ==
false) {
313 cds_error(
"name is not a String format.");
317 if (colObj[
"name"].toString() != column) {
324 if (colObj.contains(
"vIdx") ==
false) {
325 cds_error(
"Columns description does not contain vIdx field.");
328 if (colObj[
"vIdx"].isDouble() ==
false) {
329 cds_error(
"vIdx is not a Number format.");
332 auto vIdxConf = colObj[
"vIdx"].toInt();
334 refContener.push_back({ ii, vIdxConf });
337 if (jj == colArray.size()) {
338 cds_error(
"Required parameter in column description was not found.");
344 std::sort(refContener.rbegin(), refContener.rend());
345 for (
const auto& pp : refContener) {
348 if (vIdx != pp.vIdxConf) {
352 cds_info(
"Column properties were restored correctly");
359 for (
const auto& p : _supportedProps) {
374 _uniqueRxMap.clear();
375 _uniqueTxMap.clear();
383 void sort(
const int clickedIndex)
386 _sortIndex = clickedIndex;
388 if (_prevIndex == clickedIndex) {
389 if (_currentSortOrder == Qt::DescendingOrder) {
398 _prevIndex = clickedIndex;
405 void setFilter(
bool enabled)
436 Qt::SortOrder _currentSortOrder{ Qt::AscendingOrder };
437 QStringList _columnsOrder;
440 std::tuple<QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*>>
443 std::tuple<QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*, QStandardItem*>>
446 const QString _nameProperty =
"name";
453 std::make_tuple(_nameProperty, QVariant::String,
true, cf(
nullptr))
Definition canrawview.h:14
void mainWidgetDockToggled(QWidget *widget) override
Definition canrawview_p.h:20
std::map< QString, QVariant > _props
Definition canrawview_p.h:428
bool _simStarted
Definition canrawview_p.h:425
void frameView(const QCanBusFrame &frame, const QString &direction)
Definition canrawview_p.h:79
void saveSettings(QJsonObject &json)
Definition canrawview_p.h:71
CanRawViewCtx _ctx
Definition canrawview_p.h:421
~CanRawViewPrivate()
Definition canrawview_p.h:69
QElapsedTimer _timer
Definition canrawview_p.h:422
SortModel _tvModelSort
Definition canrawview_p.h:429
QStandardItemModel _tvModel
Definition canrawview_p.h:423
CanRawViewPrivate(CanRawView *q, CanRawViewCtx &&ctx=CanRawViewCtx(new CRVGui))
Definition canrawview_p.h:25
ComponentInterface::ComponentProperties getSupportedProperties() const
Used to get list of properties supported by component.
Definition canrawview_p.h:204
SortModel _tvModelUniqueSort
Definition canrawview_p.h:430
QStandardItemModel _tvModelUnique
Definition canrawview_p.h:424
bool restoreConfiguration(const QJsonObject &json)
Definition canrawview_p.h:191
CRVGuiInterface & _ui
Definition canrawview_p.h:426
bool docked
Definition canrawview_p.h:427
void setFilterActive(bool enabled)
Definition sortmodel.cpp:50
Context< CRVGuiInterface > CanRawViewCtx
Definition context.h:48
#define cds_debug(fmt,...)
Definition log.h:13
#define cds_warn(fmt,...)
Definition log.h:17
#define cds_error(fmt,...)
Definition log.h:21
#define cds_info(fmt,...)
Definition log.h:25
Definition crvguiinterface.h:10
virtual void setViewFrozen(bool state)=0
virtual QWidget * mainWidget()=0
virtual void scrollToBottom()=0
virtual void setDockUndockCbk(const dockUndock_t &cb)=0
virtual void setModel(QAbstractItemModel *model)=0
virtual bool isViewFrozen()=0
virtual void getColumnProper(int ndx, int &vIdx)=0
virtual void setClearCbk(const clear_t &cb)=0
virtual void setSectionClikedCbk(const sectionClicked_t &cb)=0
virtual bool isColumnHidden(int ndx)=0
virtual void initTableView(QAbstractItemModel &tvModel)=0
virtual void setSorting(int sortNdx, Qt::SortOrder order)=0
virtual Qt::SortOrder getSortOrder()=0
virtual void setFilterCbk(const filter_t &cb)=0
virtual void setColumnProper(int vIdxFrom, int vIdxTo)=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