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

Triggers autosave request after some accumulated ammount of document changes. More...

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

Signals

void autosaveRequest ()
 

Public Member Functions

 AutosaveController (QObject *parent=0)
 
QString autosaveDir () const
 The complete path to the autosave dir (e.g. '/projects/Untitled2/autosave'). More...
 
QString autosaveName () const
 
void removeAutosaveDir ()
 remove auto save directory for given project and all its content More...
 
void setAutosaveTime (int timerInterval)
 Sets autosave time (in msec) More...
 
void setDocument (ProjectDocument *document)
 

Private Slots

void onDocumentDestroyed (QObject *object)
 
void onDocumentModified ()
 
void onTimerTimeout ()
 

Private Member Functions

bool assureAutoSaveDirExists () const
 Tries to make sure that the directory for auto saving exists. More...
 
void autosave ()
 
void setDocumentConnected (bool set_connected)
 

Private Attributes

ProjectDocumentm_document
 
UpdateTimerm_timer
 

Detailed Description

Triggers autosave request after some accumulated ammount of document changes.

Definition at line 25 of file AutosaveController.h.

Constructor & Destructor Documentation

◆ AutosaveController()

AutosaveController::AutosaveController ( QObject *  parent = 0)
explicit

Definition at line 25 of file AutosaveController.cpp.

26  : QObject(parent), m_document(0), m_timer(new UpdateTimer(update_every, this))
27 {
29 }
ProjectDocument * m_document
The UpdateTimer class accumulates update requests during certain period of time, and at the end of th...
Definition: UpdateTimer.h:27
void timeToUpdate()

References m_timer, onTimerTimeout(), and UpdateTimer::timeToUpdate().

Here is the call graph for this function:

Member Function Documentation

◆ assureAutoSaveDirExists()

bool AutosaveController::assureAutoSaveDirExists ( ) const
private

Tries to make sure that the directory for auto saving exists.

Tries to create it if not existing so far. No creation, if project directory itself doesn't exist at all. Returns true, if the directory finally exists.

Definition at line 104 of file AutosaveController.cpp.

105 {
107  const QDir projectDir = m_document->projectDir();
108  if (projectDir.exists() && !projectDir.exists(ProjectUtils::autosaveSubdir()))
110 
111  return QDir(autosaveDir()).exists();
112  }
113 
114  return false;
115 }
QString autosaveDir() const
The complete path to the autosave dir (e.g. '/projects/Untitled2/autosave').
QString projectDir() const
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.
QString autosaveSubdir()
Returns fixed name for autosave sub-directory.

References autosaveDir(), ProjectUtils::autosaveSubdir(), ProjectDocument::hasValidNameAndPath(), m_document, ProjectDocument::projectDir(), and ProjectUtils::projectDir().

Referenced by autosave().

Here is the call graph for this function:

◆ autosave()

void AutosaveController::autosave ( )
private

Definition at line 117 of file AutosaveController.cpp.

118 {
119  try {
120  if (!autosaveName().isEmpty() && assureAutoSaveDirExists())
121  emit autosaveRequest();
122  } catch (...) {
123  // catch any exception - autosave itself never should cause a crash by an unhandled
124  // exception
125  }
126 }
QString autosaveName() const
bool assureAutoSaveDirExists() const
Tries to make sure that the directory for auto saving exists.

References assureAutoSaveDirExists(), autosaveName(), and autosaveRequest().

Referenced by onTimerTimeout().

Here is the call graph for this function:

◆ autosaveDir()

QString AutosaveController::autosaveDir ( ) const

The complete path to the autosave dir (e.g. '/projects/Untitled2/autosave').

Returns the name of autosave directory.

Definition at line 57 of file AutosaveController.cpp.

58 {
61 
62  return "";
63 }
QString projectFileName() const
QString autosaveDir(const QString &projectFileName)
Returns name of autosave directory for project with given project file name.

References ProjectUtils::autosaveDir(), ProjectDocument::hasValidNameAndPath(), m_document, and ProjectDocument::projectFileName().

Referenced by assureAutoSaveDirExists(), and removeAutosaveDir().

Here is the call graph for this function:

◆ autosaveName()

QString AutosaveController::autosaveName ( ) const

Definition at line 65 of file AutosaveController.cpp.

66 {
69 
70  return "";
71 }
QString autosaveName(const QString &projectFileName)
Returns name of project for autoSave from given project file name.

