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