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

Provide read/write of heavy data files in a separate thread. More...

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

Public Member Functions

 OutputDataIOService (ApplicationModels *models, QObject *parent=nullptr)
 
 OutputDataIOService (QObject *parent=nullptr)
 
void load (const QString &projectDir, MessageService *messageService=nullptr)
 
QVector< SaveLoadInterface * > nonXMLItems () const
 Returns all non-XML items available for save/load. More...
 
void save (const QString &projectDir)
 
void setApplicationModels (ApplicationModels *models)
 

Private Member Functions

void cleanOldFiles (const QString &projectDir, const QStringList &oldSaves, const QStringList &newSaves)
 Clean old saved files. More...
 

Private Attributes

ApplicationModelsm_applicationModels
 
OutputDataIOHistory m_history
 

Detailed Description

Provide read/write of heavy data files in a separate thread.

Listens all models and keep tracks of changes in items. Provides logic to not to re-save already saved data.

Definition at line 30 of file OutputDataIOService.h.

Constructor & Destructor Documentation

◆ OutputDataIOService() [1/2]

OutputDataIOService::OutputDataIOService ( QObject *  parent = nullptr)
explicit

Definition at line 28 of file OutputDataIOService.cpp.

29  : QObject(parent), m_applicationModels(nullptr)
30 {
31  setObjectName("OutputDataIOService");
32 }
ApplicationModels * m_applicationModels

◆ OutputDataIOService() [2/2]

OutputDataIOService::OutputDataIOService ( ApplicationModels models,
QObject *  parent = nullptr 
)
explicit

Definition at line 34 of file OutputDataIOService.cpp.

35  : QObject(parent), m_applicationModels(nullptr)
36 {
37  setObjectName("OutputDataIOService");
38  setApplicationModels(models);
39 }
void setApplicationModels(ApplicationModels *models)

References setApplicationModels().

Here is the call graph for this function:

Member Function Documentation

◆ cleanOldFiles()

void OutputDataIOService::cleanOldFiles ( const QString &  projectDir,
const QStringList &  oldSaves,
const QStringList &  newSaves 
)
private

Clean old saved files.

All files in oldSaves list, which are not in newSaves list, will be removed.

Definition at line 119 of file OutputDataIOService.cpp.

121 {
122  QStringList to_remove = ProjectUtils::substract(oldSaves, newSaves);
124 }
QStringList substract(const QStringList &lhs, const QStringList &rhs)
Returns list of string from lhs, which are not in rhs.
bool removeFiles(const QString &dirname, const QStringList &filenames)
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.

References ProjectUtils::projectDir(), ProjectUtils::removeFiles(), and ProjectUtils::substract().

Referenced by save().

Here is the call graph for this function:

◆ load()

void OutputDataIOService::load ( const QString &  projectDir,
MessageService messageService = nullptr 
)

Definition at line 68 of file OutputDataIOService.cpp.

69 {
70  OutputDataDirHistory newHistory;
71 
72  for (auto item : nonXMLItems()) {
73  try {
74  item->load(projectDir);
75  newHistory.markAsSaved(item);
76  // handling crash of GUI during job run and non-existing file
77  if (auto jobItem = parentJobItem(item)) {
78  if (jobItem->isRunning()) {
79  jobItem->setComments("Possible GUI crash while job was running");
80  jobItem->setStatus("Failed");
81  }
82  }
83 
84  } catch (const std::exception& ex) {
85  if (auto jobItem = parentJobItem(item)) {
86  // Handling corrupted file on disk
87  jobItem->setComments(
88  QString("Load of the data from disk failed with '%1'").arg(QString(ex.what())));
89  jobItem->setStatus("Failed");
90  }
91  if (messageService)
92  messageService->send_warning(this, QString(ex.what()));
93  else
94  throw ex;
95  }
96  }
97  m_history.setHistory(projectDir, newHistory);
98 }
void send_warning(QObject *sender, const QString &description)
Save history information for collection of items with non-XML data.
void markAsSaved(const SaveLoadInterface *item)
void setHistory(const QString &dirname, const OutputDataDirHistory &history)
Sets history for given directory. Previous history will be rewritten.
QVector< SaveLoadInterface * > nonXMLItems() const
Returns all non-XML items available for save/load.
OutputDataIOHistory m_history

References m_history, OutputDataDirHistory::markAsSaved(), nonXMLItems(), ProjectUtils::projectDir(), MessageService::send_warning(), and OutputDataIOHistory::setHistory().

Referenced by ProjectDocument::load().

Here is the call graph for this function:

◆ nonXMLItems()

QVector< SaveLoadInterface * > OutputDataIOService::nonXMLItems ( ) const

Returns all non-XML items available for save/load.

Definition at line 102 of file OutputDataIOService.cpp.

103 {
104  QVector<SaveLoadInterface*> result;
105 
106  if (!m_applicationModels)
107  return result;
108 
109  for (auto item : m_applicationModels->nonXMLItems())
110  if (auto non_xml_item = dynamic_cast<SaveLoadInterface*>(item))
111  result.push_back(non_xml_item);
112 
113  return result;
114 }
QVector< SessionItem * > nonXMLItems() const
Returns all non-XML items.
Purely virtual interface to handle non-XML data save and load.

References m_applicationModels, and ApplicationModels::nonXMLItems().

Referenced by ProjectDocument::hasData(), load(), and save().

Here is the call graph for this function:

◆ save()

void OutputDataIOService::save ( const QString &  projectDir)

Definition at line 46 of file OutputDataIOService.cpp.

47 {
50 
51  OutputDataDirHistory newHistory;
52 
53  for (auto item : nonXMLItems()) {
55  item->save(projectDir);
56  newHistory.markAsSaved(item);
57  }
58 
59  // dealing with files
60  QStringList oldFiles = m_history.savedFileNames(projectDir);
61  QStringList newFiles = newHistory.savedFileNames();
62  cleanOldFiles(projectDir, oldFiles, newFiles);
63 
64  // if oldHistory contained some deleted items, that info will be dropped here
65  m_history.setHistory(projectDir, newHistory);
66 }
QStringList savedFileNames() const
Returns list of file names used to save all items in a history.
bool wasModifiedSinceLastSave(const QString &dirname, const SaveLoadInterface *item)
bool hasHistory(const QString &dirname) const
QStringList savedFileNames(const QString &dirname) const
void cleanOldFiles(const QString &projectDir, const QStringList &oldSaves, const QStringList &newSaves)
Clean old saved files.

References cleanOldFiles(), OutputDataIOHistory::hasHistory(), m_history, OutputDataDirHistory::markAsSaved(), nonXMLItems(), ProjectUtils::projectDir(), OutputDataDirHistory::savedFileNames(), OutputDataIOHistory::savedFileNames(), OutputDataIOHistory::setHistory(), and OutputDataIOHistory::wasModifiedSinceLastSave().

Referenced by ProjectDocument::save_project_data().

Here is the call graph for this function:

◆ setApplicationModels()

void OutputDataIOService::setApplicationModels ( ApplicationModels models)

Definition at line 41 of file OutputDataIOService.cpp.

42 {
43  m_applicationModels = models;
44 }

References m_applicationModels.

Referenced by OutputDataIOService(), and ProjectDocument::setApplicationModels().

Member Data Documentation

◆ m_applicationModels

ApplicationModels* OutputDataIOService::m_applicationModels
private

Definition at line 49 of file OutputDataIOService.h.

Referenced by nonXMLItems(), and setApplicationModels().

◆ m_history

OutputDataIOHistory OutputDataIOService::m_history
private

Definition at line 48 of file OutputDataIOService.h.

Referenced by load(), and save().


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