src/ldDocument.h

changeset 794
c254ddc6618b
parent 789
4b7306f52bb5
child 834
3e697ba996e8
equal deleted inserted replaced
793:ceb1b1aaf7db 794:c254ddc6618b
60 // The default name is a placeholder, initially suggested name for a file. The 60 // The default name is a placeholder, initially suggested name for a file. The
61 // primitive generator uses this to give initial names to primitives. 61 // primitive generator uses this to give initial names to primitives.
62 // 62 //
63 class LDDocument : public QObject 63 class LDDocument : public QObject
64 { 64 {
65 public: 65 public:
66 using KnownVertexMap = QMap<Vertex, int>; 66 using KnownVertexMap = QMap<Vertex, int>;
67 67
68 PROPERTY (public, QString, name, setName, STOCK_WRITE) 68 PROPERTY (public, QString, name, setName, STOCK_WRITE)
69 PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE) 69 PROPERTY (private, LDObjectList, objects, setObjects, STOCK_WRITE)
70 PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE) 70 PROPERTY (private, LDObjectList, cache, setCache, STOCK_WRITE)
71 PROPERTY (private, History*, history, setHistory, STOCK_WRITE) 71 PROPERTY (private, History*, history, setHistory, STOCK_WRITE)
72 PROPERTY (private, KnownVertexMap, vertices, setVertices, STOCK_WRITE) 72 PROPERTY (private, KnownVertexMap, vertices, setVertices, STOCK_WRITE)
73 PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE) 73 PROPERTY (public, QString, fullPath, setFullPath, STOCK_WRITE)
74 PROPERTY (public, QString, defaultName, setDefaultName, STOCK_WRITE) 74 PROPERTY (public, QString, defaultName, setDefaultName, STOCK_WRITE)
75 PROPERTY (public, bool, isImplicit, setImplicit, CUSTOM_WRITE) 75 PROPERTY (public, bool, isImplicit, setImplicit, CUSTOM_WRITE)
76 PROPERTY (public, long, savePosition, setSavePosition, STOCK_WRITE) 76 PROPERTY (public, long, savePosition, setSavePosition, STOCK_WRITE)
77 PROPERTY (public, int, tabIndex, setTabIndex, STOCK_WRITE) 77 PROPERTY (public, int, tabIndex, setTabIndex, STOCK_WRITE)
78 PROPERTY (public, QList<LDPolygon>, polygonData, setPolygonData, STOCK_WRITE) 78 PROPERTY (public, QList<LDPolygon>, polygonData, setPolygonData, STOCK_WRITE)
79 PROPERTY (private, LDDocumentFlags, flags, setFlags, STOCK_WRITE) 79 PROPERTY (private, LDDocumentFlags, flags, setFlags, STOCK_WRITE)
80 PROPERTY (private, LDDocumentWeakPtr, self, setSelf, STOCK_WRITE) 80 PROPERTY (private, LDDocumentWeakPtr, self, setSelf, STOCK_WRITE)
81 81
82 public: 82 public:
83 LDDocument(LDDocumentPtr* selfptr); 83 LDDocument(LDDocumentPtr* selfptr);
84 ~LDDocument(); 84 ~LDDocument();
85 85
86 int addObject (LDObjectPtr obj); // Adds an object to this file at the end of the file. 86 int addObject (LDObjectPtr obj); // Adds an object to this file at the end of the file.
87 void addObjects (const LDObjectList objs); 87 void addObjects (const LDObjectList objs);
88 void clearSelection(); 88 void clearSelection();
89 void forgetObject (LDObjectPtr obj); // Deletes the given object from the object chain. 89 void forgetObject (LDObjectPtr obj); // Deletes the given object from the object chain.
90 QString getDisplayName(); 90 QString getDisplayName();
91 const LDObjectList& getSelection() const; 91 const LDObjectList& getSelection() const;
92 bool hasUnsavedChanges() const; // Does this document have unsaved changes? 92 bool hasUnsavedChanges() const; // Does this document have unsaved changes?
93 void initializeCachedData(); 93 void initializeCachedData();
94 LDObjectList inlineContents (bool deep, bool renderinline); 94 LDObjectList inlineContents (bool deep, bool renderinline);
95 void insertObj (int pos, LDObjectPtr obj); 95 void insertObj (int pos, LDObjectPtr obj);
96 int getObjectCount() const; 96 int getObjectCount() const;
97 LDObjectPtr getObject (int pos) const; 97 LDObjectPtr getObject (int pos) const;
98 bool save (QString path = ""); // Saves this file to disk. 98 bool save (QString path = ""); // Saves this file to disk.
99 void swapObjects (LDObjectPtr one, LDObjectPtr other); 99 void swapObjects (LDObjectPtr one, LDObjectPtr other);
100 bool isSafeToClose(); // Perform safety checks. Do this before closing any files! 100 bool isSafeToClose(); // Perform safety checks. Do this before closing any files!
101 void setObject (int idx, LDObjectPtr obj); 101 void setObject (int idx, LDObjectPtr obj);
102 QList<LDPolygon> inlinePolygons(); 102 QList<LDPolygon> inlinePolygons();
103 void vertexChanged (const Vertex& a, const Vertex& b); 103 void vertexChanged (const Vertex& a, const Vertex& b);
104 void addKnownVerticesOf(LDObjectPtr obj); 104 void addKnownVerticesOf(LDObjectPtr obj);
105 void removeKnownVerticesOf (LDObjectPtr sub); 105 void removeKnownVerticesOf (LDObjectPtr sub);
106 QList<Vertex> inlineVertices(); 106 QList<Vertex> inlineVertices();
107 void clear(); 107 void clear();
108 108
109 inline LDDocument& operator<< (LDObjectPtr obj) 109 inline LDDocument& operator<< (LDObjectPtr obj)
110 { 110 {
111 addObject (obj); 111 addObject (obj);
112 return *this; 112 return *this;
113 } 113 }
114 114
115 inline void addHistoryStep() 115 inline void addHistoryStep()
116 { 116 {
117 history()->addStep(); 117 history()->addStep();
118 } 118 }
119 119
120 inline void undo() 120 inline void undo()
121 { 121 {
122 history()->undo(); 122 history()->undo();
123 } 123 }
124 124
125 inline void redo() 125 inline void redo()
126 { 126 {
127 history()->redo(); 127 history()->redo();
128 } 128 }
129 129
130 inline void clearHistory() 130 inline void clearHistory()
131 { 131 {
132 history()->clear(); 132 history()->clear();
133 } 133 }
134 134
135 inline void addToHistory (AbstractHistoryEntry* entry) 135 inline void addToHistory (AbstractHistoryEntry* entry)
136 { 136 {
137 *history() << entry; 137 *history() << entry;
138 } 138 }
139 139
140 inline void dismiss() 140 inline void dismiss()
141 { 141 {
142 setImplicit (true); 142 setImplicit (true);
143 } 143 }
144 144
145 static void closeUnused(); 145 static void closeUnused();
146 static LDDocumentPtr current(); 146 static LDDocumentPtr current();
147 static void setCurrent (LDDocumentPtr f); 147 static void setCurrent (LDDocumentPtr f);
148 static void closeInitialFile(); 148 static void closeInitialFile();
149 static int countExplicitFiles(); 149 static int countExplicitFiles();
150 static LDDocumentPtr createNew(); 150 static LDDocumentPtr createNew();
151 151
152 // Turns a full path into a relative path 152 // Turns a full path into a relative path
153 static QString shortenName (QString a); 153 static QString shortenName (QString a);
154 static QList<LDDocumentPtr> const& explicitDocuments(); 154 static QList<LDDocumentPtr> const& explicitDocuments();
155 155
156 protected: 156 protected:
157 void addToSelection (LDObjectPtr obj); 157 void addToSelection (LDObjectPtr obj);
158 void removeFromSelection (LDObjectPtr obj); 158 void removeFromSelection (LDObjectPtr obj);
159 159
160 LDGLData* getGLData() 160 LDGLData* getGLData()
161 { 161 {
162 return m_gldata; 162 return m_gldata;
163 } 163 }
164 164
165 friend class LDObject; 165 friend class LDObject;
166 friend class GLRenderer; 166 friend class GLRenderer;
167 167
168 private: 168 private:
169 LDObjectList m_sel; 169 LDObjectList m_sel;
170 LDGLData* m_gldata; 170 LDGLData* m_gldata;
171 QList<Vertex> m_storedVertices; 171 QList<Vertex> m_storedVertices;
172 172
173 // If set to true, next polygon inline of this document discards the 173 // If set to true, next polygon inline of this document discards the
174 // stored polygon data and re-builds it. 174 // stored polygon data and re-builds it.
175 bool m_needsReCache; 175 bool m_needsReCache;
176 176
177 void addKnownVertexReference (const Vertex& a); 177 void addKnownVertexReference (const Vertex& a);
178 void removeKnownVertexReference (const Vertex& a); 178 void removeKnownVertexReference (const Vertex& a);
179 }; 179 };
180 180
181 inline LDDocumentPtr getCurrentDocument() 181 inline LDDocumentPtr getCurrentDocument()
182 { 182 {
183 return LDDocument::current(); 183 return LDDocument::current();

mercurial