Go to the documentation of this file.
19 template <
class _ElementT>
20 struct TreeWidgetBuilder
37 compareFn(compareFn), makeItemFn(makeItemFn), updateItemFn(updateItemFn)
41 compareFn(
MakeCompareNameFn(nameFn, nameColumn)), makeItemFn(makeItemFn), updateItemFn(updateItemFn)
47 this->compareFn = compareFn;
55 this->makeItemFn = makeItemFn;
59 this->updateItemFn = updateItemFn;
64 this->expand = expand;
78 template <
class ParentT,
class IteratorFn>
91 template <
class ParentT,
class ContainerT>
98 (void) element, (
void) item;
123 template <
class KeyT,
class ValueT>
126 using MapT = std::map<KeyT, ValueT>;
131 using NameFn = std::function<std::string(
const KeyT& key,
const ValueT&
value)>;
133 using MakeItemFn = std::function<QTreeWidgetItem*(
const KeyT& key,
const ValueT&
value)>;
134 using UpdateItemFn = std::function<bool(
const KeyT& key,
const ValueT&
value, QTreeWidgetItem* item)>;
161 const auto& [key,
value] = element;
162 return nameFn(key,
value);
175 const auto& [key,
value] = element;
176 return makeItemFn(key,
value);
183 const auto& [key,
value] = element;
184 return updateItemFn(key,
value, item);
194 template <
class ParentT>
205 if constexpr(std::is_same<KeyT, std::string>())
211 std::stringstream ss;
218 static bool NoUpdate(
const KeyT& key,
const ValueT&
value, QTreeWidgetItem* item)
220 (void) key, (
void)
value, (void) item;
241 return tree->topLevelItemCount();
245 return tree->topLevelItem(
index);
249 tree->insertTopLevelItem(
index, item);
253 return tree->takeTopLevelItem(
index);
261 return parent->childCount();
265 return parent->child(
index);
269 return parent->takeChild(
index);
273 parent->insertChild(
index, item);
277 template <
typename T>
293 inline int compare(
const std::string& lhs,
const std::string& rhs)
295 return lhs.compare(rhs);
300 template <
class ElementT>
303 return [nameFn, nameColumn](
const ElementT & element, QTreeWidgetItem * item)
305 return detail::compare(nameFn(element), item->text(nameColumn).toStdString());
310 template <
class ElementT>
311 template <
class ParentT,
class ContainerT>
314 this->updateTreeWithIterator(parent, [&elements](
auto&& elementFn)
316 for (
const auto& element : elements)
318 if (not elementFn(element))
327 template <
class ElementT>
328 template <
class ParentT,
class IteratorFn>
337 int currentIndex = 0;
338 iteratorFn([
this, &parent, ¤tIndex](
const auto & element)
340 bool inserted =
false;
341 QTreeWidgetItem* item =
nullptr;
342 if (currentIndex >= api::getItemCount(parent))
346 item = makeItemFn(element);
347 api::insertItem(parent, api::getItemCount(parent), item);
353 QTreeWidgetItem* currentItem = api::getItem(parent, currentIndex);
354 while (currentItem !=
nullptr && compareFn(element, currentItem) > 0)
356 delete api::takeItem(parent, currentIndex);
357 currentItem = api::getItem(parent, currentIndex);
359 if (currentItem ==
nullptr || compareFn(element, currentItem) < 0)
362 item = makeItemFn(element);
363 api::insertItem(parent, currentIndex, item);
367 else if (currentItem !=
nullptr && compareFn(element, currentItem) == 0)
375 bool cont = updateItemFn(element, item);
376 if (inserted && expand)
378 item->setExpanded(
true);
383 while (api::getItemCount(parent) > currentIndex)
385 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.