-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathChartSelFrm.pas
137 lines (103 loc) · 3.7 KB
/
ChartSelFrm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//This Source Code Form is subject to the terms of the Mozilla Public
//License, v. 2.0. If a copy of the MPL was not distributed with this
//file, You can obtain one at http://mozilla.org/MPL/2.0/.
//Copyright (c) 2013 Alex Shovkoplyas VE3NEA
unit ChartSelFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, VnaResults, CommCtrl, Math;
type
TChartSelectionFrame = class(TFrame)
ListView1: TListView;
procedure ListViewChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
private
TrackChanges: boolean;
FParamGroup: TVnaParamGroup;
procedure SetParamGroup(const Value: TVnaParamGroup);
function GetListViewHeight(Lv: TListView): integer;
public
Selection: TVnaParams;
constructor Create(AOwner: TComponent); override;
procedure PrepareToShow;
function IsParamPlottable(APm: TVnaParam): boolean;
function IsParamSelected(APm: TVnaParam): boolean;
property ParamGroup: TVnaParamGroup read FParamGroup write SetParamGroup;
end;
implementation
uses Main;
{$R *.dfm}
constructor TChartSelectionFrame.Create(AOwner: TComponent);
begin
inherited;
end;
function TChartSelectionFrame.GetListViewHeight(Lv: TListView): integer;
begin
Result := TSmallpoint(ListView_ApproximateViewRect(Lv.Handle, Word(-1), Word(-1), -1)).y;
end;
procedure TChartSelectionFrame.PrepareToShow;
var
Pm: TVnaParam;
Item: TListItem;
begin
TrackChanges := false;
for Pm:=Low(TVnaParam) to High(TVnaParam) do
begin
Item := ListView1.Items.Add;
Item.Caption := ParamInfo[Pm].ParamLabel;
Item.SubItems.Add(ParamInfo[Pm].ParamName);
Item.Data := Pointer(Ord(Pm));
end;
TrackChanges := true;
ListView1.Parent.ClientHeight := GetListViewHeight(ListView1);
end;
function TChartSelectionFrame.IsParamPlottable(APm: TVnaParam): boolean;
begin
Result := (APm in AllowedParamsByGroup[FParamGroup]) and (MainForm.Res.Params[APm] <> nil)
end;
function TChartSelectionFrame.IsParamSelected(APm: TVnaParam): boolean;
begin
Result := IsParamPlottable(APm) and (APm in Selection);
end;
procedure TChartSelectionFrame.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
with ListView1.Canvas.Font do
if IsParamPlottable(TVnaParam(Item.Data))
then begin Color := ListView1.Font.Color; Style := [fsBold]; end
else begin Color := clGrayText; Style := []; end
end;
procedure TChartSelectionFrame.ListViewChange(Sender: TObject; Item: TListItem;
Change: TItemChange);
begin
if Item.Caption = '' then Exit;
if not TrackChanges then Exit;
if Item.Checked
then Selection := Selection + [TVnaParam(Item.Data)]
else Selection := Selection - [TVnaParam(Item.Data)];
MainForm.Chart.ParamsToChart;
end;
procedure TChartSelectionFrame.SetParamGroup(const Value: TVnaParamGroup);
var
i: integer;
begin
FParamGroup := Value;
TrackChanges := false;
Selection := [];
for i:=0 to ListView1.Items.Count-1 do
with ListView1.Items[i] do if Checked
then Include(Selection, TVnaParam(Data));
if (Selection * AllowedParamsByGroup[FParamGroup]) = [] then
begin
Selection := Selection + DefaultParamsByGroup[FParamGroup];
for i:=0 to ListView1.Items.Count-1 do
with ListView1.Items[i] do
if TVnaParam(Data) in Selection then Checked := true;
end;
TrackChanges := true;
ListView1.Invalidate;
end;
end.