1+ # The MIT License (MIT)
2+ #
3+ # Copyright (C) 2024 - Ericsson
4+ #
5+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6+ # of this software and associated documentation files (the "Software"), to deal
7+ # in the Software without restriction, including without limitation the rights
8+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+ # copies of the Software, and to permit persons to whom the Software is
10+ # furnished to do so, subject to the following conditions:
11+ #
12+ # The above copyright notice and this permission notice shall be included in
13+ # all copies or substantial portions of the Software.
14+ #
15+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+ # SOFTWARE.
22+
23+ """VirtualTableModel class file."""
24+
25+ SIZE_KEY = "size"
26+ LOW_INDEX_KEY = "lowIndex"
27+ COLUMN_IDS_KEY = "columnIds"
28+ LINES_KEY = "lines"
29+
30+ TABLE_LINE_INDEX_KEY = "index"
31+ TABLE_LINE_CELLS_KEY = "cells"
32+ TABLE_LINE_CELL_CONTENT_KEY = "content"
33+
34+
35+ # pylint: disable=too-few-public-methods
36+ class VirtualTableModel :
37+ '''
38+ Virtual table model that will be returned by the server
39+ '''
40+
41+ def __init__ (self , params ):
42+ # Size of the virtual table
43+ self .size = 0
44+ if SIZE_KEY in params :
45+ if params .get (SIZE_KEY ) is not None and type (params .get (SIZE_KEY )) is int :
46+ self .size = int (params .get (SIZE_KEY ))
47+ del params [SIZE_KEY ]
48+
49+ # Index of the first line in the virtual table
50+ self .low_index = 0
51+ if LOW_INDEX_KEY in params :
52+ if params .get (LOW_INDEX_KEY ) is not None and type (params .get (LOW_INDEX_KEY )) is int :
53+ self .low_index = int (params .get (LOW_INDEX_KEY ))
54+ del params [LOW_INDEX_KEY ]
55+
56+ # Array of column IDs in the virtual table
57+ self .column_ids = []
58+ if COLUMN_IDS_KEY in params :
59+ if params .get (COLUMN_IDS_KEY ) is not None :
60+ for column_id in params .get (COLUMN_IDS_KEY ):
61+ self .column_ids .append (column_id )
62+ del params [COLUMN_IDS_KEY ]
63+
64+ # Array of lines in the virtual table
65+ self .lines = []
66+ if LINES_KEY in params :
67+ for line in params .get (LINES_KEY ):
68+ self .lines .append (VirtualTableLine (line ))
69+ del params [LINES_KEY ]
70+
71+ def print (self ):
72+ print ("VirtualTableModel:" )
73+ print (f" size: { self .size } " )
74+ print (f" low_index: { self .low_index } " )
75+ print (f" column_ids: { self .column_ids } " )
76+
77+ print (" lines:" )
78+ for i , line in enumerate (self .lines ):
79+ line .print ()
80+
81+ class VirtualTableLine :
82+ '''
83+ Virtual table line that will be returned by the server
84+ '''
85+
86+ def __init__ (self , params ):
87+ # Index of the line in the virtual table
88+ self .index = - 1
89+ if TABLE_LINE_INDEX_KEY in params :
90+ if params .get (TABLE_LINE_INDEX_KEY ) is not None and type (params .get (TABLE_LINE_INDEX_KEY )) is int :
91+ self .index = int (params .get (TABLE_LINE_INDEX_KEY ))
92+ del params [TABLE_LINE_INDEX_KEY ]
93+
94+ # Array of cells in the line
95+ self .cells = []
96+ if TABLE_LINE_CELLS_KEY in params :
97+ if params .get (TABLE_LINE_CELLS_KEY ) is not None :
98+ for cell in params .get (TABLE_LINE_CELLS_KEY ):
99+ self .cells .append (VirtualTableLineCell (cell ))
100+ del params [TABLE_LINE_CELLS_KEY ]
101+
102+ def print (self ):
103+
104+ print (f" index: { self .index } " )
105+ print (" cells:" )
106+ for i , cell in enumerate (self .cells ):
107+ cell .print ()
108+ print (f" { '-' * 10 } " )
109+
110+ class VirtualTableLineCell :
111+ '''
112+ Virtual table line cell that will be returned by the server
113+ '''
114+
115+ def __init__ (self , params ):
116+ # Content of the cell
117+ self .content = None
118+ if TABLE_LINE_CELL_CONTENT_KEY in params :
119+ if params .get (TABLE_LINE_CELL_CONTENT_KEY ) is not None :
120+ self .content = params .get (TABLE_LINE_CELL_CONTENT_KEY )
121+ del params [TABLE_LINE_CELL_CONTENT_KEY ]
122+
123+ def print (self ):
124+ print (f" \" { TABLE_LINE_CELL_CONTENT_KEY } \" : \" { self .content } \" " )
0 commit comments