{********************************************}
{ TeeChart Pro Charting Library              }
{ TSubsetTeeFunction editor dialog.          }
{                                            }
{ Copyright (c) 1995-2020 by Steema Software }
{ All Rights Reserved                        }
{********************************************}
unit TeeSubsetEditor;
{$I TeeDefs.inc}

interface

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

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

  TeEngine, TeCanvas, TeeProcs, TeeBaseFuncEdit, TeeFunci, ExtCtrls;

type
  TSubsetFuncEditor = class(TBaseFunctionEditor)
    Label1: TLabel;
    EStart: TEdit;
    Label2: TLabel;
    EEnd: TEdit;
    Label3: TLabel;
    CBValues: TComboFlat;
    procedure EStartChange(Sender: TObject);
    procedure EEndChange(Sender: TObject);
    procedure CBValuesChange(Sender: TObject);
  private
    { Private declarations }
    Function Series:TChartSeries;
  protected
    procedure ApplyFormChanges; override;
    Procedure SetFunction; override;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeeConst, Chart, TeeFuncEdit;

Procedure TSubsetFuncEditor.SetFunction;
var t : Integer;
begin
  inherited;

  with TSubsetTeeFunction(IFunction) do
  begin
    EStart.Text:=FloatToStr(StartValue);
    EEnd.Text:=FloatToStr(EndValue);

    TTeeFuncEditor.SetValueListCombo(Series,CBValues);
  end;

  if Series<>nil then
  with Series do
  for t:=0 to ValuesList.Count-1 do
      CBValues.Items.AddObject(ValuesList[t].Name,ValuesList[t]);

  CBValues.ItemIndex:=0;
  CBValuesChange(Self);
end;

Function TSubsetFuncEditor.Series:TChartSeries;
begin
  if Owner is TTeeFuncEditor then
     result:=TTeeFuncEditor(Owner).TheSeries
  else
     result:=nil;
end;

procedure TSubsetFuncEditor.ApplyFormChanges;
begin
  inherited;

  with TSubsetTeeFunction(IFunction) do
  begin
    BeginUpdate;
    try
      StartValue:=StrToFloat(EStart.Text);
      EndValue:=StrToFloat(EEnd.Text);
      Series.MandatoryValueList.ValueSource:=CBValues.Text;
    finally
      EndUpdate;
    end;
  end;
end;

procedure TSubsetFuncEditor.EStartChange(Sender: TObject);
begin
  EnableApply;
end;

procedure TSubsetFuncEditor.EEndChange(Sender: TObject);
begin
  EnableApply;
end;

procedure TSubsetFuncEditor.CBValuesChange(Sender: TObject);
var tmpList : TChartValueList;
begin
  if (Series<>nil) and (Series.MandatoryValueList.ValueSource='') then
  begin
    tmpList:=TChartValueList(CBValues.SelectedObject);

    EStart.Text:=FloatToStr(tmpList.MinValue);
    EEnd.Text:=FloatToStr(tmpList.MaxValue);
  end;

  EnableApply;
end;

initialization
  RegisterClass(TSubsetFuncEditor);
end.
