Commit 237bcf29 authored by Frédéric Larue's avatar Frédéric Larue

Proxy model for enabling UIData to delete their content improved.

parent d03d77f8
......@@ -452,7 +452,7 @@ bool UIMainWindow::closeCurrentProject()
if( m_CurrentProject )
{
m_CurrentProject->RemoveAll();
m_CurrentProject->RemoveAndDeleteAll();
delete m_CurrentProject;
m_CurrentProject = NULL;
}
......@@ -750,8 +750,7 @@ void UIMainWindow::removeFromCurrentProject()
for( auto i=toRemove.begin(); i!=toRemove.end(); ++i )
{
m_CurrentViewer->removeDisplayable( *i );
m_CurrentProject->Remove( *i );
delete *i;
m_CurrentProject->RemoveAndDelete( *i );
}
updateTypeFilters();
......
......@@ -52,14 +52,6 @@ public:
/** Recover the current state of the set of display parameters. */
inline const UIParamSet& getParameters() const { return *m_Data->GetDisplayOptions(); }
/** Recover the bounding box of the displayed item in global space. */
virtual void boundingBox( Box3f &box ) const = 0;
/** Recover the label to be displayed. */
virtual QString label() const { return QString(); }
/** Recover parameters describing the display options of the current item. */
virtual void declareParameters( UIParamSet &params ) {}
/** Function called when the value of a parameter has changed. */
virtual void onUpdatingParameter( UIParam *p ) {}
/** Function called once, after the creation of the displayer object but before its first display.
* The OpenGL context is active, which means that any OpenGL operation can be done here.
*/
......@@ -68,6 +60,15 @@ public:
* The OpenGL context is active, which means that any OpenGL operation can be done here.
*/
virtual void release( UIParamSet &params ) {}
/** Recover the bounding box of the displayed item in global space. */
virtual void boundingBox( Box3f &box ) const = 0;
/** Recover the label to be displayed. */
virtual QString label() const { return QString(); }
/** Recover parameters describing the display options of the current item. */
virtual void declareParameters( UIParamSet &params ) {}
/** Function called when the value of a parameter has changed. */
virtual void onUpdatingParameter( UIParam *p ) {}
/** Function that effectively performs the display. */
virtual void onDisplay( UIParamSet &params ) = 0;
/** Called when the viewport of the GL widget into which this object is displayed is resized. */
......
......@@ -77,7 +77,10 @@ public:
// Remove from project.
if( m_Project )
{
m_Project->Remove( this );
m_Project->OnDeletingData( this );
}
// Remove hierarchy links.
......@@ -167,18 +170,16 @@ public:
template <typename T>
class UIDATA_API UIData : public GenericUIData
{
private:
protected:
static QString s_ClassTypeString;
T *m_Content;
bool m_IsProxy;
public:
inline UIData( T* content, const QString& filename, bool isProxy = false ) :
inline UIData( T* content, const QString& filename ) :
GenericUIData( s_ClassTypeString, filename ),
m_Content( content ),
m_IsProxy( isProxy )
m_Content( content )
{}
virtual ~UIData() { if( !m_IsProxy ) delete m_Content; }
virtual ~UIData() {}
inline void SetContent( T* content ) { m_Content = content; }
......@@ -191,6 +192,15 @@ public:
};
template <typename T>
class UIDataNoProxy : public UIData<T>
{
public:
inline UIDataNoProxy( T* content, const QString& filename ) : UIData<T>( content, filename ) {}
virtual ~UIDataNoProxy() { delete m_Content; }
};
#ifndef UI_DATA_DECLARED
#define DEFINE_UI_DATA( CLASS_LINKAGE, TYPE ) \
template class CLASS_LINKAGE UIData<TYPE>
......
......@@ -70,7 +70,6 @@ void UIProject::Remove( GenericUIData* data )
{
m_ItemNames.remove( data->GetFileName() );
m_ItemCollection.remove( data );
OnRemovingData( data );
}
......@@ -82,6 +81,21 @@ void UIProject::RemoveAll()
}
void UIProject::RemoveAndDelete( GenericUIData* data )
{
Remove( data );
OnDeletingData( data );
delete data;
}
void UIProject::RemoveAndDeleteAll()
{
while( !m_ItemCollection.empty() )
RemoveAndDelete( *m_ItemCollection.begin() );
}
#ifdef _WIN32
......@@ -92,8 +106,7 @@ void UIProject::RemoveAll()
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
......
......@@ -34,12 +34,15 @@ public:
template <typename T> bool Add( T *content, const QString &filename ) { return Add( new UIData<T>(content,filename) ); }
void Remove( GenericUIData* data );
void RemoveAll();
void RemoveAndDelete( GenericUIData* data );
void RemoveAndDeleteAll();
inline const QSet<GenericUIData*>& GetAll() const { return m_ItemCollection; }
virtual void OnAddingData( GenericUIData *data ) {}
virtual void OnRemovingData( GenericUIData *data ) {}
virtual void OnRenamingData( GenericUIData* data,
const QString& newFileName ) {}
virtual void OnDeletingData( GenericUIData *data ) {}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment