gui_utils.cpp
Go to the documentation of this file.
1 #include "gui_utils.h"
2 
3 #include <QLayout>
4 #include <QLayoutItem>
5 #include <QSplitter>
6 #include <QWidget>
7 #include <QTreeWidgetItem>
8 
10 
11 
12 void armarx::gui::clearLayout(QLayout* layout)
13 {
14  // Source: https://stackoverflow.com/a/4857631
15 
16  ARMARX_CHECK(layout);
17 
18  QLayoutItem* item;
19  while ((item = layout->takeAt(0)))
20  {
21  if (item->layout())
22  {
23  clearLayout(item->layout());
24  delete item->layout();
25  }
26  if (item->widget())
27  {
28  delete item->widget();
29  }
30  delete item;
31  }
32 }
33 
34 void armarx::gui::clearItem(QTreeWidgetItem* item)
35 {
36  while (item->childCount() > 0)
37  {
38  delete item->takeChild(0);
39  }
40 }
41 
42 
43 QSplitter* armarx::gui::useSplitter(QLayout* layout)
44 {
45  ARMARX_CHECK(layout);
46 
47  // Check all items
48  for (int i = 0; i < layout->count(); ++i)
49  {
50  ARMARX_CHECK_NOT_NULL(layout->itemAt(i)->widget())
51  << "QSplitter only supports widgets, but layout item #" << i << " is not a widget.";
52  }
53 
54  QSplitter* splitter;
55  if (dynamic_cast<QHBoxLayout*>(layout))
56  {
57  splitter = new QSplitter(Qt::Orientation::Horizontal);
58  }
59  else if (dynamic_cast<QVBoxLayout*>(layout))
60  {
61  splitter = new QSplitter(Qt::Orientation::Vertical);
62  }
63  else
64  {
65  splitter = new QSplitter();
66  }
67 
68  while (layout->count() > 0)
69  {
70  const int index = 0;
71  if (layout->itemAt(index))
72  {
73  QLayoutItem* item = layout->takeAt(index);
74 
75  ARMARX_CHECK(item->widget());
76  splitter->addWidget(item->widget());
77 
78  delete item;
79  }
80  }
81  ARMARX_CHECK_EQUAL(layout->count(), 0);
82 
83  layout->addWidget(splitter);
84  ARMARX_CHECK_EQUAL(layout->count(), 1);
85  ARMARX_CHECK_EQUAL(layout->itemAt(0)->widget(), splitter);
86 
87  return splitter;
88 }
89 
91  numDigits(numDigits), base(base)
92 {
93 }
94 
95 QString
97 {
98  return QString("%1").arg(value, numDigits, base, QChar('0'));
99 }
armarx::splitter
std::vector< std::string > splitter(std::string const &propertyValue)
Definition: ResultImageFuser.h:44
index
uint8_t index
Definition: EtherCATFrame.h:59
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
clearLayout
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Definition: SimoxCSpaceVisualizerWidgetController.cpp:59
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::gui::clearItem
void clearItem(QTreeWidgetItem *item)
Clear a tree widget item.
Definition: gui_utils.cpp:34
armarx::gui::clearLayout
void clearLayout(QLayout *layout)
Clear a layout.
Definition: gui_utils.cpp:12
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::gui::LeadingZeroSpinBox::textFromValue
QString textFromValue(int value) const override
Definition: gui_utils.cpp:96
ExpressionException.h
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::gui::LeadingZeroSpinBox::LeadingZeroSpinBox
LeadingZeroSpinBox(int numDigits, int base)
Definition: gui_utils.cpp:90
armarx::gui::useSplitter
QSplitter * useSplitter(QLayout *layout)
Let items in layout be children of a splitter.
Definition: gui_utils.cpp:43
gui_utils.h