BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemComboToolbar Class Reference

Description

The ItemComboToolbar class is a styled toolbar on top of ItemComboWidget. Contains ComboBox to switch ItemComboWidget, and dynamic list of actions, which are updated according to current state of ItemComboWidget.

Definition at line 28 of file ItemComboToolbar.h.

Inheritance diagram for ItemComboToolbar:
[legend]
Collaboration diagram for ItemComboToolbar:
[legend]

Signals

void comboChanged (const QString &presentation)
 

Public Member Functions

 ItemComboToolbar (QWidget *parent=nullptr)
 
void addSpacing (int width=2)
 Width of the spacing between buttons. More...
 
void addStyledExpand ()
 
void addStyledSeparator ()
 
QString currentPresentation () const
 
void setActionList (const QList< QAction * > &actionList)
 Sets external actions to tool bar (previous actions will be removed). More...
 
void setPresentation (const QString &name)
 
void setPresentationList (const QStringList &presentationList, const QStringList &activeList={})
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *) override
 

Private Member Functions

void makeItemsEnabled (const QStringList &activePresentations)
 All items in QComboBox which are not in given list, will be disabled (gray and unselectable). More...
 
void setComboConnected (bool value)
 

Private Attributes

QComboBox * m_comboBox
 
QAction * m_comboBoxAction
 

Constructor & Destructor Documentation

◆ ItemComboToolbar()

ItemComboToolbar::ItemComboToolbar ( QWidget *  parent = nullptr)
explicit

Definition at line 20 of file ItemComboToolbar.cpp.

21  : StyledToolbar(parent)
22  , m_comboBox(new QComboBox)
23  , m_comboBoxAction(nullptr)
24 {
25  setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
26 
27  m_comboBox->setToolTip("Select type of graphical presentation.");
28 
29  m_comboBoxAction = addWidget(m_comboBox);
30 
31  setComboConnected(true);
32 }
QAction * m_comboBoxAction
QComboBox * m_comboBox
void setComboConnected(bool value)
StyledToolbar(QWidget *parent=nullptr)

References m_comboBox, m_comboBoxAction, and setComboConnected().

Here is the call graph for this function:

Member Function Documentation

◆ addSpacing()

void StyledToolbar::addSpacing ( int  width = 2)
inherited

Width of the spacing between buttons.

Definition at line 38 of file StyledToolbar.cpp.

39 {
40  QString space;
41  space.fill(' ', width);
42  addWidget(new QLabel(space));
43 }

Referenced by setActionList().

◆ addStyledExpand()

void StyledToolbar::addStyledExpand ( )
inherited

Definition at line 45 of file StyledToolbar.cpp.

46 {
47  auto* empty = new QWidget();
48  empty->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
49  addWidget(empty);
50 }

Referenced by setActionList().

◆ addStyledSeparator()

void StyledToolbar::addStyledSeparator ( )
inherited

Definition at line 29 of file StyledToolbar.cpp.

30 {
31  addWidget(new QLabel(" "));
32  addSeparator();
33  addWidget(new QLabel(" "));
34 }

◆ comboChanged

void ItemComboToolbar::comboChanged ( const QString &  presentation)
signal

◆ contextMenuEvent()

void StyledToolbar::contextMenuEvent ( QContextMenuEvent *  )
overrideprotectedinherited

Definition at line 52 of file StyledToolbar.cpp.

53 {
54  // Context menu reimplemented to suppress the default one
55 }

◆ currentPresentation()

QString ItemComboToolbar::currentPresentation ( ) const

Definition at line 58 of file ItemComboToolbar.cpp.

59 {
60  return m_comboBox->currentText();
61 }

References m_comboBox.

Referenced by ItemComboWidget::selectedPresentation(), and setPresentationList().

◆ makeItemsEnabled()

void ItemComboToolbar::makeItemsEnabled ( const QStringList &  activePresentations)
private

All items in QComboBox which are not in given list, will be disabled (gray and unselectable).

Definition at line 93 of file ItemComboToolbar.cpp.

94 {
95  const auto* model = dynamic_cast<const QStandardItemModel*>(m_comboBox->model());
96  ASSERT(model);
97 
98  for (int row = 0; row < m_comboBox->count(); ++row) {
99  QString text = m_comboBox->itemText(row);
100  model->item(row)->setEnabled(activePresentations.contains(text));
101  }
102 }

References m_comboBox.

Referenced by setPresentationList().

◆ setActionList()

void ItemComboToolbar::setActionList ( const QList< QAction * > &  actionList)

Sets external actions to tool bar (previous actions will be removed).

Definition at line 65 of file ItemComboToolbar.cpp.

66 {
67  for (auto* action : actions())
68  removeAction(action);
69 
70  for (auto* action : actionList) {
71  addAction(action);
72  addSpacing();
73  }
75  addAction(m_comboBoxAction);
76 }
void addStyledExpand()
void addSpacing(int width=2)
Width of the spacing between buttons.

References StyledToolbar::addSpacing(), StyledToolbar::addStyledExpand(), and m_comboBoxAction.

Referenced by ItemComboWidget::setPresentation().

Here is the call graph for this function:

◆ setComboConnected()

void ItemComboToolbar::setComboConnected ( bool  value)
private

Definition at line 78 of file ItemComboToolbar.cpp.

79 {
80  if (value)
81  connect(m_comboBox,
82  static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
83  this, &ItemComboToolbar::comboChanged, Qt::UniqueConnection);
84  else
85  disconnect(
86  m_comboBox,
87  static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this,
89 }
void comboChanged(const QString &presentation)

References comboChanged(), and m_comboBox.

Referenced by ItemComboToolbar(), setPresentation(), and setPresentationList().

◆ setPresentation()

void ItemComboToolbar::setPresentation ( const QString &  name)

Definition at line 34 of file ItemComboToolbar.cpp.

35 {
36  setComboConnected(false);
37  m_comboBox->setCurrentText(name);
38  setComboConnected(true);
39 }
QString const & name(EShape k)
Definition: particles.cpp:20

References m_comboBox, GUI::RealSpace::Particles::name(), and setComboConnected().

Referenced by ItemComboWidget::setPresentation().

Here is the call graph for this function:

◆ setPresentationList()

void ItemComboToolbar::setPresentationList ( const QStringList &  presentationList,
const QStringList &  activeList = {} 
)

Definition at line 41 of file ItemComboToolbar.cpp.

43 {
44  QString previous = currentPresentation();
45 
46  setComboConnected(false);
47  m_comboBox->clear();
48  m_comboBox->addItems(presentationList);
49  if (activeList.contains(previous))
50  m_comboBox->setCurrentText(previous);
51 
52  if (!activeList.isEmpty())
53  makeItemsEnabled(activeList);
54 
55  setComboConnected(true);
56 }
QString currentPresentation() const
void makeItemsEnabled(const QStringList &activePresentations)
All items in QComboBox which are not in given list, will be disabled (gray and unselectable).

References currentPresentation(), m_comboBox, makeItemsEnabled(), and setComboConnected().

Referenced by ItemComboWidget::subscribeToItem().

Here is the call graph for this function:

Member Data Documentation

◆ m_comboBox

QComboBox* ItemComboToolbar::m_comboBox
private

◆ m_comboBoxAction

QAction* ItemComboToolbar::m_comboBoxAction
private

Definition at line 51 of file ItemComboToolbar.h.

Referenced by ItemComboToolbar(), and setActionList().


The documentation for this class was generated from the following files: