Chart Control V1

This commit is contained in:
Michael Schimmel
2025-07-02 14:49:33 +02:00
parent b453236b1e
commit 58ce84e567
11 changed files with 1746 additions and 256 deletions
+164 -11
View File
@@ -10,6 +10,7 @@ uses
System.Variants,
System.DateUtils,
System.Generics.Collections,
System.Rtti,
FMX.Types,
FMX.Controls,
FMX.Forms,
@@ -33,24 +34,44 @@ uses
Myc.Lazy,
Myc.Signals.FMX,
Myc.TaskManager,
Myc.Aura.Module,
FMX.ListBox,
FMX.Layouts,
FMX.MultiView,
FMX.TreeView;
FMX.TreeView,
FMX.TabControl,
FMX.Menus,
System.ImageList,
FMX.ImgList,
System.Actions,
FMX.ActnList,
TestChartControl;
type
TForm1 = class(TForm)
LogMemo: TMemo;
Panel1: TPanel;
Layout: TFlowLayout;
MainPanel: TPanel;
SymbolsComboBox: TComboBox;
RandomBox: TCheckBox;
LoadButton: TButton;
RandomButton: TButton;
ChartButton: TButton;
StopButton: TButton;
TreeView1: TTreeView;
Splitter1: TSplitter;
ActionList: TActionList;
AddWorkspaceAction: TAction;
WorkspacePanel: TPanel;
TabControl: TTabControl;
ToolBar: TToolBar;
AddWorkspaceButton: TSpeedButton;
ObjectsPanel: TPanel;
ObjectsTabControl: TTabControl;
ModulesTabItem: TTabItem;
TreeView: TTreeView;
TestButton: TSpeedButton;
TestAction: TAction;
SpeedButton1: TSpeedButton;
TestPopup: TPopup;
FlowLayout1: TFlowLayout;
procedure RandomButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
@@ -58,6 +79,10 @@ type
procedure ChartButtonClick(Sender: TObject);
procedure StopButtonClick(Sender: TObject);
procedure LayoutResized(Sender: TObject);
procedure TreeViewDblClick(Sender: TObject);
procedure AddWorkspaceActionExecute(Sender: TObject);
procedure TestActionExecute(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
const
cnt = 20;
@@ -75,10 +100,13 @@ type
FRandom: TList<TRndItem>;
FTerminate: TEvent;
FLoadDone: TState;
FApplication: IAuraApplication;
FModulesItem: TTreeViewItem;
function SelectedSymbol: String;
function SelectedStream: IDataStream<TAskBidItem>;
public
{ Public declarations }
procedure NewWorkspace;
function CurrLayout: TFlowLayout;
published
property OnEvent: TNotifyEvent read FOnEvent write FOnEvent;
end;
@@ -88,15 +116,99 @@ var
implementation
uses
TestModule;
{$R *.fmx}
procedure TForm1.NewWorkspace;
begin
var ws: IAuraWorkspace := TMycAuraWorkspace.Create('New workspace', tmTesting);
FApplication.Workspaces.Insert(-1, ws);
var tab := TabControl.Add;
tab.Text := ws.Caption;
tab.Tag := NativeInt(ws);
var tabBtn := TSpeedButton.Create(Self);
tabBtn.Parent := tab;
tabBtn.Align := TAlignLayout.Right;
var scrollbox := TVertScrollBox.Create(Self);
scrollbox.Parent := tab;
scrollbox.Align := TAlignLayout.Client;
var flow := TFlowLayout.Create(Self);
flow.Parent := tab;
flow.Align := TAlignLayout.Client;
tab.ProcessSignal(ws.Name.Changed, procedure begin tab.Text := ws.Caption; end);
end;
procedure TForm1.StopButtonClick(Sender: TObject);
begin
FTerminate.Notify;
end;
procedure TForm1.TreeViewDblClick(Sender: TObject);
begin
var addnew := false;
var sel := TreeView.Selected as TTreeViewItem;
var parent := sel.ParentItem;
if parent = nil then
exit;
if parent = FModulesItem then
begin
if (TabControl.ActiveTab <> nil) and (TabControl.ActiveTab.Tag <> 0) then
begin
var ws := IAuraWorkspace(TabControl.ActiveTab.Tag);
var module := FApplication.Modules[sel.TagString];
if (ws <> nil) and (module <> nil) then
module.SetupWorkspace(ws);
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FApplication := TMycAuraApplication.Create;
FModulesItem := TTreeViewItem.Create(Self);
FModulesItem.Text := 'Modules';
const modName = 'Test_Module';
FApplication.RegisterModule(modName, TTestModule.Create('Test-Module', 1));
TreeView.AddObject(FModulesItem);
FModulesItem.ProcessSignal(
FApplication.ModuleNames.Changed,
procedure
begin
FModulesItem.BeginUpdate;
try
while FModulesItem.Count > 0 do
FModulesItem[0].Free;
var mods := FApplication.ModuleNames.Value;
for var i := 0 to High(mods) do
begin
var ModItem := TTreeViewItem.Create(Self);
ModItem.Text := mods[i];
ModItem.DragMode := TDragMode.dmAutomatic;
ModItem.Text := 'Module-' + mods[i];
ModItem.TagString := mods[i];
FModulesItem.AddObject(ModItem);
end;
FModulesItem.ExpandAll;
finally
FModulesItem.EndUpdate;
end;
end
);
FTerminate := TEvent.CreateEvent;
FRandom := TList<TRndItem>.Create;
@@ -130,6 +242,8 @@ begin
end;
end
);
NewWorkspace;
end;
procedure TForm1.FormDestroy(Sender: TObject);
@@ -149,6 +263,9 @@ procedure TForm1.LoadButtonClick(Sender: TObject);
begin
if SymbolsComboBox.ItemIndex < 0 then
exit;
var Layout := CurrLayout;
if Layout = nil then
exit;
var Stream := FServer.CreateStream(FSymbols.WaitFor[SymbolsComboBox.ItemIndex]);
var Data := TDataStreamProvider.Create<TAskBidItem>(30000, 10000, Stream);
@@ -181,6 +298,10 @@ end;
procedure TForm1.RandomButtonClick(Sender: TObject);
begin
var Layout := CurrLayout;
if Layout = nil then
exit;
var rnd: TRndItem;
rnd.Stream := FServer.CreateStream(FSymbols.WaitFor[Random(Length(FSymbols.WaitFor))]);
@@ -221,8 +342,22 @@ begin
Proc(FRandom.Count - 1);
end;
procedure TForm1.TestActionExecute(Sender: TObject);
begin
TestPopup.IsOpen := TestAction.Checked;
end;
procedure TForm1.AddWorkspaceActionExecute(Sender: TObject);
begin
NewWorkspace;
end;
procedure TForm1.ChartButtonClick(Sender: TObject);
begin
var Layout := CurrLayout;
if Layout = nil then
exit;
var Symbol := SelectedSymbol;
if Symbol = '' then
exit;
@@ -283,12 +418,25 @@ begin
);
end;
function TForm1.SelectedStream: IDataStream<TAskBidItem>;
function TForm1.CurrLayout: TFlowLayout;
begin
var sym := SelectedSymbol;
if sym = '' then
if TabControl.ActiveTab = nil then
exit(nil);
Result := FServer.CreateStream(sym);
var Res: TFlowLayout := nil;
TabControl.ActiveTab.EnumControls(
function(Control: TControl): TEnumControlsResult
begin
Result := TEnumControlsResult.Continue;
if Control is TFlowLayout then
begin
Res := Control as TFlowLayout;
Result := TEnumControlsResult.Stop;
end;
end
);
Result := Res;
end;
function TForm1.SelectedSymbol: String;
@@ -300,4 +448,9 @@ begin
Result := FSymbols.WaitFor[SymbolsComboBox.ItemIndex];
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
TestChartForm.Visible := true;
end;
end.