Fem: use WeakPtrT classes instead of raw pointers to avoid possible dangling pointers and to avoid undefined behaviour if a wrong static_cast is performed
This commit is contained in:
@@ -212,7 +212,8 @@ ViewProviderDataMarker::~ViewProviderDataMarker()
|
||||
// ***************************************************************************
|
||||
|
||||
TaskDlgPost::TaskDlgPost(Gui::ViewProviderDocumentObject* view)
|
||||
: TaskDialog(), m_view(view)
|
||||
: TaskDialog()
|
||||
, m_view(view)
|
||||
{
|
||||
assert(view);
|
||||
}
|
||||
@@ -289,10 +290,10 @@ void TaskDlgPost::modifyStandardButtons(QDialogButtonBox* box) {
|
||||
// ***************************************************************************
|
||||
// some task box methods
|
||||
TaskPostBox::TaskPostBox(Gui::ViewProviderDocumentObject* view, const QPixmap& icon, const QString& title, QWidget* parent)
|
||||
: TaskBox(icon, title, true, parent) {
|
||||
|
||||
m_view = view;
|
||||
m_object = view->getObject();
|
||||
: TaskBox(icon, title, true, parent)
|
||||
, m_object(view->getObject())
|
||||
, m_view(view)
|
||||
{
|
||||
}
|
||||
|
||||
TaskPostBox::~TaskPostBox() {
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#ifndef GUI_TASKVIEW_TaskPostDisplay_H
|
||||
#define GUI_TASKVIEW_TaskPostDisplay_H
|
||||
|
||||
#include <App/DocumentObserver.h>
|
||||
#include <Gui/DocumentObserver.h>
|
||||
#include <Gui/ViewProviderDocumentObject.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
@@ -143,12 +145,20 @@ public:
|
||||
virtual bool isGuiTaskOnly() {return false;} //return true if only gui properties are manipulated
|
||||
|
||||
protected:
|
||||
App::DocumentObject* getObject() {return m_object;}
|
||||
App::DocumentObject* getObject() const {
|
||||
return *m_object;
|
||||
}
|
||||
template<typename T>
|
||||
T* getTypedObject() {return static_cast<T*>(m_object);}
|
||||
Gui::ViewProviderDocumentObject* getView() {return m_view;}
|
||||
T* getTypedObject() const {
|
||||
return m_object.get<T>();
|
||||
}
|
||||
Gui::ViewProviderDocumentObject* getView() const {
|
||||
return *m_view;
|
||||
}
|
||||
template<typename T>
|
||||
T* getTypedView() {return static_cast<T*>(m_view);}
|
||||
T* getTypedView() const {
|
||||
return m_view.get<T>();
|
||||
}
|
||||
|
||||
bool autoApply();
|
||||
void recompute();
|
||||
@@ -156,8 +166,8 @@ protected:
|
||||
static void updateEnumerationList(App::PropertyEnumeration&, QComboBox* box);
|
||||
|
||||
private:
|
||||
App::DocumentObject* m_object;
|
||||
Gui::ViewProviderDocumentObject* m_view;
|
||||
App::DocumentObjectWeakPtrT m_object;
|
||||
Gui::ViewProviderWeakPtrT m_view;
|
||||
};
|
||||
|
||||
|
||||
@@ -171,8 +181,9 @@ public:
|
||||
~TaskDlgPost();
|
||||
|
||||
void appendBox(TaskPostBox* box);
|
||||
Gui::ViewProviderDocumentObject* getView() const
|
||||
{ return m_view; }
|
||||
Gui::ViewProviderDocumentObject* getView() const {
|
||||
return *m_view;
|
||||
}
|
||||
|
||||
public:
|
||||
/// is called the TaskView when the dialog is opened
|
||||
@@ -192,7 +203,7 @@ public:
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const;
|
||||
|
||||
protected:
|
||||
Gui::ViewProviderDocumentObject* m_view;
|
||||
Gui::ViewProviderWeakPtrT m_view;
|
||||
std::vector<TaskPostBox*> m_boxes;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user