Qt: correct cast, use TCustomListView instead TListView.

git-svn-id: trunk@46852 -
This commit is contained in:
zeljko 2014-11-15 09:46:32 +00:00
parent eb58ee35fa
commit 1607deedbe
2 changed files with 71 additions and 69 deletions

View File

@ -11378,6 +11378,9 @@ begin
Result := QListWidget_create(Parent);
end;
type
TCustomListViewHack = class(TCustomListView);
procedure TQtListWidget.OwnerDataNeeded(ARect: TRect);
var
R: TRect;
@ -11409,7 +11412,7 @@ begin
TopItem := getRow(Item);
RowHeight := getRowHeight(TopItem);
if (TopItem < 0) or (TopItem > TListView(LCLObject).Items.Count - 1) then
if (TopItem < 0) or (TopItem > TCustomListViewHack(LCLObject).Items.Count - 1) then
exit;
i := 0;
@ -11422,15 +11425,15 @@ begin
TopItem := getRow(Item);
RowHeight := getRowHeight(TopItem);
if (TopItem < 0) or (TopItem > TListView(LCLObject).Items.Count - 1) then
if (TopItem < 0) or (TopItem > TCustomListViewHack(LCLObject).Items.Count - 1) then
break;
if (TListView(LCLObject).Items[TopItem].ImageIndex <> -1) then
if (TCustomListViewHack(LCLObject).Items[TopItem].ImageIndex <> -1) then
begin
// TODO: paint icons and reduce paint overhead by checking icon
end;
WStr := GetUTF8String(TListView(LCLObject).Items[TopItem].Caption);
WStr := GetUTF8String(TCustomListViewHack(LCLObject).Items[TopItem].Caption);
// reduce paint overhead by checking text
v := QVariant_create();
@ -11441,7 +11444,7 @@ begin
DataStr := '';
QVariant_destroy(v);
ASelected := TListView(LCLObject).Items[TopItem].Selected;
ASelected := TCustomListViewHack(LCLObject).Items[TopItem].Selected;
if (DataStr <> WStr) then
begin
@ -13429,7 +13432,7 @@ begin
TopItem := getRow(item);
RowHeight := getRowHeight(TopItem);
if (TopItem < 0) or (TopItem > TListView(LCLObject).Items.Count - 1) then
if (TopItem < 0) or (TopItem > TCustomListViewHack(LCLObject).Items.Count - 1) then
exit;
i := 0;
@ -13443,11 +13446,11 @@ begin
TopItem := getRow(item);
RowHeight := getRowHeight(TopItem);
if (TopItem < 0) or (TopItem > TListView(LCLObject).Items.Count - 1) then
if (TopItem < 0) or (TopItem > TCustomListViewHack(LCLObject).Items.Count - 1) then
continue;
WStr := GetUTF8String(TListView(LCLObject).Items[TopItem].Caption);
ASelected := TListView(LCLObject).Items[TopItem].Selected;
WStr := GetUTF8String(TCustomListViewHack(LCLObject).Items[TopItem].Caption);
ASelected := TCustomListViewHack(LCLObject).Items[TopItem].Selected;
v := QVariant_create(PWideString(@WStr));
try
@ -13457,14 +13460,14 @@ begin
end;
ChildCount := QTreeWidgetItem_childCount(Item);
if ChildCount = TListView(LCLObject).Items[TopItem].SubItems.Count then
if ChildCount = TCustomListViewHack(LCLObject).Items[TopItem].SubItems.Count then
begin
for j := 0 to ChildCount - 1 do
begin
itemChild := QTreeWidgetItem_child(item, j);
if itemChild <> nil then
begin
WStr := GetUTF8String(TListView(LCLObject).Items[TopItem].SubItems[j]);
WStr := GetUTF8String(TCustomListViewHack(LCLObject).Items[TopItem].SubItems[j]);
v := QVariant_create(PWideString(@WStr));
QTreeWidgetItem_setData(itemChild, 0, Ord(QtDisplayRole), v);
QVariant_destroy(v);
@ -13472,9 +13475,9 @@ begin
end;
end else
begin
for j := 0 to TListView(LCLObject).Items[TopItem].SubItems.Count - 1 do
for j := 0 to TCustomListViewHack(LCLObject).Items[TopItem].SubItems.Count - 1 do
begin
WStr := GetUTF8String(TListView(LCLObject).Items[TopItem].SubItems[j]);
WStr := GetUTF8String(TCustomListViewHack(LCLObject).Items[TopItem].SubItems[j]);
v := QVariant_create(PWideString(@WStr));
QTreeWidgetItem_setData(item, j + 1, Ord(QtDisplayRole), v);
QVariant_destroy(v);
@ -14302,7 +14305,7 @@ begin
B := False;
if (ViewStyle = Ord(vsReport)) and (Previous <> nil) then
begin
ListItem := TListView(LCLObject).Selected;
ListItem := TCustomListViewHack(LCLObject).Selected;
if ListItem <> nil then
B := ListItem.Index = AIndex;
end;
@ -14351,7 +14354,7 @@ begin
if (ViewStyle = Ord(vsReport)) and (Current <> nil) and
(Current <> Previous) then
begin
ListItem := TListView(LCLObject).Selected;
ListItem := TCustomListViewHack(LCLObject).Selected;
if ListItem <> nil then
B := ListItem.Index = AIndex;
end;

