Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correção na aplicação de estilos que não identificava componentes de … #10

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Bind4Delphi.dpk
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ contains
Bind4D.Component.Mock in 'src\Bind4D.Component.Mock.pas',
Bind4D.Rest in 'src\Bind4D.Rest.pas',
Bind4D.Forms.QuickRegistration in 'src\Forms\Bind4D.Forms.QuickRegistration.pas',
Bind4D.Component.Styles in 'src\Bind4D.Component.Styles.pas';
Bind4D.Component.Styles in 'src\Bind4D.Component.Styles.pas',
Bind4D.Component.ListBox in 'src\Bind4D.Component.ListBox.pas',
Bind4D.Component.CheckListBox in 'src\Bind4D.Component.CheckListBox.pas';

end.
154 changes: 154 additions & 0 deletions src/Bind4D.Component.CheckListBox.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
unit Bind4D.Component.CheckListBox;

interface

uses
Bind4D.Component.Interfaces,
Bind4D.Attributes,
Vcl.CheckLst;

Type
TBind4DComponentCheckListBox = class(TInterfacedObject, iBind4DComponent)
private
FComponent : TCheckListBox;
FAttributes : iBind4DComponentAttributes;
public
constructor Create(aValue : TCheckListBox);
destructor Destroy; override;
class function New(aValue : TCheckListBox) : iBind4DComponent;
function Attributes : iBind4DComponentAttributes;
function AdjusteResponsivity : iBind4DComponent;
function ApplyStyles : iBind4DComponent;
function ApplyText : iBind4DComponent;
function ApplyImage : iBind4DComponent;
function ApplyValue : iBind4DComponent;
function ApplyRestData : iBind4DComponent;
function Clear : iBind4DComponent;
function FormatFieldGrid (aAttr : FieldDataSetBind) : iBind4DComponent;
function GetValueString : String;
function GetCaption : String;
end;

implementation

uses
System.Classes,
System.Variants,
Vcl.StdCtrls,
Bind4D.Component.Attributes,
System.JSON;

{ TBind4DComponentCheckListBox }

function TBind4DComponentCheckListBox.AdjusteResponsivity: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentCheckListBox.ApplyImage: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentCheckListBox.ApplyRestData: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentCheckListBox.ApplyStyles: iBind4DComponent;
begin
Result := Self;
FComponent.StyleElements := FAttributes.StyleSettings;
FComponent.Color := FAttributes.Color;
FComponent.Font.Color := FAttributes.FontColor;
FComponent.Font.Name := FAttributes.FontName;
FComponent.Font.Size := FAttributes.FontSize;
end;

function TBind4DComponentCheckListBox.ApplyText: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentCheckListBox.ApplyValue: iBind4DComponent;
var
JsonArray : TJsonArray;
ListIndex : Integer;
begin
if VarIsNull(FAttributes.ValueVariant) then
exit;

JsonArray := TJSONObject.ParseJSONValue(FAttributes.ValueVariant) as TJSONArray;
if not Assigned(JsonArray) then
exit;

try
for var JsonItem in JsonArray do
begin
ListIndex := FComponent.Items.IndexOf(JsonItem.Value);
if ListIndex > -1 then
FComponent.Checked[ListIndex] := true;
end;
finally
JsonArray.Free;
end;
end;

function TBind4DComponentCheckListBox.Attributes: iBind4DComponentAttributes;
begin
Result := FAttributes;
end;

function TBind4DComponentCheckListBox.Clear: iBind4DComponent;
begin
Result := Self;
FComponent.CheckAll(cbUnchecked, true, true);
end;

constructor TBind4DComponentCheckListBox.Create(aValue : TCheckListBox);
begin
FAttributes := TBind4DComponentAttributes.Create(Self);
FComponent := aValue;
end;

destructor TBind4DComponentCheckListBox.Destroy;
begin

inherited;
end;

function TBind4DComponentCheckListBox.FormatFieldGrid(
aAttr: FieldDataSetBind): iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentCheckListBox.GetCaption: String;
begin
Result := '';
end;

