mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-29 22:24:13 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user