mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 09:39:31 +02:00
qt intf: combobox from Luis
git-svn-id: trunk@10004 -
This commit is contained in:
parent
4f6130917f
commit
ab3ba51719
@ -141,7 +141,7 @@ type
|
||||
ParentClass: TClass): integer;
|
||||
function AddJITComponentFromStream(BinStream: TStream; ParentClass: TClass;
|
||||
const NewUnitName: ShortString;
|
||||
Interactive: Boolean):integer;
|
||||
Interactive, Visible: Boolean):integer;
|
||||
procedure DestroyJITComponent(JITComponent: TComponent);
|
||||
procedure DestroyJITComponent(Index: integer);
|
||||
function IndexOf(JITComponent: TComponent): integer;
|
||||
@ -650,8 +650,8 @@ begin
|
||||
end;
|
||||
|
||||
function TJITComponentList.AddJITComponentFromStream(BinStream: TStream;
|
||||
ParentClass: TClass; const NewUnitName: ShortString; Interactive: Boolean
|
||||
):integer;
|
||||
ParentClass: TClass; const NewUnitName: ShortString;
|
||||
Interactive, Visible: Boolean):integer;
|
||||
// returns new index
|
||||
// -1 = invalid stream
|
||||
var
|
||||
@ -663,7 +663,6 @@ begin
|
||||
Result:=-1;
|
||||
NewClassName:=GetClassNameFromLRSStream(BinStream, IsInherited);
|
||||
if IsInherited then ;
|
||||
{ TODO: If IsInherited, read ancestor form stream }
|
||||
if NewClassName='' then begin
|
||||
MessageDlg('No classname in stream found.',mtError,[mbOK],0);
|
||||
exit;
|
||||
|
@ -193,25 +193,26 @@ each control that's dropped onto the form
|
||||
function CreateUniqueComponentName(AComponent: TComponent): string;
|
||||
function CreateUniqueComponentName(const AClassName: string;
|
||||
OwnerComponent: TComponent): string;
|
||||
Function CreateComponentInterface(AComponent: TComponent): TIComponentInterface;
|
||||
function CreateComponentInterface(AComponent: TComponent): TIComponentInterface;
|
||||
procedure CreateChildComponentInterfaces(AComponent: TComponent);
|
||||
Function GetDefaultComponentParent(TypeClass: TComponentClass
|
||||
function GetDefaultComponentParent(TypeClass: TComponentClass
|
||||
): TIComponentInterface; override;
|
||||
Function GetDefaultComponentPosition(TypeClass: TComponentClass;
|
||||
function GetDefaultComponentPosition(TypeClass: TComponentClass;
|
||||
ParentCI: TIComponentInterface;
|
||||
var X,Y: integer): boolean; override;
|
||||
function CreateComponent(ParentCI: TIComponentInterface;
|
||||
TypeClass: TComponentClass;
|
||||
const AUnitName: shortstring;
|
||||
X,Y,W,H: Integer): TIComponentInterface; override;
|
||||
Function CreateComponentFromStream(BinStream: TStream;
|
||||
function CreateComponentFromStream(BinStream: TStream;
|
||||
AncestorType: TComponentClass;
|
||||
const NewUnitName: ShortString;
|
||||
Interactive: boolean): TIComponentInterface; override;
|
||||
Function CreateChildComponentFromStream(BinStream: TStream;
|
||||
Interactive: boolean;
|
||||
Visible: boolean = true): TIComponentInterface; override;
|
||||
function CreateChildComponentFromStream(BinStream: TStream;
|
||||
ComponentClass: TComponentClass; Root: TComponent;
|
||||
ParentControl: TWinControl): TIComponentInterface; override;
|
||||
Procedure SetComponentNameAndClass(CI: TIComponentInterface;
|
||||
procedure SetComponentNameAndClass(CI: TIComponentInterface;
|
||||
const NewName, NewClassName: shortstring);
|
||||
|
||||
// define properties
|
||||
@ -1427,7 +1428,8 @@ end;
|
||||
|
||||
Function TCustomFormEditor.CreateComponentFromStream(
|
||||
BinStream: TStream; AncestorType: TComponentClass;
|
||||
const NewUnitName: ShortString; Interactive: boolean): TIComponentInterface;
|
||||
const NewUnitName: ShortString; Interactive: boolean;
|
||||
Visible: boolean): TIComponentInterface;
|
||||
var
|
||||
NewJITIndex: integer;
|
||||
NewComponent: TComponent;
|
||||
@ -1439,14 +1441,14 @@ begin
|
||||
RaiseException('TCustomFormEditor.CreateComponentFromStream ClassName='+
|
||||
AncestorType.ClassName);
|
||||
NewJITIndex := JITList.AddJITComponentFromStream(BinStream,AncestorType,
|
||||
NewUnitName,Interactive);
|
||||
NewUnitName,Interactive,Visible);
|
||||
if NewJITIndex < 0 then begin
|
||||
Result:=nil;
|
||||
exit;
|
||||
end;
|
||||
NewComponent:=JITList[NewJITIndex];
|
||||
|
||||
// create a component interface for the form
|
||||
// create a component interface
|
||||
Result:=CreateComponentInterface(NewComponent);
|
||||
|
||||
CreateChildComponentInterfaces(NewComponent);
|
||||
|
237
ide/main.pp
237
ide/main.pp
@ -576,10 +576,10 @@ type
|
||||
function DoLoadLFM(AnUnitInfo: TUnitInfo; Flags: TOpenFlags): TModalResult;
|
||||
function DoLoadLFM(AnUnitInfo: TUnitInfo; LFMBuf: TCodeBuffer;
|
||||
Flags: TOpenFlags; CloseDsgnForm: boolean): TModalResult;
|
||||
function DoLoadAncestorComponent(AnUnitInfo: TUnitInfo;
|
||||
const AncestorName: string;
|
||||
var AncestorClass: TComponentClass;
|
||||
Flags: TOpenFlags): TModalResult;
|
||||
function DoLoadHiddenResourceComponent(AnUnitInfo: TUnitInfo;
|
||||
const AComponentClassName: string; Flags: TOpenFlags;
|
||||
var AComponentClass: TComponentClass;
|
||||
var ComponentUnitInfo: TUnitInfo): TModalResult;
|
||||
|
||||
// methods for 'close unit'
|
||||
function CloseDesignerForm(AnUnitInfo: TUnitInfo): TModalResult;
|
||||
@ -4736,6 +4736,7 @@ var
|
||||
APersistentClass: TPersistentClass;
|
||||
ACaption, AText: String;
|
||||
NewUnitName: String;
|
||||
AncestorUnitInfo: TUnitInfo;
|
||||
begin
|
||||
debugln('TMainIDE.DoLoadLFM A ',AnUnitInfo.Filename,' IsPartOfProject=',dbgs(AnUnitInfo.IsPartOfProject),' ');
|
||||
|
||||
@ -4748,7 +4749,11 @@ begin
|
||||
|
||||
// close old designer form
|
||||
if CloseDsgnForm then
|
||||
CloseDesignerForm(AnUnitInfo);
|
||||
CloseDesignerForm(AnUnitInfo)
|
||||
else if AnUnitInfo.Component<>nil then begin
|
||||
DebugLn(['TMainIDE.DoLoadLFM INCONSISTENCY CloseDsgnForm=',CloseDsgnForm,' Filename=',AnUnitInfo.Filename,' Component=',dbgsName(AnUnitInfo.Component)]);
|
||||
exit(mrAbort);
|
||||
end;
|
||||
|
||||
//debugln('TMainIDE.DoLoadLFM LFM file loaded, parsing "',LFMBuf.Filename,'" ...');
|
||||
|
||||
@ -4763,7 +4768,7 @@ begin
|
||||
|
||||
// find the classname of the LFM, and check for inherited form
|
||||
ReadLFMHeader(LFMBuf.Source,NewClassName,LFMType);
|
||||
if NewClassName='' then begin
|
||||
if (NewClassName='') or (LFMType='') then begin
|
||||
Result:=MessageDlg(lisLFMFileCorrupt,
|
||||
Format(lisUnableToFindAValidClassnameIn, ['"', LFMBuf.Filename, '"']),
|
||||
mtError,[mbIgnore,mbCancel,mbAbort],0);
|
||||
@ -4797,12 +4802,13 @@ begin
|
||||
|
||||
if (AncestorType=nil) then begin
|
||||
// try loading the ancestor first
|
||||
if DoLoadAncestorComponent(AnUnitInfo,NewAncestorName,AncestorType,Flags)
|
||||
=mrAbort
|
||||
then
|
||||
exit(mrAbort);
|
||||
AncestorUnitInfo:=nil;
|
||||
Result:=DoLoadHiddenResourceComponent(AnUnitInfo,NewAncestorName,Flags,
|
||||
AncestorType,AncestorUnitInfo);
|
||||
if Result<>mrOk then exit;
|
||||
end;
|
||||
|
||||
// use TForm as default ancestor
|
||||
if AncestorType=nil then
|
||||
AncestorType:=TForm;
|
||||
//DebugLn('TMainIDE.DoLoadLFM Filename="',AnUnitInfo.Filename,'" AncestorClassName=',NewAncestorName,' AncestorType=',AncestorType.ClassName);
|
||||
@ -4839,7 +4845,8 @@ begin
|
||||
TxtLFMStream.Free;
|
||||
end;
|
||||
if ComponentLoadingOk then begin
|
||||
if not (ofProjectLoading in Flags) then FormEditor1.ClearSelection;
|
||||
if ([ofProjectLoading,ofLoadHiddenResource]*Flags=[]) then
|
||||
FormEditor1.ClearSelection;
|
||||
|
||||
// create JIT component
|
||||
NewUnitName:=AnUnitInfo.UnitName;
|
||||
@ -4864,24 +4871,27 @@ begin
|
||||
NewComponent:=CInterface.Component;
|
||||
DebugLn('SUCCESS: streaming lfm="',LFMBuf.Filename,'"');
|
||||
AnUnitInfo.Component:=NewComponent;
|
||||
CreateDesignerForComponent(NewComponent);
|
||||
AnUnitInfo.ComponentName:=NewComponent.Name;
|
||||
AnUnitInfo.ComponentResourceName:=AnUnitInfo.ComponentName;
|
||||
DesignerForm:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
|
||||
|
||||
if not (ofProjectLoading in Flags) then begin
|
||||
FDisplayState:= dsForm;
|
||||
if not (ofLoadHiddenResource in Flags) then begin
|
||||
CreateDesignerForComponent(NewComponent);
|
||||
DesignerForm:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
|
||||
end else begin
|
||||
DesignerForm:=nil;
|
||||
end;
|
||||
|
||||
// select the new form (object inspector, formeditor, control selection)
|
||||
if not (ofProjectLoading in Flags) then begin
|
||||
if ([ofProjectLoading,ofLoadHiddenResource]*Flags=[]) then begin
|
||||
FDisplayState:= dsForm;
|
||||
GlobalDesignHook.LookupRoot := NewComponent;
|
||||
TheControlSelection.AssignPersistent(NewComponent);
|
||||
end;
|
||||
//DesignerForm.HandleNeeded;
|
||||
LCLIntf.ShowWindow(DesignerForm.Handle,SW_SHOWNORMAL);
|
||||
|
||||
FLastFormActivated:=DesignerForm;
|
||||
// show new form
|
||||
if DesignerForm<>nil then begin
|
||||
LCLIntf.ShowWindow(DesignerForm.Handle,SW_SHOWNORMAL);
|
||||
FLastFormActivated:=DesignerForm;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
{$IFDEF IDE_DEBUG}
|
||||
@ -4893,79 +4903,136 @@ begin
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
function TMainIDE.DoLoadAncestorComponent(AnUnitInfo: TUnitInfo;
|
||||
const AncestorName: string; var AncestorClass: TComponentClass;
|
||||
Flags: TOpenFlags): TModalResult;
|
||||
function TMainIDE.DoLoadHiddenResourceComponent(AnUnitInfo: TUnitInfo;
|
||||
const AComponentClassName: string; Flags: TOpenFlags;
|
||||
var AComponentClass: TComponentClass; var ComponentUnitInfo: TUnitInfo
|
||||
): TModalResult;
|
||||
|
||||
function TryUnit(const UnitFilename: string; out TheModalResult: TModalResult
|
||||
): boolean;
|
||||
// returns true if the unit contains the component class and sets
|
||||
// TheModalResult to the result of the loading
|
||||
var
|
||||
LFMFilename: String;
|
||||
LFMCode: TCodeBuffer;
|
||||
LFMClassName: string;
|
||||
LFMType: string;
|
||||
CurUnitInfo: TUnitInfo;
|
||||
UnitCode: TCodeBuffer;
|
||||
begin
|
||||
Result:=false;
|
||||
TheModalResult:=mrCancel;
|
||||
|
||||
CurUnitInfo:=Project1.UnitInfoWithFilename(UnitFilename);
|
||||
if (CurUnitInfo<>nil) and (CurUnitInfo.Component<>nil) then
|
||||
begin
|
||||
if CompareText(CurUnitInfo.Component.ClassName,AComponentClassName)=0
|
||||
then begin
|
||||
// component found
|
||||
ComponentUnitInfo:=CurUnitInfo;
|
||||
AComponentClass:=TComponentClass(ComponentUnitInfo.Component.ClassType);
|
||||
Result:=true;
|
||||
end else begin
|
||||
// this unit does not have this component
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
LFMFilename:=ChangeFileExt(UnitFilename,'.lfm');
|
||||
if not FileExists(LFMFilename) then exit;
|
||||
|
||||
// load the lfm file
|
||||
TheModalResult:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText]);
|
||||
if TheModalResult<>mrOk then begin
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent Failed loading ',LFMFilename);
|
||||
exit;
|
||||
end;
|
||||
// read the LFM classname
|
||||
ReadLFMHeader(LFMCode.Source,LFMClassName,LFMType);
|
||||
if LFMType='' then ;
|
||||
if CompareText(LFMClassName,AComponentClassName)<>0 then exit;
|
||||
|
||||
// component LFM found
|
||||
Result:=true;
|
||||
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent ',AnUnitInfo.Filename,' Loading ancestor unit ',UnitFilename);
|
||||
// load unit source
|
||||
TheModalResult:=LoadCodeBuffer(UnitCode,UnitFilename,[lbfCheckIfText]);
|
||||
if TheModalResult<>mrOk then begin
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent Failed loading ',UnitFilename);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// create unit info
|
||||
if CurUnitInfo=nil then begin
|
||||
CurUnitInfo:=TUnitInfo.Create(UnitCode);
|
||||
CurUnitInfo.ReadUnitNameFromSource(true);
|
||||
Project1.AddFile(CurUnitInfo,false);
|
||||
end;
|
||||
|
||||
// load resource hidden
|
||||
TheModalResult:=DoLoadLFM(CurUnitInfo,LFMCode,
|
||||
Flags+[ofLoadHiddenResource],false);
|
||||
if (TheModalResult=mrOk) then begin
|
||||
ComponentUnitInfo:=CurUnitInfo;
|
||||
AComponentClass:=TComponentClass(ComponentUnitInfo.Component.ClassType);
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent Wanted=',AComponentClassName,' Class=',AComponentClass.ClassName);
|
||||
TheModalResult:=mrOk;
|
||||
end else begin
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent Failed to load component ',AComponentClassName);
|
||||
TheModalResult:=mrCancel;
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
UsedUnitFilenames: TStrings;
|
||||
i: Integer;
|
||||
LFMFilename: String;
|
||||
LFMCode: TCodeBuffer;
|
||||
LFMClassName: string;
|
||||
LFMType: string;
|
||||
UnitFilename: string;
|
||||
AncestorUnitInfo: TUnitInfo;
|
||||
begin
|
||||
Result:=mrCancel;
|
||||
|
||||
// search ancestor lfm
|
||||
debugln('TMainIDE.DoLoadAncestorComponent ',AnUnitInfo.Filename,' AncestorName=',AncestorName);
|
||||
|
||||
// search used units filenames
|
||||
UsedUnitFilenames:=nil;
|
||||
try
|
||||
if not CodeToolBoss.FindUsedUnitFiles(AnUnitInfo.Source,UsedUnitFilenames)
|
||||
then begin
|
||||
DoJumpToCodeToolBossError;
|
||||
Result:=mrCancel;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// search for every used unit the .lfm file
|
||||
if (UsedUnitFilenames<>nil) then begin
|
||||
for i:=UsedUnitFilenames.Count-1 downto 0 do begin
|
||||
UnitFilename:=UsedUnitFilenames[i];
|
||||
LFMFilename:=ChangeFileExt(UnitFilename,'.lfm');
|
||||
if FileExists(LFMFilename) then begin
|
||||
// load the lfm file
|
||||
Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText]);
|
||||
if Result<>mrOk then begin
|
||||
debugln('TMainIDE.DoLoadAncestorComponent Failed loading ',LFMFilename);
|
||||
exit;
|
||||
end;
|
||||
// read the LFM classname
|
||||
ReadLFMHeader(LFMCode.Source,LFMClassName,LFMType);
|
||||
if LFMType='' then ;
|
||||
if CompareText(LFMClassName,AncestorName)=0 then begin
|
||||
// ancestor LFM found
|
||||
|
||||
debugln('TMainIDE.DoLoadAncestorComponent ',AnUnitInfo.Filename,' Loading ancestor unit ',UnitFilename);
|
||||
// TODO: open ancestor hidden
|
||||
// WORKAROUND: just open it
|
||||
// beware: don't close it or you will get strange errors
|
||||
Result:=DoOpenEditorFile(UnitFilename,AnUnitInfo.EditorIndex+1,
|
||||
Flags+[ofDoLoadResource,ofRegularFile]);
|
||||
if (Result=mrOk) then begin
|
||||
AncestorUnitInfo:=Project1.UnitInfoWithFilename(UnitFilename);
|
||||
if (AncestorUnitInfo.Component<>nil) then begin
|
||||
AncestorClass:=
|
||||
TComponentClass(AncestorUnitInfo.Component.ClassType);
|
||||
debugln('TMainIDE.DoLoadAncestorComponent AncestorClass=',AncestorClass.ClassName);
|
||||
Result:=mrOk;
|
||||
end else
|
||||
debugln('TMainIDE.DoLoadAncestorComponent Failed to load ancestor component');
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
finally
|
||||
UsedUnitFilenames.Free;
|
||||
// check for circles
|
||||
if AnUnitInfo.LoadingComponent then begin
|
||||
Result:=QuestionDlg('Error','Unable to load the component class '
|
||||
+'"'+AComponentClassName+'", because it depends on itself.',
|
||||
mtError,[mrCancel,'Cancel loading this component',
|
||||
mrAbort,'Abort whole loading'],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
Result:=mrCancel;
|
||||
AnUnitInfo.LoadingComponent:=true;
|
||||
try
|
||||
// search component lfm
|
||||
debugln('TMainIDE.DoLoadHiddenResourceComponent ',AnUnitInfo.Filename,' AComponentName=',AComponentClassName,' AComponentClass=',dbgsName(AComponentClass));
|
||||
|
||||
// first search the resource of ComponentUnitInfo
|
||||
if ComponentUnitInfo<>nil then begin
|
||||
if TryUnit(ComponentUnitInfo.Filename,Result) then exit;
|
||||
end;
|
||||
|
||||
// then search in used units
|
||||
UsedUnitFilenames:=nil;
|
||||
try
|
||||
if not CodeToolBoss.FindUsedUnitFiles(AnUnitInfo.Source,UsedUnitFilenames)
|
||||
then begin
|
||||
DoJumpToCodeToolBossError;
|
||||
Result:=mrCancel;
|
||||
exit;
|
||||
end;
|
||||
|
||||
// search for every used unit the .lfm file
|
||||
if (UsedUnitFilenames<>nil) then begin
|
||||
for i:=UsedUnitFilenames.Count-1 downto 0 do begin
|
||||
if TryUnit(UsedUnitFilenames[i],Result) then exit;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
UsedUnitFilenames.Free;
|
||||
end;
|
||||
|
||||
Result:=mrCancel;
|
||||
finally
|
||||
AnUnitInfo.LoadingComponent:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
|
@ -202,6 +202,7 @@ const
|
||||
'ofMultiOpen',
|
||||
'ofDoNotLoadResource',
|
||||
'ofDoLoadResource',
|
||||
'ofLoadHiddenResource',
|
||||
'ofAddToProject'
|
||||
);
|
||||
|
||||
|
@ -109,6 +109,7 @@ type
|
||||
FIgnoreFileDateOnDiskValid: boolean;
|
||||
FIgnoreFileDateOnDisk: longint;
|
||||
fLoaded: Boolean; // loaded in the source editor
|
||||
FLoadingComponent: boolean;
|
||||
fModified: boolean;
|
||||
fNext, fPrev: array[TUnitInfoList] of TUnitInfo;
|
||||
fOnFileBackup: TOnFileBackup;
|
||||
@ -226,6 +227,7 @@ type
|
||||
property FileReadOnly: Boolean read fFileReadOnly write SetFileReadOnly;
|
||||
property HasResources: boolean read GetHasResources write fHasResources;
|
||||
property Loaded: Boolean read fLoaded write SetLoaded;
|
||||
property LoadingComponent: boolean read FLoadingComponent write FLoadingComponent;
|
||||
property Modified: boolean read fModified write fModified;// not Session data
|
||||
property SessionModified: boolean read FSessionModified write SetSessionModified;
|
||||
property OnFileBackup: TOnFileBackup read fOnFileBackup write fOnFileBackup;
|
||||
|
@ -1,2 +1,2 @@
|
||||
// Created by Svn2RevisionInc
|
||||
const RevisionStr = '9891';
|
||||
const RevisionStr = '10002M';
|
||||
|
@ -107,7 +107,8 @@ type
|
||||
function CreateComponentFromStream(BinStream: TStream;
|
||||
AncestorType: TComponentClass;
|
||||
const NewUnitName: ShortString;
|
||||
Interactive: boolean): TIComponentInterface; virtual; abstract;
|
||||
Interactive: boolean;
|
||||
Visible: boolean = true): TIComponentInterface; virtual; abstract;
|
||||
function CreateChildComponentFromStream(BinStream: TStream;
|
||||
ComponentClass: TComponentClass;
|
||||
Root: TComponent;
|
||||
|
@ -40,6 +40,7 @@ type
|
||||
ofMultiOpen, // set during loading multiple files
|
||||
ofDoNotLoadResource,// do not open form, datamodule, ... (overriding default)
|
||||
ofDoLoadResource,// do open form, datamodule, ... (overriding default)
|
||||
ofLoadHiddenResource,// load component hidden
|
||||
ofAddToProject // add file to project (if exists)
|
||||
);
|
||||
TOpenFlags = set of TOpenFlag;
|
||||
|
@ -8,6 +8,38 @@ uses Classes, StdCtrls, Controls, Graphics, SysUtils, qt4;
|
||||
|
||||
type
|
||||
|
||||
{ TQtComboStrings }
|
||||
|
||||
TQtComboStrings = class(TStrings)
|
||||
private
|
||||
FComboChanged: Boolean; // StringList and QtComboBox out of sync
|
||||
FStringList: TStringList; // Holds the items to show
|
||||
FQtComboBox: QComboBoxH; // Qt Widget
|
||||
FOwner: TWinControl; // Lazarus Control Owning ListStrings
|
||||
FUpdating: Boolean; // We're changing Qt Widget
|
||||
procedure InternalUpdate;
|
||||
procedure ExternalUpdate(var Astr: TStringList; Clear: Boolean = True);
|
||||
procedure IsChanged; // OnChange triggered by program action
|
||||
protected
|
||||
function GetTextStr: string; override;
|
||||
function GetCount: integer; override;
|
||||
function Get(Index : Integer) : string; override;
|
||||
//procedure SetSorted(Val : boolean); virtual;
|
||||
public
|
||||
constructor Create(ComboBoxH : QComboBoxH; TheOwner: TWinControl);
|
||||
destructor Destroy; override;
|
||||
procedure Assign(Source : TPersistent); override;
|
||||
procedure Clear; override;
|
||||
procedure Delete(Index : integer); override;
|
||||
procedure Insert(Index : integer; const S: string); override;
|
||||
procedure SetText(TheText: PChar); override;
|
||||
//procedure Sort; virtual;
|
||||
public
|
||||
//property Sorted: boolean read FSorted write SetSorted;
|
||||
property Owner: TWinControl read FOwner;
|
||||
end;
|
||||
|
||||
|
||||
{ TQtListStrings }
|
||||
|
||||
TQtListStrings = class(TStrings)
|
||||
@ -567,5 +599,129 @@ begin
|
||||
Result := QImage_numBytes(Handle);
|
||||
end;
|
||||
|
||||
{ TQtComboStrings }
|
||||
|
||||
procedure TQtComboStrings.InternalUpdate;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.ExternalUpdate(var Astr: TStringList; Clear: Boolean
|
||||
);
|
||||
var
|
||||
i: Integer;
|
||||
data: QVariantH;
|
||||
begin
|
||||
|
||||
data := QVariant_create(10); //Creates dummy data
|
||||
|
||||
FUpdating := True;
|
||||
if Clear then
|
||||
QComboBox_clear(FQtComboBox);
|
||||
for i := 0 to AStr.Count -1 do
|
||||
QComboBox_additem(FQtComboBox, @WideString(Astr[i]), data);
|
||||
FUpdating := False;
|
||||
IsChanged;
|
||||
FUpdating := False;
|
||||
|
||||
QVariant_destroy(data); // Clean up
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.IsChanged;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function TQtComboStrings.GetTextStr: string;
|
||||
begin
|
||||
Result:=inherited GetTextStr;
|
||||
end;
|
||||
|
||||
function TQtComboStrings.GetCount: integer;
|
||||
begin
|
||||
if FComboChanged then InternalUpdate;
|
||||
Result := FStringList.Count;
|
||||
end;
|
||||
|
||||
function TQtComboStrings.Get(Index: Integer): string;
|
||||
begin
|
||||
if FComboChanged then InternalUpdate;
|
||||
if Index < FStringList.Count then
|
||||
Result := FStringList.Strings[Index]
|
||||
else Result := '';
|
||||
end;
|
||||
|
||||
constructor TQtComboStrings.Create(ComboBoxH: QComboBoxH; TheOwner: TWinControl
|
||||
);
|
||||
var
|
||||
Method: TMethod;
|
||||
Hook : QComboBox_hookH;
|
||||
// Astr: WideString;
|
||||
i: Integer;
|
||||
begin
|
||||
inherited Create;
|
||||
|
||||
{$ifdef VerboseQt}
|
||||
if (ComboBoxH = nil) then WriteLn('TQtComboStrings.Create Unspecified ComboBoxH widget');
|
||||
if (TheOwner = nil) then WriteLn('TQtComboStrings.Create Unspecified owner');
|
||||
{$endif}
|
||||
|
||||
FStringList := TStringList.Create;
|
||||
FQtComboBox := ComboBoxH;
|
||||
FStringList.Text := TCustomComboBox(TheOwner).Items.Text;
|
||||
FOwner:=TheOwner;
|
||||
end;
|
||||
|
||||
destructor TQtComboStrings.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.Assign(Source: TPersistent);
|
||||
begin
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.Clear;
|
||||
begin
|
||||
FUpdating := True;
|
||||
FStringList.Clear;
|
||||
QComboBox_clear(FQtComboBox);
|
||||
FComboChanged := False;
|
||||
FUpdating := False;
|
||||
IsChanged;
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.Delete(Index: integer);
|
||||
begin
|
||||
if FComboChanged then InternalUpdate;
|
||||
|
||||
if Index < FStringList.Count then
|
||||
begin
|
||||
FStringList.Delete(Index);
|
||||
ExternalUpdate(FStringList,True);
|
||||
FComboChanged := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.Insert(Index: integer; const S: string);
|
||||
begin
|
||||
if FComboChanged then InternalUpdate;
|
||||
|
||||
if Index < 0 then Index := 0;
|
||||
|
||||
if Index <= FStringList.Count then
|
||||
begin
|
||||
FStringList.Insert(Index,S);
|
||||
ExternalUpdate(FStringList,True);
|
||||
FComboChanged := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TQtComboStrings.SetText(TheText: PChar);
|
||||
begin
|
||||
inherited SetText(TheText);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -1071,10 +1071,11 @@ end;
|
||||
Returns: The state of the control
|
||||
------------------------------------------------------------------------------}
|
||||
class function TQtWSCustomComboBox.GetItems(const ACustomComboBox: TCustomComboBox): TStrings;
|
||||
var
|
||||
ComboBoxH: QComboBoxH;
|
||||
begin
|
||||
Result := TStringList.Create;
|
||||
|
||||
Result.Text := ACustomComboBox.Items.Text;
|
||||
ComboBoxH := QComboBoxH((TQtWidget(ACustomComboBox.Handle).Widget));
|
||||
Result := TQtComboStrings.Create(ComboBoxH, ACustomComboBox);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user