Skip to content

Commit

Permalink
[SVN版本:641]
Browse files Browse the repository at this point in the history
[SVN版本:641]
+ 增加 TQVTImageDrawer 实现图标绘制
+ 修改 TQVTMasterDrawer 支持图标绘制
[SVN版本:640]
[QJSON]
* 移除 Add(Name,Value,Type) 中 Type 的默认值,以避免自动判断引起的额外问题(仓井很空建议)
[QXML]
* 修正对引号转义的支持,属性值中引号进行转义,其它场景不转义
[QPlugins/MenuService]
* 修改 AddMenu/AddCategory 接口定义
+ 增加多个接口声明
  • Loading branch information
qdac committed Dec 19, 2017
1 parent 6afe687 commit affb8aa
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 58 deletions.
74 changes: 41 additions & 33 deletions Source/qdac_fmx_virtualtree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ TQVTColumn = class;
function StateSizable: Boolean;
end;

IQVTImageCellData = interface(IQVTCellLayoutData)
['{4D9429CE-C5C3-4D97-B177-FBD17D315C42}']
function GetImage: TBitmap;
function GetHighSpeed: Boolean;
end;

TQCellBlockData = record
Bounds: TRectF;
Size: TSizeF;
Expand Down Expand Up @@ -183,14 +189,6 @@ TQCellBlockData = record
property RadioBounds: TRectF read GetRadioBounds write SetRadioBounds;
end;

// 带图标的单元格数据
IQVTImageCellData = interface
['{C018C791-B524-465A-8AE1-7C8ACEEF1E1A}']
// 图像
function GetBitmap: TBitmap;
property Bitmap: TBitmap read GetBitmap;
end;

IQVTDrawer = interface
['{3F8FF8B2-F5D4-470F-ADFB-F21D357E0B64}']
procedure Draw(ARect: TRectF; AData: IQVTCellData);
Expand Down Expand Up @@ -547,28 +545,6 @@ TQVTIndicatorDrawer = class(TQVTTextDrawer)
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
end;

// 默认的主列绘制器,用于绘制带树形视图的文本内容
TQVTMasterDrawer = class(TQVTTextDrawer)
private
class var FStatePath: array [Boolean] of TPathData;
class function GetCascadedPath: TPathData; static;
class function GetExpandedPath: TPathData; static;
class procedure SetCascadedPath(const Value: TPathData); static;
class procedure SetExpandedPath(const Value: TPathData); static;
protected
FCurrentPath: array [Boolean] of TPathData;
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
public
class constructor Create;
class destructor Destroy;
constructor Create; overload;
destructor Destroy; override;
class property ExpandedPath: TPathData read GetExpandedPath
write SetExpandedPath;
class property CascadedPath: TPathData read GetCascadedPath
write SetCascadedPath;
end;

// 默认的进度状态绘制器,用于绘制进度条
TQVTProgressDrawer = class(TQVTTextDrawer)
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
Expand Down Expand Up @@ -642,10 +618,32 @@ TQVTRadioDrawer = class(TQVTStateDrawer)
end;

// 默认的图片绘制器,用于绘制图片结点
TQVTImageDrawer = class(TQVTTextDrawer)
TQVTImageDrawer = class(TQVTStateDrawer)
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
end;

// 默认的主列绘制器,用于绘制带树形视图的文本内容
TQVTMasterDrawer = class(TQVTImageDrawer)
private
class var FStatePath: array [Boolean] of TPathData;
class function GetCascadedPath: TPathData; static;
class function GetExpandedPath: TPathData; static;
class procedure SetCascadedPath(const Value: TPathData); static;
class procedure SetExpandedPath(const Value: TPathData); static;
protected
FCurrentPath: array [Boolean] of TPathData;
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
public
class constructor Create;
class destructor Destroy;
constructor Create; overload;
destructor Destroy; override;
class property ExpandedPath: TPathData read GetExpandedPath
write SetExpandedPath;
class property CascadedPath: TPathData read GetCascadedPath
write SetCascadedPath;
end;

// 默认带状态图片绘制器,用于绘制带状态的结点
TQVTImageStateDrawer = class(TQVTStateDrawer)
procedure Draw(ARect: TRectF; AData: IQVTCellData); override;
Expand Down Expand Up @@ -4216,9 +4214,19 @@ class function TQVTRadioDrawer.GetUncheckPath: TPathData;
{ TQVTImageDrawer }

procedure TQVTImageDrawer.Draw(ARect: TRectF; AData: IQVTCellData);
var
AImage: IQVTImageCellData;
ABitmap: TBitmap;
AStateRect, AContentRect: TRectF;
begin
inherited;

