SAGA API v9.10
Loading...
Searching...
No Matches
table_selection.cpp
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// table_selection.cpp //
15// //
16// Copyright (C) 2005 by Olaf Conrad //
17// //
18//-------------------------------------------------------//
19// //
20// This file is part of 'SAGA - System for Automated //
21// Geoscientific Analyses'. //
22// //
23// This library is free software; you can redistribute //
24// it and/or modify it under the terms of the GNU Lesser //
25// General Public License as published by the Free //
26// Software Foundation, either version 2.1 of the //
27// License, or (at your option) any later version. //
28// //
29// This library is distributed in the hope that it will //
30// be useful, but WITHOUT ANY WARRANTY; without even the //
31// implied warranty of MERCHANTABILITY or FITNESS FOR A //
32// PARTICULAR PURPOSE. See the GNU Lesser General Public //
33// License for more details. //
34// //
35// You should have received a copy of the GNU Lesser //
36// General Public License along with this program; if //
37// not, see <http://www.gnu.org/licenses/>. //
38// //
39//-------------------------------------------------------//
40// //
41// contact: Olaf Conrad //
42// Institute of Geography //
43// University of Goettingen //
44// Goldschmidtstr. 5 //
45// 37077 Goettingen //
46// Germany //
47// //
48// e-mail: oconrad@saga-gis.org //
49// //
51
52//---------------------------------------------------------
53#include "table.h"
54
55
57// //
58// //
59// //
61
62//---------------------------------------------------------
64{
65 if( m_Selection.Inc_Array() )
66 {
67 return( _Set_Selection(iRecord, m_Selection.Get_Size() - 1) );
68 }
69
70 return( false );
71}
72
73//---------------------------------------------------------
75{
76 if( Selected < m_Selection.Get_Size() )
77 {
78 *((sLong *)m_Selection.Get_Entry(Selected)) = Index;
79
80 return( true );
81 }
82
83 return( false );
84}
85
86//---------------------------------------------------------
88{
89 for(sLong i=0; i<m_Selection.Get_Size(); i++)
90 {
91 if( Index == Get_Selection_Index(i) )
92 {
93 sLong *Selection = (sLong *)m_Selection.Get_Array();
94
95 for(sLong j=i+1; j<m_Selection.Get_Size(); i++, j++)
96 {
97 Selection[i] = Selection[j];
98 }
99
100 m_Selection.Dec_Array();
101
102 return( true );
103 }
104 }
105
106 return( false );
107}
108
109
111// //
113
114//---------------------------------------------------------
115bool CSG_Table::_Destroy_Selection(void)
116{
117 if( Get_Selection_Count() > 0 )
118 {
119 for(size_t iRecord=0; iRecord<(size_t)m_nRecords; iRecord++)
120 {
121 m_Records[iRecord]->Set_Selected(false);
122 }
123
124 m_Selection.Set_Array(0);
125 }
126
127 return( true );
128}
129
130
132// //
134
135//---------------------------------------------------------
136bool CSG_Table::Select(sLong iRecord, bool bInvert)
137{
138 if( !bInvert )
139 {
140 _Destroy_Selection();
141 }
142
143 CSG_Table_Record *pRecord = Get_Record(iRecord);
144
145 if( pRecord == NULL )
146 {
147 return( false );
148 }
149
150 if( pRecord->is_Selected() == false )
151 {
152 pRecord->Set_Selected(true);
153
154 _Add_Selection(iRecord);
155 }
156 else // if( pRecord->is_Selected() == true )
157 {
158 pRecord->Set_Selected(false);
159
160 _Del_Selection(iRecord);
161 }
162
163 return( true );
164}
165
166//---------------------------------------------------------
167bool CSG_Table::Select(CSG_Table_Record *pRecord, bool bInvert)
168{
169 return( Select(pRecord ? pRecord->Get_Index() : -1, bInvert) );
170}
171
172
174// //
176
177//---------------------------------------------------------
179{
180 sLong n = 0;
181
182 if( Get_Selection_Count() > 0 )
183 {
184 for(sLong i=m_nRecords-1; i>=0; i--)
185 {
186 if( m_Records[i]->is_Selected() )
187 {
188 m_Records[i]->Set_Selected(false);
189
190 Del_Record(i);
191
192 n++;
193 }
194 }
195
196 m_Selection.Set_Array(0);
197 }
198
199 return( n );
200}
201
202//---------------------------------------------------------
204{
205 if( m_nRecords > 0 )
206 {
207 m_Selection.Set_Array(m_nRecords - m_Selection.Get_Size());
208
209 for(sLong i=0, n=0; i<Get_Count(); i++)
210 {
211 CSG_Table_Record *pRecord = Get_Record(i);
212
213 if( pRecord->is_Selected() == false )//&& n < m_Selection.Get_Size() )
214 {
215 pRecord->Set_Selected(true);
216
217 *((sLong *)m_Selection.Get_Entry(n++)) = i;
218 }
219 else
220 {
221 pRecord->Set_Selected(false);
222 }
223 }
224 }
225
226 return( Get_Selection_Count() );
227}
228
229
231// //
232// //
233// //
235
236//---------------------------------------------------------
signed long long sLong
Definition api_core.h:158
void Set_Selected(bool bOn=true)
sLong Get_Index(void) const
Definition table.h:136
bool is_Selected(void) const
Definition table.h:244
sLong Get_Count(void) const
Definition table.h:400
bool _Set_Selection(sLong Index, sLong Selected)
sLong m_nRecords
Definition table.h:489
virtual bool Select(sLong Index, bool bInvert=false)
friend class CSG_Table_Record
Definition table.h:286
CSG_Array m_Selection
Definition table.h:491
virtual sLong Inv_Selection(void)
virtual CSG_Table_Record * Get_Record(sLong Index) const
Definition table.h:402
virtual bool Del_Record(sLong Index)
Definition table.cpp:897
bool _Add_Selection(sLong Index)
virtual bool is_Selected(sLong Index) const
Definition table.h:432
sLong Get_Selection_Index(sLong Index=0) const
Definition table.h:429
sLong Get_Selection_Count(void) const
Definition table.h:428
bool _Del_Selection(sLong Index)
virtual sLong Del_Selection(void)