BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ItemComboToolBar Class Reference

The ItemComboToolBar class is a styled toolbar on top of ItemComboWidget. More...

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

Signals

void comboChanged (const QString &presentation)
 

Public Member Functions

 ItemComboToolBar (QWidget *parent=0)
 
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 *)
 

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
 

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

Constructor & Destructor Documentation

◆ ItemComboToolBar()

ItemComboToolBar::ItemComboToolBar ( QWidget *  parent = 0)
explicit

Definition at line 21 of file ItemComboToolBar.cpp.

22  : StyledToolBar(parent), m_comboBox(new QComboBox), m_comboBoxAction(nullptr)
23 {
24  setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
25 
26  m_comboBox->setToolTip("Select type of graphical presentation.");
27 
28  m_comboBoxAction = addWidget(m_comboBox);
29 
30  setComboConnected(true);
31 }
QComboBox * m_comboBox
void setComboConnected(bool value)
QAction * m_comboBoxAction
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 37 of file StyledToolBar.cpp.

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

Referenced by setActionList().

◆ addStyledExpand()

void StyledToolBar::addStyledExpand ( )
inherited

Definition at line 44 of file StyledToolBar.cpp.

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

Referenced by setActionList().

◆ addStyledSeparator()

void StyledToolBar::addStyledSeparator ( )
inherited

Definition at line 28 of file StyledToolBar.cpp.

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

Referenced by SampleToolBar::SampleToolBar().

◆ comboChanged

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

◆ contextMenuEvent()

void StyledToolBar::contextMenuEvent ( QContextMenuEvent *  )
protectedinherited

Definition at line 51 of file StyledToolBar.cpp.

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

◆ currentPresentation()

QString ItemComboToolBar::currentPresentation ( ) const

Definition at line 59 of file ItemComboToolBar.cpp.

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

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 94 of file ItemComboToolBar.cpp.

95 {
96  const QStandardItemModel* model = dynamic_cast<const QStandardItemModel*>(m_comboBox->model());
97  ASSERT(model);
98 
99  for (int row = 0; row < m_comboBox->count(); ++row) {
100  QString text = m_comboBox->itemText(row);
101  model->item(row)->setEnabled(activePresentations.contains(text));
102  }
103 }
#define ASSERT(condition)
Definition: Assert.h:31

References ASSERT, and 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 66 of file ItemComboToolBar.cpp.

67 {
68  for (auto action : actions())
69  removeAction(action);
70 
71  for (auto action : actionList) {
72  addAction(action);
73  addSpacing();
74  }
76  addAction(m_comboBoxAction);
77 }
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 79 of file ItemComboToolBar.cpp.

80 {
81  if (value)
82  connect(m_comboBox,
83  static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged),
84  this, &ItemComboToolBar::comboChanged, Qt::UniqueConnection);
85  else
86  disconnect(
87  m_comboBox,
88  static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this,
90 }
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 33 of file ItemComboToolBar.cpp.

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

References m_comboBox, 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 40 of file ItemComboToolBar.cpp.

42 {
43  ASSERT(presentationList.size());
44 
45  QString previous = currentPresentation();
46 
47  setComboConnected(false);
48  m_comboBox->clear();
49  m_comboBox->addItems(presentationList);
50  if (activeList.contains(previous))
51  m_comboBox->setCurrentText(previous);
52 
53  if (!activeList.isEmpty())
54  makeItemsEnabled(activeList);
55 
56  setComboConnected(true);
57 }
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 ASSERT, 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: