Convert ListCommandStats from TSortListView to VirtualTree.

- Make OnInitNode a general procedure by detecting which list was the Sender.
- Add recommended OnFreeNode procedure for all VT's.
This commit is contained in:
Ansgar Becker
2007-08-17 22:25:26 +00:00
parent e1101b1c2f
commit 17cad32f1c
3 changed files with 98 additions and 43 deletions

View File

@ -139,7 +139,7 @@ object MDIChild: TMDIChild
OnGetImageIndex = vstGetImageIndex
OnGetNodeDataSize = vstGetNodeDataSize
OnHeaderClick = vstHeaderClick
OnInitNode = ListVariablesInitNode
OnInitNode = vstInitNode
Columns = <
item
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
@ -216,47 +216,71 @@ object MDIChild: TMDIChild
object tabCommandStats: TTabSheet
Caption = 'Command-Statistics'
ImageIndex = 2
object ListCommandStats: TSortListView
object ListCommandStats: TVirtualStringTree
Left = 0
Top = 0
Width = 488
Height = 175
Align = alClient
Header.AutoSizeIndex = 4
Header.Font.Charset = DEFAULT_CHARSET
Header.Font.Color = clWindowText
Header.Font.Height = -11
Header.Font.Name = 'Tahoma'
Header.Font.Style = []
Header.Height = 20
Header.Options = [hoAutoResize, hoColumnResize, hoDblClickResize, hoDrag, hoShowSortGlyphs, hoVisible]
Header.SortColumn = 1
Header.SortDirection = sdDescending
Header.Style = hsFlatButtons
Images = MainForm.ImageList1
IncrementalSearch = isInitializedOnly
PopupMenu = popupHost
TabOrder = 0
TreeOptions.MiscOptions = [toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning]
TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowVertGridLines, toThemeAware, toUseBlendedImages]
TreeOptions.SelectionOptions = [toFullRowSelect]
OnCompareNodes = vstCompareNodes
OnFreeNode = vstFreeNode
OnGetText = vstGetText
OnGetImageIndex = vstGetImageIndex
OnGetNodeDataSize = vstGetNodeDataSize
OnHeaderClick = vstHeaderClick
OnInitNode = vstInitNode
Columns = <
item
Caption = 'Command-type'
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
Position = 0
Width = 120
WideText = 'Command-type'
end
item
Alignment = taRightJustify
Caption = 'Total count'
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
Position = 1
Width = 100
WideText = 'Total count'
end
item
Alignment = taRightJustify
Caption = 'Average per hour'
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
Position = 2
Width = 100
WideText = 'Average per hour'
end
item
Alignment = taRightJustify
Caption = 'Average per second'
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
Position = 3
Width = 100
WideText = 'Average per second'
end
item
Alignment = taRightJustify
Caption = 'Percentage'
Width = 67
Options = [coAllowClick, coEnabled, coParentBidiMode, coParentColor, coResizable, coShowDropMark, coVisible]
Position = 4
Width = 64
WideText = 'Percentage'
end>
GridLines = True
ReadOnly = True
RowSelect = True
PopupMenu = popupHost
SmallImages = MainForm.ImageList1
SortType = stBoth
TabOrder = 0
ViewStyle = vsReport
ImageIndexSortAsc = 95
ImageIndexSortDesc = 94
end
end
end

View File

