界面库

优化树控件
This commit is contained in:
JianjunLiu 2022-08-09 16:30:11 +08:00
parent 146101a46f
commit 3d3a47f190
3 changed files with 75 additions and 5 deletions

View File

@ -1768,6 +1768,7 @@ type TVclDesigner = class(tvcform)
@explan(说明) 设置当前类使用的函数名称 %% @explan(说明) 设置当前类使用的函数名称 %%
**} **}
FFunctionSelecter.clean(); FFunctionSelecter.clean();
FFunctionSelecter.additem("(none)");
for i,vi in v do for i,vi in v do
begin begin
if vi in array("create","destroy","recycling","loadfromtfm") then continue; if vi in array("create","destroy","recycling","loadfromtfm") then continue;
@ -7480,7 +7481,14 @@ type TBitmapGrid = class(TGridList)
end end
end end
type tnone = class()
function create();
begin
name := "(none)";
end
name;
end
type TListVariableFilter = class(TListVariable) type TListVariableFilter = class(TListVariable)
private private
FVlist; FVlist;
@ -7547,7 +7555,7 @@ type TListVariableFilter = class(TListVariable)
vs[length(vs)] := vi; vs[length(vs)] := vi;
end end
end end
additems(vs); additems(array(new tnone()) union vs);
end end
function create(AOwner);override; function create(AOwner);override;
begin begin
@ -7633,7 +7641,7 @@ type TListVariable = class(TGridList)
begin begin
id := e.iitem; id := e.iitem;
inherited; inherited;
if id<0 then if id<0 or (SelectedValue is class(tnone)) or (SelectedValue = "(none)") then
begin begin
UnSelected(); UnSelected();
end end

View File

@ -305,6 +305,7 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
function Create(AOwner);override; function Create(AOwner);override;
begin begin
inherited; inherited;
FVisible := true;
FMouseCanChecked := true; FMouseCanChecked := true;
FModifyChildrenChecked := true; FModifyChildrenChecked := true;
FFocusColor := array(rgb(230,240,250),rgb(0,192,250)); FFocusColor := array(rgb(230,240,250),rgb(0,192,250));
@ -509,7 +510,12 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
@return(TcustomTreeCtlNode) %% @return(TcustomTreeCtlNode) %%
**} **}
if FItems.Count<1 or not(FExpanded)then return self; if FItems.Count<1 or not(FExpanded)then return self;
it := FItems[FItems.Count-1]; for i := FItems.Count-1 downto 0 do
begin
it := FItems[i];
if it.Visible then return it.GetLastShowNode();
end
return self;
return it.GetLastShowNode(); return it.GetLastShowNode();
end end
function InsertNodes(its,idx);virtual; function InsertNodes(its,idx);virtual;
@ -683,9 +689,12 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
for i := 0 to FItems.Count-1 do for i := 0 to FItems.Count-1 do
begin begin
it := FItems[i]; it := FItems[i];
if it.Visible then //可见
begin
r++; r++;
if it.ItemCount and it.Expanded then r += it.GetShowItemCount(); if it.ItemCount and it.Expanded then r += it.GetShowItemCount();
end end
end
return r; return r;
end end
function GetShowNodes(); function GetShowNodes();
@ -698,9 +707,12 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
for i := 0 to FItems.Count-1 do for i := 0 to FItems.Count-1 do
begin begin
it := FItems[i]; it := FItems[i];
if it.Visible then
begin
lst union=array(it); lst union=array(it);
if it.ItemCount and it.Expanded then lst union=it.GetShowNodes(); if it.ItemCount and it.Expanded then lst union=it.GetShowNodes();
end end
end
return lst; return lst;
end end
function toarray();virtual; function toarray();virtual;
@ -730,6 +742,7 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
property ImgId read FImgId write SetImgId; property ImgId read FImgId write SetImgId;
property SelImgId read FSelImgId write SetSelImgId; property SelImgId read FSelImgId write SetSelImgId;
property ExpandImgId read FExpandImgId write SetExpandImgId; property ExpandImgId read FExpandImgId write SetExpandImgId;
property Visible read FVisible write SetVisible;
property ItemCount read GetItemCount; //½ÚµãÊý property ItemCount read GetItemCount; //½ÚµãÊý
property Hierarchy Read FHierarchy; //²ã´Î property Hierarchy Read FHierarchy; //²ã´Î
property Expanded read GetExpanded; //Õ¹¿ª property Expanded read GetExpanded; //Õ¹¿ª
@ -825,6 +838,55 @@ type TcustomTreeCtlNode = class(TVirtualListItem)
FSelImgId := id; FSelImgId := id;
end end
end end
function SetVisible(v); //可见设置
begin
if Owner.RootNode = self then return ;
nv := v?true:false;
if nv<>FVisible then
begin
FVisible := nv;
p := Parent;
if not p then return ; //无父节点
if p<>Owner.RootNode then //非根节点
begin
if not Owner.NodeInList(p) then return 0;// 不在列表中
if not p.Expanded then return 0; //非展开
pidx := Owner.GetItemIndex(p); //获得位置
end else //根节点
begin
pidx := -1;
end
UnExpand(); //折叠
if nv then //变得可见
begin
cidx := p.GetShowNodeidx(self);
idx := pidx+cidx+1;
Owner.InsertItem(self(true),idx);
end else //变得不可见
begin
idx := Owner.GetItemIndex(self);
owner.DeleteItemByBounds(idx,idx);
end
end
end
function GetShowNodeidx(nd); //获得子节点在父节点后面的序号
begin
idx := 0;
for i := 0 to FItems.Count-1 do
begin
it := FItems[i];
if it = nd then return idx;
if it.Visible then
begin
idx++;
if it.ItemCount and it.Expanded then
idx += it.GetShowNodeidx(0);
end
end
return idx;
end
FVisible;
FDirtype; FDirtype;
FImgId; FImgId;
FMouseCanChecked; FMouseCanChecked;