| Integration with Qt's Meta System |
|---|
Table of ContentsQt's Meta System is an important part of Qt frameworks. The main reason for it introductions is the signal and slots communication between objects. In addition it provides an ability for runtime classes and objects analisis — the very important feature for some kinds of applications (for example, Qt Designer use meta object system for retrieving list of object's properties and getting/setting their values). QtAda includes special tool — Ada-aware meta object compiler (amoc) — for the generation of code for Qt's Meta System. It reads information directly from Ada source code and produces corresponding source code files for the integration with Qt's Meta System. Ada language constructs cann't provide all information required for amoc. User should explicitly add to the Ada source code some hints for the amoc. QtAda use several amoc defined pragmas for such hints, thus annotated source code still be a valid Ada source code. Integration of generated code into the program accomplished throught separate compilation units. Ada source code declare standard Ada stubs for generated subprograms, amoc generate their implemenation in separate files and compiler produce executable from consolidated source code. Pragmas for amocPragma Q_Declare_Objectpragma Q_Declare_Object (Class_Interface => direct_interface_type_name); Pragma Q_Declare_Object defines specified interface type as public class's interface. The direct_interface_type_name should denote an limited interface type. Pragma Q_Object
pragma Q_Object
(Class_Implementation => direct_tagged_type_name,
Class_Interface => interface_type_name,
Class_Name => string_literal);
Pragma Q_Object defines specified tagged type as class's implementation. Optionally, may be specified interface type of the public class's interface and internal class name. The direct_tagged_type_name should denote an tagged type directly or indirectly drived from Qt4.Objects.Impl.Q_Object_Impl type. If specified, interface_type_name should denote an limited interface type for which pragma Q_Declare_Object is applied. In this case interface_type_name should be one of progenior of direct_tagged_type_name, Optional class name used as class's name in the Qt's Meta System. Pragma Q_Declare_Interface
pragma Q_Declare_Interface
(Class_Interface => direct_interface_type_name,
Class_Name => string_literal,
Class_Identifier => string_literal);
Pragma Q_Declare_Interface defines specified limited interface type as an interface with specified public identifier. This pragma intended for use with plugins. Pragma Q_Slot
pragma Q_Slot
(Class => direct_tagged_or_interface_type_name,
Subprogram => direct_procedure_name,
Signature => string_literal);
Pragma Q_Slot defines specified procedure as class's slot. The direct_tagged_or_interface_type_name should denote direct interface type or tagged type name for which corresponding pragma Q_Declare_Object or pragma Q_Object was applied. Pragma Q_Signal
pragma Q_Signal
(Class => direct_tagged_type_name,
Subprogram => direct_procedure_name,
Signature => string_literal);
Pragma Q_Signal defines specified procedure as class's signal. The direct_tagged_type_name should denote direct tagged type name for which pragma Q_Object was applied. Pragma Q_Property
pragma Q_Property
(Class => direct_tagged_type_name,
Property_Type => type_name,
Property_Name => string_literal,
Read => function_name,
Write => procedure_name,
Reset => procedure_name,
Is_Designable => boolean_literal,
Is_Scriptable => boolean_literal,
Is_Stored => boolean_literal);
Pragma Q_Property defines class's property. The Property_Type specifies the type name and Property_Name specified public property name. Each property should have read function with one of the following specifications: function Read (Self : not null access constant Class) return Property_Type;or
function Read (Self : not null access constant Class'Class)
return Property_Type;
Optionally, property may have write procedure with one of the following
specifications:
procedure Write (Self : not null access Class;
Value : in Property_Type);
or
procedure Write (Self : not null access Class'Class;
Value : in Property_Type);
Optionally, property may have reset procedure with one of the following
specifications:
procedure Reset (Self : not null access Class);or procedure Reset (Self : not null access Class'Class); Optional Is_Designable parameter indicates whether it makes sense to make the property available in a GUI builder. Optional Is_Stored parameter declares whether this property is suited for access by a scripting engine. Optional Is_Stored parameter declares whether the property's value must be remembered when storing an object's state. User defined signalsFor each delared class's signal procedure user must place implementation stub in the package body. Signal procedure's implementation is generated by the amoc. An ExampleFollowing example code copied from the examples/tutorial/t7 directory.
with System;
with Qt4.Meta_Objects;
with Qt4.Sliders;
with Qt4.Widgets.Impl;
package LCD_Ranges.Impl is
type LCD_Range_Impl is
new Qt4.Widgets.Impl.Q_Widget_Impl and LCD_Range with
record
Slider : access Qt4.Sliders.Q_Slider'Class;
end record;
pragma Q_Object (LCD_Range_Impl, LCD_Range, "LCDRange");
procedure Emit_Value_Changed (Self : not null access LCD_Range_Impl;
New_Value : in Qt4.Q_Integer);
pragma Q_Signal
(LCD_Range_Impl, Emit_Value_Changed, "Emit_Value_Changed(int)");
procedure Set_Value (Self : not null access LCD_Range_Impl;
Value : in Qt4.Q_Integer);
pragma Q_Slot (LCD_Range_Impl, Set_Value, "Set_Value(int)");
end LCD_Ranges.Impl;
package body LCD_Ranges.Impl is
procedure Emit_Value_Changed (Self : not null access LCD_Range_Impl;
New_Value : in Qt4.Q_Integer)
is separate;
procedure Set_Value (Self : not null access LCD_Range_Impl;
Value : in Qt4.Q_Integer)
is
begin
Self.Slider.Set_Value (Value);
end Set_Value;
end LCD_Ranges.Impl;
|