From 3d3a47f1907730f021452edfdf144da6d0261742 Mon Sep 17 00:00:00 2001 From: JianjunLiu Date: Tue, 9 Aug 2022 16:30:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化树控件 --- designer/tslvcldesigner.tsf | 12 +++- funcext/tvclib/utslvcltree.tsf | 64 ++++++++++++++++++- .../tvclib/uvcpropertytypespersistence.tsf | 4 +- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/designer/tslvcldesigner.tsf b/designer/tslvcldesigner.tsf index d56e6e4..e1725cb 100644 --- a/designer/tslvcldesigner.tsf +++ b/designer/tslvcldesigner.tsf @@ -1768,6 +1768,7 @@ type TVclDesigner = class(tvcform) @explan(˵Ã÷) ÉèÖõ±Ç°ÀàʹÓõĺ¯ÊýÃû³Æ %% **} FFunctionSelecter.clean(); + FFunctionSelecter.additem("(none)"); for i,vi in v do begin if vi in array("create","destroy","recycling","loadfromtfm") then continue; @@ -7480,7 +7481,14 @@ type TBitmapGrid = class(TGridList) end end +type tnone = class() + function create(); + begin + name := "(none)"; + end + name; +end type TListVariableFilter = class(TListVariable) private FVlist; @@ -7547,7 +7555,7 @@ type TListVariableFilter = class(TListVariable) vs[length(vs)] := vi; end end - additems(vs); + additems(array(new tnone()) union vs); end function create(AOwner);override; begin @@ -7633,7 +7641,7 @@ type TListVariable = class(TGridList) begin id := e.iitem; inherited; - if id<0 then + if id<0 or (SelectedValue is class(tnone)) or (SelectedValue = "(none)") then begin UnSelected(); end diff --git a/funcext/tvclib/utslvcltree.tsf b/funcext/tvclib/utslvcltree.tsf index b0b709d..7adf135 100644 --- a/funcext/tvclib/utslvcltree.tsf +++ b/funcext/tvclib/utslvcltree.tsf @@ -305,6 +305,7 @@ type TcustomTreeCtlNode = class(TVirtualListItem) function Create(AOwner);override; begin inherited; + FVisible := true; FMouseCanChecked := true; FModifyChildrenChecked := true; FFocusColor := array(rgb(230,240,250),rgb(0,192,250)); @@ -509,7 +510,12 @@ type TcustomTreeCtlNode = class(TVirtualListItem) @return(TcustomTreeCtlNode) %% **} 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(); end function InsertNodes(its,idx);virtual; @@ -683,8 +689,11 @@ type TcustomTreeCtlNode = class(TVirtualListItem) for i := 0 to FItems.Count-1 do begin it := FItems[i]; + if it.Visible then //¿É¼û + begin r++; if it.ItemCount and it.Expanded then r += it.GetShowItemCount(); + end end return r; end @@ -698,8 +707,11 @@ type TcustomTreeCtlNode = class(TVirtualListItem) for i := 0 to FItems.Count-1 do begin it := FItems[i]; + if it.Visible then + begin lst union=array(it); if it.ItemCount and it.Expanded then lst union=it.GetShowNodes(); + end end return lst; end @@ -730,6 +742,7 @@ type TcustomTreeCtlNode = class(TVirtualListItem) property ImgId read FImgId write SetImgId; property SelImgId read FSelImgId write SetSelImgId; property ExpandImgId read FExpandImgId write SetExpandImgId; + property Visible read FVisible write SetVisible; property ItemCount read GetItemCount; //½ÚµãÊý property Hierarchy Read FHierarchy; //²ã´Î property Expanded read GetExpanded; //Õ¹¿ª @@ -825,6 +838,55 @@ type TcustomTreeCtlNode = class(TVirtualListItem) FSelImgId := id; 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; FImgId; FMouseCanChecked; diff --git a/funcext/tvclib/uvcpropertytypespersistence.tsf b/funcext/tvclib/uvcpropertytypespersistence.tsf index 5d09f79..a4fc44a 100644 --- a/funcext/tvclib/uvcpropertytypespersistence.tsf +++ b/funcext/tvclib/uvcpropertytypespersistence.tsf @@ -1524,8 +1524,8 @@ type UniObjectMember=class(UniSelProperty) FNameMap := New tstrindexarray(); FValueMap := New tstrindexarray(); FInfoObj := CreateInfoOBJ(); - r := array(); - if not ifobj(FInfoObj)then return array(); + r := array(); + if not ifobj(FInfoObj)then return array(); for i,v in FInfoObj.classinfo()["members"] do begin ni := v["name"];