{********************************************}
{ TeeChart Exp.Average Function Editor       }
{ Copyright (c) 2002-2020 by Steema Software }
{    All Rights Reserved                     }
{********************************************}
unit TeeExpAveFuncEdit;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,

  StatChar, TeeBaseFuncEdit, TeCanvas, TeEngine, TeeProcs, ExtCtrls;

type
  TExpAveFuncEditor = class(TBaseFunctionEditor)
    Label1: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    CBAlign: TComboFlat;
    procedure Edit1Change(Sender: TObject);
    procedure CBAlignChange(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure ApplyFormChanges; override;
    procedure SetFunction; override;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.dfm}
{$ELSE}
{$R *.lfm}
{$ENDIF}

procedure TExpAveFuncEditor.Edit1Change(Sender: TObject);
begin
  EnableApply;
end;

procedure TExpAveFuncEditor.SetFunction;
begin
  inherited;

  Edit1.Text:=FloatToStr(TExpAverageFunction(IFunction).Weight);
  CBAlign.ItemIndex:=Ord(IFunction.PeriodAlign);
end;

procedure TExpAveFuncEditor.ApplyFormChanges;
begin
  inherited;

  with TExpAverageFunction(IFunction) do
  begin
    BeginUpdate;
    try
      Weight:=StrToFloat(Edit1.Text);
      PeriodAlign:=TFunctionPeriodAlign(CBAlign.ItemIndex);
    finally
      EndUpdate;
    end;
  end;
end;

procedure TExpAveFuncEditor.CBAlignChange(Sender: TObject);
begin
  EnableApply;
end;

initialization
  RegisterClass(TExpAveFuncEditor);
end.
