DataTreeBuilderBase.cpp
Go to the documentation of this file.
1 #include "DataTreeBuilderBase.h"
2 
3 #include <QTreeWidgetItem>
4 
6 // #include <ArmarXCore/core/logging/Logging.h>
7 
11 
12 
14 {
15 
16  const int keyIndexRole = Qt::UserRole + 10;
17 
18 
20  {
21  }
22 
24  {}
25 
26  void DataTreeBuilderBase::setColumns(int key, int value, int type)
27  {
28  this->columnKey = key;
29  this->columnType = type;
30  this->columnValue = value;
31  }
32 
33 
34  QTreeWidgetItem* DataTreeBuilderBase::makeItem(const std::string& key) const
35  {
36  return new QTreeWidgetItem(QStringList{QString::fromStdString(key)});
37  }
38 
39  QTreeWidgetItem* DataTreeBuilderBase::makeItem(size_t key) const
40  {
41  QTreeWidgetItem* item = new QTreeWidgetItem();
42  item->setData(0, keyIndexRole, static_cast<int>(key));
43  return item;
44  }
45 
46  void DataTreeBuilderBase::setRowTexts(QTreeWidgetItem* item, const std::string& key, const std::string& value, const std::string& typeName) const
47  {
48  item->setText(columnKey, QString::fromStdString(key));
49  item->setText(columnValue, QString::fromStdString(value));
50  item->setText(columnType, QString::fromStdString(typeName));
51  }
52 
53 
55  QTreeWidgetItem* item, const std::string& key, const aron::data::VariantPtr& data)
56  {
57  if (!data)
58  {
59  return;
60  }
62  setRowTexts(item, key, value, sanitizeTypeName(data->getFullName()));
63  }
64 
66  {
67  DictBuilder builder;
68  builder.setCompareFn([](const std::string & key, QTreeWidgetItem * item)
69  {
70  return armarx::detail::compare(key, item->text(0).toStdString());
71  });
72  builder.setMakeItemFn([this](const std::string & key)
73  {
74  return this->makeItem(key);
75  });
76  return builder;
77  }
78 
79 
81  {
82  ListBuilder builder;
83  builder.setCompareFn([](size_t key, QTreeWidgetItem * item)
84  {
85  QVariant itemKey = item->data(0, keyIndexRole);
86  ARMARX_CHECK_EQUAL(itemKey.type(), QVariant::Type::Int);
87  // << VAROUT(key) << " | " << VAROUT(item->text(0).toStdString()) << itemKey.typeName();
88 
89  return armarx::detail::compare(static_cast<int>(key), itemKey.toInt());
90  });
91  builder.setMakeItemFn([this](size_t key)
92  {
93  return this->makeItem(key);
94  });
95  return builder;
96  }
97 
98 
99  std::vector<size_t> DataTreeBuilderBase::getIndex(size_t size) const
100  {
101  std::vector<size_t> index;
102  index.reserve(size);
103  for (size_t i = 0; i < size; ++i)
104  {
105  index.push_back(i);
106  }
107  return index;
108  }
109 
110 }
sanitize_typename.h
armarx::armem::gui::instance::sanitizeTypeName
std::string sanitizeTypeName(const std::string &typeName)
Definition: sanitize_typename.cpp:29
armarx::armem::gui::instance::DataTreeBuilderBase::setRowTexts
void setRowTexts(QTreeWidgetItem *item, const std::string &key, const std::string &value, const std::string &typeName="") const
Definition: DataTreeBuilderBase.cpp:46
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::armem::gui::instance::DataTreeBuilderBase::getListBuilder
ListBuilder getListBuilder() const
Definition: DataTreeBuilderBase.cpp:80
armarx::armem::gui::instance::DataTreeBuilderBase::~DataTreeBuilderBase
virtual ~DataTreeBuilderBase()
Definition: DataTreeBuilderBase.cpp:23
armarx::armem::gui::instance::DataTreeBuilderBase::columnType
int columnType
Definition: DataTreeBuilderBase.h:50
armarx::armem::gui::instance::DataTreeBuilderBase::setColumns
void setColumns(int key, int value, int type)
Definition: DataTreeBuilderBase.cpp:26
TreeWidgetBuilder.h
armarx::armem::gui::instance::keyIndexRole
const int keyIndexRole
Definition: DataTreeBuilderBase.cpp:16
armarx::armem::gui::instance::DataTreeBuilderBase::columnValue
int columnValue
Definition: DataTreeBuilderBase.h:49
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::armem::gui::instance::DataTreeBuilderBase::columnKey
int columnKey
Definition: DataTreeBuilderBase.h:48
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::armem::gui::instance
Definition: AronDataView.cpp:2
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::TreeWidgetBuilder
A class to efficiently build and maintain sorted items of QTreeWidget or QTreeWidgetItem based on a s...
Definition: DataTreeBuilderBase.h:10
armarx::TreeWidgetBuilder::setMakeItemFn
void setMakeItemFn(MakeItemFn makeItemFn)
Definition: TreeWidgetBuilder.h:53
armarx::armem::gui::instance::DataTreeBuilderBase::getDictBuilder
DictBuilder getDictBuilder() const
Definition: DataTreeBuilderBase.cpp:65
armarx::aron::DataDisplayVisitor::getValue
static std::string getValue(const data::VariantPtr &n)
Definition: DataDisplayVisitor.cpp:9
armarx::detail::compare
int compare(const T &lhs, const T &rhs)
Definition: TreeWidgetBuilder.h:278
ExpressionException.h
DataTreeBuilderBase.h
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::armem::gui::instance::DataTreeBuilderBase::DataTreeBuilderBase
DataTreeBuilderBase()
Definition: DataTreeBuilderBase.cpp:19
armarx::armem::gui::instance::DataTreeBuilderBase::makeItem
QTreeWidgetItem * makeItem(const std::string &key) const
Definition: DataTreeBuilderBase.cpp:34
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::TreeWidgetBuilder::setCompareFn
void setCompareFn(CompareFn compareFn)
Definition: TreeWidgetBuilder.h:45
armarx::armem::gui::instance::DataTreeBuilderBase::getIndex
std::vector< size_t > getIndex(size_t size) const
Definition: DataTreeBuilderBase.cpp:99
DataDisplayVisitor.h