Remove memory leaks by using smart pointers or explicit delete
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
#ifndef _WX_QT_WINDOW_H_
|
#ifndef _WX_QT_WINDOW_H_
|
||||||
#define _WX_QT_WINDOW_H_
|
#define _WX_QT_WINDOW_H_
|
||||||
|
|
||||||
|
#include <QtCore/QScopedPointer>
|
||||||
|
|
||||||
class QShortcut;
|
class QShortcut;
|
||||||
template < class T > class QList;
|
template < class T > class QList;
|
||||||
|
|
||||||
@@ -216,24 +218,24 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init();
|
||||||
QScrollArea *m_qtContainer;
|
QScrollArea *m_qtContainer; // either NULL or the same as m_qtWindow pointer
|
||||||
|
|
||||||
QScrollBar *m_horzScrollBar;
|
QScrollBar *m_horzScrollBar; // owned by m_qtWindow when allocated
|
||||||
QScrollBar *m_vertScrollBar;
|
QScrollBar *m_vertScrollBar; // owned by m_qtWindow when allocated
|
||||||
|
|
||||||
QScrollBar *QtGetScrollBar( int orientation ) const;
|
QScrollBar *QtGetScrollBar( int orientation ) const;
|
||||||
QScrollBar *QtSetScrollBar( int orientation, QScrollBar *scrollBar=NULL );
|
QScrollBar *QtSetScrollBar( int orientation, QScrollBar *scrollBar=NULL );
|
||||||
|
|
||||||
bool QtSetBackgroundStyle();
|
bool QtSetBackgroundStyle();
|
||||||
|
|
||||||
QPicture *m_qtPicture;
|
QPicture *m_qtPicture; // not owned
|
||||||
QPainter *m_qtPainter;
|
QScopedPointer<QPainter> m_qtPainter; // always allocated
|
||||||
|
|
||||||
bool m_mouseInside;
|
bool m_mouseInside;
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
QList< QShortcut* > *m_qtShortcuts;
|
QScopedPointer< QList<QShortcut*> > m_qtShortcuts; // always allocated
|
||||||
wxQtShortcutHandler *m_qtShortcutHandler;
|
QScopedPointer<wxQtShortcutHandler> m_qtShortcutHandler; // always allocated
|
||||||
bool m_processingShortcut;
|
bool m_processingShortcut;
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
|
@@ -211,14 +211,13 @@ void wxWindowQt::Init()
|
|||||||
m_vertScrollBar = NULL;
|
m_vertScrollBar = NULL;
|
||||||
|
|
||||||
m_qtPicture = NULL;
|
m_qtPicture = NULL;
|
||||||
m_qtPainter = new QPainter();
|
m_qtPainter.reset(new QPainter());
|
||||||
|
|
||||||
m_mouseInside = false;
|
m_mouseInside = false;
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
m_qtShortcutHandler = new wxQtShortcutHandler( this );
|
m_qtShortcutHandler.reset(new wxQtShortcutHandler(this));
|
||||||
m_processingShortcut = false;
|
m_processingShortcut = false;
|
||||||
m_qtShortcuts = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
m_qtWindow = NULL;
|
m_qtWindow = NULL;
|
||||||
m_qtContainer = NULL;
|
m_qtContainer = NULL;
|
||||||
@@ -251,11 +250,14 @@ wxWindowQt::~wxWindowQt()
|
|||||||
|
|
||||||
DestroyChildren(); // This also destroys scrollbars
|
DestroyChildren(); // This also destroys scrollbars
|
||||||
|
|
||||||
delete m_qtPainter;
|
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
m_qtShortcutHandler->deleteLater();
|
if ( m_qtShortcuts )
|
||||||
delete m_qtShortcuts;
|
{
|
||||||
|
for ( int i = 0; i < m_qtShortcuts->size(); ++i )
|
||||||
|
{
|
||||||
|
delete m_qtShortcuts->at(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if wxUSE_DRAG_AND_DROP
|
#if wxUSE_DRAG_AND_DROP
|
||||||
@@ -266,23 +268,8 @@ wxWindowQt::~wxWindowQt()
|
|||||||
if (m_qtWindow)
|
if (m_qtWindow)
|
||||||
{
|
{
|
||||||
wxLogTrace(TRACE_QT_WINDOW, wxT("wxWindow::~wxWindow %s m_qtWindow=%p"), GetName(), m_qtWindow);
|
wxLogTrace(TRACE_QT_WINDOW, wxT("wxWindow::~wxWindow %s m_qtWindow=%p"), GetName(), m_qtWindow);
|
||||||
// Avoid sending further signals (i.e. if deleting the current page)
|
|
||||||
m_qtWindow->blockSignals(true);
|
delete m_qtWindow;
|
||||||
// Reset the pointer to avoid handling pending event and signals
|
|
||||||
QtStoreWindowPointer( GetHandle(), NULL );
|
|
||||||
if ( m_horzScrollBar )
|
|
||||||
{
|
|
||||||
QtStoreWindowPointer( m_horzScrollBar, NULL );
|
|
||||||
m_horzScrollBar->deleteLater();
|
|
||||||
}
|
|
||||||
if ( m_vertScrollBar )
|
|
||||||
{
|
|
||||||
QtStoreWindowPointer( m_vertScrollBar, NULL );
|
|
||||||
m_vertScrollBar->deleteLater();
|
|
||||||
}
|
|
||||||
// Delete QWidget when control return to event loop (safer)
|
|
||||||
m_qtWindow->deleteLater();
|
|
||||||
m_qtWindow = NULL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -622,6 +609,8 @@ QScrollBar *wxWindowQt::QtSetScrollBar( int orientation, QScrollBar *scrollBar )
|
|||||||
|
|
||||||
void wxWindowQt::SetScrollbar( int orientation, int pos, int thumbvisible, int range, bool WXUNUSED(refresh) )
|
void wxWindowQt::SetScrollbar( int orientation, int pos, int thumbvisible, int range, bool WXUNUSED(refresh) )
|
||||||
{
|
{
|
||||||
|
wxCHECK_RET(GetHandle(), "Window has not been created");
|
||||||
|
|
||||||
//If not exist, create the scrollbar
|
//If not exist, create the scrollbar
|
||||||
QScrollBar *scrollBar = QtGetScrollBar( orientation );
|
QScrollBar *scrollBar = QtGetScrollBar( orientation );
|
||||||
if ( scrollBar == NULL )
|
if ( scrollBar == NULL )
|
||||||
@@ -1013,19 +1002,15 @@ void wxWindowQt::SetAcceleratorTable( const wxAcceleratorTable& accel )
|
|||||||
// Disable previously set accelerators
|
// Disable previously set accelerators
|
||||||
while ( !m_qtShortcuts->isEmpty() )
|
while ( !m_qtShortcuts->isEmpty() )
|
||||||
delete m_qtShortcuts->takeFirst();
|
delete m_qtShortcuts->takeFirst();
|
||||||
|
|
||||||
// Create new shortcuts (use GetHandle() so all events inside
|
|
||||||
// the window are handled, not only in the container subwindow)
|
|
||||||
delete m_qtShortcuts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_qtShortcuts = accel.ConvertShortcutTable( GetHandle() );
|
m_qtShortcuts.reset(accel.ConvertShortcutTable(GetHandle()));
|
||||||
|
|
||||||
// Connect shortcuts to window
|
// Connect shortcuts to window
|
||||||
Q_FOREACH( QShortcut *s, *m_qtShortcuts )
|
Q_FOREACH( QShortcut *s, *m_qtShortcuts )
|
||||||
{
|
{
|
||||||
QObject::connect( s, &QShortcut::activated, m_qtShortcutHandler, &wxQtShortcutHandler::activated );
|
QObject::connect( s, &QShortcut::activated, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated );
|
||||||
QObject::connect( s, &QShortcut::activatedAmbiguously, m_qtShortcutHandler, &wxQtShortcutHandler::activated );
|
QObject::connect( s, &QShortcut::activatedAmbiguously, m_qtShortcutHandler.get(), &wxQtShortcutHandler::activated );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
@@ -1191,7 +1176,7 @@ bool wxWindowQt::QtHandlePaintEvent ( QWidget *handler, QPaintEvent *event )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Data from wxClientDC, paint it
|
// Data from wxClientDC, paint it
|
||||||
m_qtPicture->play( m_qtPainter );
|
m_qtPicture->play( m_qtPainter.get() );
|
||||||
// Reset picture
|
// Reset picture
|
||||||
m_qtPicture->setData( NULL, 0 );
|
m_qtPicture->setData( NULL, 0 );
|
||||||
handled = true;
|
handled = true;
|
||||||
@@ -1572,5 +1557,5 @@ void wxWindowQt::QtSetPicture( QPicture* pict )
|
|||||||
|
|
||||||
QPainter *wxWindowQt::QtGetPainter()
|
QPainter *wxWindowQt::QtGetPainter()
|
||||||
{
|
{
|
||||||
return m_qtPainter;
|
return m_qtPainter.get();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user