------------------------------------------------------------------------------
--                                                                          --
--                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 Qt4.Sql_Fields;
with Qt4.Strings;
with Qt_Ada.Internals.Boolean_Conversions;
with System;

package body Qt4.Sql_Records.Sql_Indices is

   function initialize_QSqlIndex
    (Storage : System.Address)
      return Qt4.Sql_Records.Internals.QSqlRecord_Access;
   pragma Import (C, initialize_QSqlIndex, "__QtAda_inititialize_QSqlIndex");

   function initialize_QSqlIndex_QStringCR_QStringCR
    (Storage : System.Address;
     Cursor_Name : Qt4.Strings.Internals.QString_Access;
     Name : Qt4.Strings.Internals.QString_Access)
      return Qt4.Sql_Records.Internals.QSqlRecord_Access;
   pragma Import (C, initialize_QSqlIndex_QStringCR_QStringCR, "__QtAda_inititialize_QSqlIndex_QStringCR_QStringCR");

   function adjust_QSqlIndex
    (Storage : System.Address;
     From    : Qt4.Sql_Records.Internals.QSqlRecord_Access)
       return Qt4.Sql_Records.Internals.QSqlRecord_Access;
   pragma Import (C, adjust_QSqlIndex, "__QtAda_adjust_QSqlIndex");

   procedure finalize_QSqlIndex (Object : Qt4.Sql_Records.Internals.QSqlRecord_Access);
   pragma Import (C, finalize_QSqlIndex, "__QtAda_finalize_QSqlIndex");

   procedure QSqlIndex_append_QSqlFieldCR
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Field : Qt4.Sql_Fields.Internals.QSqlField_Access);
   pragma Import (C, QSqlIndex_append_QSqlFieldCR, "__QtAda_QSqlIndex_append_QSqlFieldCR");

   procedure QSqlIndex_append_QSqlFieldCR_bool
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Field : Qt4.Sql_Fields.Internals.QSqlField_Access;
     Desc : Interfaces.C.unsigned);
   pragma Import (C, QSqlIndex_append_QSqlFieldCR_bool, "__QtAda_QSqlIndex_append_QSqlFieldCR_bool");

   procedure QSqlIndex_cursorName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Qt4.Sql_Records.Internals.QSqlRecord_Access);
   pragma Import (C, QSqlIndex_cursorName, "__QtAda_QSqlIndex_cursorName_Q");

   function QSqlIndex_isDescending_int
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Index : Qt4.Q_Integer)
       return Interfaces.C.unsigned;
   pragma Import (C, QSqlIndex_isDescending_int, "__QtAda_QSqlIndex_isDescending_int_Q");

   procedure QSqlIndex_name
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Qt4.Sql_Records.Internals.QSqlRecord_Access);
   pragma Import (C, QSqlIndex_name, "__QtAda_QSqlIndex_name_Q");

   procedure QSqlIndex_setCursorName_QStringCR
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Cursor_Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlIndex_setCursorName_QStringCR, "__QtAda_QSqlIndex_setCursorName_QStringCR");

   procedure QSqlIndex_setDescending_int_bool
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Index : Qt4.Q_Integer;
     Desc : Interfaces.C.unsigned);
   pragma Import (C, QSqlIndex_setDescending_int_bool, "__QtAda_QSqlIndex_setDescending_int_bool");

   procedure QSqlIndex_setName_QStringCR
    (Self : Qt4.Sql_Records.Internals.QSqlRecord_Access;
     Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QSqlIndex_setName_QStringCR, "__QtAda_QSqlIndex_setName_QStringCR");

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Sql_Index) is
      use type Qt4.Sql_Records.Internals.QSqlRecord_Access;

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

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

   function Create
    (Cursor_Name : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create;
     Name : Qt4.Strings.Q_String'Class
       := Qt4.Strings.Create)
       return Q_Sql_Index
   is
   begin
      return Self : Q_Sql_Index
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QSqlIndex_QStringCR_QStringCR (Self.Storage'Address, Qt4.Strings.Internals.QString_View (Cursor_Name), Qt4.Strings.Internals.QString_View (Name));
      end return;
   end Create;

   ------------
   -- Append --
   ------------

   procedure Append
    (Self : in out Q_Sql_Index'Class;
     Field : Qt4.Sql_Fields.Q_Sql_Field'Class)
   is
   begin
      QSqlIndex_append_QSqlFieldCR (Self.Object, Qt4.Sql_Fields.Internals.QSqlField_View (Field));
   end Append;

   ------------
   -- Append --
   ------------

   procedure Append
    (Self : in out Q_Sql_Index'Class;
     Field : Qt4.Sql_Fields.Q_Sql_Field'Class;
     Desc : Boolean)
   is
   begin
      QSqlIndex_append_QSqlFieldCR_bool (Self.Object, Qt4.Sql_Fields.Internals.QSqlField_View (Field), Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Desc));
   end Append;

   -----------------
   -- Cursor_Name --
   -----------------

   function Cursor_Name
    (Self : Q_Sql_Index'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QSqlIndex_cursorName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Cursor_Name;

   -------------------
   -- Is_Descending --
   -------------------

   function Is_Descending
    (Self : Q_Sql_Index'Class;
     Index : Qt4.Q_Integer)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QSqlIndex_isDescending_int (Self.Object, Index), 0);
   end Is_Descending;

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

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

   ---------------------
   -- Set_Cursor_Name --
   ---------------------

   procedure Set_Cursor_Name
    (Self : in out Q_Sql_Index'Class;
     Cursor_Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QSqlIndex_setCursorName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Cursor_Name));
   end Set_Cursor_Name;

   --------------------
   -- Set_Descending --
   --------------------

   procedure Set_Descending
    (Self : in out Q_Sql_Index'Class;
     Index : Qt4.Q_Integer;
     Desc : Boolean)
   is
   begin
      QSqlIndex_setDescending_int_bool (Self.Object, Index, Qt_Ada.Internals.Boolean_Conversions.To_unsigned (Desc));
   end Set_Descending;

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

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

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

   package body Internals is

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

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

   end Internals;

end Qt4.Sql_Records.Sql_Indices;
