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

The dialog to inform user about encountered problems during the loading of old project. More...

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

Public Member Functions

 ProjectLoadWarningDialog (QWidget *parent, const MessageService *messageService=0, const QString &documentVersion="")
 

Private Member Functions

QLayout * buttonLayout ()
 
QWidget * createDetailsPanel ()
 Info panel with table widget containing error messages. More...
 
QWidget * createExplanationPanel ()
 Info panel with explanations what had happened and what to do. More...
 
QWidget * createModelInfoPanel ()
 Info panel with summary over warnings in different models. More...
 
QTableWidgetItem * createTableItem (const QString &name)
 
QTableWidget * createTableWidget ()
 Creates QTableWidget and fills it with error messages. More...
 
QWidget * createTopPanel ()
 Top panel with warning icon and the header. More...
 
QString explanationText () const
 Returns explanations what went wrong. More...
 
int numberOfTableRows () const
 Returns number of rows in table with error messages, each row represents an error message. More...
 
QStringList tableHeaderLabels () const
 Returns labels for table header. More...
 

Private Attributes

const MessageServicem_messageService
 
QString m_projectDocumentVersion
 

Detailed Description

The dialog to inform user about encountered problems during the loading of old project.

Definition at line 30 of file ProjectLoadWarningDialog.h.

Constructor & Destructor Documentation

◆ ProjectLoadWarningDialog()

ProjectLoadWarningDialog::ProjectLoadWarningDialog ( QWidget *  parent,
const MessageService messageService = 0,
const QString &  documentVersion = "" 
)

Definition at line 32 of file ProjectLoadWarningDialog.cpp.

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 }
QWidget * createModelInfoPanel()
Info panel with summary over warnings in different models.
QWidget * createExplanationPanel()
Info panel with explanations what had happened and what to do.
const MessageService * m_messageService
QWidget * createDetailsPanel()
Info panel with table widget containing error messages.
QWidget * createTopPanel()
Top panel with warning icon and the header.

References buttonLayout(), createDetailsPanel(), createExplanationPanel(), createModelInfoPanel(), and createTopPanel().

Here is the call graph for this function:

Member Function Documentation

◆ buttonLayout()

QLayout * ProjectLoadWarningDialog::buttonLayout ( )
private

Definition at line 206 of file ProjectLoadWarningDialog.cpp.

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 }

Referenced by ProjectLoadWarningDialog().

◆ createDetailsPanel()

QWidget * ProjectLoadWarningDialog::createDetailsPanel ( )
private

Info panel with table widget containing error messages.

Definition at line 155 of file ProjectLoadWarningDialog.cpp.

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 }
static int getSectionFontSize()
QTableWidget * createTableWidget()
Creates QTableWidget and fills it with error messages.

References createTableWidget(), and DesignerHelper::getSectionFontSize().

Referenced by ProjectLoadWarningDialog().

Here is the call graph for this function:

◆ createExplanationPanel()

QWidget * ProjectLoadWarningDialog::createExplanationPanel ( )
private

Info panel with explanations what had happened and what to do.

Definition at line 115 of file ProjectLoadWarningDialog.cpp.

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 }
QString explanationText() const
Returns explanations what went wrong.

References explanationText(), and DesignerHelper::getSectionFontSize().

Referenced by ProjectLoadWarningDialog().

Here is the call graph for this function:

◆ createModelInfoPanel()

QWidget * ProjectLoadWarningDialog::createModelInfoPanel ( )
private

Info panel with summary over warnings in different models.

Definition at line 87 of file ProjectLoadWarningDialog.cpp.

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 }
QStringList senderList() const

References m_messageService, and MessageService::senderList().

Referenced by ProjectLoadWarningDialog().

Here is the call graph for this function:

◆ createTableItem()

QTableWidgetItem * ProjectLoadWarningDialog::createTableItem ( const QString &  name)
private

Definition at line 235 of file ProjectLoadWarningDialog.cpp.

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 }
QString const & name(EShape k)
Definition: particles.cpp:21

References RealSpace::Particles::name().

Referenced by createTableWidget().

Here is the call graph for this function:

◆ createTableWidget()

QTableWidget * ProjectLoadWarningDialog::createTableWidget ( )
private

Creates QTableWidget and fills it with error messages.

Definition at line 178 of file ProjectLoadWarningDialog.cpp.

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 }
const QList< GUIMessage * > messages() const
QStringList tableHeaderLabels() const
Returns labels for table header.
QTableWidgetItem * createTableItem(const QString &name)
int numberOfTableRows() const
Returns number of rows in table with error messages, each row represents an error message.

References createTableItem(), m_messageService, MessageService::messages(), numberOfTableRows(), and tableHeaderLabels().

Referenced by createDetailsPanel().

Here is the call graph for this function:

◆ createTopPanel()

QWidget * ProjectLoadWarningDialog::createTopPanel ( )
private

Top panel with warning icon and the header.

Definition at line 54 of file ProjectLoadWarningDialog.cpp.

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 }

References DesignerHelper::getSectionFontSize().

Referenced by ProjectLoadWarningDialog().

Here is the call graph for this function:

◆ explanationText()

QString ProjectLoadWarningDialog::explanationText ( ) const
private

Returns explanations what went wrong.

Definition at line 248 of file ProjectLoadWarningDialog.cpp.

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 }
QString getBornAgainVersionString()
Definition: GUIHelpers.cpp:130

References GUIHelpers::getBornAgainVersionString(), and m_projectDocumentVersion.

Referenced by createExplanationPanel().

Here is the call graph for this function:

◆ numberOfTableRows()

int ProjectLoadWarningDialog::numberOfTableRows ( ) const
private

Returns number of rows in table with error messages, each row represents an error message.

Definition at line 222 of file ProjectLoadWarningDialog.cpp.

223 {
224  return m_messageService->messages().size();
225 }

References m_messageService, and MessageService::messages().

Referenced by createTableWidget().

Here is the call graph for this function:

◆ tableHeaderLabels()

QStringList ProjectLoadWarningDialog::tableHeaderLabels ( ) const
private

Returns labels for table header.

Definition at line 228 of file ProjectLoadWarningDialog.cpp.

229 {
230  return QStringList() << "Sender"
231  << "Message"
232  << "Description";
233 }

Referenced by createTableWidget().

Member Data Documentation

◆ m_messageService

const MessageService* ProjectLoadWarningDialog::m_messageService
private

◆ m_projectDocumentVersion

QString ProjectLoadWarningDialog::m_projectDocumentVersion
private

Definition at line 52 of file ProjectLoadWarningDialog.h.

Referenced by explanationText().


The documentation for this class was generated from the following files: