BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
GUI::Util::Layout Namespace Reference

Description

Utility functions to add/remove widgets to the layout on the fly. Taken from https://stackoverflow.com/questions/5395266/removing-widgets-from-qgridlayout.

Functions

void clearGridLayout (QGridLayout *layout, bool deleteWidgets=true)
 Clear layout completely. More...
 
void clearLayout (QLayout *layout, bool deleteWidgets=true)
 Removes content from box layout. More...
 
QWidget * placeHolder ()
 Returns empty widget to occupy place in layout. More...
 
void removeColumn (QGridLayout *layout, int column, bool deleteWidgets=true)
 Removes column from grid layout. More...
 
void removeRow (QGridLayout *layout, int row, bool deleteWidgets=true)
 Removes row from grid layout (important: doesn't change row count). More...
 

Function Documentation

◆ clearGridLayout()

void GUI::Util::Layout::clearGridLayout ( QGridLayout *  layout,
bool  deleteWidgets = true 
)

Clear layout completely.

Definition at line 115 of file LayoutUtils.cpp.

116 {
117  for (int i_row = 0; i_row < layout->rowCount(); ++i_row)
118  GUI::Util::Layout::removeRow(layout, i_row, deleteWidgets);
119 }
void removeRow(QGridLayout *layout, int row, bool deleteWidgets=true)
Removes row from grid layout (important: doesn't change row count).
Definition: LayoutUtils.cpp:92

References removeRow().

Here is the call graph for this function:

◆ clearLayout()

void GUI::Util::Layout::clearLayout ( QLayout *  layout,
bool  deleteWidgets = true 
)

Removes content from box layout.

Definition at line 68 of file LayoutUtils.cpp.

69 {
70  if (!layout)
71  return;
72 
73  while (layout->count() > 0) {
74  QLayoutItem* item = layout->takeAt(0);
75  if (deleteWidgets)
76  delete item->widget();
77  if (QLayout* childLayout = item->layout())
78  GUI::Util::Layout::clearLayout(childLayout, deleteWidgets);
79  delete item;
80  }
81 }
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:68

Referenced by AbstractSelectionContainerForm::clear(), MinimizerSettingsWidget::createMimimizerEdits(), MultiLayerForm::onAboutToRemoveLayer(), MaterialInplaceForm::selectMaterial(), SpecularDataPropertyWidget::setCurrentItem(), MaskEditorPropertyPanel::setCurrentMaskItem(), IntensityDataPropertyWidget::setItem(), MinimizerSettingsWidget::setItem(), and WelcomeView::updateRecentProjectPanel().

◆ placeHolder()

QWidget * GUI::Util::Layout::placeHolder ( )

Returns empty widget to occupy place in layout.

Definition at line 121 of file LayoutUtils.cpp.

122 {
123  auto* result = new QWidget;
124  result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
125  return result;
126 }

◆ removeColumn()

void GUI::Util::Layout::removeColumn ( QGridLayout *  layout,
int  column,
bool  deleteWidgets = true 
)

Removes column from grid layout.

Removes all layout items on the given column from the given grid layout. If deleteWidgets is true, all concerned child widgets become not only removed from the layout, but also deleted. Note that this function doesn't actually remove the column itself from the grid layout, as this isn't possible (i.e. the columnCount() and column indices will stay the same after this function has been called).

Definition at line 108 of file LayoutUtils.cpp.

109 {
110  remove(layout, -1, column, deleteWidgets);
111  layout->setColumnMinimumWidth(column, 0);
112  layout->setColumnStretch(column, 0);
113 }

◆ removeRow()

void GUI::Util::Layout::removeRow ( QGridLayout *  layout,
int  row,
bool  deleteWidgets = true 
)

Removes row from grid layout (important: doesn't change row count).

Removes all layout items on the given row from the given grid layout. If deleteWidgets is true, all concerned child widgets become not only removed from the layout, but also deleted. Note that this function doesn't actually remove the row itself from the grid layout, as this isn't possible (i.e. the rowCount() and row indices will stay the same after this function has been called).

Definition at line 92 of file LayoutUtils.cpp.

93 {
94  remove(layout, row, -1, deleteWidgets);
95  layout->setRowMinimumHeight(row, 0);
96  layout->setRowStretch(row, 0);
97 }

Referenced by clearGridLayout().