EditMatrixWidget.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3
4#include <QHBoxLayout>
5#include <QLineEdit>
6#include <QObject>
7#include <QTreeWidgetItem>
8#include <QVBoxLayout>
9
10#include <SimoxUtility/algorithm/string/string_conversion.h>
11
13
14#include "CustomWidget.h"
15
16namespace armarx
17{
18 // Custom Widget used to display Matrices
19 // MAX_ROWS_DISPLAY and MAX_COLS_DISPLAY are the maximal number of elements displayable
20 // everything else will not be displayed. However, there can still be made changes to this data with setText()
22 {
23 Q_OBJECT
24 public:
25 EditMatrixWidget() = delete;
26 EditMatrixWidget(long numRows,
27 long numCols,
28 aron::type::matrix::ElementType elemType,
29 QTreeWidgetItem* currentWidget);
30
31 static EditMatrixWidget* DynamicCast(QWidget*);
32 static EditMatrixWidget* DynamicCastAndCheck(QWidget*);
33
34 // Sets the text on all visible rows and cols.
35 void setText(long row, long col, const std::string& str);
36 std::string getText(long row, long col);
38 bool hasParseErrors();
39 // returns an empty vector if parsing failed. Else, contains the individual bytes.
40 std::vector<unsigned char> parseElement(long row, long col);
41
42
43 private:
44 // Dimensions of the underlying Type to represent
45 long realRows = 1;
46 long realCols = 1;
47
48 // maximum of rows / cols to display
49 static constexpr long MAX_ROWS_DISPLAY = 5;
50 static constexpr long MAX_COLS_DISPLAY = 5;
51 long getDisplayedRows() const;
52 long getDisplayedCols() const;
53
54 // Want to add dots to show the user that not all is displayed. This needs some wrapping layouts
55 QVBoxLayout* outerVerticalLayout;
56 QHBoxLayout* innerHorizontalLayout;
57
58 // Using row major layout
59 std::vector<QLineEdit*> dispElements;
60 // rows<cols<text>>: stores get and set messages for hidden elements (if there is not enough space for all elements)
61 std::vector<std::vector<std::string>> hiddenElems;
62
63 template <typename T>
64 static std::vector<unsigned char> toByteVector(const std::string& str);
65
66 // TODO: It would be nice to have this code somewhere else, this way, at least the GUI-responses
67 // are restricted to this Widget (signal & slot stuff)
68 aron::type::matrix::ElementType elemType;
69
70 private slots:
71 void matrixElementChanged();
72 };
73
74 template <typename T>
75 std::vector<unsigned char>
76 EditMatrixWidget::toByteVector(const std::string& str)
77 {
78 auto val = simox::alg::to_<T>(str);
79 std::vector<unsigned char> res(sizeof(val), 0);
80 *reinterpret_cast<T*>(res.data()) = val;
81 return res;
82 }
83} // namespace armarx
std::string str(const T &t)
CustomWidget(QTreeWidgetItem *overlayingItem)
static EditMatrixWidget * DynamicCast(QWidget *)
std::string getText(long row, long col)
void setText(long row, long col, const std::string &str)
static EditMatrixWidget * DynamicCastAndCheck(QWidget *)
std::vector< unsigned char > parseElement(long row, long col)
This file offers overloads of toIce() and fromIce() functions for STL container types.