mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 16:31:40 +02:00
Qt: simplified code in qtwschecklst by using properties Enabled[] and Selected[]
git-svn-id: trunk@33173 -
This commit is contained in:
parent
bec12a3edc
commit
241bbc0b79
@ -1109,8 +1109,10 @@ type
|
||||
FItemTextChangedHook: QListWidget_hookH;
|
||||
FDontPassSelChange: Boolean;
|
||||
function getItemCount: Integer;
|
||||
function GetItemEnabled(AIndex: Integer): Boolean;
|
||||
function GetSelected(AIndex: Integer): Boolean;
|
||||
procedure setItemCount(const AValue: Integer);
|
||||
procedure SetItemEnabled(AIndex: Integer; AValue: Boolean);
|
||||
procedure SetSelected(AIndex: Integer; AValue: Boolean);
|
||||
protected
|
||||
function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
|
||||
@ -1159,6 +1161,7 @@ type
|
||||
procedure ExchangeItems(const AIndex1, AIndex2: Integer);
|
||||
procedure MoveItem(const AFromIndex, AToIndex: Integer);
|
||||
property ItemCount: Integer read getItemCount write setItemCount;
|
||||
property Enabled[AIndex: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
|
||||
property Selected[AIndex: Integer]: Boolean read GetSelected write SetSelected;
|
||||
end;
|
||||
|
||||
@ -9064,6 +9067,16 @@ begin
|
||||
Result := QListWidget_count(QListWidgetH(Widget));
|
||||
end;
|
||||
|
||||
function TQtListWidget.GetItemEnabled(AIndex: Integer): Boolean;
|
||||
var
|
||||
AItem: QListWidgetItemH;
|
||||
begin
|
||||
Result := False;
|
||||
AItem := getItem(AIndex);
|
||||
if Assigned(AItem) then
|
||||
Result := QListWidgetItem_flags(AItem) and QtItemIsEnabled <> 0;
|
||||
end;
|
||||
|
||||
function TQtListWidget.GetSelected(AIndex: Integer): Boolean;
|
||||
var
|
||||
AItem: QListWidgetItemH;
|
||||
@ -9096,6 +9109,23 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtListWidget.SetItemEnabled(AIndex: Integer; AValue: Boolean);
|
||||
var
|
||||
AItem: QListWidgetItemH;
|
||||
Flags: QtItemFlags;
|
||||
begin
|
||||
AItem := getItem(AIndex);
|
||||
if Assigned(AItem) then
|
||||
begin
|
||||
Flags := QListWidgetItem_flags(AItem);
|
||||
if AValue then
|
||||
Flags := Flags or QtItemIsEnabled
|
||||
else
|
||||
Flags := Flags and not QtItemIsEnabled;
|
||||
QListWidgetItem_setFlags(AItem, Flags);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtListWidget.SetSelected(AIndex: Integer; AValue: Boolean);
|
||||
begin
|
||||
if (AIndex >= 0) and (AIndex < RowCount) then
|
||||
|
@ -59,6 +59,7 @@ type
|
||||
|
||||
|
||||
implementation
|
||||
uses WSProc;
|
||||
|
||||
const
|
||||
LCLCheckStateToQtCheckStateMap: array[TCheckBoxState] of QtCheckState =
|
||||
@ -110,13 +111,11 @@ class function TQtWSCustomCheckListBox.GetItemEnabled(
|
||||
const ACheckListBox: TCustomCheckListBox; const AIndex: integer): Boolean;
|
||||
var
|
||||
QtListWidget: TQtCheckListBox;
|
||||
AListWidget: QListWidgetH;
|
||||
AItem: QListWidgetItemH;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACheckListBox, 'GetItemEnabled') then
|
||||
Exit;
|
||||
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
|
||||
AListWidget := QListWidgetH(QtListWidget.Widget);
|
||||
AItem := QListWidget_item(AListWidget, AIndex);
|
||||
Result := (QListWidgetItem_flags(AItem) and QtItemIsEnabled) <> 0;
|
||||
Result := QtListWidget.Enabled[AIndex];
|
||||
end;
|
||||
|
||||
class function TQtWSCustomCheckListBox.GetState(
|
||||
@ -124,13 +123,11 @@ class function TQtWSCustomCheckListBox.GetState(
|
||||
): TCheckBoxState;
|
||||
var
|
||||
QtListWidget: TQtCheckListBox;
|
||||
AListWidget: QListWidgetH;
|
||||
AItem: QListWidgetItemH;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACheckListBox, 'GetState') then
|
||||
Exit;
|
||||
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
|
||||
AListWidget := QListWidgetH(QtListWidget.Widget);
|
||||
AItem := QListWidget_item(AListWidget, AIndex);
|
||||
Result := QtCheckStateToLCLCheckStateMap[QListWidgetItem_checkState(AItem)];
|
||||
Result := QtCheckStateToLCLCheckStateMap[QtListWidget.ItemCheckState[AIndex]];
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomCheckListBox.SetItemEnabled(
|
||||
@ -138,19 +135,11 @@ class procedure TQtWSCustomCheckListBox.SetItemEnabled(
|
||||
const AEnabled: Boolean);
|
||||
var
|
||||
QtListWidget: TQtCheckListBox;
|
||||
AListWidget: QListWidgetH;
|
||||
AItem: QListWidgetItemH;
|
||||
Flags: QtItemFlags;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACheckListBox, 'SetItemEnabled') then
|
||||
Exit;
|
||||
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
|
||||
AListWidget := QListWidgetH(QtListWidget.Widget);
|
||||
AItem := QListWidget_item(AListWidget, AIndex);
|
||||
Flags := QListWidgetItem_flags(AItem);
|
||||
if AEnabled then
|
||||
Flags := Flags or QtItemIsEnabled
|
||||
else
|
||||
Flags := Flags and not QtItemIsEnabled;
|
||||
QListWidgetItem_setFlags(AItem, Flags);
|
||||
QtListWidget.Enabled[AIndex] := AEnabled;
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomCheckListBox.SetState(
|
||||
@ -158,14 +147,12 @@ class procedure TQtWSCustomCheckListBox.SetState(
|
||||
const AState: TCheckBoxState);
|
||||
var
|
||||
QtListWidget: TQtCheckListBox;
|
||||
AListWidget: QListWidgetH;
|
||||
AItem: QListWidgetItemH;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACheckListBox, 'SetState') then
|
||||
Exit;
|
||||
QtListWidget := TQtCheckListBox(ACheckListBox.Handle);
|
||||
AListWidget := QListWidgetH(QtListWidget.Widget);
|
||||
AItem := QListWidget_item(AListWidget, AIndex);
|
||||
QtListWidget.BeginUpdate;
|
||||
QListWidgetItem_setCheckState(AItem, LCLCheckStateToQtCheckStateMap[AState]);
|
||||
QtListWidget.ItemCheckState[AIndex] := LCLCheckStateToQtCheckStateMap[AState];
|
||||
QtListWidget.EndUpdate;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user