# HG changeset patch # User Santeri Piippo # Date 1389181419 -7200 # Node ID 353e418f161a74aa3d271c9fe6d3afcda8b1d936 # Parent 3dd6f343ec06eaa951a254dbb45c735709d025a8 - corrected relationships between documents: opening a main file with the same name as another document is to overload it and editing the document is to invalidate its cache so that it gets rendered properly in other documents possibly referencing it. diff -r 3dd6f343ec06 -r 353e418f161a src/document.cc --- a/src/document.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/document.cc Wed Jan 08 13:43:39 2014 +0200 @@ -626,6 +626,20 @@ void openMainFile (QString path) { g_loadingMainFile = true; + + // If there's already a file with the same name, this file must replace it. + LDDocument* documentToReplace = null; + QString shortName = LDDocument::shortenName (path); + + for (LDDocument* doc : g_loadedFiles) + { + if (doc->getName() == shortName) + { + documentToReplace = doc; + break; + } + } + LDDocument* file = openDocument (path, false); if (!file) @@ -647,6 +661,19 @@ file->setImplicit (false); + // Replace references to the old file with the new file. + if (documentToReplace != null) + { + for (LDDocumentPointer* ptr : documentToReplace->getReferences()) + { dlog ("ptr: %1 (%2)\n", + ptr, ptr->getPointer() ? ptr->getPointer()->getName() : ""); + + ptr->operator= (file); + } + + assert (documentToReplace->countReferences() == 0); + } + // If we have an anonymous, unchanged file open as the only open file // (aside of the one we just opened), close it now. LDDocument::closeInitialFile(); @@ -1091,7 +1118,7 @@ void LDDocument::closeUnused() { for (LDDocument* file : g_loadedFiles) - if (file->isImplicit() && file->numReferences() == 0) + if (file->isImplicit() && file->countReferences() == 0) delete file; } @@ -1155,8 +1182,14 @@ bool deep = flags & LDSubfile::DeepInline, doCache = flags & LDSubfile::CacheInline; + if (m_needsCache) + { + clearCache(); + doCache = true; + } + // If we have this cached, just create a copy of that - if (deep && getCache().size()) + if (deep && getCache().isEmpty() == false) { for (LDObject* obj : getCache()) objs << obj->createCopy(); @@ -1357,15 +1390,15 @@ // ----------------------------------------------------------------------------- void LDDocument::addReference (LDDocumentPointer* ptr) { - m_refs << ptr; + pushToReferences (ptr); } // ============================================================================= // ----------------------------------------------------------------------------- void LDDocument::removeReference (LDDocumentPointer* ptr) { - m_refs.removeOne (ptr); + removeFromReferences (ptr); - if (m_refs.size() == 0) + if (getReferences().size() == 0) invokeLater (closeUnused); } \ No newline at end of file diff -r 3dd6f343ec06 -r 353e418f161a src/document.h --- a/src/document.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/document.h Wed Jan 08 13:43:39 2014 +0200 @@ -56,16 +56,17 @@ { properties: Q_OBJECT - PROPERTY (private, QList, Objects, NO_OPS, STOCK_WRITE) - PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) - PROPERTY (private, QList, Vertices, NO_OPS, STOCK_WRITE) - PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE) - PROPERTY (public, QString, FullPath, STR_OPS, STOCK_WRITE) - PROPERTY (public, QString, DefaultName, STR_OPS, STOCK_WRITE) - PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, QList, Cache, NO_OPS, STOCK_WRITE) - PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) - PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) + PROPERTY (private, QList, Objects, LIST_OPS, STOCK_WRITE) + PROPERTY (private, History*, History, NO_OPS, STOCK_WRITE) + PROPERTY (private, QList, Vertices, LIST_OPS, STOCK_WRITE) + PROPERTY (private, QList, References, LIST_OPS, STOCK_WRITE) + PROPERTY (public, QString, Name, STR_OPS, STOCK_WRITE) + PROPERTY (public, QString, FullPath, STR_OPS, STOCK_WRITE) + PROPERTY (public, QString, DefaultName, STR_OPS, STOCK_WRITE) + PROPERTY (public, bool, Implicit, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, QList, Cache, LIST_OPS, STOCK_WRITE) + PROPERTY (public, long, SavePosition, NUM_OPS, STOCK_WRITE) + PROPERTY (public, QListWidgetItem*, ListItem, NO_OPS, STOCK_WRITE) public: LDDocument(); @@ -88,7 +89,6 @@ void setObject (int idx, LDObject* obj); void addReference (LDDocumentPointer* ptr); void removeReference (LDDocumentPointer* ptr); - int numReferences() const { return m_refs.size(); } inline LDDocument& operator<< (LDObject* obj) { @@ -136,8 +136,11 @@ friend class LDObject; private: - QList m_sel; - QList m_refs; + QList m_sel; + + // If set to true, next inline of this document discards the cache and + // re-builds it. + bool m_needsCache; static LDDocument* m_curdoc; }; diff -r 3dd6f343ec06 -r 353e418f161a src/gldraw.cc --- a/src/gldraw.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/gldraw.cc Wed Jan 08 13:43:39 2014 +0200 @@ -997,10 +997,7 @@ LDSubfile* ref = static_cast (obj); QList objs; - objs = ref->inlineContents ( - LDSubfile::DeepInline | - LDSubfile::CacheInline | - LDSubfile::RendererInline); + objs = ref->inlineContents (LDSubfile::DeepInline | LDSubfile::RendererInline); bool oldinvert = g_glInvert; if (ref->getTransform().getDeterminant() < 0) @@ -1396,6 +1393,7 @@ continue; // White is background; skip LDObject* obj = LDObject::fromID (idx); + assert (obj != null); // If this is an additive single pick and the object is currently selected, // we remove it from selection instead. diff -r 3dd6f343ec06 -r 353e418f161a src/ldtypes.h --- a/src/ldtypes.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/ldtypes.h Wed Jan 08 13:43:39 2014 +0200 @@ -67,13 +67,13 @@ // ============================================================================= class LDObject { - PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) - PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) - PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ - PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) - PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) - PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, bool, Hidden, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, bool, Selected, BOOL_OPS, STOCK_WRITE) + PROPERTY (public, LDObject*, Parent, NO_OPS, STOCK_WRITE) + PROPERTY (public, LDDocument*, File, NO_OPS, STOCK_WRITE) // TODO: rename~ + PROPERTY (private, int, ID, NUM_OPS, STOCK_WRITE) + PROPERTY (public, int, Color, NUM_OPS, CUSTOM_WRITE) + PROPERTY (public, bool, GLInit, BOOL_OPS, STOCK_WRITE) public: // Object type codes. Codes are sorted in order of significance. diff -r 3dd6f343ec06 -r 353e418f161a src/misc/documentPointer.cc --- a/src/misc/documentPointer.cc Tue Jan 07 12:21:46 2014 +0200 +++ b/src/misc/documentPointer.cc Wed Jan 08 13:43:39 2014 +0200 @@ -18,10 +18,10 @@ #include "documentPointer.h" #include "../document.h" +#include "../misc.h" LDDocumentPointer::LDDocumentPointer() : m_Pointer (null) {} - // ============================================================================= // ----------------------------------------------------------------------------- LDDocumentPointer::LDDocumentPointer (LDDocument* ptr) : diff -r 3dd6f343ec06 -r 353e418f161a src/misc/documentPointer.h --- a/src/misc/documentPointer.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/misc/documentPointer.h Wed Jan 08 13:43:39 2014 +0200 @@ -21,11 +21,12 @@ #include "../main.h" +class LDSubfile; class LDDocument; class LDDocumentPointer { - PROPERTY (private, LDDocument*, Pointer, NO_OPS, STOCK_WRITE) + PROPERTY (private, LDDocument*, Pointer, NO_OPS, STOCK_WRITE) public: LDDocumentPointer(); diff -r 3dd6f343ec06 -r 353e418f161a src/property.h --- a/src/property.h Tue Jan 07 12:21:46 2014 +0200 +++ b/src/property.h Wed Jan 08 13:43:39 2014 +0200 @@ -113,6 +113,12 @@ inline void clear##NAME() \ { \ set##NAME( TYPE() ); \ + } \ + \ + public: \ + inline int count##NAME() \ + { \ + return get##NAME().size(); \ } #endif // LDFORGE_PROPERTY_H \ No newline at end of file