CalcLayouts(AData, ARect, AStateRect, AContentRect);
if Supports(AData, IQVTImageCellData, AImage) then
begin
ABitmap := AImage.GetImage;
AData.TreeView.Canvas.DrawBitmap(ABitmap, RectF(0, 0, ABitmap.Width,
ABitmap.Height), AStateRect, AData.TreeView.Opacity, AImage.GetHighSpeed);
end;
inherited Draw(AContentRect, AData);
end;

{ TQVTStateDrawer }
Expand Down
18 changes: 9 additions & 9 deletions Source/qjson.pas
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ TQJson = class
/// <param name="AValue">要添加的内容的值表达式(字符串)</param>
/// <param name="ADataType">表达式类型,如果为jdtUnknown,则会自动检测内容类型</param>
/// <returns>返回创建的结点索引</returns>
function Add(AName, AValue: QStringW;
ADataType: TQJsonDataType = jdtUnknown): Integer; overload;
function Add(AName, AValue: QStringW; ADataType: TQJsonDataType)
: Integer; overload;
/// <summary>添加一个数组</summary>
/// <param name="AName">要添加的对象的结点名称</param>
/// <param name="AItems">要添加的数组内容</param>
Expand Down Expand Up @@ -2798,18 +2798,18 @@ function TQJson.ForcePath(APath: QStringW): TQJson;
if Length(AName) > 0 then
begin
Result := AParent.ItemByName(AName);
if EndWithW(AName,']',false) then
begin
Result:=AParent.ForcePath(AName);
Result.DataType:=jdtArray;
end
if EndWithW(AName, ']', false) then
begin
Result := AParent.ForcePath(AName);
Result.DataType := jdtArray;
end
else if Result = nil then
Result := AParent.Add(AName, jdtArray)
else if Result.DataType <> jdtArray then
raise Exception.CreateFmt(SBadJsonArray, [AName]);
end
else //Self
Result:=AParent;
else // Self
Result := AParent;
if AIndex >= 0 then
begin
while Result.Count <= AIndex do
Expand Down
34 changes: 29 additions & 5 deletions Source/qplugins_menusvc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ interface

uses classes, sysutils, qplugins_base;

const
MC_CAPTION = $01;
MC_ICON = $02;
MC_VISIBLE = $04;
MC_ENABLED = $08;
MC_EXTS = $10;
MC_ALIGN = $20;
MC_CHILDREN = $40;

type

IQMenuCategory = interface;
Expand Down Expand Up @@ -90,7 +99,7 @@ interface
/// <summary>
/// 从另一个图片中复制一份拷贝
/// </summary>
procedure Assign(ASource:IQImage);stdcall;
procedure Assign(ASource: IQImage); stdcall;
/// <summary>
/// 图片末次变更ID
/// </summary>
Expand Down Expand Up @@ -226,6 +235,11 @@ interface
/// </seealso>
procedure SetImage(AImage: IQImage); stdcall;

function GetTag: Pointer; stdcall;
procedure SetTag(const V: Pointer); stdcall;
function GetChanges: Integer; stdcall;
procedure BeginUpdate; stdcall;
procedure EndUpdate; stdcall;
/// <summary>
/// 项目标题
/// </summary>
Expand Down Expand Up @@ -258,6 +272,8 @@ interface
/// 末次变更ID
/// </summary>
property LastChangeId: Integer read GetLastChangeId;
property Tag: Pointer read GetTag write SetTag;
property Changes: Integer read GetChanges;
end;

