BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ProjectLoadProblemDialog.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Info/ProjectLoadProblemDialog.cpp
6 //! @brief Implements class ProjectLoadProblemDialog
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/Util/Path.h"
18 #include <QBoxLayout>
19 #include <QGridLayout>
20 #include <QLabel>
21 #include <QListWidget>
22 #include <QPushButton>
23 #include <utility>
24 
25 namespace {
26 
27 const int top_panel_height = 80;
28 }
29 
30 ProjectLoadProblemDialog::ProjectLoadProblemDialog(QWidget* parent, const QStringList& details,
31  QString documentVersion)
32  : QDialog(parent)
33  , m_projectDocumentVersion(std::move(documentVersion))
34 {
35  setMinimumSize(256, 256);
36  resize(520, 620);
37  setWindowTitle("Problems encountered while loading project");
38  setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
39 
40  auto* mainLayout = new QVBoxLayout;
41 
42  QFont titleFont;
43  titleFont.setPointSize(DesignerHelper::getSectionFontSize());
44  titleFont.setBold(true);
45 
46  const auto addHeadline = [&](const QString& text) {
47  auto* label = new QLabel(text, this);
48  label->setFont(titleFont);
49  mainLayout->addWidget(label);
50  };
51 
52  // -- warning icon + info
53  auto* topPanelLayout = new QHBoxLayout;
54  auto* messageLabel = new QLabel("Some parts of the project were not loaded correctly.");
55  messageLabel->setFont(titleFont);
56  messageLabel->setWordWrap(true);
57 
58  topPanelLayout->addWidget(createWarningWidget());
59  topPanelLayout->addWidget(messageLabel);
60  topPanelLayout->setContentsMargins(0, 0, 0, 0);
61  mainLayout->addLayout(topPanelLayout);
62 
63  // -- explanations
64  addHeadline("Why did this happen?");
65  auto* explanationLabel = new QLabel(explanationText());
66  explanationLabel->setWordWrap(true);
67  mainLayout->addWidget(explanationLabel);
68 
69  addHeadline("What to do?");
70  auto* adviceLabel =
71  new QLabel("Check parameters of your items and re-enter uninitialized values. "
72  "Use detailed log below to get a hint what went wrong. "
73  "After that, save your project and work as normal.");
74  adviceLabel->setWordWrap(true);
75  mainLayout->addWidget(adviceLabel);
76 
77  // -- details view
78  addHeadline("Details:");
79  auto* detailsWidget = new QListWidget;
80  detailsWidget->setWordWrap(true);
81  detailsWidget->setAlternatingRowColors(true);
82  detailsWidget->addItems(details);
83  mainLayout->addWidget(detailsWidget);
84 
85  // -- buttons
86  mainLayout->addLayout(buttonLayout());
87 
88  setLayout(mainLayout);
89  setAttribute(Qt::WA_DeleteOnClose, true);
90 }
91 
93 {
94  auto* warningLabel = new QLabel;
95  warningLabel->setPixmap(QPixmap(":/images/warning_64x64.png"));
96 
97  auto* warningWidget = new QWidget;
98  warningWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
99  warningWidget->resize(top_panel_height, top_panel_height);
100  auto* warningWidgetLayout = new QHBoxLayout;
101  warningWidgetLayout->addWidget(warningLabel);
102  warningWidget->setLayout(warningWidgetLayout);
103 
104  return warningWidget;
105 }
106 
108 {
109  auto* button = new QPushButton("Close", this);
110  button->setAutoDefault(false);
111  connect(button, &QPushButton::clicked, this, &ProjectLoadProblemDialog::close);
112 
113  auto* result = new QHBoxLayout;
114  result->addStretch(3);
115  result->setContentsMargins(0, 0, 0, 0);
116  result->addWidget(button);
117 
118  return result;
119 }
120 
121 //! Returns explanations what went wrong.
123 {
125  return QString(
126  "Given project was created using BornAgain version %1 "
127  " which is different from version %2 you are currently using. "
128  "At the moment we provide only limited support for import from older versions.")
131  }
132 
133  return QString("Given project was created using BornAgain version %1 "
134  "which is the same as the current version of the framework. "
135  "Strangely enough, some parts were not loaded correctly due to format mismatch. "
136  "Please contact the developers.")
138 }
Defines class DesignerHelper.
Defines class Helpers functions.
Defines class ProjectLoadProblemDialog.
static int getSectionFontSize()
Returns system dependent font size.
QString explanationText() const
Returns explanations what went wrong.
ProjectLoadProblemDialog(QWidget *parent, const QStringList &details, QString documentVersion)
QString getBornAgainVersionString()
Definition: Path.cpp:60