View File

@ -689,20 +689,19 @@ end;
{ TQtWSCustomListView }
type
TCustomListViewHack = class(TCustomListView);
class function TQtWSCustomListView.IsIconView(const AList: TCustomListView): boolean;
begin
Result := TCustomListViewHack(AList).ViewStyle <> vsReport;
end;
{------------------------------------------------------------------------------
Method: TQtWSCustomListView.CreateHandle
Params: None
Returns: Nothing
------------------------------------------------------------------------------}
class function TQtWSCustomListView.IsIconView(const AList: TCustomListView): boolean;
begin
Result := TListView(AList).ViewStyle <> vsReport;
end;
type
TCustomListViewHack = class(TCustomListView);
class function TQtWSCustomListView.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
var
@ -714,8 +713,8 @@ begin
if IsIconView(TCustomListView(AWinControl)) then
begin
QtListWidget := TQtListWidget.Create(AWinControl, AParams);
QtListWidget.ViewStyle := Ord(TListView(AWinControl).ViewStyle);
if TListView(AWinControl).ViewStyle in [vsIcon, vsSmallIcon] then
QtListWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
if TCustomListViewHack(AWinControl).ViewStyle in [vsIcon, vsSmallIcon] then
begin
// emabarcadero docs says
// vsIcon, vsSmallIcon
@ -742,7 +741,7 @@ begin
end else
begin
QtTreeWidget := TQtTreeWidget.Create(AWinControl, AParams);
QtTreeWidget.ViewStyle := Ord(TListView(AWinControl).ViewStyle);
QtTreeWidget.ViewStyle := Ord(TCustomListViewHack(AWinControl).ViewStyle);
QtTreeWidget.OwnerDrawn := ALV.IsCustomDrawn(dtControl, cdPrePaint) or (ALV.OwnerDraw and
(ALV.ViewStyle = vsReport));
QtTreeWidget.setStretchLastSection(False);
@ -794,10 +793,10 @@ begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
if QtTreeWidget.ColCount <> TListView(ALV).Columns.Count then
QtTreeWidget.ColCount := TListView(ALV).Columns.Count;
if QtTreeWidget.ColCount <> TCustomListViewHack(ALV).Columns.Count then
QtTreeWidget.ColCount := TCustomListViewHack(ALV).Columns.Count;
if (QtTreeWidget.ColCount <= 1) and TListView(ALV).ShowColumnHeaders then
if (QtTreeWidget.ColCount <= 1) and TCustomListViewHack(ALV).ShowColumnHeaders then
QtTreeWidget.setHeaderVisible(True);
TWI := QtTreeWidget.headerItem;
@ -814,7 +813,7 @@ begin
if (csDesigning in ALV.ComponentState) then
exit;
QtTreeWidget.Header.Clickable := TListView(ALV).ColumnClick;
QtTreeWidget.Header.Clickable := TCustomListViewHack(ALV).ColumnClick;
end;
{------------------------------------------------------------------------------
@ -978,13 +977,13 @@ begin
begin
ImgList := TImageList.Create(nil);
try
if (TListView(ALV).ViewStyle = vsIcon) and
Assigned(TListView(ALV).LargeImages) then
ImgList.Assign(TListView(ALV).LargeImages);
if (TCustomListViewHack(ALV).ViewStyle = vsIcon) and
Assigned(TCustomListViewHack(ALV).LargeImages) then
ImgList.Assign(TCustomListViewHack(ALV).LargeImages);
if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TListView(ALV).SmallImages) then
ImgList.Assign(TListView(ALV).SmallImages);
if (TCustomListViewHack(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TCustomListViewHack(ALV).SmallImages) then
ImgList.Assign(TCustomListViewHack(ALV).SmallImages);
if (ImgList.Count > 0) and
((AImageIndex >= 0) and (AImageIndex < ImgList.Count)) then
@ -1273,8 +1272,8 @@ begin
if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then
Exit;
if not Assigned(TListView(ALV).LargeImages) and not
Assigned(TListView(ALV).SmallImages) then
if not Assigned(TCustomListViewHack(ALV).LargeImages) and not
Assigned(TCustomListViewHack(ALV).SmallImages) then
exit;
TWI := nil;
LWI := nil;
@ -1293,13 +1292,13 @@ begin
begin
ImgList := TImageList.Create(nil);
try
if (TListView(ALV).ViewStyle = vsIcon) and
Assigned(TListView(ALV).LargeImages) then
ImgList.Assign(TListView(ALV).LargeImages);
if (TCustomListViewHack(ALV).ViewStyle = vsIcon) and
Assigned(TCustomListViewHack(ALV).LargeImages) then
ImgList.Assign(TCustomListViewHack(ALV).LargeImages);
if (TListView(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TListView(ALV).SmallImages) then
ImgList.Assign(TListView(ALV).SmallImages);
if (TCustomListViewHack(ALV).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TCustomListViewHack(ALV).SmallImages) then
ImgList.Assign(TCustomListViewHack(ALV).SmallImages);
if (ImgList.Count > 0) and
((AImageIndex >= 0) and (AImageIndex < ImgList.Count)) then
@ -1453,7 +1452,7 @@ begin
end;
AAlignment := QtAlignLeft;
if TListView(ALV).Columns.Count > 0 then
if TCustomListViewHack(ALV).Columns.Count > 0 then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[0].Alignment];
if Str <> '' then
@ -1464,7 +1463,7 @@ begin
for i := 0 to AItem.SubItems.Count - 1 do
begin
AAlignment := QtAlignLeft;
if (TListView(ALV).Columns.Count > 0) and (i + 1 < TListView(ALV).Columns.Count) then
if (TCustomListViewHack(ALV).Columns.Count > 0) and (i + 1 < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[i + 1].Alignment];
if AItem.Subitems.Strings[i] <> '' then
begin
@ -1515,7 +1514,7 @@ begin
if ASubIndex >0 Then exit;
QtListWidget := TQtListWidget(ALV.Handle);
AAlignment := QtAlignLeft;
if (TListView(ALV).Columns.Count > 0) and (ASubIndex < TListView(ALV).Columns.Count) then
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment];
QtListWidget.setItemText(AIndex, AText, AAlignment);
end else
@ -1526,7 +1525,7 @@ begin
if TWI <> NiL then
begin
AAlignment := QtAlignLeft;
if (TListView(ALV).Columns.Count > 0) and (ASubIndex < TListView(ALV).Columns.Count) then
if (TCustomListViewHack(ALV).Columns.Count > 0) and (ASubIndex < TCustomListViewHack(ALV).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[ALV.Column[ASubIndex].Alignment];
QtTreeWidget.setItemText(TWI, ASubIndex, Str, AAlignment);
end;
@ -1759,7 +1758,7 @@ begin
Exit;
// according to embarcadero docs this should return
// only for vsList and vsReport
if not (TListView(ALV).ViewStyle in [vsList, vsReport]) then
if not (TCustomListViewHack(ALV).ViewStyle in [vsList, vsReport]) then
exit;
QtItemView := TQtAbstractItemView(ALV.Handle);
Result := QtItemView.getTopItem;
@ -1788,13 +1787,13 @@ begin
QtTreeWidget := TQtTreeWidget(AList.Handle);
ImgList := TImageList.Create(nil);
if (TListView(AList).ViewStyle = vsIcon) and
Assigned(TListView(AList).LargeImages) then
ImgList.Assign(TListView(AList).LargeImages);
if (TCustomListViewHack(AList).ViewStyle = vsIcon) and
Assigned(TCustomListViewHack(AList).LargeImages) then
ImgList.Assign(TCustomListViewHack(AList).LargeImages);
if (TListView(AList).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TListView(AList).SmallImages) then
ImgList.Assign(TListView(AList).SmallImages);
if (TCustomListViewHack(AList).ViewStyle in [vsSmallIcon, vsReport, vsList]) and
Assigned(TCustomListViewHack(AList).SmallImages) then
ImgList.Assign(TCustomListViewHack(AList).SmallImages);
BeginUpdate(AList);
try
@ -1830,8 +1829,8 @@ begin
for j := 0 to AItem.SubItems.Count - 1 do
begin
AAlignment := QtAlignLeft;
if (TListView(AList).Columns.Count > 0) and (j + 1 < TListView(AList).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[TListView(AList).Column[j + 1].Alignment];
if (TCustomListViewHack(AList).Columns.Count > 0) and (j + 1 < TCustomListViewHack(AList).Columns.Count) then
AAlignment := AlignmentToQtAlignmentMap[TCustomListViewHack(AList).Column[j + 1].Alignment];
WStr := GetUtf8String(AItem.Subitems.Strings[j]);
QtTreeWidget.setItemText(Item, j + 1, WStr, AAlignment);
QtTreeWidget.setItemData(Item, j + 1, AItem);
@ -1952,7 +1951,7 @@ var
begin
if not WSCheckHandleAllocated(ALV, 'SetAllocBy') then
Exit;
if TListView(ALV).ViewStyle <> vsReport then
if TCustomListViewHack(ALV).ViewStyle <> vsReport then
begin
NewValue := AValue;
if NewValue < 0 then
@ -2082,8 +2081,8 @@ begin
begin
if not IsIconView(ALV) then
with TQtTreeWidget(ALV.Handle) do
setHeaderVisible(AIsSet and (TListView(ALV).ViewStyle = vsReport)
and (TListView(ALV).Columns.Count > 0) );
setHeaderVisible(AIsSet and (TCustomListViewHack(ALV).ViewStyle = vsReport)
and (TCustomListViewHack(ALV).Columns.Count > 0) );
end;
lvpOwnerDraw: ; // utilized automatically.
lvpReadOnly: QtItemView.setEditTriggers(BoolToEditTriggers[AIsSet]);
@ -2156,8 +2155,8 @@ begin
QtTreeWidget := TQtTreeWidget(ALV.Handle);
ItemViewWidget := QTreeWidgetH(QtTreeWidget.Widget);
with QtTreeWidget do
setHeaderVisible(TListView(ALV).ShowColumnHeaders and (AValue = vsReport)
and (TListView(ALV).Columns.Count > 0) );
setHeaderVisible(TCustomListViewHack(ALV).ShowColumnHeaders and (AValue = vsReport)
and (TCustomListViewHack(ALV).Columns.Count > 0) );
end;
case AValue of
vsIcon:
@ -2165,10 +2164,10 @@ begin
x := GetPixelMetric(QStylePM_IconViewIconSize, nil, ItemViewWidget);
Size.cx := x;
Size.cy := x;
if Assigned(TListView(ALV).LargeImages) then
if Assigned(TCustomListViewHack(ALV).LargeImages) then
begin
Size.cy := TListView(ALV).LargeImages.Height;
Size.cx := TListView(ALV).LargeImages.Width;
Size.cy := TCustomListViewHack(ALV).LargeImages.Height;
Size.cx := TCustomListViewHack(ALV).LargeImages.Width;
end;
end;
vsSmallIcon:
@ -2176,10 +2175,10 @@ begin
x := GetPixelMetric(QStylePM_ListViewIconSize, nil, ItemViewWidget);
Size.cx := x;
Size.cy := x;
if Assigned(TListView(ALV).SmallImages) then
if Assigned(TCustomListViewHack(ALV).SmallImages) then
begin
Size.cy := TListView(ALV).SmallImages.Height;
Size.cx := TListView(ALV).SmallImages.Width;
Size.cy := TCustomListViewHack(ALV).SmallImages.Height;
Size.cx := TCustomListViewHack(ALV).SmallImages.Width;
end;
end;
vsList, vsReport: