src/file.h

changeset 493
16766ac1bbd9
parent 484
5b5c77c7f3dd
child 494
bd005c78a089
equal deleted inserted replaced
492:e964085e6913 493:16766ac1bbd9
27 #define curfile LDFile::current() 27 #define curfile LDFile::current()
28 28
29 class History; 29 class History;
30 class OpenProgressDialog; 30 class OpenProgressDialog;
31 31
32 namespace LDPaths { 32 namespace LDPaths
33 void initPaths(); 33 { void initPaths();
34 bool tryConfigure (str path); 34 bool tryConfigure (str path);
35 35
36 str ldconfig(); 36 str ldconfig();
37 str prims(); 37 str prims();
38 str parts(); 38 str parts();
39 str getError(); 39 str getError();
40 } 40 }
46 // for the user or for subfile caching. Its methods handle file input and output. 46 // for the user or for subfile caching. Its methods handle file input and output.
47 // 47 //
48 // A file is implicit when they are opened automatically for caching purposes 48 // A file is implicit when they are opened automatically for caching purposes
49 // and are hidden from the user. User-opened files are explicit (not implicit). 49 // and are hidden from the user. User-opened files are explicit (not implicit).
50 // ============================================================================= 50 // =============================================================================
51 class LDFile : public QObject { 51 class LDFile : public QObject
52 Q_OBJECT 52 { Q_OBJECT
53 READ_PROPERTY (List<LDObject*>, objects, setObjects) 53 READ_PROPERTY (List<LDObject*>, objects, setObjects)
54 READ_PROPERTY (History, history, setHistory) 54 READ_PROPERTY (History, history, setHistory)
55 READ_PROPERTY (List<LDObject*>, vertices, setVertices) 55 READ_PROPERTY (List<LDObject*>, vertices, setVertices)
56 PROPERTY (str, name, setName) 56 PROPERTY (str, name, setName)
57 PROPERTY (bool, implicit, setImplicit) 57 PROPERTY (bool, implicit, setImplicit)
58 PROPERTY (List<LDObject*>, cache, setCache) 58 PROPERTY (List<LDObject*>, cache, setCache)
59 PROPERTY (long, savePos, setSavePos) 59 PROPERTY (long, savePos, setSavePos)
60 DECLARE_PROPERTY (QListWidgetItem*, listItem, setListItem) 60 DECLARE_PROPERTY (QListWidgetItem*, listItem, setListItem)
61
62 public:
63 typedef List<LDObject*>::it it;
64 typedef List<LDObject*>::c_it c_it;
65
66 LDFile();
67 ~LDFile();
68
69 ulong addObject (LDObject* obj); // Adds an object to this file at the end of the file.
70 void addObjects (const List<LDObject*> objs);
71 void forgetObject (LDObject* obj); // Deletes the given object from the object chain.
72 str getShortName();
73 bool hasUnsavedChanges() const; // Does this file have unsaved changes?
74 List<LDObject*> inlineContents (LDSubfile::InlineFlags flags);
75 void insertObj (const ulong pos, LDObject* obj);
76 ulong numObjs() const;
77 LDObject* object (ulong pos) const;
78 LDObject* obj (ulong pos) const;
79 bool save (str path = ""); // Saves this file to disk.
80 bool safeToClose(); // Perform safety checks. Do this before closing any files!
81 void setObject (ulong idx, LDObject* obj);
82 61
83 inline LDFile& operator<< (LDObject* obj) { addObject (obj); return *this; } 62 public:
84 inline void openHistory() { m_history.open(); } 63 typedef List<LDObject*>::it it;
85 inline void closeHistory() { m_history.close(); } 64 typedef List<LDObject*>::c_it c_it;
86 inline void undo() { m_history.undo(); } 65
87 inline void redo() { m_history.redo(); } 66 LDFile();
88 inline void clearHistory() { m_history.clear(); } 67 ~LDFile();
89 inline void addToHistory (AbstractHistoryEntry* entry) { m_history << entry; } 68
90 69 ulong addObject (LDObject* obj); // Adds an object to this file at the end of the file.
91 static void closeUnused(); 70 void addObjects (const List<LDObject*> objs);
92 static LDFile* current(); 71 void forgetObject (LDObject* obj); // Deletes the given object from the object chain.
93 static void setCurrent (LDFile* f); 72 str getShortName();
94 static void closeInitialFile(); 73 bool hasUnsavedChanges() const; // Does this file have unsaved changes?
95 static int countExplicitFiles(); 74 List<LDObject*> inlineContents (LDSubfile::InlineFlags flags);
96 75 void insertObj (const ulong pos, LDObject* obj);
97 private: 76 ulong numObjs() const;
98 static LDFile* m_curfile; 77 LDObject* object (ulong pos) const;
78 LDObject* obj (ulong pos) const;
79 bool save (str path = ""); // Saves this file to disk.
80 bool safeToClose(); // Perform safety checks. Do this before closing any files!
81 void setObject (ulong idx, LDObject* obj);
82
83 inline LDFile& operator<< (LDObject* obj)
84 { addObject (obj);
85 return *this;
86 }
87
88 inline void openHistory()
89 { m_history.open();
90 }
91
92 inline void closeHistory()
93 { m_history.close();
94 }
95
96 inline void undo()
97 { m_history.undo();
98 }
99
100 inline void redo()
101 { m_history.redo();
102 }
103
104 inline void clearHistory()
105 { m_history.clear();
106 }
107
108 inline void addToHistory (AbstractHistoryEntry* entry)
109 { m_history << entry;
110 }
111
112 static void closeUnused();
113 static LDFile* current();
114 static void setCurrent (LDFile* f);
115 static void closeInitialFile();
116 static int countExplicitFiles();
117
118 private:
119 static LDFile* m_curfile;
99 }; 120 };
100 121
101 // Close all current loaded files and start off blank. 122 // Close all current loaded files and start off blank.
102 void newFile(); 123 void newFile();
103 124
146 // FileLoader 167 // FileLoader
147 // 168 //
148 // Loads the given file and parses it to LDObjects using parseLine. It's a 169 // Loads the given file and parses it to LDObjects using parseLine. It's a
149 // separate class so as to be able to do the work in a separate thread. 170 // separate class so as to be able to do the work in a separate thread.
150 // ============================================================================= 171 // =============================================================================
151 class FileLoader : public QObject { 172 class FileLoader : public QObject
152 Q_OBJECT 173 { Q_OBJECT
153 READ_PROPERTY (List<LDObject*>, objs, setObjects) 174 READ_PROPERTY (List<LDObject*>, objs, setObjects)
154 READ_PROPERTY (bool, done, setDone) 175 READ_PROPERTY (bool, done, setDone)
155 READ_PROPERTY (ulong, progress, setProgress) 176 READ_PROPERTY (ulong, progress, setProgress)
156 READ_PROPERTY (bool, aborted, setAborted) 177 READ_PROPERTY (bool, aborted, setAborted)
157 PROPERTY (List<str>, lines, setLines) 178 PROPERTY (List<str>, lines, setLines)
158 PROPERTY (ulong*, warningsPointer, setWarningsPointer) 179 PROPERTY (ulong*, warningsPointer, setWarningsPointer)
159 PROPERTY (bool, concurrent, setConcurrent) 180 PROPERTY (bool, concurrent, setConcurrent)
160 181
161 public slots: 182 public slots:
162 void start(); 183 void start();
163 void abort(); 184 void abort();
164 185
165 private: 186 private:
166 OpenProgressDialog* dlg; 187 OpenProgressDialog* dlg;
167 188
168 private slots: 189 private slots:
169 void work (int i); 190 void work (int i);
170 191
171 signals: 192 signals:
172 void progressUpdate (int progress); 193 void progressUpdate (int progress);
173 void workDone(); 194 void workDone();
174 }; 195 };
175 196
176 #endif // FILE_H 197 #endif // FILE_H

mercurial