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
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbGridOrderTable.cpp - Table implementation for Order By Panel Grid
//
//////////////////////////////////////////////////////////////////////////
// App headers
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "gqb/gqbGridOrderTable.h"
#include "gqb/gqbColumn.h"
#include "gqb/gqbArrayCollection.h"
#include "gqb/gqbModel.h"
gqbGridOrderTable::gqbGridOrderTable(int numColumns, gqbObjsArray *cols, gqbObjsArray *parent, charArray *orderBy)
{
numberColumns = numColumns;
columns = cols;
colsParents = parent;
kindOfOrder = orderBy;
}
gqbGridOrderTable::~gqbGridOrderTable()
{
}
int gqbGridOrderTable::GetNumberRows()
{
return (columns->GetCount());
}
int gqbGridOrderTable::GetNumberCols()
{
return numberColumns;
}
bool gqbGridOrderTable::IsEmptyCell( int row, int col )
{
int count = columns->GetCount();
if(row + 1 <= count)
return false;
else
return true;
}
wxString gqbGridOrderTable::GetValue( int row, int col )
{
if(col == 0)
{
wxString col = wxT("");
if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length() > 0)
{
col += ((gqbQueryObject *)colsParents->Item(row))->getAlias() + wxT(".");
}
else
{
col += ((gqbQueryObject *)colsParents->Item(row))->getName() + wxT(".");
}
col += ((gqbColumn *)columns->Item(row))->getName();
return col;
}
if(numberColumns == 2)
{
if(col == 1)
{
wxString ord = wxT("");
if(kindOfOrder->Item(row) == 'A')
ord += wxT("ASC");
else
ord += wxT("DESC");
return ord;
}
}
return wxT("");
}
wxString gqbGridOrderTable::GetColLabelValue(int col)
{
switch(col)
{
case 0:
if(numberColumns == 2)
{
return _("Column");
}
else
{
return _("Available Columns");
}
break;
case 1:
return _("Order");
break;
};
return wxT("");
}
void gqbGridOrderTable::SetValue( int row, int col, const wxString &value )
{
if(col == 1 && numberColumns == 2)
{
if(value.Contains(wxT("ASC")))
{
kindOfOrder->Item(row) = 'A';
}
else
{
kindOfOrder->Item(row) = 'D';
}
}
}
void gqbGridOrderTable::AppendItem(gqbColumn *column, gqbQueryObject *parent, char kindOrder)
{
columns->Add(column);
colsParents->Add(parent);
if(numberColumns == 2)
{
kindOfOrder->Add(kindOrder);
}
if (GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
(columns->GetCount() - 1),
1 );
GetView()->ProcessTableMessage( msg );
}
}
bool gqbGridOrderTable::removeFirstRow(gqbObject *itemTable)
{
bool found = false;
int i, size = colsParents->GetCount();
for(i = 0; i < size; i++)
{
if (colsParents->Item(i) == itemTable)
{
found = true;
break;
}
}
if(found)
{
columns->RemoveAt(i);
colsParents->RemoveAt(i);
if(numberColumns == 2)
{
kindOfOrder->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 gqbGridOrderTable::emptyTableData(gqbQueryObject *object)
{
// Because items positions on array changes when I delete one, I have to do the remove in this way
while(removeFirstRow(object));
}
void gqbGridOrderTable::removeRowAt(int i)
{
columns->RemoveAt(i);
colsParents->RemoveAt(i);
if(numberColumns == 2)
{
kindOfOrder->RemoveAt(i);
}
// Notify Grid about the change
if ( GetView() )
{
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
i + 1,
1 );
GetView()->ProcessTableMessage( msg );
}
}
gqbObject *gqbGridOrderTable::getObjectAt(int pos, int col)
{
gqbObject *value = NULL;
switch(col)
{
case 0:
value = columns->Item(pos);
break;
case 1:
value = colsParents->Item(pos);
break;
};
return value;
}
void gqbGridOrderTable::changesPositions(int sPos, int dPos)
{
int size = columns->GetCount();
gqbObject *tmpTable = NULL, *tmpColumn = NULL;
char tmpKind = 'N';
if( (sPos >= 0 && sPos < size) && (dPos >= 0 && dPos < size) )
{
tmpTable = colsParents->Item(sPos);
tmpColumn = columns->Item(sPos);
tmpKind = kindOfOrder->Item(sPos);
colsParents->Item(sPos) = colsParents->Item(dPos);
columns->Item(sPos) = columns->Item(dPos);
kindOfOrder->Item(sPos) = kindOfOrder->Item(dPos);
colsParents->Item(dPos) = tmpTable;
columns->Item(dPos) = tmpColumn;
kindOfOrder->Item(dPos) = tmpKind;
}
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 gqbGridOrderTable::changesRangeOnePos(int topPos, int bottomPos, int newTop)
{
// Eliminate side effect of zero base array on calculations, but carefull 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);
}
}
}
}
|