File: gqbGridProjTable.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (327 lines) | stat: -rw-r--r-- 7,142 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbGridProjTable.cpp - Table implementation for Projection Panel Grid
//
//////////////////////////////////////////////////////////////////////////

// App headers
#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>
#include <wx/settings.h>
#include <wx/utils.h>
#include <wx/notebook.h>
#include <wx/regex.h>

// App headers
#include "gqb/gqbGridProjTable.h"
#include "gqb/gqbColumn.h"
#include "gqb/gqbQueryObjs.h"

gqbGridProjTable::gqbGridProjTable(gqbObjsArray *position, gqbObjsArray *parent, wxArrayString *alias):
	wxGridTableBase()
{
	colsPosition = position;
	colsParents = parent;
	columnsAlias = alias;
	// GQB-TODO: replace above pointers array with local variable if possible or research what it's causing bug in destructor???
}


gqbGridProjTable::~gqbGridProjTable()
{
}


int gqbGridProjTable::GetNumberRows()
{
	return (colsPosition->GetCount());
}


int gqbGridProjTable::GetNumberCols()
{

	return 3;
}


bool gqbGridProjTable::IsEmptyCell( int row, int col )
{

	int count = colsParents->GetCount();
	if(row + 1 <= count)
		return false;
	else
		return true;
}


wxString gqbGridProjTable::GetValue( int row, int col )
{
	switch(col)
	{
		case 0:
			if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length() > 0)
			{
				return ((gqbQueryObject *)colsParents->Item(row))->getAlias();
			}
			else
			{
				return ((gqbQueryObject *)colsParents->Item(row))->getName();
			}
			break;
		case 1:
			return ((gqbColumn *)colsPosition->Item(row))->getName();
			break;
		case 2:
			return columnsAlias->Item(row);
			break;
	};
	return wxT("");
}


wxString gqbGridProjTable::GetColLabelValue( int col)
{
	switch(col)
	{
		case 0:
			return _("Relation");
			break;
		case 1:
			return _("Column");
			break;
		case 2:
			return _("Alias");
			break;
	};
	return wxT("");
}


void gqbGridProjTable::SetValue( int row, int col, const wxString &value )
{
	// Do nothing on values that cannot be edited on this model [Column & Relation Name]
	switch(col)
	{
		case 2:
			columnsAlias->Item(row) = value;
			break;
	};
}

void *gqbGridProjTable::GetValueAsCustom( int row, int col, const wxString &typeName )
{
	switch(col)
	{
		case 0:
			return (void *)&colsParents->Item(row);
			break;
		case 1:
			return (void *)&colsPosition->Item(row);
			break;
		case 2:
			break;
	};
	return NULL;
}


void  gqbGridProjTable::SetValueAsCustom( int row, int col, const wxString &typeName, void *value )
{
	switch(col)
	{
		case 0:
			colsParents->Add(((gqbQueryObject *)value));
			break;
		case 1:
			colsPosition->Add(((gqbColumn *)value));
	};
}


void gqbGridProjTable::AppendItem(int col, gqbObject *item)
{
	bool notify = false;
	switch(col)
	{
		case 0:
			colsParents->Add(item);
			break;
		case 1:
			colsPosition->Add(item);
			notify = true;
			break;
		case 2:
			columnsAlias->Add(wxT(""));
			break;
	};

	if (notify && GetView() )
	{
		wxGridTableMessage msg( this,
		                        wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
		                        (colsParents->GetCount() - 1),
		                        1 );
		GetView()->ProcessTableMessage( msg );

		// Set the cells read-only
		GetView()->SetReadOnly(GetView()->GetNumberRows() - 1, 0);
		GetView()->SetReadOnly(GetView()->GetNumberRows() - 1, 1);
	}

}

