Qt: optimisation: save few kbs by adding checkable property to TQtListWidget instead of checking for TCheckListBox class

git-svn-id: trunk@23663 -
This commit is contained in:
zeljko 2010-02-08 16:38:53 +00:00
parent f091ac2f5d
commit fd8aec52d9
2 changed files with 38 additions and 2 deletions

View File

@ -911,6 +911,7 @@ type
TQtListWidget = class(TQtListView)
private
FCheckable: boolean;
FCurrentItemChangeHook: QListWidget_hookH;
FSelectionChangeHook: QListWidget_hookH;
FItemClickedHook: QListWidget_hookH;
@ -940,6 +941,7 @@ type
procedure scrollToItem(row: integer; hint: QAbstractItemViewScrollHint);
procedure removeItem(AIndex: Integer);
procedure exchangeItems(AIndex1, AIndex2: Integer);
property Checkable: boolean read FCheckable write FCheckable;
end;
{ TQtHeaderView }
@ -7061,6 +7063,7 @@ end;
function TQtListWidget.CreateWidget(const AParams: TCreateParams): QWidgetH;
begin
FCheckable := False;
FDontPassSelChange := False;
Result := QListWidget_create();
QWidget_setAttribute(Result, QtWA_NoMousePropagation);
@ -7125,7 +7128,7 @@ begin
QEventMouseButtonRelease,
QEventMouseButtonDblClick:
begin
if (LCLObject.ClassType = TCheckListBox) and
if (Checkable) and
(QEvent_type(Event) <> QEventMouseButtonDblClick) and
(QMouseEvent_button(QMouseEventH(Event)) = QtLeftButton) then
begin
@ -7212,7 +7215,7 @@ begin
{$ifdef VerboseQt}
WriteLn('TQtListWidget.signalItemClicked');
{$endif}
if LCLObject.ClassType = TCheckListBox then
if Checkable then
begin
FillChar(Msg, SizeOf(Msg), #0);
Msg.Msg := LM_CHANGED;

View File

@ -45,6 +45,8 @@ type
TQtWSCustomCheckListBox = class(TWSCustomCheckListBox)
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetItemEnabled(const ACheckListBox: TCustomCheckListBox;
const AIndex: integer): Boolean; override;
class function GetState(const ACheckListBox: TCustomCheckListBox;
@ -73,6 +75,37 @@ const
{QtChecked } cbChecked
);
class function TQtWSCustomCheckListBox.CreateHandle(
const AWinControl: TWinControl; const AParams: TCreateParams
): TLCLIntfHandle;
var
QtListWidget: TQtListWidget;
SelMode: QAbstractItemViewSelectionMode;
begin
QtListWidget := TQtListWidget.Create(AWinControl, AParams);
QtListWidget.Checkable := True;
if TCheckListBox(AWinControl).MultiSelect then
if TCheckListBox(AWinControl).ExtendedSelect then
SelMode := QAbstractItemViewExtendedSelection
else
SelMode := QAbstractItemViewMultiSelection
else
SelMode := QAbstractItemViewSingleSelection;
QtListWidget.setSelectionMode(SelMode);
QtListWidget.AttachEvents;
// create our FList helper
QtListWidget.FList := TQtListStrings.Create(QtListWidget);
QtListWidget.OwnerDrawn := TCheckListBox(AWinControl).Style in [lbOwnerDrawFixed, lbOwnerDrawVariable];
Result := TLCLIntfHandle(QtListWidget);
end;
class function TQtWSCustomCheckListBox.GetItemEnabled(
const ACheckListBox: TCustomCheckListBox; const AIndex: integer): Boolean;
var