BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
JobPropertiesWidget.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/JobWidgets/JobPropertiesWidget.cpp
6 //! @brief Implements class JobPropertiesWidget
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QTabBar>
21 #include <QTabWidget>
22 #include <QTextEdit>
23 #include <QVBoxLayout>
24 
26  : SessionItemWidget(parent)
27  , m_tabWidget(new QTabWidget)
28  , m_componentEditor(new ComponentEditor)
29  , m_commentsEditor(new QTextEdit)
30  , m_block_update(false)
31 {
32  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
33  setWindowTitle(Constants::JobPropertiesWidgetName);
34 
35  auto mainLayout = new QVBoxLayout;
36  mainLayout->setMargin(0);
37  mainLayout->setSpacing(0);
38  mainLayout->setContentsMargins(0, 0, 0, 0);
39 
40  m_tabWidget->setTabPosition(QTabWidget::South);
41  m_tabWidget->insertTab(JOB_PROPERTIES, m_componentEditor, "Job Properties");
42  m_tabWidget->insertTab(JOB_COMMENTS, m_commentsEditor, "Details");
43 
44  mainLayout->addWidget(m_tabWidget);
45  setLayout(mainLayout);
46 
47  connect(m_commentsEditor, &QTextEdit::textChanged, this, &JobPropertiesWidget::onTextChanged);
48 }
49 
51 {
53 }
54 
56 {
58 }
59 
61 {
63  [this](const QString& name) {
65  updateItem();
66  },
67  this);
68 
70 
71  updateItem();
72 }
73 
75 {
76  m_componentEditor->setItem(nullptr);
77 }
78 
79 void JobPropertiesWidget::contextMenuEvent(QContextMenuEvent*)
80 {
81  // Reimplemented to suppress menu from main window
82 }
83 
85 {
86  m_block_update = true;
87  jobItem()->setComments(m_commentsEditor->toPlainText());
88  m_block_update = false;
89 }
90 
92 {
93  if (m_block_update)
94  return;
95 
96  if (JobItem* item = jobItem()) {
97  if (item->getStatus() == "Failed")
98  m_tabWidget->tabBar()->setTabTextColor(JOB_COMMENTS, Qt::red);
99  else
100  m_tabWidget->tabBar()->setTabTextColor(JOB_COMMENTS, Qt::black);
101 
102  m_commentsEditor->setText(item->getComments());
103  }
104 }
105 
107 {
108  return dynamic_cast<JobItem*>(currentItem());
109 }
Defines ComponentEditor class.
Defines class JobItem.
Defines class JobPropertiesWidget.
DefinesStyleUtils namespace.
Component editor for SessionItem.
void setItem(SessionItem *item)
void setComments(const QString &comments)
Definition: JobItem.cpp:194
static const QString P_COMMENTS
Definition: JobItem.h:44
JobPropertiesWidget(QWidget *parent=nullptr)
ComponentEditor * m_componentEditor
void contextMenuEvent(QContextMenuEvent *)
void setOnPropertyChange(std::function< void(QString)> f, const void *caller=0)
Definition: ModelMapper.cpp:35
The SessionItemWidget class is a base for all widgets representing the content of SessionItem.
SessionItem * currentItem()
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
Defines namespace Constants.
const QString JobPropertiesWidgetName
QString const & name(EShape k)
Definition: particles.cpp:21
int PropertyPanelWidth()
Returns typical width of the vertical property panel.
Definition: StyleUtils.cpp:121