Go to the documentation of this file.
18 template <
class _ElementT>
19 struct TreeWidgetBuilder
40 compareFn(compareFn), makeItemFn(makeItemFn), updateItemFn(updateItemFn)
49 makeItemFn(makeItemFn),
50 updateItemFn(updateItemFn)
57 this->compareFn = compareFn;
69 this->makeItemFn = makeItemFn;
75 this->updateItemFn = updateItemFn;
81 this->expand = expand;
95 template <
class ParentT,
class IteratorFn>
108 template <
class ParentT,
class ContainerT>
115 (void)element, (
void)item;
136 template <
class KeyT,
class ValueT>
139 using MapT = std::map<KeyT, ValueT>;
144 using NameFn = std::function<std::string(
const KeyT& key,
const ValueT&
value)>;
146 using MakeItemFn = std::function<QTreeWidgetItem*(
const KeyT& key,
const ValueT&
value)>;
148 std::function<bool(
const KeyT& key,
const ValueT&
value, QTreeWidgetItem* item)>;
182 const auto& [key,
value] = element;
183 return nameFn(key,
value);
197 [makeItemFn](
const ElementT& element)
199 const auto& [key,
value] = element;
200 return makeItemFn(key,
value);
208 [updateItemFn](
const ElementT& element, QTreeWidgetItem* item)
210 const auto& [key,
value] = element;
211 return updateItemFn(key,
value, item);
221 template <
class ParentT>
233 if constexpr (std::is_same<KeyT, std::string>())
239 std::stringstream ss;
249 (void)key, (
void)
value, (void)item;
260 template <
class ParentT>
269 return tree->topLevelItemCount();
272 static QTreeWidgetItem*
275 return tree->topLevelItem(
index);
281 tree->insertTopLevelItem(
index, item);
284 static QTreeWidgetItem*
287 return tree->takeTopLevelItem(
index);
297 return parent->childCount();
300 static QTreeWidgetItem*
303 return parent->child(
index);
306 static QTreeWidgetItem*
309 return parent->takeChild(
index);
315 parent->insertChild(
index, item);
319 template <
typename T>
338 compare(
const std::string& lhs,
const std::string& rhs)
340 return lhs.compare(rhs);
344 template <
class ElementT>
348 return [nameFn, nameColumn](
const ElementT& element, QTreeWidgetItem* item)
349 {
return detail::compare(nameFn(element), item->text(nameColumn).toStdString()); };
352 template <
class ElementT>
353 template <
class ParentT,
class ContainerT>
356 const ContainerT& elements)
358 this->updateTreeWithIterator(parent,
359 [&elements](
auto&& elementFn)
361 for (
const auto& element : elements)
363 if (not elementFn(element))
371 template <
class ElementT>
372 template <
class ParentT,
class IteratorFn>
382 int currentIndex = 0;
384 [
this, &parent, ¤tIndex](
const auto& element)
386 bool inserted =
false;
387 QTreeWidgetItem* item =
nullptr;
388 if (currentIndex >= api::getItemCount(parent))
392 item = makeItemFn(element);
393 api::insertItem(parent, api::getItemCount(parent), item);
399 QTreeWidgetItem* currentItem = api::getItem(parent, currentIndex);
400 while (currentItem !=
nullptr && compareFn(element, currentItem) > 0)
402 delete api::takeItem(parent, currentIndex);
403 currentItem = api::getItem(parent, currentIndex);
405 if (currentItem ==
nullptr || compareFn(element, currentItem) < 0)
408 item = makeItemFn(element);
409 api::insertItem(parent, currentIndex, item);
413 else if (currentItem !=
nullptr && compareFn(element, currentItem) == 0)
421 bool cont = updateItemFn(element, item);
422 if (inserted && expand)
424 item->setExpanded(
true);
429 while (api::getItemCount(parent) > currentIndex)
431 delete api::takeItem(parent, api::getItemCount(parent) - 1);
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
std::shared_ptr< Value > value()
int compare(const T &lhs, const T &rhs)
#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...
This file offers overloads of toIce() and fromIce() functions for STL container types.