------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2008-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 System.Address_To_Access_Conversions;
with System.Address_Image;
--  This is a GNAT specific package.

with Qt4.Abstract_Item_Models;
with Qt4_Debug;
with Qt_Ada.Internals.Object_Registry;
with Qt_Ada.Internals.Objects;
with Qt_Ada.Internals.Objects.Abstract_Item_Model_Utilities;

package body Qt4.Model_Indices is

   procedure Q_Model_Index_Image (Item : Q_Model_Index);
   pragma Export (Ada, Q_Model_Index_Image, "q_model_index_image");

   function initialize_QModelIndex
    (Storage : System.Address)
      return not null Internals.QModelIndex_Access;
   pragma Import (C, initialize_QModelIndex, "__QtAda_inititialize_QModelIndex");

   function adjust_QModelIndex
    (Storage : System.Address;
     From    : not null Internals.QModelIndex_Access)
       return not null Internals.QModelIndex_Access;
   pragma Import (C, adjust_QModelIndex, "__QtAda_adjust_QModelIndex");

   procedure finalize_QModelIndex
    (Object : not null Internals.QModelIndex_Access);
   pragma Import (C, finalize_QModelIndex, "__QtAda_finalize_QModelIndex");

   function internalPointer_wrapper
     (Cpp_Object : not null Internals.QModelIndex_Access)
        return System.Address;
   pragma Import (C,
                  internalPointer_wrapper,
                  "__Qt4Ada_QModelIndex_internalPointer_wrapper");

   function model_wrapper
    (Self : not null Internals.QModelIndex_Access)
       return Qt_Ada.Internals.Objects.QObject_Access;
   pragma Import (C, model_wrapper, "__Qt4Ada_QModelIndex_model_wrapper");

   procedure QModelIndex_child_int_int
    (Returns : not null Internals.QModelIndex_Access;
     Self    : Internals.QModelIndex_Access;
     Row     : Qt4.Q_Integer;
     Column  : Qt4.Q_Integer);
   pragma Import
    (C, QModelIndex_child_int_int, "__QtAda_QModelIndex_child_int_int_Q");

   function QModelIndex_column
    (Self : not null Internals.QModelIndex_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QModelIndex_column, "__QtAda_QModelIndex_column_Q");

   procedure QModelIndex_data_ItemDataRole
    (Returns : not null Qt4.Variants.Internals.QVariant_Access;
     Self    : not null Internals.QModelIndex_Access;
     Role    : Qt4.Item_Data_Role);
   pragma Import
    (C,
     QModelIndex_data_ItemDataRole,
     "__QtAda_QModelIndex_data_ItemDataRole_Q");

   function QModelIndex_flags
    (Self : not null Internals.QModelIndex_Access)
       return Qt4.Item_Flags;
   pragma Import (C, QModelIndex_flags, "__QtAda_QModelIndex_flags_Q");

   function QModelIndex_isValid
    (Self : not null Internals.QModelIndex_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QModelIndex_isValid, "__QtAda_QModelIndex_isValid_Q");

   procedure QModelIndex_parent
    (Returns : not null Internals.QModelIndex_Access;
     Self : not null Internals.QModelIndex_Access);
   pragma Import (C, QModelIndex_parent, "__QtAda_QModelIndex_parent_Q");

   function QModelIndex_row
    (Self : not null Internals.QModelIndex_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QModelIndex_row, "__QtAda_QModelIndex_row_Q");

   procedure QModelIndex_sibling_int_int
    (Returns : not null Internals.QModelIndex_Access;
     Self    : not null Internals.QModelIndex_Access;
     Row     : Qt4.Q_Integer;
     Column  : Qt4.Q_Integer);
   pragma Import
    (C, QModelIndex_sibling_int_int, "__QtAda_QModelIndex_sibling_int_int_Q");

   function lt_QModelIndexCR
    (Self  : not null Internals.QModelIndex_Access;
     Other : not null Internals.QModelIndex_Access)
       return Interfaces.C.unsigned;
   pragma Import
    (C, lt_QModelIndexCR, "__QtAda_QModelIndex_lt_QModelIndexCR_Q");

   function eq_QModelIndexCR
    (Self  : not null Internals.QModelIndex_Access;
     Other : not null Internals.QModelIndex_Access)
       return Interfaces.C.unsigned;
   pragma Import
    (C, eq_QModelIndexCR, "__QtAda_QModelIndex_eq_QModelIndexCR_Q");

   -------------------------
   -- Q_Model_Index_Image --
   -------------------------

   procedure Q_Model_Index_Image (Item : Q_Model_Index) is
   begin
      Qt4_Debug.Output
       ("(row => "
          & Q_Integer_Image (Item.Row)
          & ", column => "
          & Q_Integer_Image (Item.Column)
          & ", internal_pointer => 0x"
          & System.Address_Image (Item.Internal_Pointer)
          & ')');
   end Q_Model_Index_Image;

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

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

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

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

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

   overriding procedure Initialize (Self : in out Q_Model_Index) is
      use type Internals.QModelIndex_Access;

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

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

   function Create return Q_Model_Index is
   begin
      return Self : Q_Model_Index
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QModelIndex (Self.Storage'Address);
      end return;
   end Create;

   -----------
   -- Child --
   -----------

   function Child
    (Self   : Q_Model_Index'Class;
     Row    : Qt4.Q_Integer;
     Column : Qt4.Q_Integer)
       return Q_Model_Index
   is
   begin
      return Returns : Q_Model_Index do
         QModelIndex_child_int_int (Returns.Object, Self.Object, Row, Column);
      end return;
   end Child;

   ------------
   -- Column --
   ------------

   function Column (Self : Q_Model_Index'Class) return Qt4.Q_Integer is
   begin
      return QModelIndex_column (Self.Object);
   end Column;

   ----------
   -- Data --
   ----------

   function Data
    (Self : Q_Model_Index'Class;
     Role : Qt4.Item_Data_Role := Qt4.Display_Role)
       return Qt4.Variants.Q_Variant
   is
   begin
      return Returns : Qt4.Variants.Q_Variant do
         QModelIndex_data_ItemDataRole
          (Qt4.Variants.Internals.QVariant_View (Returns), Self.Object, Role);
      end return;
   end Data;

   -----------
   -- Flags --
   -----------

   function Flags (Self : Q_Model_Index'Class) return Qt4.Item_Flags is
   begin
      return QModelIndex_flags (Self.Object);
   end Flags;

   ----------------------
   -- Internal_Pointer --
   ----------------------

   function Internal_Pointer (Self : Q_Model_Index) return System.Address is
   begin
      return internalPointer_wrapper (Self.Object);
   end Internal_Pointer;

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

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

   -----------
   -- Model --
   -----------

   function Model (Self : Q_Model_Index)
     return access Qt4.Abstract_Item_Models.Q_Abstract_Item_Model'Class
   is
   begin
      return
        Qt_Ada.Internals.Objects.Abstract_Item_Model_Utilities.
          Corresponding_Q_Abstract_Item_Model (model_wrapper (Self.Object));
   end Model;

   ------------
   -- Parent --
   ------------

   function Parent (Self : Q_Model_Index'Class) return Q_Model_Index is
   begin
      return Returns : Q_Model_Index do
         QModelIndex_parent (Returns.Object, Self.Object);
      end return;
   end Parent;

   ---------
   -- Row --
   ---------

   function Row (Self : Q_Model_Index'Class) return Qt4.Q_Integer is
   begin
      return QModelIndex_row (Self.Object);
   end Row;

   -------------
   -- Sibling --
   -------------

   function Sibling
    (Self   : Q_Model_Index'Class;
     Row    : Qt4.Q_Integer;
     Column : Qt4.Q_Integer)
       return Q_Model_Index
   is
   begin
      return Returns : Q_Model_Index do
         QModelIndex_sibling_int_int (Returns.Object, Self.Object, Row, Column);
      end return;
   end Sibling;

   ---------
   -- "<" --
   ---------

   function "<"
    (Self  : Q_Model_Index;
     Other : Q_Model_Index)
       return Boolean
   is
   begin
      return
        Interfaces.C."/=" (lt_QModelIndexCR (Self.Object, Other.Object), 0);
   end "<";

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

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

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

   package body Internals is

      ----------------------
      -- QModelIndex_View --
      ----------------------

      function QModelIndex_View
       (Item : Q_Model_Index'Class)
          return QModelIndex_Access
      is
      begin
         return Item.Object;
      end QModelIndex_View;

      package QModelIndex_Conversions is
        new System.Address_To_Access_Conversions
             (QModelIndex);

      ---------------------------
      -- QModelIndexTo_Pointer --
      ---------------------------

      function To_Pointer
       (Address : System.Address)
          return QModelIndex_Access
      is
      begin
         return
           QModelIndex_Access
            (QModelIndex_Conversions.To_Pointer
            (Address));
      end To_Pointer;

      ---------------------------
      -- QModelIndexTo_Address --
      ---------------------------

      function To_Address
       (Pointer : QModelIndex_Access)
          return System.Address
      is
      begin
         return
           QModelIndex_Conversions.To_Address
            (QModelIndex_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

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

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

   end Internals;

end Qt4.Model_Indices;
