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*>, objs, 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) |
65 |
65 |
66 LDFile(); |
66 LDFile(); |
67 ~LDFile(); |
67 ~LDFile(); |
68 |
68 |
69 ulong addObject (LDObject* obj); // Adds an object to this file at the end of the file. |
69 ulong addObject (LDObject* obj); // Adds an object to this file at the end of the file. |
|
70 void addObjects (const List<LDObject*> objs); |
70 void forgetObject (LDObject* obj); // Deletes the given object from the object chain. |
71 void forgetObject (LDObject* obj); // Deletes the given object from the object chain. |
|
72 str getShortName(); |
71 bool hasUnsavedChanges() const; // Does this file have unsaved changes? |
73 bool hasUnsavedChanges() const; // Does this file have unsaved changes? |
|
74 List<LDObject*> inlineContents (LDSubfile::InlineFlags flags); |
72 void insertObj (const ulong pos, LDObject* obj); |
75 void insertObj (const ulong pos, LDObject* obj); |
73 ulong numObjs() const; |
76 ulong numObjs() const; |
74 LDObject* object (ulong pos) const; |
77 LDObject* object (ulong pos) const; |
75 LDObject* obj (ulong pos) const; |
78 LDObject* obj (ulong pos) const; |
76 bool save (str path = ""); // Saves this file to disk. |
79 bool save (str path = ""); // Saves this file to disk. |
77 bool safeToClose(); // Perform safety checks. Do this before closing any files! |
80 bool safeToClose(); // Perform safety checks. Do this before closing any files! |
78 void setObject (ulong idx, LDObject* obj); |
81 void setObject (ulong idx, LDObject* obj); |
79 |
82 |
80 LDFile& operator<< (LDObject* obj) { |
83 inline LDFile& operator<< (LDObject* obj) { addObject (obj); return *this; } |
81 addObject (obj); |
84 inline void openHistory() { m_history.open(); } |
82 return *this; |
85 inline void closeHistory() { m_history.close(); } |
83 } |
86 inline void undo() { m_history.undo(); } |
84 |
87 inline void redo() { m_history.redo(); } |
85 LDFile& operator<< (List<LDObject*> objs); |
88 inline void clearHistory() { m_history.clear(); } |
86 |
89 inline void addToHistory (AbstractHistoryEntry* entry) { m_history << entry; } |
87 it begin() { |
|
88 return PROP_NAME (objs).begin(); |
|
89 } |
|
90 |
|
91 c_it begin() const { |
|
92 return PROP_NAME (objs).begin(); |
|
93 } |
|
94 |
|
95 it end() { |
|
96 return PROP_NAME (objs).end(); |
|
97 } |
|
98 |
|
99 c_it end() const { |
|
100 return PROP_NAME (objs).end(); |
|
101 } |
|
102 |
|
103 void openHistory() { |
|
104 m_history.open(); |
|
105 } |
|
106 |
|
107 void closeHistory() { |
|
108 m_history.close(); |
|
109 } |
|
110 |
|
111 void undo() { |
|
112 m_history.undo(); |
|
113 } |
|
114 |
|
115 void redo() { |
|
116 m_history.redo(); |
|
117 } |
|
118 |
|
119 void clearHistory() { |
|
120 m_history.clear(); |
|
121 } |
|
122 |
|
123 void addToHistory (AbstractHistoryEntry* entry) { |
|
124 m_history << entry; |
|
125 } |
|
126 |
90 |
127 static void closeUnused(); |
91 static void closeUnused(); |
128 static LDFile* current(); |
92 static LDFile* current(); |
129 static void setCurrent (LDFile* f); |
93 static void setCurrent (LDFile* f); |
130 static void closeInitialFile(); |
94 static void closeInitialFile(); |
131 static int countExplicitFiles(); |
95 static int countExplicitFiles(); |
132 str getShortName(); |
|
133 List<LDObject*> inlineContents (LDSubfile::InlineFlags flags); |
|
134 |
96 |
135 private: |
97 private: |
136 static LDFile* m_curfile; |
98 static LDFile* m_curfile; |
137 }; |
99 }; |
138 |
100 |