// Remove a column at the grid
bool gqbGridProjTable::removeRow(gqbObject *itemTable, gqbObject *itemColumn)
{
	bool found = false;
	int i, size = colsPosition->GetCount();

	for(i = 0; i < size; i++)
	{
		if (colsParents->Item(i) == itemTable && colsPosition->Item(i) == itemColumn)
		{
			found = true;
			break;
		}
	}

	if(found)
	{
		colsParents->RemoveAt(i);
		colsPosition->RemoveAt(i);
		columnsAlias->RemoveAt(i);

		if ( GetView() )                          // Notify Grid about the change
		{
			wxGridTableMessage msg( this,
			                        wxGRIDTABLE_NOTIFY_ROWS_DELETED,
			                        i + 1,
			                        1 );
			GetView()->ProcessTableMessage( msg );
		}
	}

	return found;
}


void gqbGridProjTable::removeAllRows(gqbObject *itemTable)
{

	int size = colsParents->GetCount();
	for(int i = (size - 1); i >= 0; i--)
	{
		if (colsParents->Item(i) == itemTable)
		{
			colsParents->RemoveAt(i);
			colsPosition->RemoveAt(i);
			columnsAlias->RemoveAt(i);

			// Notify Grid about the change
			if ( GetView() )
			{
				wxGridTableMessage msg( this,
				                        wxGRIDTABLE_NOTIFY_ROWS_DELETED,
				                        i + 1,
				                        1 );
				GetView()->ProcessTableMessage( msg );
			}
		}
	}
}


void gqbGridProjTable::changesPositions(int sPos, int dPos)
{

	int size = colsPosition->GetCount();
	gqbObject *tmpTable = NULL, *tmpColumn = NULL;
	wxString tmpAlias = wxT("");

	if( (sPos >= 0 && sPos < size) && (dPos >= 0 && dPos < size) )
	{
		tmpTable = colsParents->Item(sPos);
		tmpColumn = colsPosition->Item(sPos);
		tmpAlias = columnsAlias->Item(sPos);

		colsParents->Item(sPos) = colsParents->Item(dPos);
		colsPosition->Item(sPos) = colsPosition->Item(dPos);
		columnsAlias->Item(sPos) = columnsAlias->Item(dPos);
		colsParents->Item(dPos) = tmpTable;
		colsPosition->Item(dPos) = tmpColumn;
		columnsAlias->Item(dPos) = tmpAlias;
	}

	wxGridTableMessage msg( this,
	                        wxGRIDTABLE_REQUEST_VIEW_GET_VALUES,
	                        sPos,
	                        1 );
	GetView()->ProcessTableMessage( msg );

}


// GQB-TODO: optimize this functions & related buttons events at gqbView because works but are a mess.
// Change a single row or a range to one pos up or down (but no more than one position)
void gqbGridProjTable::changesRangeOnePos(int topPos, int bottomPos, int newTop)
{
	// Eliminate side effect of zero base array on calculations, but careful newTop still it's zero based
	topPos++;
	bottomPos++;
	int sizeRange = bottomPos - (topPos - 1), size = GetNumberRows();
	if(topPos > newTop)                           // Go Down
	{
		// Only if the movement don't create an overflow
		if( (topPos > 1) && ((newTop + sizeRange) <  size)  )
		{
			for(int i = newTop ; i < (newTop + sizeRange) ; i++)
			{
				changesPositions(i, i + 1);
			}
		}

	}                                             // Go Up
	else
	{
		// Only if the movement don't create an overflow
		if( (bottomPos < size) && ((newTop + sizeRange) <=  size)  )
		{
			// Go Up Down
			for(int i = (newTop + sizeRange - 1) ; i >= newTop  ; i--)
			{
				changesPositions(i - 1, i);
			}
		}
	}
}


// Removes all items from gqbGridProjTable
void gqbGridProjTable::emptyTableData()
{

	int count = colsPosition->GetCount();
	colsPosition->Empty();
	colsParents->Empty();
	columnsAlias->Empty();

	// Notify Grid about the change
	if ( GetView() )
	{
		wxGridTableMessage msg( this,
		                        wxGRIDTABLE_NOTIFY_ROWS_DELETED,
		                        1,
		                        count);
		GetView()->ProcessTableMessage( msg );
	}
}