function TBind4DComponentCheckListBox.GetValueString: String;
var
JsonArray : TJsonArray;
I : Integer;
begin
JsonArray := TJsonArray.Create;
try
for I := 0 to Pred(FComponent.Count) do
begin
if FComponent.Checked[I] then
JsonArray.Add(FComponent.Items[I]);
end;
Result := JsonArray.ToString;
finally
JsonArray.Free;
end;
end;

class function TBind4DComponentCheckListBox.New (aValue : TCheckListBox) : iBind4DComponent;
begin
Result := Self.Create(aValue);
end;

end.
2 changes: 1 addition & 1 deletion src/Bind4D.Component.DBGrid.pas
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function TBind4DComponentDBGrid.FormatFieldGrid(
TStringField(aField).EditMask := aAttr.EditMask;
end;

if (RttiUtils.TryGet<Translation>(aAttr.Component, aAttranslation)) or
if (RttiUtils.TryGet<Translation>(aAttr.Component(Attributes.Form), aAttranslation)) or
(Length(RttiUtils.GetAttClass<Translation>(Attributes.Form)) > 0)
then
aField.DisplayLabel :=
Expand Down
8 changes: 7 additions & 1 deletion src/Bind4D.Component.Factory.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface
Vcl.DBGrids,
Vcl.ComCtrls,
Vcl.Buttons,
Vcl.CheckLst,
{$ENDIF}
Bind4D.Component.Interfaces,
System.Classes;
Expand Down Expand Up @@ -50,7 +51,9 @@ implementation
Bind4D.Component.SpeedButton,
Bind4D.Component.Edit,
Bind4D.Component.Memo,
Bind4D.Helpers, Bind4D.Component.Helpers, Bind4D.Component.Mock;
Bind4D.Helpers,
Bind4D.Component.Helpers,
Bind4D.Component.Mock;

{ TBind4DComponentFactory }

Expand All @@ -64,6 +67,7 @@ function TBind4DComponentFactory.Component(aValue: TComponent): iBind4DComponent
if aValue.TryGet<TMaskEdit> then Result := aValue.Get<TMaskEdit>.asIBind4DComponent;
if aValue.TryGet<TDBGrid> then Result := aValue.Get<TDBGrid>.asIBind4DComponent;
if aValue.TryGet<TDateTimePicker> then Result := aValue.Get<TDateTimePicker>.asIBind4DComponent;
if aValue.TryGet<TCheckListBox> then Result := aValue.Get<TCheckListBox>.asIBind4DComponent;
{$ENDIF}
if aValue.TryGet<TPanel> then Result := aValue.Get<TPanel>.asIBind4DComponent;
if aValue.TryGet<TLabel> then Result := aValue.Get<TLabel>.asIBind4DComponent;
Expand All @@ -74,6 +78,8 @@ function TBind4DComponentFactory.Component(aValue: TComponent): iBind4DComponent
if aValue.TryGet<TEdit> then Result := aValue.Get<TEdit>.asIBind4DComponent;
if aValue.TryGet<TImage> then Result := aValue.Get<TImage>.asIBind4DComponent;
if aValue.TryGet<TMemo> then Result := aValue.Get<TMemo>.asIBind4DComponent;
if aValue.TryGet<TListBox> then Result := aValue.Get<TListBox>.asIBind4DComponent;

if not Assigned(Result) then Result := TBind4DComponentMock.New;

end;
Expand Down
28 changes: 27 additions & 1 deletion src/Bind4D.Component.Helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface
Vcl.DBGrids,
Vcl.ComCtrls,
Vcl.Buttons,
Vcl.CheckLst,
{$ENDIF}
System.Classes,
Bind4D.Component.Interfaces;
Expand Down Expand Up @@ -100,13 +101,22 @@ TMaskEditHelper = class helper for TMaskEdit
function asIBind4DComponent : iBind4DComponent;
end;

TCheckListBoxHelper = class helper for TCheckListBox
public
function asIBind4DComponent : iBind4dComponent;
end;
{$ENDIF}

TMemoHelper = class helper for TMemo
public
function asIBind4DComponent : iBind4DComponent;
end;

TListBoxHelper = class helper for TListBox
public
function asIBind4DComponent : iBind4DComponent;
end;

implementation

uses
Expand All @@ -125,7 +135,9 @@ implementation
Bind4D.Component.Rectangle,
Bind4D.Component.DateEdit,
Bind4D.Component.Memo,
Bind4D.Component.Image;
Bind4D.Component.Image,
Bind4D.Component.ListBox,
Bind4D.Component.CheckListBox;

{ TEditHelper }

Expand Down Expand Up @@ -223,6 +235,13 @@ function TMaskEditHelper.asIBind4DComponent: iBind4DComponent;
Result := TBind4DComponentMaskEdit.New(Self);
end;

{ TCheckListBoxHelper }

function TCheckListBoxHelper.asIBind4DComponent: iBind4dComponent;
begin
Result := TBind4DComponentCheckListBox.New(Self);
end;

{$ENDIF}

{ TImageHelper }
Expand All @@ -239,4 +258,11 @@ function TMemoHelper.asIBind4DComponent: iBind4DComponent;
Result := TBind4DComponentMemo.New(Self);
end;

{ TListBoxHelper }

function TListBoxHelper.asIBind4DComponent: iBind4DComponent;
begin
Result := TBind4DComponentListBox.New(Self);
end;

end.
118 changes: 118 additions & 0 deletions src/Bind4D.Component.ListBox.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
unit Bind4D.Component.ListBox;

interface
uses
Bind4D.Component.Interfaces,
Bind4D.Attributes,
Vcl.StdCtrls;
Type
TBind4DComponentListBox = class(TInterfacedObject, iBind4DComponent)
private
FComponent : TListBox;
FAttributes : iBind4DComponentAttributes;
public
constructor Create(aValue : TListBox);
destructor Destroy; override;
class function New(aValue : TListBox) : iBind4DComponent;
function Attributes : iBind4DComponentAttributes;
function AdjusteResponsivity : iBind4DComponent;
function ApplyStyles : iBind4DComponent;
function ApplyText : iBind4DComponent;
function ApplyImage : iBind4DComponent;
function ApplyValue : iBind4DComponent;
function ApplyRestData : iBind4DComponent;
function Clear : iBind4DComponent;
function FormatFieldGrid (aAttr : FieldDataSetBind) : iBind4DComponent;
function GetValueString : String;
function GetCaption : String;
end;

implementation

uses
Bind4D.Component.Attributes;

{ TBind4DComponentListBox }

function TBind4DComponentListBox.AdjusteResponsivity: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentListBox.ApplyImage: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentListBox.ApplyRestData: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentListBox.ApplyStyles: iBind4DComponent;
begin
Result := Self;
FComponent.StyleElements := FAttributes.StyleSettings;
FComponent.Color := FAttributes.Color;
FComponent.Font.Color := FAttributes.FontColor;
FComponent.Font.Name := FAttributes.FontName;
FComponent.Font.Size := FAttributes.FontSize;
end;

function TBind4DComponentListBox.ApplyText: iBind4DComponent;
begin
Result := Self;
FComponent.Items.Text := FAttributes.Text;
end;

function TBind4DComponentListBox.ApplyValue: iBind4DComponent;
begin
Result := Self;
FComponent.Items.Text := FAttributes.ValueVariant;
end;

function TBind4DComponentListBox.Attributes: iBind4DComponentAttributes;
begin
Result := FAttributes;
end;

function TBind4DComponentListBox.Clear: iBind4DComponent;
begin
Result := Self;
FComponent.Items.Clear;
end;

constructor TBind4DComponentListBox.Create(aValue : TListBox);
begin
FAttributes := TBind4DComponentAttributes.Create(Self);
FComponent := aValue;
end;

destructor TBind4DComponentListBox.Destroy;
begin

inherited;
end;

function TBind4DComponentListBox.FormatFieldGrid(
aAttr: FieldDataSetBind): iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentListBox.GetCaption: String;
begin
Result := FComponent.Items.Text;
end;

function TBind4DComponentListBox.GetValueString: String;
begin
Result := FComponent.Items.Text;
end;

class function TBind4DComponentListBox.New (aValue : TListBox) : iBind4DComponent;
begin
Result := Self.Create(aValue);
end;

end.
Loading