@ -266,7 +266,7 @@ type
ManageIndexes1: TMenuItem;
btnTableManageIndexes: TToolButton;
tabCommandStats: TTabSheet;
ListCommandStats: TSortListView;
ListCommandStats: TVirtualStringTree;
CheckBoxDataSearch: TCheckBox;
QF13: TMenuItem;
QF14: TMenuItem;
@ -499,8 +499,9 @@ type
procedure RunAsyncPost(ds: TDeferDataSet);
procedure vstGetNodeDataSize(Sender: TBaseVirtualTree; var
NodeDataSize: Integer);
procedure ListVariablesInitNode(Sender: TBaseVirtualTree; ParentNode, Node:
procedure vstInitNode(Sender: TBaseVirtualTree; ParentNode, Node:
PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure vstFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vstGetImageIndex(Sender: TBaseVirtualTree; Node:
@ -529,7 +530,8 @@ type
UserQueryFired : Boolean;
CachedTableLists : TStringList;
QueryHelpersSelectedItems : Array[0..3] of Integer;
VTRowDataListVariables : Array of TVTreeData;
VTRowDataListVariables,
VTRowDataListCommandStats : Array of TVTreeData;
function GetQueryRunning: Boolean;
procedure SetQueryRunning(running: Boolean);
@ -2546,30 +2548,32 @@ procedure TMDIChild.ShowVariablesAndProcesses(Sender: TObject);
procedure addLVitem( caption: String; commandCount: Int64; totalCount: Int64 );
var
n : TListItem;
i : Integer;
tmpval : Double;
begin
n := ListCommandStats.Items.Add;
n.ImageIndex := 86;
SetLength( VTRowDataListCommandStats, Length(VTRowDataListCommandStats)+1 );
i := Length(VTRowDataListCommandStats)-1;
VTRowDataListCommandStats[i].ImageIndex := 86;
VTRowDataListCommandStats[i].Captions := TStringList.Create;
caption := Copy( caption, 5, Length(caption) );
caption := StringReplace( caption, '_', ' ', [rfReplaceAll] );
n.Caption := caption;
VTRowDataListCommandStats[i].Captions.Add( caption );
// Total Frequency
n.Subitems.Add( FormatNumber( commandCount ) );
VTRowDataListCommandStats[i].Captions.Add( FormatNumber( commandCount ) );
// Average per hour
uptime := max(uptime, 1);
tmpval := commandCount / ( uptime / 60 / 60 );
n.Subitems.Add( FormatNumber( tmpval, 1 ) );
VTRowDataListCommandStats[i].Captions.Add( FormatNumber( tmpval, 1 ) );
// Average per second
tmpval := commandCount / uptime;
n.Subitems.Add( FormatNumber( tmpval, 1 ) );
VTRowDataListCommandStats[i].Captions.Add( FormatNumber( tmpval, 1 ) );
// Percentage. Take care of division by zero errors and Int64's
if commandCount < 1 then
commandCount := 1;
if totalCount < 1 then
totalCount := 1;
tmpval := 100 / totalCount * commandCount;
n.Subitems.Add( FormatNumber( tmpval, 1 ) + ' %' );
VTRowDataListCommandStats[i].Captions.Add( FormatNumber( tmpval, 1 ) + ' %' );
end;
var
@ -2623,8 +2627,8 @@ begin
tabVariables.Caption := 'Variables (' + IntToStr(ListVariables.RootNodeCount) + ')';
// Command-Statistics
ListCommandStats.Items.BeginUpdate;
ListCommandStats.Items.Clear;
ListCommandStats.BeginUpdate;
SetLength( VTRowDataListCommandStats, 0 );
addLVitem( ' All commands', questions, questions );
ds.First;
for i:=1 to ds.RecordCount do
@ -2635,10 +2639,13 @@ begin
end;
ds.Next;
end;
ListCommandStats.Items.EndUpdate;
// Sort 2nd column descending
ListCommandStats.ColClick( ListCommandStats.Columns[1] );
ListCommandStats.ColClick( ListCommandStats.Columns[1] );
// Tell VirtualTree the number of nodes it will display
ListCommandStats.RootNodeCount := Length(VTRowDataListCommandStats);
ListCommandStats.ReinitNode(nil, true);
// Manually invoke sorting
ListCommandStats.SortTree( ListCommandStats.Header.SortColumn, ListCommandStats.Header.SortDirection );
ListCommandStats.EndUpdate;
TimerHostUptime.Enabled := true;
TimerHostUptimeTimer(self);
@ -5899,19 +5906,43 @@ end;
{**
ListVariables initializes its nodes by calling the following procedure
Various lists initialize their nodes by calling the following procedure
once per node
}
procedure TMDIChild.ListVariablesInitNode(Sender: TBaseVirtualTree; ParentNode,
procedure TMDIChild.vstInitNode(Sender: TBaseVirtualTree; ParentNode,
Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
NodeData : PVTreeData;
begin
// Get the pointer to the node data
NodeData := ListVariables.GetNodeData(Node);
NodeData := Sender.GetNodeData(Node);
// Bind data to node
if Sender = ListVariables then
begin
NodeData.Captions := VTRowDataListVariables[Node.Index].Captions;
NodeData.ImageIndex := VTRowDataListVariables[Node.Index].ImageIndex;
end
else if Sender = ListCommandStats then
begin
NodeData.Captions := VTRowDataListCommandStats[Node.Index].Captions;
NodeData.ImageIndex := VTRowDataListCommandStats[Node.Index].ImageIndex;
end;
end;
{**
Free data of a node
}
procedure TMDIChild.vstFreeNode(Sender: TBaseVirtualTree; Node:
PVirtualNode);
var
NodeData : PVTreeData;
begin
// Get the pointer to the node data
NodeData := Sender.GetNodeData(Node);
// Free data
NodeData.Captions.Free;
NodeData.ImageIndex := -1;
end;

View File

@ -76,7 +76,7 @@ begin
0 : case cwin.PageControlHost.ActivePageIndex of
// 0 : begin list := cwin.ListVariables; title := 'Server-Variables for ' + cwin.Conn.MysqlParams.Host; end;
1 : begin list := cwin.ListProcesses; title := 'Processlist for ' + cwin.Conn.MysqlParams.Host; end;
2 : begin list := cwin.ListCommandStats; title := 'Command-statistics for ' + cwin.Conn.MysqlParams.Host; end;
// 2 : begin list := cwin.ListCommandStats; title := 'Command-statistics for ' + cwin.Conn.MysqlParams.Host; end;
end;
1 : begin list := cwin.ListTables; title := 'Tables-List for Database ' + cwin.ActualDatabase; end;
2 : begin list := cwin.ListColumns; title := 'Field-List for ' + cwin.ActualDatabase + '/' + cwin.ActualTable; end;