(Qt): Fixed few memleaks inside TQtDeviceContext (ifdef-ed for linux only pls. remove those ifdefs and test on Win32&Mac) provoked mostly by SynEdit & Bitmaps. At this moment each SynEdit&Bitmaps leaves 3 unfreed mem blocks because of vBackgroundBrush & vFont creation inside TQtDeviceContext.Create(). All tests maded with heaptrc enabled.

git-svn-id: trunk@11718 -
This commit is contained in:
zeljko 2007-08-02 21:31:58 +00:00
parent 0f906599f6
commit b360405b18

View File

@ -1057,6 +1057,9 @@ end;
Returns: Nothing Returns: Nothing
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
constructor TQtDeviceContext.Create(AWidget: QWidgetH; Const APaintEvent: Boolean = False); constructor TQtDeviceContext.Create(AWidget: QWidgetH; Const APaintEvent: Boolean = False);
var
W: Integer;
H: Integer;
begin begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
WriteLn('TQtDeviceContext.Create ( WidgetHandle: ', dbghex(WidgetHandle), ' FromPaintEvent:',BoolToStr(FromPaintEvent),' )'); WriteLn('TQtDeviceContext.Create ( WidgetHandle: ', dbghex(WidgetHandle), ' FromPaintEvent:',BoolToStr(FromPaintEvent),' )');
@ -1066,7 +1069,8 @@ begin
of TQtWidgetSet.BeginPaint() SET APaintEvent TO FALSE !} of TQtWidgetSet.BeginPaint() SET APaintEvent TO FALSE !}
if AWidget = nil then if AWidget = nil then
begin begin
ParentPixmap := QPixmap_Create(10,10); Parent := nil;
ParentPixmap := QPixmap_Create(10, 10);
Widget := QPainter_Create(QPaintDeviceH(ParentPixmap)); Widget := QPainter_Create(QPaintDeviceH(ParentPixmap));
end end
else else
@ -1074,22 +1078,38 @@ begin
Parent := AWidget; Parent := AWidget;
if not APaintEvent then if not APaintEvent then
begin begin
ParentPixmap := QPixmap_Create(QWidget_width(Parent), QWidget_height(Parent)); {avoid paints on null pixmaps !}
W := QWidget_width(Parent);
H := QWidget_height(Parent);
if W <= 0 then W := 1;
if H <= 0 then H := 1;
ParentPixmap := QPixmap_Create(W, H);
Widget := QPainter_create(QPaintDeviceH(ParentPixmap)); Widget := QPainter_create(QPaintDeviceH(ParentPixmap));
end end
else else
Widget := QPainter_create(QWidget_to_QPaintDevice(Parent)); Widget := QPainter_create(QWidget_to_QPaintDevice(Parent));
end; end;
vBrush := TQtBrush.Create(False);
vBrush.Owner := Self;
vFont := TQtFont.Create(False); vFont := TQtFont.Create(False);
vFont.Owner := Self;; vFont.Owner := Self;
vPen := TQtPen.Create(False);
vPen.Owner := Self; if Parent <> nil then
vRegion := TQtRegion.Create(False); begin
vRegion.Owner := Self; vBrush := TQtBrush.Create(False);
vBrush.Owner := Self;
vPen := TQtPen.Create(False);
vPen.Owner := Self;
vRegion := TQtRegion.Create(False);
vRegion.Owner := Self;
end;
vBackgroundBrush := TQtBrush.Create(False); vBackgroundBrush := TQtBrush.Create(False);
vBackgroundBrush.Owner := Self; vBackgroundBrush.Owner := Self;
vTextColor := ColorToRGB(clWindowText); vTextColor := ColorToRGB(clWindowText);
end; end;
@ -1107,17 +1127,23 @@ begin
if (vClipRect <> nil) then if (vClipRect <> nil) then
dispose(vClipRect); dispose(vClipRect);
vBrush.Widget := nil;
vBrush.Free;
vFont.Widget := nil; vFont.Widget := nil;
vFont.Free; vFont.Free;
vPen.Widget := nil;
vPen.Free; if Parent <> nil then
vRegion.Widget := nil; begin
vRegion.Free; vBrush.Widget := nil;
vBrush.Free;
vPen.Widget := nil;
vPen.Free;
vRegion.Widget := nil;
vRegion.Free;
end;
vBackgroundBrush.Widget := nil; vBackgroundBrush.Widget := nil;
vBackgroundBrush.Free; vBackgroundBrush.Free;
if vImage <> nil then if vImage <> nil then
QImage_destroy(vImage); QImage_destroy(vImage);
@ -1441,8 +1467,12 @@ begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
Write('TQtDeviceContext.font()'); Write('TQtDeviceContext.font()');
{$endif} {$endif}
vFont.Widget := QPainter_font(Widget); {$ifdef linux}
if vFont <> nil then
{$endif}
vFont.Widget := QPainter_font(Widget);
if SelFont=nil then if SelFont=nil then
Result := vFont Result := vFont
else else
@ -1477,7 +1507,12 @@ begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
Write('TQtDeviceContext.brush() '); Write('TQtDeviceContext.brush() ');
{$endif} {$endif}
vBrush.Widget := QPainter_brush(Widget);
{$ifdef linux}
if vBrush <> nil then
{$endif}
vBrush.Widget := QPainter_brush(Widget);
if SelBrush=nil then if SelBrush=nil then
Result := vBrush Result := vBrush
else else
@ -1518,7 +1553,12 @@ begin
{$ifdef VerboseQt} {$ifdef VerboseQt}
Write('TQtDeviceContext.pen() '); Write('TQtDeviceContext.pen() ');
{$endif} {$endif}
vPen.Widget := QPainter_pen(Widget);
{$ifdef linux}
if vPen <> nil then
{$endif}
vPen.Widget := QPainter_pen(Widget);
if SelPen=nil then if SelPen=nil then
Result := vPen Result := vPen
else else