------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009-2010 Vadim Godunko <vgodunko@gmail.com>                 --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
------------------------------------------------------------------------------
--    This file has been generated automatically. Please don't edit it.     --
------------------------------------------------------------------------------
with Qt_Ada.Internals.Boolean_Conversions;
with System.Address_To_Access_Conversions;

package body Qt4.Sql_Fields is

   function initialize_QSqlField
    (Storage : System.Address)
      return Internals.QSqlField_Access;
   pragma Import (C, initialize_QSqlField, "__QtAda_inititialize_QSqlField");

   function initialize_QSqlField_QStringCR_Type
    (Storage : System.Address;
     Field_Name : Qt4.Strings.Internals.QString_Access;
     The_Type : Qt4.Variants.Variant_Type)
      return Internals.QSqlField_Access;
   pragma Import (C, initialize_QSqlField_QStringCR_Type, "__QtAda_inititialize_QSqlField_QStringCR_Type");

   function adjust_QSqlField
    (Storage : System.Address;
     From    : Internals.QSqlField_Access)
       return Internals.QSqlField_Access;
   pragma Import (C, adjust_QSqlField, "__QtAda_adjust_QSqlField");

   procedure finalize_QSqlField (Object : Internals.QSqlField_Access);
   pragma Import (C, finalize_QSqlField, "__QtAda_finalize_QSqlField");

   procedure QSqlField_clear
    (Self : Internals.QSqlField_Access);
   pragma Import (C, QSqlField_clear, "__QtAda_QSqlField_clear");

   procedure QSqlField_defaultValue
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlField_Access);
   pragma Import (C, QSqlField_defaultValue, "__QtAda_QSqlField_defaultValue_Q");

   function QSqlField_isAutoValue
    (Self : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlField_isAutoValue, "__QtAda_QSqlField_isAutoValue_Q");

   function QSqlField_isGenerated
    (Self : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlField_isGenerated, "__QtAda_QSqlField_isGenerated_Q");

   function QSqlField_isNull
    (Self : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlField_isNull, "__QtAda_QSqlField_isNull_Q");

   function QSqlField_isReadOnly
    (Self : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlField_isReadOnly, "__QtAda_QSqlField_isReadOnly_Q");

   function QSqlField_isValid
    (Self : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlField_isValid, "__QtAda_QSqlField_isValid_Q");

   function QSqlField_length
    (Self : Internals.QSqlField_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlField_length, "__QtAda_QSqlField_length_Q");

   procedure QSqlField_name
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QSqlField_Access);
   pragma Import (C, QSqlField_name, "__QtAda_QSqlField_name_Q");

   function QSqlField_precision
    (Self : Internals.QSqlField_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QSqlField_precision, "__QtAda_QSqlField_precision_Q");

   function QSqlField_requiredStatus
    (Self : Internals.QSqlField_Access)
       return Field_Required_Status;
   pragma Import (C, QSqlField_requiredStatus, "__QtAda_QSqlField_requiredStatus_Q");

   procedure QSqlField_setAutoValue_bool
    (Self : Internals.QSqlField_Access;
     Auto_Val : Interfaces.C.unsigned);
   pragma Import (C, QSqlField_setAutoValue_bool, "__QtAda_QSqlField_setAutoValue_bool");

   procedure QSqlField_setDefaultValue_QVariantCR
    (Self : Internals.QSqlField_Access;
     Value : Qt4.Variants.Internals.QVariant_Access);
   pragma Import (C, QSqlField_setDefaultValue_QVariantCR, "__QtAda_QSqlField_setDefaultValue_QVariantCR");

   procedure QSqlField_setGenerated_bool
    (Self : Internals.QSqlField_Access;
     Gen : Interfaces.C.unsigned);
   pragma Import (C, QSqlField_setGenerated_bool, "__QtAda_QSqlField_setGenerated_bool");

   procedure QSqlField_setLength_int
    (Self : Internals.QSqlField_Access;
     Field_Length : Qt4.Q_Integer);
   pragma Import (C, QSqlField_setLength_int, "__QtAda_QSqlField_setLength_int");

   procedure QSqlField_setName_QStringCR
    (Self : Internals.QSqlField_Access;
     Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlField_setName_QStringCR, "__QtAda_QSqlField_setName_QStringCR");

   procedure QSqlField_setPrecision_int
    (Self : Internals.QSqlField_Access;
     Precision : Qt4.Q_Integer);
   pragma Import (C, QSqlField_setPrecision_int, "__QtAda_QSqlField_setPrecision_int");

   procedure QSqlField_setReadOnly_bool
    (Self : Internals.QSqlField_Access;
     Read_Only : Interfaces.C.unsigned);
   pragma Import (C, QSqlField_setReadOnly_bool, "__QtAda_QSqlField_setReadOnly_bool");

   procedure QSqlField_setRequired_bool
    (Self : Internals.QSqlField_Access;
     Required : Interfaces.C.unsigned);
   pragma Import (C, QSqlField_setRequired_bool, "__QtAda_QSqlField_setRequired_bool");

   procedure QSqlField_setRequiredStatus_RequiredStatus
    (Self : Internals.QSqlField_Access;
     Status : Field_Required_Status);
   pragma Import (C, QSqlField_setRequiredStatus_RequiredStatus, "__QtAda_QSqlField_setRequiredStatus_RequiredStatus");

   procedure QSqlField_setType_Type
    (Self : Internals.QSqlField_Access;
     The_Type : Qt4.Variants.Variant_Type);
   pragma Import (C, QSqlField_setType_Type, "__QtAda_QSqlField_setType_Type");

   procedure QSqlField_setValue_QVariantCR
    (Self : Internals.QSqlField_Access;
     Value : Qt4.Variants.Internals.QVariant_Access);
   pragma Import (C, QSqlField_setValue_QVariantCR, "__QtAda_QSqlField_setValue_QVariantCR");

   function QSqlField_type
    (Self : Internals.QSqlField_Access)
       return Qt4.Variants.Variant_Type;
   pragma Import (C, QSqlField_type, "__QtAda_QSqlField_type_Q");

   procedure QSqlField_value
    (Returns : Qt4.Variants.Internals.QVariant_Access;
     Self : Internals.QSqlField_Access);
   pragma Import (C, QSqlField_value, "__QtAda_QSqlField_value_Q");

   function eq_QSqlFieldCR
    (Self : Internals.QSqlField_Access;
     Other : Internals.QSqlField_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QSqlFieldCR, "__QtAda_QSqlField_eq_QSqlFieldCR_Q");

   ------------
   -- Adjust --
   ------------

   overriding
   procedure Adjust (Self : in out Q_Sql_Field) is
   begin
      Self.Object := adjust_QSqlField (Self.Storage'Address, Self.Object);
      Self.Wrapper := False;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_Sql_Field) is
   begin
      if not Self.Wrapper then
         finalize_QSqlField (Self.Object);
      end if;
   end Finalize;

   ----------------
   -- Initialize --
   ----------------

   overriding
   procedure Initialize (Self : in out Q_Sql_Field) is
      use type Internals.QSqlField_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QSqlField (Self.Storage'Address);
      end if;
   end Initialize;

   ------------
   -- Create --
   ------------

   function Create
    (Field_Name : Qt4.Strings.Q_String'Class;
     The_Type : Qt4.Variants.Variant_Type
       := Qt4.Variants.Invalid)
       return Q_Sql_Field
   is
   begin
      return Self : Q_Sql_Field
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlField_QStringCR_Type (Self.Storage'Address, Qt4.Strings.Internals.QString_View (Field_Name), The_Type);
      end return;
   end Create;

   -----------
   -- Clear --
   -----------

   procedure Clear
    (Self : in out Q_Sql_Field'Class)
   is
   begin
      QSqlField_clear (Self.Object);
   end Clear;

   -------------------
   -- Default_Value --
   -------------------

   function Default_Value
    (Self : Q_Sql_Field'Class)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlField_defaultValue (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object);
      end return;
   end Default_Value;

   -------------------
   -- Is_Auto_Value --
   -------------------

   function Is_Auto_Value
    (Self : Q_Sql_Field'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlField_isAutoValue (Self.Object), 0);
   end Is_Auto_Value;

   ------------------
   -- Is_Generated --
   ------------------

   function Is_Generated
    (Self : Q_Sql_Field'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlField_isGenerated (Self.Object), 0);
   end Is_Generated;

   -------------
   -- Is_Null --
   -------------

   function Is_Null
    (Self : Q_Sql_Field'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlField_isNull (Self.Object), 0);
   end Is_Null;

   ------------------
   -- Is_Read_Only --
   ------------------

   function Is_Read_Only
    (Self : Q_Sql_Field'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlField_isReadOnly (Self.Object), 0);
   end Is_Read_Only;

   --------------
   -- Is_Valid --
   --------------

   function Is_Valid
    (Self : Q_Sql_Field'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlField_isValid (Self.Object), 0);
   end Is_Valid;

   ------------
   -- Length --
   ------------

   function Length
    (Self : Q_Sql_Field'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlField_length (Self.Object);
   end Length;

   ----------
   -- Name --
   ----------

   function Name
    (Self : Q_Sql_Field'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlField_name (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Name;

   ---------------
   -- Precision --
   ---------------

   function Precision
    (Self : Q_Sql_Field'Class)
       return Qt4.Q_Integer
   is
   begin
      return QSqlField_precision (Self.Object);
   end Precision;

   ---------------------
   -- Required_Status --
   ---------------------

   function Required_Status
    (Self : Q_Sql_Field'Class)
       return Field_Required_Status
   is
   begin
      return QSqlField_requiredStatus (Self.Object);
   end Required_Status;

   --------------------
   -- Set_Auto_Value --
   --------------------

   procedure Set_Auto_Value
    (Self : in out Q_Sql_Field'Class;
     Auto_Val : Boolean)
   is
   begin
      QSqlField_setAutoValue_bool (Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Auto_Val));
   end Set_Auto_Value;

   -----------------------
   -- Set_Default_Value --
   -----------------------

   procedure Set_Default_Value
    (Self : in out Q_Sql_Field'Class;
     Value : Qt4.Variants.Q_Variant'Class)
   is
   begin
      QSqlField_setDefaultValue_QVariantCR (Self.Object, Qt4.Variants.Internals.QVariant_View (Value));
   end Set_Default_Value;

   -------------------
   -- Set_Generated --
   -------------------

   procedure Set_Generated
    (Self : in out Q_Sql_Field'Class;
     Gen : Boolean)
   is
   begin
      QSqlField_setGenerated_bool (Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Gen));
   end Set_Generated;

   ----------------
   -- Set_Length --
   ----------------

   procedure Set_Length
    (Self : in out Q_Sql_Field'Class;
     Field_Length : Qt4.Q_Integer)
   is
   begin
      QSqlField_setLength_int (Self.Object, Field_Length);
   end Set_Length;

   --------------
   -- Set_Name --
   --------------

   procedure Set_Name
    (Self : in out Q_Sql_Field'Class;
     Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlField_setName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name));
   end Set_Name;

   -------------------
   -- Set_Precision --
   -------------------

   procedure Set_Precision
    (Self : in out Q_Sql_Field'Class;
     Precision : Qt4.Q_Integer)
   is
   begin
      QSqlField_setPrecision_int (Self.Object, Precision);
   end Set_Precision;

   -------------------
   -- Set_Read_Only --
   -------------------

   procedure Set_Read_Only
    (Self : in out Q_Sql_Field'Class;
     Read_Only : Boolean)
   is
   begin
      QSqlField_setReadOnly_bool (Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Read_Only));
   end Set_Read_Only;

   ------------------
   -- Set_Required --
   ------------------

   procedure Set_Required
    (Self : in out Q_Sql_Field'Class;
     Required : Boolean)
   is
   begin
      QSqlField_setRequired_bool (Self.Object, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Required));
   end Set_Required;

   -------------------------
   -- Set_Required_Status --
   -------------------------

   procedure Set_Required_Status
    (Self : in out Q_Sql_Field'Class;
     Status : Field_Required_Status)
   is
   begin
      QSqlField_setRequiredStatus_RequiredStatus (Self.Object, Status);
   end Set_Required_Status;

   --------------
   -- Set_Type --
   --------------

   procedure Set_Type
    (Self : in out Q_Sql_Field'Class;
     The_Type : Qt4.Variants.Variant_Type)
   is
   begin
      QSqlField_setType_Type (Self.Object, The_Type);
   end Set_Type;

   ---------------
   -- Set_Value --
   ---------------

   procedure Set_Value
    (Self : in out Q_Sql_Field'Class;
     Value : Qt4.Variants.Q_Variant'Class)
   is
   begin
      QSqlField_setValue_QVariantCR (Self.Object, Qt4.Variants.Internals.QVariant_View (Value));
   end Set_Value;

   ----------------
   -- Field_Type --
   ----------------

   function Field_Type
    (Self : Q_Sql_Field'Class)
       return Qt4.Variants.Variant_Type
   is
   begin
      return QSqlField_type (Self.Object);
   end Field_Type;

   -----------
   -- Value --
   -----------

   function Value
    (Self : Q_Sql_Field'Class)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QSqlField_value (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object);
      end return;
   end Value;

   ---------
   -- "=" --
   ---------

   overriding function "="
    (Self : Q_Sql_Field;
     Other : Q_Sql_Field)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QSqlFieldCR (Self.Object, Other.Object), 0);
   end "=";

   ---------------
   -- Internals --
   ---------------

   package body Internals is

   --------------------
   -- QSqlField_View --
   --------------------

      function QSqlField_View
       (Item : Q_Sql_Field'Class)
          return QSqlField_Access
      is
      begin
         return Item.Object;
      end QSqlField_View;

      package QSqlField_Conversions is
        new System.Address_To_Access_Conversions
             (QSqlField);

   -------------------------
   -- QSqlFieldTo_Pointer --
   -------------------------

      function To_Pointer
       (Address : System.Address)
          return QSqlField_Access
      is
      begin
         return
           QSqlField_Access
            (QSqlField_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -------------------------
   -- QSqlFieldTo_Address --
   -------------------------

      function To_Address
       (Pointer : QSqlField_Access)
          return System.Address
      is
      begin
         return
           QSqlField_Conversions.To_Address
            (QSqlField_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : Internals.QSqlField_Access)
          return Q_Sql_Field
      is
      begin
         return Q_Sql_Field'
          (Ada.Finalization.Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Sql_Fields;
