BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
LayoutUtils Namespace Reference

Utility functions to add/remove widgets to the layout on the fly. More...

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...
 

Detailed Description

Utility functions to add/remove widgets to the layout on the fly.

Taken from https://stackoverflow.com/questions/5395266/removing-widgets-from-qgridlayout

Taken from https://stackoverflow.com/questions/5395266/removing-widgets-from-qgridlayout Caveat: according to explanations given, grid layouts can only grow and never shrink.

Function Documentation

◆ clearGridLayout()

MVVM_VIEW_EXPORT void LayoutUtils::clearGridLayout ( QGridLayout *  layout,
bool  deleteWidgets = true 
)

Clear layout completely.

Definition at line 81 of file LayoutUtils.cpp.

82 {
83  for (int i_row = 0; i_row < layout->rowCount(); ++i_row) {
84  LayoutUtils::removeRow(layout, i_row, deleteWidgets);
85  }
86 }
void removeRow(QGridLayout *layout, int row, bool deleteWidgets=true)
Removes row from grid layout (important: doesn't change row count).
Definition: LayoutUtils.cpp:58

References removeRow().

Referenced by ComponentFlatView::clearLayout(), and ModelView::PropertyFlatView::PropertyFlatViewImpl::update_grid_layout().

Here is the call graph for this function:

◆ clearLayout()

MVVM_VIEW_EXPORT void LayoutUtils::clearLayout ( QLayout *  layout,
bool  deleteWidgets = true 
)

Removes content from box layout.

Definition at line 21 of file LayoutUtils.cpp.

22 {
23  if (!layout)
24  return;
25 
26  while (QLayoutItem* item = layout->takeAt(0)) {
27  if (deleteWidgets) {
28  if (QWidget* widget = item->widget())
29  delete widget;
30  }
31  if (QLayout* childLayout = item->layout())
32  LayoutUtils::clearLayout(childLayout, deleteWidgets);
33  delete item;
34  }
35 }
void clearLayout(QLayout *layout, bool deleteWidgets=true)
Removes content from box layout.
Definition: LayoutUtils.cpp:21

Referenced by WelcomeView::updateRecentProjectPanel().

◆ placeHolder()

MVVM_VIEW_EXPORT QWidget * LayoutUtils::placeHolder ( )

Returns empty widget to occupy place in layout.

Definition at line 131 of file LayoutUtils.cpp.

132 {
133  auto result = new QWidget;
134  result->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
135  return result;
136 }

Referenced by EnvironmentEditor::EnvironmentEditor(), and SpecularBeamEditor::SpecularBeamEditor().

◆ removeColumn()

MVVM_VIEW_EXPORT void LayoutUtils::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 74 of file LayoutUtils.cpp.

75 {
76  remove(layout, -1, column, deleteWidgets);
77  layout->setColumnMinimumWidth(column, 0);
78  layout->setColumnStretch(column, 0);
79 }
MVVM_MODEL_EXPORT bool remove(const std::string &path)
Removes file or empty directory.
Definition: fileutils.cpp:57

References ModelView::Utils::remove().

Here is the call graph for this function:

◆ removeRow()

MVVM_VIEW_EXPORT void LayoutUtils::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 58 of file LayoutUtils.cpp.

59 {
60  remove(layout, row, -1, deleteWidgets);
61  layout->setRowMinimumHeight(row, 0);
62  layout->setRowStretch(row, 0);
63 }

References ModelView::Utils::remove().

Referenced by clearGridLayout().

Here is the call graph for this function: