LazMapViewer: Introduce in TMarkerEditorPlugin FState as statevariable to replace individual flag variables. Unselect only after confirmation.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9702 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2025-03-25 09:51:14 +00:00
parent 0c94a4cd90
commit d9536cca8a

View File

@ -41,7 +41,7 @@ interface
uses
Classes, SysUtils,
Graphics, Controls, Forms, LCLIntf,
Graphics, Controls, LCLIntf, Forms, Dialogs,
mvMapViewer, mvDrawingEngine, mvPluginCommon, mvGPSObj, mvGeoMath, mvTypes;
type
@ -149,6 +149,9 @@ type
TMarkerEditorPlugin = class(TMarkerClickPlugin)
private
type
TPluginStateEnum = (psDragging, psRubberBandMode, psExtendingSelection);
TPluginState = set of TPluginStateEnum;
const
DEFAULT_CLICKMODE = cmSelectPoint;
DEFAULT_RUBBERBAND_BORDERCOLOR = clGray;
@ -162,13 +165,10 @@ type
private
FClickMode: TMarkerClickMode;
FDragCursor: TCursor;
FDragging: Boolean;
FExtendSelection: Boolean;
FNewPointType: TMarkerNewPointType;
FRubberbandBorderColor: TColor;
FRubberbandFillColor: TColor;
FRubberbandOpacity: Single;
FRubberbandMode: Boolean;
FRubberbandStartPt: TPoint;
FRubberbandEndPt: TPoint;
FSelection: TGPSPointList;
@ -177,6 +177,7 @@ type
FShiftToSelectShape: TShiftState;
FShiftToSelectByRubberband: TShiftState;
FShiftToExtendSelection: TShiftState;
FState: TPluginState;
FOrigSelection: array of TRealPoint; // Selection before dragging starts
FOnDrawPoint: TMarkerDrawPointEvent;
FOnNewPoint: TMarkerNewPointEvent;
@ -535,7 +536,7 @@ procedure TMarkerEditorPlugin.AfterDrawObjects(AMapView: TMapView;
begin
inherited;
DrawSelection(AMapView);
if FRubberbandMode then
if (psRubberBandMode in FState) then
DrawRubberband(AMapView);
end;
@ -686,7 +687,7 @@ begin
if not canDrag then exit;
end;
AMapView.Cursor := DragCursor;
FDragging := true;
Include(FState, psDragging);
// Save original selection point coordinates in case they must be restored later.
SetLength(FOrigSelection, FSelection.Count);
for i := 0 to High(FOrigSelection) do
@ -697,7 +698,7 @@ procedure TMarkerEditorPlugin.DragTo(AMapView: TMapView; X, Y: Integer);
var
dX, dY: Integer;
begin
if FDragging then
if (psDragging in FState) then
begin
dX := X - FMousePoint.X;
dY := Y - FMousePoint.Y;
@ -709,7 +710,7 @@ end;
procedure TMarkerEditorPlugin.DragEnd(AMapView: TMapView);
begin
FDragging := false;
Exclude(FState, psDragging);
AMapView.Cursor := FSavedCursor;
if Assigned(FOnEndDrag) then
FOnEndDrag(AMapView);
@ -994,8 +995,12 @@ begin
end else
exit;
FExtendSelection := (AShift * FShiftToExtendSelection = FShiftToExtendSelection);
if FExtendSelection then Shift := Shift + FShiftToExtendSelection;
if (AShift * FShiftToExtendSelection = FShiftToExtendSelection) then
Include(FState, psExtendingSelection)
else
Exclude(FState, psExtendingSelection);
if (psExtendingSelection in FState) then
Shift := Shift + FShiftToExtendSelection;
inherited;
@ -1003,9 +1008,9 @@ begin
begin
case FClickMode of
cmSelectPoint:
AddToSelection(AMapView, FOrigGPSPoint, FExtendSelection);
AddToSelection(AMapView, FOrigGPSPoint, psExtendingSelection in FState);
cmSelectShape:
SelectAllPointsOfShape(AMapView, FOrigGPSPoint, FExtendSelection);
SelectAllPointsOfShape(AMapView, FOrigGPSPoint, psExtendingSelection in FState);
cmTogglePoint:
ToggleSelected(AMapView, FOrigGPSPoint);
end;
@ -1017,13 +1022,18 @@ begin
cmNewPoint:
begin
FOrigGPSPoint := NewPoint(AMapView, X, Y);
AddToSelection(AMapView, FOrigGPSPoint, FExtendSelection);
AddToSelection(AMapView, FOrigGPSPoint, psExtendingSelection in FState);
Handled := true;
end;
cmRubberband:
;
else
FSelection.Clear;
if (FSelection.Count > 0) and
(MessageDlg('Do you really want to unselect these points?', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
begin
FSelection.Clear;
Handled := true;
end;
end;
Update;
end;
@ -1039,24 +1049,21 @@ begin
inherited;
if FMouseDownOnMarker then
begin
if not FDragging then
if not (psDragging in FState) then
begin
// The mouse must be moved by more than SENSITIVITY pixels for dragging to
// start
R := Rect(X - SENSITIVITY, Y - SENSITIVITY, X + SENSITIVITY, Y + SENSITIVITY);
if not PtInRect(R, Point(X, Y)) then
begin
FDragging := false;
exit;
end;
DragStart(AMapView);
end;
DragTo(AMapView, X, Y);
Handled := true;
end else
if not FDragging and (FClickMode = cmRubberband) and IsShiftOfClickMode(AShift, cmRubberband) then
if not (psDragging in FState) and (FClickMode = cmRubberband) and IsShiftOfClickMode(AShift, cmRubberband) then
begin
if not FRubberbandMode then
if not (psRubberbandMode in FState) then
RubberbandStart(AMapView, X, Y)
else
RubberbandTo(AMapView, X, Y);
@ -1069,9 +1076,9 @@ procedure TMarkerEditorPlugin.MouseUp(AMapView: TMapView;
X, Y: Integer; var Handled: Boolean);
begin
inherited;
if FDragging then
if (psDragging in FState) then
DragEnd(AMapView);
if FRubberbandMode then
if (psRubberbandMode in FState) then
RubberbandEnd(AMapView, X, Y);
end;
@ -1110,7 +1117,7 @@ end;
procedure TMarkerEditorPlugin.RubberbandEnd(AMapView: TMapView; X, Y: Integer);
begin
FRubberbandMode := false;
Exclude(FState, psRubberbandMode);
FRubberbandEndPt := Point(X, Y);
SelectInRubberband(AMapview);
Update;
@ -1125,7 +1132,7 @@ end;
procedure TMarkerEditorPlugin.RubberbandStart(AMapView: TMapView; X, Y: Integer);
begin
FRubberbandMode := true;
Include(FState, psRubberbandMode);
FRubberbandStartPt := Point(X, Y);
FRubberbandEndPt := Point(X, Y);
end;
@ -1206,7 +1213,7 @@ var
pts: TGPSObjArray;
i: Integer;
begin
if not FExtendSelection then
if not (psExtendingSelection in FState) then
FSelection.Clear;
R := RubberbandRect;
area.TopLeft := AMapView.ScreenToLatLon(R.TopLeft);
@ -1219,9 +1226,12 @@ end;
procedure TMarkerEditorPlugin.SetExtendSelection(AValue: Boolean);
begin
if FExtendSelection = AValue then exit;
FExtendSelection := AValue;
if (not FExtendSelection) then
if AValue = (psExtendingSelection in FState) then exit;
if AValue then
Include(FState, psExtendingSelection)
else
Exclude(FState, psExtendingSelection);
if not (psExtendingSelection in FState) then
begin
FSelection.Clear;
if (FOrigGPSPoint <> nil) then
@ -1238,7 +1248,7 @@ begin
idx := FSelection.IndexOf(APoint);
if idx = -1 then
begin
if not FExtendSelection then
if not (psExtendingSelection in FState)then
FSelection.Clear;
FSelection.Add(APoint);
end else