BornAgain  1.19.79
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/View/Job/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 
16 #include "GUI/Model/Job/JobItem.h"
20 #include <QTabBar>
21 #include <QTabWidget>
22 #include <QTextEdit>
23 #include <QTreeView>
24 #include <QVBoxLayout>
25 
26 namespace {
27 
28 enum ETabId { JOB_PROPERTIES, JOB_MESSAGES };
29 }
30 
31 //==================================================================================================
32 // JobPropertiesWidget
33 //==================================================================================================
34 
35 //--------------------------------------------------------------------------------------------------
36 // public member functions
37 //--------------------------------------------------------------------------------------------------
38 
39 JobPropertiesWidget::JobPropertiesWidget(QWidget* parent, Qt::WindowFlags f)
40  : QWidget(parent, f)
41  , m_item(nullptr)
42 {
43  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
45 
46  auto* layout = new QVBoxLayout(this);
47  layout->setMargin(0);
48  layout->setSpacing(0);
49  layout->setContentsMargins(0, 0, 0, 0);
50 
51  m_tabWidget = new QTabWidget(this);
52  m_tabWidget->setTabPosition(QTabWidget::South);
53  layout->addWidget(m_tabWidget);
54 
55  m_propertiesView = new QTreeView(this);
56  m_propertiesView->setRootIsDecorated(false);
57  m_propertiesView->setAlternatingRowColors(true);
58  m_tabWidget->insertTab(JOB_PROPERTIES, m_propertiesView, "Job Properties");
61 
62  m_commentsEditor = new QTextEdit(this);
63  m_tabWidget->insertTab(JOB_MESSAGES, m_commentsEditor, "Messages");
64 
65  connect(m_commentsEditor, &QTextEdit::textChanged, this,
67 }
68 
70 {
71  if (m_item)
72  disconnect(m_item, nullptr, this, nullptr);
73 }
74 
76 {
78 }
79 
81 {
83 }
84 
86 {
87  if (m_item)
88  disconnect(m_item, nullptr, this, nullptr);
89  m_item = item;
91  if (m_item) {
92  if (m_item->isFailed())
93  m_tabWidget->tabBar()->setTabTextColor(JOB_MESSAGES, Qt::red);
94  else
95  m_tabWidget->tabBar()->setTabTextColor(JOB_MESSAGES, Qt::black);
96  m_commentsEditor->setText(m_item->getComments());
97 
99  } else
100  m_commentsEditor->clear();
101 }
102 
103 //--------------------------------------------------------------------------------------------------
104 // private member functions
105 //--------------------------------------------------------------------------------------------------
106 
108 {
109  connect(m_item, &JobItem::jobCommentsChanged, this, [=](const QString&) {
110  if (m_item && m_item->getComments() != m_commentsEditor->toPlainText()) {
111  m_commentsEditor->blockSignals(true);
112  m_commentsEditor->setPlainText(m_item->getComments());
113  m_commentsEditor->blockSignals(false);
114  }
115  });
116 }
117 
118 //--------------------------------------------------------------------------------------------------
119 // private slots
120 //--------------------------------------------------------------------------------------------------
121 
123 {
124  if (m_item) {
125  m_item->blockSignals(true);
126  m_item->setComments(m_commentsEditor->toPlainText());
127  m_item->blockSignals(false);
128  }
129 }
Defines class JobItem.
Defines class JobPropertiesWidget.
Defines class JobPropertiesWidget.
Defines GUI::StyleUtils namespace.
void setComments(const QString &comments)
Definition: JobItem.cpp:195
QString getComments() const
Definition: JobItem.cpp:190
void jobCommentsChanged(const QString &comments)
bool isFailed() const
Definition: JobItem.cpp:144
The JobPropertiesTableModel is a table model for the properties of a job except for the comment....
QSize sizeHint() const override
JobPropertiesWidget(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
QSize minimumSizeHint() const override
JobPropertiesTableModel * m_propertiesModel
void setItem(JobItem *item)
Defines namespace GUI::Constants.
const QString JobPropertiesWidgetName
int PropertyPanelWidth()
Returns typical width of the vertical property panel.
Definition: StyleUtils.cpp:124