HAL
file_status_manager.cpp
Go to the documentation of this file.
3 
4 #include "gui/gui_globals.h"
5 
6 namespace hal
7 {
9  mModifiedFilesUuid(QSet<QUuid>()), mModifiedFilesDescriptors(QMap<QUuid, QString>()),
10  mNetlistState(NotOpen), mGatelibState(NotOpen)
11  {;}
12 
14  {;}
15 
16  void FileStatusManager::fileChanged(const QUuid uuid, const QString& descriptor)
17  {
18  bool before = modifiedFilesExisting();
19  mModifiedFilesUuid.insert(uuid);
20  mModifiedFilesDescriptors.insert(uuid, descriptor);
21  if (before != modifiedFilesExisting())
22  Q_EMIT status_changed(false, true);
23  }
24 
26  {
27  bool before = modifiedFilesExisting();
28  mModifiedFilesUuid.remove(uuid);
29  mModifiedFilesDescriptors.remove(uuid);
30  if (before != modifiedFilesExisting())
31  Q_EMIT status_changed(false, false);
32  }
33 
35  {
36  if (!FileManager::get_instance()->fileOpen())
37  return false;
38 
39  return !mModifiedFilesUuid.empty() || mNetlistState == Dirty;
40  }
41 
43  {
44  mNetlistState = Clean;
45  Q_EMIT open_changed(false, true);
46  }
47 
49  {
50  bool before = modifiedFilesExisting();
51  mNetlistState = Dirty;
52  if (before != modifiedFilesExisting())
53  Q_EMIT status_changed(false, true);
54  }
55 
57  {
58  bool before = modifiedFilesExisting();
59  mNetlistState = Clean;
60  if (before != modifiedFilesExisting())
61  Q_EMIT status_changed(false, false);
62  }
63 
65  {
66  mNetlistState = NotOpen;
67  mModifiedFilesUuid.clear();
68  mModifiedFilesDescriptors.clear();
69  Q_EMIT status_changed(false, false);
70  Q_EMIT open_changed(false, false);
71  }
72 
74  {
75  mGatelibState = Clean;
76  Q_EMIT open_changed(true, true);
77  }
78 
80  {
81  mGatelibState = Dirty;
82  Q_EMIT status_changed(true, true);
83  }
84 
86  {
87  mGatelibState = Clean;
88  Q_EMIT status_changed(true, false);
89  }
90 
92  {
93  return mGatelibState == Dirty;
94  }
95 
97  {
98  mGatelibState = NotOpen;
99  Q_EMIT open_changed(true, false);
100  }
101 
103  {
104  QList<QString> unsaved_changes_descriptors;
105 
106  if(mNetlistState==Dirty)
107  {
108  unsaved_changes_descriptors.append("Netlist modifications");
109  }
110 
111  for(QUuid uuid : mModifiedFilesUuid)
112  {
113  unsaved_changes_descriptors.append(mModifiedFilesDescriptors.value(uuid));
114  }
115 
116  return unsaved_changes_descriptors;
117  }
118 }
static FileManager * get_instance()
void fileChanged(const QUuid uuid, const QString &descriptor)
void status_changed(bool gateLibraryAffected, bool isDirty)
FileStatusManager(QObject *parent=nullptr)
QList< QString > getUnsavedChangeDescriptors() const
void fileSaved(const QUuid uuid)
void open_changed(bool gateLibraryAffected, bool isOpen)
void append(const T &value)
void clear()
QMap::iterator insert(const Key &key, const T &value)
int remove(const Key &key)
const T value(const Key &key, const T &defaultValue) const const
Q_EMITQ_EMIT
void clear()
bool empty() const const
QSet::iterator insert(const T &value)
bool remove(const T &value)