Core: Enable TaskDialogs to associate view (#17373)

* Core: Add possibility for task dialogs to associate a view and be able to close when associated view is closed.

* TaskImage: Use task dialog view association.

* Sketcher: Use task dialog view association. Preventing crash (https://github.com/FreeCAD/FreeCAD/issues/16702)

* EditableDatumLabel: Use QPointer to prevent crash
This commit is contained in:
PaddleStroke
2024-10-29 09:58:11 -05:00
committed by GitHub
parent 04fb809665
commit 4f323f9580
11 changed files with 109 additions and 5 deletions
+27
View File
@@ -295,6 +295,9 @@ TaskView::TaskView(QWidget *parent)
connectApplicationDeleteDocument =
App::GetApplication().signalDeleteDocument.connect
(std::bind(&Gui::TaskView::TaskView::slotDeletedDocument, this, sp::_1));
connectApplicationClosedView =
Gui::Application::Instance->signalCloseView.connect
(std::bind(&Gui::TaskView::TaskView::slotViewClosed, this, sp::_1));
connectApplicationUndoDocument =
App::GetApplication().signalUndoDocument.connect
(std::bind(&Gui::TaskView::TaskView::slotUndoDocument, this, sp::_1));
@@ -310,6 +313,7 @@ TaskView::~TaskView()
{
connectApplicationActiveDocument.disconnect();
connectApplicationDeleteDocument.disconnect();
connectApplicationClosedView.disconnect();
connectApplicationUndoDocument.disconnect();
connectApplicationRedoDocument.disconnect();
Gui::Selection().Detach(this);
@@ -479,6 +483,29 @@ void TaskView::slotDeletedDocument(const App::Document& doc)
}
}
void TaskView::slotViewClosed(const Gui::MDIView* view)
{
// It can happen that only a view is closed an not the document
if (ActiveDialog) {
if (ActiveDialog->isAutoCloseOnClosedView()) {
const Gui::MDIView* associatedView = ActiveDialog->getAssociatedView();
if (!associatedView) {
Base::Console().Warning(std::string("TaskView::slotViewClosed"),
"No view associated\n");
}
if (associatedView == view) {
ActiveDialog->autoClosedOnClosedView();
removeDialog();
}
}
}
if (!ActiveDialog) {
updateWatcher();
}
}
void TaskView::transactionChangeOnDocument(const App::Document& doc)
{
if (ActiveDialog) {