prevent creating timers in each widget and use at one instead of two

This commit is contained in:
Basile Burg 2019-02-08 22:11:09 +01:00
parent 3f343fe634
commit 0f04a66e63
8 changed files with 66 additions and 23 deletions

View File

@ -881,6 +881,10 @@
</CompilerMessages>
<CustomOptions Value="-dRELEASE
-dGTK_REMOVE_CLIPBOARD_NULL"/>
<OtherDefines Count="2">
<Define0 Value="RELEASE"/>
<Define1 Value="GTK_REMOVE_CLIPBOARD_NULL"/>
</OtherDefines>
</Other>
</CompilerOptions>
<Debugging>

View File

@ -435,6 +435,8 @@ begin
EntitiesConnector.addObserver(self);
EntitiesConnector.addSingleService(self);
timedUpdateKind := tukDelay;
fOptions:= TPagesOptions.construct(self);
end;

View File

@ -12,7 +12,6 @@ object MainForm: TMainForm
OnResize = FormResize
OnWindowStateChange = FormWindowStateChange
ShowHint = True
LCLVersion = '2.0.0.4'
object mainMenu: TMainMenu
top = 1
object MenuItem1: TMenuItem

View File

@ -335,9 +335,9 @@ begin
widg.fAutoDemangle:=fAutoDemangle;
widg.fAlwaysFilter:=fAlwaysFilter;
if fFastDisplay then
widg.updaterByLoopInterval:= 70
widg.timedUpdateKind := tukLoop
else
widg.updaterByLoopInterval:= 0;
widg.timedUpdateKind := tukNone;
end
else inherited;
end;

View File

@ -178,6 +178,8 @@ begin
end;
end;
timedUpdateKind := tukDelay;
EntitiesConnector.addObserver(self);
end;

View File

@ -441,6 +441,8 @@ begin
Tree.OnDblClick := @TreeDblClick;
Tree.PopupMenu := contextMenu;
timedUpdateKind := tukDelay;
EntitiesConnector.addObserver(self);
end;

View File

@ -9,7 +9,6 @@ object DexedWidget: TDexedWidget
ClientWidth = 332
ShowHint = True
ShowInTaskBar = stNever
LCLVersion = '2.0.0.3'
object Back: TPanel
Left = 0
Height = 121

View File

@ -10,6 +10,15 @@ uses
type
TTimedUpdateKind = (
// update timer is diabled.
tukNone,
// update timer update only one time, if required, and after a delay
tukDelay,
// update tiemr update periodically
tukLoop
);
(**
* Base type for an UI module.
*)
@ -37,15 +46,16 @@ type
fUpdating: boolean;
fDelayDur: Integer;
fLoopInter: Integer;
fUpdaterAuto: TTimer;
fUpdaterDelay: TTimer;
fUpdateTimer: TTimer;
fImperativeUpdateCount: Integer;
fLoopUpdateCount: Integer;
fOnDockingChanged: TWidgetDockingChangedEvent;
fTimerUpdateKind: TTimedUpdateKind;
procedure setDelayDur(value: Integer);
procedure setLoopInt(value: Integer);
procedure updaterAutoProc(Sender: TObject);
procedure updaterLatchProc(Sender: TObject);
procedure setTimerUpdateKind(value: TTimedUpdateKind);
protected
fIsDockable: boolean;
fIsModal: boolean;
@ -99,6 +109,8 @@ type
procedure showWidget;
// set if the update based on a timer is enabled.
property timedUpdateKind: TTimedUpdateKind read fTimerUpdateKind write setTimerUpdateKind;
// returns true if one of the three updater is processing.
property updating: boolean read fUpdating;
// true by default, allow a widget to be docked.
@ -149,10 +161,6 @@ begin
inherited;
fToolBarVisible := true;
fIsDockable := true;
fUpdaterAuto := TTimer.Create(self);
fUpdaterAuto.Interval := 0;
fUpdaterAuto.OnTimer := @updaterAutoProc;
fUpdaterDelay := TTimer.Create(self);
updaterByLoopInterval := 70;
updaterByDelayDuration := 500;
@ -170,6 +178,7 @@ end;
destructor TDexedWidget.destroy;
begin
fUpdateTimer.Free;
EntitiesConnector.removeObserver(self);
inherited;
end;
@ -271,6 +280,35 @@ end;
{$ENDREGION}
{$REGION Updaters---------------------------------------------------------------}
procedure TDexedWidget.setTimerUpdateKind(value: TTimedUpdateKind);
begin
if fTimerUpdateKind = value then
exit;
fTimerUpdateKind := value;
if fTimerUpdateKind = tukNone then
begin
if fUpdateTimer.isNil then
exit;
FreeAndNil(fUpdateTimer);
end
else
begin
if fUpdateTimer.isNotNil then
exit;
fUpdateTimer := TTimer.Create(nil);
if fTimerUpdateKind = tukDelay then
begin
fUpdateTimer.Enabled := false;
fUpdateTimer.OnTimer := @updaterAutoProc;
fUpdateTimer.Interval:= fDelayDur;
end
else begin
fUpdateTimer.Enabled := true;
fUpdateTimer.Interval:= fLoopInter;
end;
end;
end;
procedure TDexedWidget.setDelayDur(value: Integer);
begin
if value < 100 then
@ -278,7 +316,8 @@ begin
if fDelayDur = value then
exit;
fDelayDur := value;
fUpdaterDelay.Interval := fDelayDur;
if fUpdateTimer.isNotNil and (fTimerUpdateKind = tukDelay) then
fUpdateTimer.Interval := fDelayDur;
end;
procedure TDexedWidget.setLoopInt(value: Integer);
@ -286,13 +325,8 @@ begin
if fLoopInter = value then
exit;
fLoopInter := value;
fUpdaterAuto.Interval := fLoopInter;
if value = 0 then
begin
fUpdaterAuto.Enabled:= false;
fLoopUpdateCount := 0;
end
else fUpdaterAuto.Enabled:= true;
if fUpdateTimer.isNotNil and (fTimerUpdateKind = tukLoop) then
fUpdateTimer.Interval := fLoopInter;
end;
procedure TDexedWidget.IncLoopUpdate;
@ -326,14 +360,14 @@ end;
procedure TDexedWidget.beginDelayedUpdate;
begin
fUpdaterDelay.Enabled := false;
fUpdaterDelay.Enabled := true;
fUpdaterDelay.OnTimer := @updaterLatchProc;
fUpdateTimer.OnTimer := @updaterLatchProc;
fUpdateTimer.Enabled := true;
end;
procedure TDexedWidget.stopDelayedUpdate;
begin
fUpdaterDelay.OnTimer := nil;
fUpdateTimer.OnTimer := nil;
fUpdateTimer.Enabled := false;
end;
procedure TDexedWidget.forceDelayedUpdate;
@ -355,7 +389,8 @@ begin
fUpdating := true;
updateDelayed;
fUpdating := false;
fUpdaterDelay.OnTimer := nil;
fUpdateTimer.OnTimer := nil;
fUpdateTimer.Enabled:=false;
end;
procedure TDexedWidget.updateLoop;