References ProjectUtils::autosaveName(), ProjectDocument::hasValidNameAndPath(), m_document, and ProjectDocument::projectFileName().

Referenced by autosave(), and SaveService::onAutosaveRequest().

Here is the call graph for this function:

◆ autosaveRequest

void AutosaveController::autosaveRequest ( )
signal

◆ onDocumentDestroyed

void AutosaveController::onDocumentDestroyed ( QObject *  object)
privateslot

Definition at line 88 of file AutosaveController.cpp.

89 {
90  Q_UNUSED(object);
91  m_timer->reset();
92  m_document = 0;
93 }
void reset()
Definition: UpdateTimer.cpp:30

References m_document, m_timer, and UpdateTimer::reset().

Referenced by setDocumentConnected().

Here is the call graph for this function:

◆ onDocumentModified

void AutosaveController::onDocumentModified ( )
privateslot

Definition at line 95 of file AutosaveController.cpp.

96 {
97  if (!m_document)
98  return;
99 
102 }
void scheduleUpdate()
Definition: UpdateTimer.cpp:42

References ProjectDocument::hasValidNameAndPath(), ProjectDocument::isModified(), m_document, m_timer, and UpdateTimer::scheduleUpdate().

Referenced by setDocument(), and setDocumentConnected().

Here is the call graph for this function:

◆ onTimerTimeout

void AutosaveController::onTimerTimeout ( )
privateslot

Definition at line 82 of file AutosaveController.cpp.

83 {
84  if (m_document->isModified())
85  autosave();
86 }

References autosave(), ProjectDocument::isModified(), and m_document.

Referenced by AutosaveController().

Here is the call graph for this function:

◆ removeAutosaveDir()

void AutosaveController::removeAutosaveDir ( )

remove auto save directory for given project and all its content

Definition at line 73 of file AutosaveController.cpp.

74 {
75  if (autosaveDir().isEmpty())
76  return;
77 
78  QDir dir(autosaveDir());
79  dir.removeRecursively();
80 }

References autosaveDir().

Referenced by SaveService::stopService().

Here is the call graph for this function:

◆ setAutosaveTime()

void AutosaveController::setAutosaveTime ( int  timerInterval)

Sets autosave time (in msec)

Definition at line 49 of file AutosaveController.cpp.

50 {
51  m_timer->reset();
52  m_timer->setWallclockTimer(timerInterval);
53 }
void setWallclockTimer(int timerInterval)
Definition: UpdateTimer.cpp:37

References m_timer, UpdateTimer::reset(), and UpdateTimer::setWallclockTimer().

Referenced by SaveService::setAutosaveTime().

Here is the call graph for this function:

◆ setDocument()

void AutosaveController::setDocument ( ProjectDocument document)

Definition at line 31 of file AutosaveController.cpp.

32 {
33  if (document == m_document)
34  return;
35 
36  m_timer->reset();
37 
38  if (m_document)
39  setDocumentConnected(false);
40 
41  m_document = document;
42 
43  if (m_document)
45 
47 }
void setDocumentConnected(bool set_connected)

References m_document, m_timer, onDocumentModified(), UpdateTimer::reset(), and setDocumentConnected().

Referenced by SaveService::setAutosaveEnabled(), and SaveService::setDocument().

Here is the call graph for this function:

◆ setDocumentConnected()

void AutosaveController::setDocumentConnected ( bool  set_connected)
private

Definition at line 128 of file AutosaveController.cpp.

129 {
130  if (!m_document)
131  return;
132 
133  if (set_connected) {
134  connect(m_document, &ProjectDocument::destroyed, this,
135  &AutosaveController::onDocumentDestroyed, Qt::UniqueConnection);
136  connect(m_document, &ProjectDocument::modified, this,
137  &AutosaveController::onDocumentModified, Qt::UniqueConnection);
138  } else {
139  disconnect(m_document, &ProjectDocument::destroyed, this,
141  disconnect(m_document, &ProjectDocument::modified, this,
143  }
144 }
void onDocumentDestroyed(QObject *object)

References m_document, ProjectDocument::modified(), onDocumentDestroyed(), and onDocumentModified().

Referenced by setDocument().

Here is the call graph for this function:

Member Data Documentation

◆ m_document

◆ m_timer

UpdateTimer* AutosaveController::m_timer
private

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