source: trunk/dsa_messenger/client-user_list_models.adb

Last change on this file was 8, checked in by vadim.godunko, 12 years ago

Add list of users.

File size: 2.5 KB
Line 
1with Client.User_List_Models.Moc;
2
3package body Client.User_List_Models is
4
5 ------------------
6 -- Constructors --
7 ------------------
8
9 package body Constructors is
10
11 ------------
12 -- Create --
13 ------------
14
15 function Create (Parent : access Qt4.Objects.Q_Object'Class := null)
16 return not null User_List_Model_Access is
17 begin
18 return Self : constant not null User_List_Model_Access
19 := new User_List_Model
20 do
21 Qt4.Abstract_List_Models.Directors.Constructors.Initialize
22 (Self, Parent);
23 end return;
24 end Create;
25
26 end Constructors;
27
28 ----------
29 -- Data --
30 ----------
31
32 overriding function Data
33 (Self : not null access User_List_Model;
34 Index : Qt4.Model_Indices.Q_Model_Index;
35 Role : Qt4.Item_Data_Role := Qt4.Display_Role)
36 return Qt4.Variants.Q_Variant is
37 begin
38 case Role is
39 when Qt4.Display_Role =>
40 return
41 Qt4.Variants.Create (Self.Users.Element (Natural (Index.Row)));
42
43 when others =>
44 return Qt4.Variants.Create;
45 end case;
46 end Data;
47
48 ------------
49 -- Insert --
50 ------------
51
52 procedure Insert
53 (Self : not null access User_List_Model'Class;
54 Name : Qt4.Strings.Q_String)
55 is
56 use type Qt4.Q_Integer;
57
58 begin
59 Self.Begin_Insert_Rows
60 (Qt4.Model_Indices.Create,
61 Qt4.Q_Integer (Self.Users.Length),
62 Qt4.Q_Integer (Self.Users.Length) + 1);
63 Self.Users.Append (Name);
64 Self.End_Insert_Rows;
65 end Insert;
66
67 ------------
68 -- Remove --
69 ------------
70
71 procedure Remove
72 (Self : not null access User_List_Model'Class;
73 Name : Qt4.Strings.Q_String)
74 is
75 Position : Q_String_Vectors.Cursor := Self.Users.Find (Name);
76
77 begin
78 if Q_String_Vectors.Has_Element (Position) then
79 Self.Begin_Remove_Rows
80 (Qt4.Model_Indices.Create,
81 Qt4.Q_Integer (Q_String_Vectors.To_Index (Position)),
82 Qt4.Q_Integer (Q_String_Vectors.To_Index (Position)));
83 Self.Users.Delete (Position);
84 Self.End_Remove_Rows;
85 end if;
86 end Remove;
87
88 ---------------
89 -- Row_Count --
90 ---------------
91
92 overriding function Row_Count
93 (Self : not null access constant User_List_Model;
94 Parent : Qt4.Model_Indices.Q_Model_Index
95 := Qt4.Model_Indices.Create) return Qt4.Q_Integer is
96 begin
97 return Qt4.Q_Integer (Self.Users.Length);
98 end Row_Count;
99
100end Client.User_List_Models;
Note: See TracBrowser for help on using the repository browser.