Part: Introduce PreviewUpdateScheduler

This commit introduces PreviewUpdateScheduler class that is responsible
to schedule the true recompute of the preview. View Providers (or other
components) can use this service to ask for the preview recompute to
happend at a time that is convinent for a program and that won't impact
performance.

The provided implementation uses Queued Connections in Qt to calculate
preview essentially on next run of the event loop. It allows business
logic in FreeCAD (like property propagation) to execute fully and then
recompute preview once. This greately reduces number of recompute calls
for previews.
This commit is contained in:
Kacper Donat
2026-01-10 01:15:10 +01:00
committed by Chris Hennes
parent 699c539446
commit d4dc5c01d8
8 changed files with 200 additions and 7 deletions

View File

@@ -215,10 +215,15 @@ void ViewProvider::updateData(const App::Property* prop)
}
else if (auto* previewExtension = getObject()->getExtensionByType<Part::PreviewExtension>(true)) {
if (!previewExtension->isPreviewFresh() && isEditing()) {
previewExtension->updatePreview();
// Properties can be updated in batches, where some properties trigger other updates.
// We don't need to compute the preview for intermediate steps. Instead of updating
// the preview immediately (and potentially doing it multiple times in a row), we
// schedule the update to happen at a more convenient time.
if (auto* scheduler = Base::provideService<Part::PreviewUpdateScheduler>()) {
scheduler->schedulePreviewRecompute(getObject());
}
}
}
inherited::updateData(prop);
}