/// <summary>
Expand Down Expand Up @@ -352,7 +368,8 @@ interface
/// <summary>
/// 菜单图标对齐方式
/// </summary>
property ImageAlign: TImageAlignLayout read GetImageAlign write SetImageAlign;
property ImageAlign: TImageAlignLayout read GetImageAlign
write SetImageAlign;
/// <summary>
/// 当前 菜单项目类型
/// </summary>
Expand Down Expand Up @@ -388,14 +405,14 @@ interface
/// <returns>
/// 返回的实际接口类型是IQMenuItem,注意用完要减少引用计数
/// </returns>
function AddMenu: Pointer; stdcall;
function AddMenu(const AName, ACaption: PWidechar): Pointer; stdcall;
/// <summary>
/// 添加一个子分类
/// </summary>
/// <returns>
/// 返回的实际接口类型是 IQMenuCategory,注意用完要减少引用计数
/// </returns>
function AddCategory: Pointer; stdcall;
function AddCategory(const AName, ACaption: PWidechar): Pointer; stdcall;
/// <summary>
/// 删除指定索引的子项
/// </summary>
Expand Down Expand Up @@ -503,7 +520,7 @@ interface
/// <returns>
/// 实际返回的接口类型为 IQMenuCategory,注意使用完成需要减小引用计数
/// </returns>
function AddCategory: Pointer; stdcall;
function AddCategory(const AName, ACaption: PWidechar): Pointer; stdcall;
/// <summary>
/// 删除指定索引的项目
/// </summary>
Expand All @@ -515,6 +532,13 @@ interface
/// 清除所有的项目
/// </summary>
procedure Clear; stdcall;
/// <summary>获取指定路径的项目地址,路径分隔符以/分隔</summary>
/// <returns>返回对应的路径的IQMenuBase实例地址</returns>
function ItemByPath(APath: PWideChar): Pointer; stdcall; // IQMenuBase
/// <summary>强制创建指定分类路径,路径分隔符以/分隔</summary>
/// <returns>返回对应的路径的IQMenuBase实例地址</returns>
function ForceCategories(APath: PWideChar): Pointer; stdcall;
// IQMenuCategory
/// <summary>
/// 获取指定分类的索引
/// </summary>
Expand Down
42 changes: 31 additions & 11 deletions Source/qxml.pas
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
}
// 测试环境仅为Delphi 2007或XE6,其它版本的开发环境,请自行修改
{ 修订日志
2017.12.15
==========
* 修正了 XMLEncode 的编码处理,对属性值的引号进行转义,对结点内容文本的引号不进行转义
2017.1.4
=========
* 修正了 XML 编码时,未正确处理空 XML 文件的问题(麦子仲肥报告)
Expand Down Expand Up @@ -391,8 +394,8 @@ TQXMLNode = class
FData: Pointer;
function GetCount: Integer;
function GetItems(AIndex: Integer): TQXMLNode;
function XMLEncode(const S: QStringW; AppendSpace: Boolean = False)
: QStringW;
function XMLEncode(const S: QStringW; AConvertQuoter: Boolean;
AppendSpace: Boolean): QStringW;
function XMLDecode(const p: PQCharW; l: Integer): QStringW; overload;
function GetItemIndex: Integer;
function GetText: QStringW;
Expand Down Expand Up @@ -2739,7 +2742,7 @@ function TQXMLNode.InternalEncode(ABuilder: TQStringCatHelperW;
begin
for I := 0 to AItem.FAttrs.Count - 1 do
ABuilder.Cat(Space, 1).Cat(AItem.Attrs[I].FName).Cat(ValueStart, 2)
.Cat(XMLEncode(AItem.Attrs[I].FValue)).Cat(Quoter);
.Cat(XMLEncode(AItem.Attrs[I].FValue,true,false)).Cat(Quoter);
end;
if AItem.Count = 0 then
begin
Expand Down Expand Up @@ -2783,7 +2786,7 @@ function TQXMLNode.InternalEncode(ABuilder: TQStringCatHelperW;
begin
// if ADoFormat then
// ABuilder.Replicate(AIndent, ALevel);
ABuilder.Cat(XMLEncode(ANode.FName, True));
ABuilder.Cat(XMLEncode(ANode.FName,false, True));
if ADoFormat and (I < AItem.Count - 1) then
ABuilder.Cat(SLineBreak);
end;
Expand Down Expand Up @@ -2847,7 +2850,7 @@ function TQXMLNode.InternalEncode(ABuilder: TQStringCatHelperW;
end;
end
else
Result:=False;
Result := False;
end
else
Result := False;
Expand All @@ -2856,7 +2859,7 @@ function TQXMLNode.InternalEncode(ABuilder: TQStringCatHelperW;
begin
Result := ABuilder;
ACount := Count;
ADefaultTag:=DefaultTagNeeded;
ADefaultTag := DefaultTagNeeded;
if ADefaultTag then
begin
ABuilder.Cat(TagXMLStart, 4);
Expand Down Expand Up @@ -4644,7 +4647,8 @@ function TQXMLNode.XMLDecode(const p: PQCharW; l: Integer): QStringW;
SetLength(Result, pd - PQCharW(Result));
end;

function TQXMLNode.XMLEncode(const S: QStringW; AppendSpace: Boolean): QStringW;
function TQXMLNode.XMLEncode(const S: QStringW;
AConvertQuoter, AppendSpace: Boolean): QStringW;
var
ps, pd: PQCharW;
ASpaceCount: Integer;
Expand Down Expand Up @@ -4694,10 +4698,26 @@ function TQXMLNode.XMLEncode(const S: QStringW; AppendSpace: Boolean): QStringW;
StrCat(pd, '&gt;');
'&':
StrCat(pd, '&amp;');
// '''':
// StrCat(pd, '&apos;');
// '"':
// StrCat(pd, '&quot;')
'''':
begin
if AConvertQuoter then
StrCat(pd, '&apos;')
else
begin
pd^ := ps^;
Inc(pd);
end;
end;
'"':
begin
if AConvertQuoter then
StrCat(pd, '&quot;')
else
begin
pd^ := ps^;
Inc(pd);
end;
end
else
begin
pd^ := ps^;
Expand Down

0 comments on commit affb8aa

Please sign in to comment.