src/ldDocument.cpp

changeset 983
05ba93066194
parent 981
5d5d84ab2c48
child 984
a7b6f987d269
equal deleted inserted replaced
982:a3a2e62a581b 983:05ba93066194
44 const QStringList g_specialSubdirectories ({ "s", "48", "8" }); 44 const QStringList g_specialSubdirectories ({ "s", "48", "8" });
45 45
46 LDDocument::LDDocument (QObject* parent) : 46 LDDocument::LDDocument (QObject* parent) :
47 QObject (parent), 47 QObject (parent),
48 HierarchyElement (parent), 48 HierarchyElement (parent),
49 m_history (new History), 49 m_history (new EditHistory (this)),
50 m_isCache (true), 50 m_isCache (true),
51 m_verticesOutdated (true), 51 m_verticesOutdated (true),
52 m_needVertexMerge (true), 52 m_needVertexMerge (true),
53 m_beingDestroyed (false), 53 m_beingDestroyed (false),
54 m_gldata (new LDGLData) 54 m_gldata (new LDGLData)
55 { 55 {
56 setSavePosition (-1); 56 setSavePosition (-1);
57 setTabIndex (-1); 57 setTabIndex (-1);
58 m_history->setDocument (this);
59 m_needsReCache = true; 58 m_needsReCache = true;
60 } 59 }
61 60
62 LDDocument::~LDDocument() 61 LDDocument::~LDDocument()
63 { 62 {
79 const LDObjectList& LDDocument::objects() const 78 const LDObjectList& LDDocument::objects() const
80 { 79 {
81 return m_objects; 80 return m_objects;
82 } 81 }
83 82
84 History* LDDocument::history() const 83 EditHistory* LDDocument::history() const
85 { 84 {
86 return m_history; 85 return m_history;
87 } 86 }
88 87
89 QString LDDocument::fullPath() 88 QString LDDocument::fullPath()
170 history()->clear(); 169 history()->clear();
171 } 170 }
172 171
173 void LDDocument::addToHistory (AbstractHistoryEntry* entry) 172 void LDDocument::addToHistory (AbstractHistoryEntry* entry)
174 { 173 {
175 *history() << entry; 174 history()->add (entry);
176 } 175 }
177 176
178 void LDDocument::close() 177 void LDDocument::close()
179 { 178 {
180 if (not isCache()) 179 if (not isCache())
959 958
960 // ============================================================================= 959 // =============================================================================
961 // 960 //
962 int LDDocument::addObject (LDObject* obj) 961 int LDDocument::addObject (LDObject* obj)
963 { 962 {
964 history()->add (new AddHistory (objects().size(), obj)); 963 history()->add (new AddHistoryEntry (objects().size(), obj));
965 m_objects << obj; 964 m_objects << obj;
966 addKnownVertices (obj); 965 addKnownVertices (obj);
967 obj->setDocument (this); 966 obj->setDocument (this);
968 m_window->renderer()->compileObject (obj); 967 m_window->renderer()->compileObject (obj);
969 return getObjectCount() - 1; 968 return getObjectCount() - 1;
982 981
983 // ============================================================================= 982 // =============================================================================
984 // 983 //
985 void LDDocument::insertObj (int pos, LDObject* obj) 984 void LDDocument::insertObj (int pos, LDObject* obj)
986 { 985 {
987 history()->add (new AddHistory (pos, obj)); 986 history()->add (new AddHistoryEntry (pos, obj));
988 m_objects.insert (pos, obj); 987 m_objects.insert (pos, obj);
989 obj->setDocument (this); 988 obj->setDocument (this);
990 m_window->renderer()->compileObject (obj); 989 m_window->renderer()->compileObject (obj);
991 990
992 991
1021 { 1020 {
1022 obj->deselect(); 1021 obj->deselect();
1023 1022
1024 if (not isCache() and not m_beingDestroyed) 1023 if (not isCache() and not m_beingDestroyed)
1025 { 1024 {
1026 history()->add (new DelHistory (idx, obj)); 1025 history()->add (new DelHistoryEntry (idx, obj));
1027 m_objectVertices.remove (obj); 1026 m_objectVertices.remove (obj);
1028 } 1027 }
1029 1028
1030 m_objects.removeAt (idx); 1029 m_objects.removeAt (idx);
1031 obj->setDocument (nullptr); 1030 obj->setDocument (nullptr);
1055 // Mark this change to history 1054 // Mark this change to history
1056 if (not m_history->isIgnoring()) 1055 if (not m_history->isIgnoring())
1057 { 1056 {
1058 QString oldcode = getObject (idx)->asText(); 1057 QString oldcode = getObject (idx)->asText();
1059 QString newcode = obj->asText(); 1058 QString newcode = obj->asText();
1060 *m_history << new EditHistory (idx, oldcode, newcode); 1059 m_history->add (new EditHistoryEntry (idx, oldcode, newcode));
1061 } 1060 }
1062 1061
1063 m_objectVertices.remove (m_objects[idx]); 1062 m_objectVertices.remove (m_objects[idx]);
1064 m_objects[idx]->deselect(); 1063 m_objects[idx]->deselect();
1065 m_objects[idx]->setDocument (nullptr); 1064 m_objects[idx]->setDocument (nullptr);
1280 1279
1281 if (a != b and a != -1 and b != -1) 1280 if (a != b and a != -1 and b != -1)
1282 { 1281 {
1283 m_objects[b] = one; 1282 m_objects[b] = one;
1284 m_objects[a] = other; 1283 m_objects[a] = other;
1285 addToHistory (new SwapHistory (one->id(), other->id())); 1284 addToHistory (new SwapHistoryEntry (one->id(), other->id()));
1286 } 1285 }
1287 } 1286 }
1288 1287
1289 // ============================================================================= 1288 // =============================================================================
1290 // 1289 //

mercurial