From 2f988e6e2c13257fabce5877438d5bbc6edb05c8 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 24 Sep 2026 12:09:01 +1200 Subject: [PATCH] Refresh cached element preview after saving from the editor Editing an element already in the user collection, saving, and closing the editor left the old thumbnail in the elements panel until the whole collection was reloaded. ElementsLocation::icon() serves the preview from two caches keyed by path+uuid -- ElementPictureFactory's in-memory picture cache and ElementsCollectionCache's on-disk SQLite cache -- and neither was ever told the file changed. QETElementEditor::toLocation() writes the new XML and returns; ElementsCollectionWidget::locationWasSaved() then refreshes the panel item, but it reads the icon through the same two stale caches, so the refresh was a no-op. slot_reloadElementDrawings() already shows the correct invalidation call for ElementPictureFactory; this wires the same pattern, plus a matching refresh of ElementsCollectionCache's row, into the save path itself. Fixes the preview half of #1004. The paste-cursor-jump half of that report is a live design disagreement between two recent commits from a different contributor and is written up separately rather than fixed here. Co-Authored-By: Claude Sonnet 5 --- sources/editor/ui/qetelementeditor.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index 424cabccf..5428ec1b9 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -25,6 +25,8 @@ #include "../../qetapp.h" #include "../../qetmainwindow.h" #include "../../recentfiles.h" +#include "../../elementscollectioncache.h" +#include "../../factory/elementpicturefactory.h" #include "../graphicspart/customelementpart.h" #include "../elementitemeditor.h" #include "../styleeditor.h" @@ -348,6 +350,24 @@ bool QETElementEditor::toLocation(const ElementsLocation &location) tr("Impossible d'enregistrer l'élément", "message box content")); return(false); } + + //setXml() just wrote the new drawing to disk, but the preview shown + //in the elements panel comes from two caches keyed by path+uuid that + //nothing here has told about the change: ElementPictureFactory's + //in-memory picture cache and ElementsCollectionCache's on-disk + //SQLite cache (see ElementsLocation::icon()). locationWasSaved() + //(elementscollectionwidget.cpp) re-reads the icon right after this + //call returns, but both caches still hand back the pre-edit pixmap, + //so the panel keeps showing the stale preview until the whole + //collection is reloaded. Drop and rebuild them here. + ElementPictureFactory::instance()->dropCache(location); + if (ElementsCollectionCache *cache = QETApp::collectionCache()) { + if (cache->fetchData(location)) { + cache->cacheName(location.toString(), location.uuid()); + cache->cachePixmap(location.toString(), location.uuid()); + } + } + return(true); }