BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectLoadWarningDialog.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/InfoWidgets/ProjectLoadWarningDialog.cpp
6 //! @brief Implements class ProjectLoadWarningDialog
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 <QBoxLayout>
21 #include <QGridLayout>
22 #include <QHeaderView>
23 #include <QLabel>
24 #include <QPushButton>
25 #include <QTableWidget>
26 #include <QTableWidgetItem>
27 
28 namespace {
29 const int top_panel_height = 80;
30 }
31 
33  const MessageService* messageService,
34  const QString& documentVersion)
35  : QDialog(parent), m_messageService(messageService), m_projectDocumentVersion(documentVersion)
36 {
37  setMinimumSize(256, 256);
38  resize(520, 620);
39  setWindowTitle("Problems encountered while loading project");
40  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
41 
42  auto mainLayout = new QVBoxLayout;
43  mainLayout->addWidget(createTopPanel());
44  mainLayout->addWidget(createModelInfoPanel());
45  mainLayout->addWidget(createExplanationPanel());
46  mainLayout->addWidget(createDetailsPanel());
47  mainLayout->addLayout(buttonLayout());
48 
49  setLayout(mainLayout);
50  setAttribute(Qt::WA_DeleteOnClose, true);
51 }
52 
53 //! Top panel with warning icon and the header
55 {
56  auto result = new QWidget(this);
57  auto layout = new QHBoxLayout;
58 
59  auto warningLabel = new QLabel;
60  warningLabel->setPixmap(QPixmap(":/images/warning_64x64.png"));
61 
62  auto warningWidget = new QWidget;
63  warningWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
64  warningWidget->resize(top_panel_height, top_panel_height);
65  auto warningWidgetLayout = new QHBoxLayout;
66  warningWidgetLayout->addWidget(warningLabel);
67  warningWidget->setLayout(warningWidgetLayout);
68 
69  QFont titleFont;
70  titleFont.setPointSize(DesignerHelper::getSectionFontSize());
71  titleFont.setBold(true);
72 
73  auto messageLabel = new QLabel();
74  messageLabel->setFont(titleFont);
75  messageLabel->setText("Some parts of the project were not loaded correctly.");
76  messageLabel->setWordWrap(true);
77 
78  layout->addWidget(warningWidget);
79  layout->addWidget(messageLabel);
80  layout->setContentsMargins(0, 0, 0, 0);
81  result->setLayout(layout);
82 
83  return result;
84 }
85 
86 //! Info panel with summary over warnings in different models
88 {
89  auto result = new QWidget(this);
90  auto layout = new QHBoxLayout;
91 
92  auto line = new QFrame();
93  line->setFrameShape(QFrame::VLine);
94  line->setFrameShadow(QFrame::Sunken);
95 
96  auto gridLayout = new QGridLayout;
97 
98  QStringList names = m_messageService->senderList();
99  for (int irow = 0; irow < names.size(); ++irow) {
100  gridLayout->addWidget(new QLabel(names.at(irow)), irow, 0);
101  gridLayout->addWidget(new QLabel("WARNINGS"), irow, 1);
102  }
103 
104  layout->addWidget(line);
105  layout->addLayout(gridLayout);
106  layout->addWidget(new QWidget);
107 
108  layout->setContentsMargins(0, 0, 0, 0);
109 
110  result->setLayout(layout);
111  return result;
112 }
113 
114 //! Info panel with explanations what had happened and what to do
116 {
117  auto result = new QWidget(this);
118  auto layout = new QVBoxLayout;
119 
120  QFont titleFont;
121  titleFont.setPointSize(DesignerHelper::getSectionFontSize());
122  titleFont.setBold(true);
123 
124  auto whyLabel = new QLabel;
125  whyLabel->setFont(titleFont);
126  whyLabel->setText("Why did this happen to me?");
127 
128  auto explanationLabel = new QLabel;
129  explanationLabel->setText(explanationText());
130  explanationLabel->setWordWrap(true);
131 
132  auto whatLabel = new QLabel;
133  whatLabel->setFont(titleFont);
134  whatLabel->setText("What to do?");
135 
136  auto adviceLabel = new QLabel;
137  QString adviceText("Check parameters of your items and re-enter uninitialized values. "
138  "Use detailed log below to get a hint what went wrong. "
139  "After that, save you project and work as normal.");
140  adviceLabel->setText(adviceText);
141  adviceLabel->setWordWrap(true);
142 
143  layout->addWidget(whyLabel);
144  layout->addWidget(explanationLabel);
145  layout->addWidget(whatLabel);
146  layout->addWidget(adviceLabel);
147 
148  layout->setContentsMargins(0, 0, 0, 0);
149 
150  result->setLayout(layout);
151  return result;
152 }
153 
154 //! Info panel with table widget containing error messages
156 {
157  auto result = new QWidget(this);
158  auto layout = new QVBoxLayout;
159 
160  QFont titleFont;
161  titleFont.setPointSize(DesignerHelper::getSectionFontSize());
162  titleFont.setBold(true);
163 
164  auto detailsLabel = new QLabel;
165  detailsLabel->setFont(titleFont);
166  detailsLabel->setText("Details");
167 
168  layout->addWidget(detailsLabel);
169  layout->addWidget(createTableWidget());
170 
171  layout->setContentsMargins(0, 0, 0, 0);
172 
173  result->setLayout(layout);
174  return result;
175 }
176 
177 //! Creates QTableWidget and fills it with error messages
179 {
180  auto result = new QTableWidget;
181  result->setWordWrap(true);
182  // result->setTextElideMode(Qt::ElideMiddle);
183 
184  result->setStyleSheet(
185  "QToolTip { color: #ffffff; background-color: #fcfcfc; border: 1px solid black; }");
186 
187  result->setRowCount(numberOfTableRows());
188  result->setColumnCount(tableHeaderLabels().size());
189  result->setHorizontalHeaderLabels(tableHeaderLabels());
190  result->verticalHeader()->setVisible(false);
191  result->horizontalHeader()->setStretchLastSection(true);
192 
193  int rowCount(0);
194  for (auto message : m_messageService->messages()) {
195  result->setItem(rowCount, 0, createTableItem(message->senderName()));
196  result->setItem(rowCount, 1, createTableItem(message->messageType()));
197  result->setItem(rowCount, 2, createTableItem(message->messageDescription()));
198  ++rowCount;
199  }
200 
201  result->resizeRowsToContents();
202 
203  return result;
204 }
205 
207 {
208  auto result = new QHBoxLayout;
209 
210  auto button = new QPushButton("Close", this);
211  button->setAutoDefault(false);
212  connect(button, &QPushButton::clicked, this, &ProjectLoadWarningDialog::close);
213 
214  result->addStretch(3);
215  result->setContentsMargins(0, 0, 0, 0);
216  result->addWidget(button);
217 
218  return result;
219 }
220 
221 //! Returns number of rows in table with error messages, each row represents an error message
223 {
224  return m_messageService->messages().size();
225 }
226 
227 //! Returns labels for table header
229 {
230  return QStringList() << "Sender"
231  << "Message"
232  << "Description";
233 }
234 
235 QTableWidgetItem* ProjectLoadWarningDialog::createTableItem(const QString& name)
236 {
237  auto result = new QTableWidgetItem(name);
238  result->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
239 
240  // trick to turn tooltip text to rich text and so have multi-line appearance
241  QString toolTip = QString("<font color=black>%1</font>").arg(name);
242  result->setToolTip(toolTip);
243 
244  return result;
245 }
246 
247 //! Returns explanations what went wrong.
249 {
250  QString result;
252  result =
253  QString("Given project was created using BornAgain version %1 "
254  " which is different from version %2 you are currently using. "
255  "At the moment we provide only limited support for import from older versions.")
258  } else {
259  result =
260  QString("Given project was created using BornAgain version %1 "
261  "which is the same as the current version of the framework. "
262  "Strangely enough, some parts was not loaded correctly due to format mismatch. "
263  "Please contact developpers.")
265  }
266  return result;
267 }
Defines class DesignerHelper.
Defines class GUIHelpers functions.
Defines class GUIMessage.
Defines MessageService class.
Defines class ProjectLoadWarningDialog.
static int getSectionFontSize()
The service to collect messages from different senders.
const QList< GUIMessage * > messages() const
QStringList senderList() const
QWidget * createModelInfoPanel()
Info panel with summary over warnings in different models.
QStringList tableHeaderLabels() const
Returns labels for table header.
QWidget * createExplanationPanel()
Info panel with explanations what had happened and what to do.
QTableWidgetItem * createTableItem(const QString &name)
const MessageService * m_messageService
ProjectLoadWarningDialog(QWidget *parent, const MessageService *messageService=0, const QString &documentVersion="")
int numberOfTableRows() const
Returns number of rows in table with error messages, each row represents an error message.
QString explanationText() const
Returns explanations what went wrong.
QWidget * createDetailsPanel()
Info panel with table widget containing error messages.
QWidget * createTopPanel()
Top panel with warning icon and the header.
QTableWidget * createTableWidget()
Creates QTableWidget and fills it with error messages.
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130
QString const & name(EShape k)
Definition: particles.cpp:21