~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

« back to all changes in this revision

Viewing changes to pgadmin/gqb/gqbGridOrderTable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2011-06-07 23:03:54 UTC
  • mfrom: (1.3.1 upstream) (13 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110607230354-3td4j9y71u4ahcvj
Tags: 1.14.0~beta1-1
* New upstream development release, adding Build-Depends on
  postgresql-server-dev-all >= 117~.
* Add Build-Depends on quilt, (un)patch to debian/rules and patch for fixing
  the include for kwlist.h in pgadmin/db/keywords.c.
* Add pg_config --includedir-server output to CPPFLAGS.
* Remove unrecognized configure options: --with-wx-config,
  --with-pgsql-include, --enable-gtk2, --enable-unicode.
* Clean up manually the files that are left behind after the broken
  distclean.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//////////////////////////////////////////////////////////////////////////
2
2
//
3
3
// pgAdmin III - PostgreSQL Tools
4
 
// 
5
 
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
 
4
//
 
5
// Copyright (C) 2002 - 2011, The pgAdmin Development Team
6
6
// This software is released under the PostgreSQL Licence
7
7
//
8
8
// gqbGridOrderTable.cpp - Table implementation for Order By Panel Grid
21
21
#include "gqb/gqbArrayCollection.h"
22
22
#include "gqb/gqbModel.h"
23
23
 
24
 
gqbGridOrderTable::gqbGridOrderTable(int numColumns, gqbObjsArray* cols, gqbObjsArray* parent, charArray* orderBy)
 
24
gqbGridOrderTable::gqbGridOrderTable(int numColumns, gqbObjsArray *cols, gqbObjsArray *parent, charArray *orderBy)
25
25
{
26
 
    numberColumns=numColumns;
27
 
    columns=cols;
28
 
    colsParents=parent;
29
 
    kindOfOrder=orderBy;
 
26
        numberColumns = numColumns;
 
27
        columns = cols;
 
28
        colsParents = parent;
 
29
        kindOfOrder = orderBy;
30
30
}
31
31
 
32
32
 
37
37
 
38
38
int gqbGridOrderTable::GetNumberRows()
39
39
{
40
 
    return (columns->GetCount());
 
40
        return (columns->GetCount());
41
41
}
42
42
 
43
43
 
44
44
int gqbGridOrderTable::GetNumberCols()
45
45
{
46
 
    return numberColumns;
 
46
        return numberColumns;
47
47
}
48
48
 
49
49
 
50
50
bool gqbGridOrderTable::IsEmptyCell( int row, int col )
51
51
{
52
 
    int count=columns->GetCount();
53
 
    if(row+1 <= count)
54
 
        return false;
55
 
    else
56
 
        return true;
 
52
        int count = columns->GetCount();
 
53
        if(row + 1 <= count)
 
54
                return false;
 
55
        else
 
56
                return true;
57
57
}
58
58
 
59
59
 
60
60
wxString gqbGridOrderTable::GetValue( int row, int col )
61
61
{
62
 
    if(col==0)
63
 
    {
64
 
        wxString col = wxT("");
65
 
        if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length()>0)
66
 
        {
67
 
            col+=((gqbQueryObject *)colsParents->Item(row))->getAlias()+wxT(".");
68
 
        }
69
 
        else
70
 
        {
71
 
            col+=((gqbQueryObject *)colsParents->Item(row))->getName()+wxT(".");
72
 
        }
73
 
        col+=((gqbColumn *)columns->Item(row))->getName();
74
 
        return col;
75
 
    }
76
 
 
77
 
    if(numberColumns==2)
78
 
    {
79
 
        if(col==1)
80
 
        {
81
 
            wxString ord = wxT("");
82
 
            if(kindOfOrder->Item(row)=='A')
83
 
                ord+=wxT("ASC");
84
 
            else
85
 
                ord+=wxT("DESC");
86
 
 
87
 
            return ord;
88
 
        }
89
 
    }
90
 
    return wxT("");
 
62
        if(col == 0)
 
63
        {
 
64
                wxString col = wxT("");
 
65
                if(((gqbQueryObject *)colsParents->Item(row))->getAlias().length() > 0)
 
66
                {
 
67
                        col += ((gqbQueryObject *)colsParents->Item(row))->getAlias() + wxT(".");
 
68
                }
 
69
                else
 
70
                {
 
71
                        col += ((gqbQueryObject *)colsParents->Item(row))->getName() + wxT(".");
 
72
                }
 
73
                col += ((gqbColumn *)columns->Item(row))->getName();
 
74
                return col;
 
75
        }
 
76
 
 
77
        if(numberColumns == 2)
 
78
        {
 
79
                if(col == 1)
 
80
                {
 
81
                        wxString ord = wxT("");
 
82
                        if(kindOfOrder->Item(row) == 'A')
 
83
                                ord += wxT("ASC");
 
84
                        else
 
85
                                ord += wxT("DESC");
 
86
 
 
87
                        return ord;
 
88
                }
 
89
        }
 
90
        return wxT("");
91
91
}
92
92
 
93
93
 
94
94
wxString gqbGridOrderTable::GetColLabelValue(int col)
95
95
{
96
 
    switch(col)
97
 
    {
98
 
        case 0:
99
 
            if(numberColumns==2)
100
 
            {
101
 
                return _("Column");
102
 
            }
103
 
            else
104
 
            {
105
 
                return _("Available Columns");
106
 
            }
107
 
            break;
108
 
        case 1:
109
 
            return _("Order");
110
 
            break;
111
 
    };
112
 
    return wxT("");
 
96
        switch(col)
 
97
        {
 
98
                case 0:
 
99
                        if(numberColumns == 2)
 
100
                        {
 
101
                                return _("Column");
 
102
                        }
 
103
                        else
 
104
                        {
 
105
                                return _("Available Columns");
 
106
                        }
 
107
                        break;
 
108
                case 1:
 
109
                        return _("Order");
 
110
                        break;
 
111
        };
 
112
        return wxT("");
113
113
}
114
114
 
115
115
 
116
 
void gqbGridOrderTable::SetValue( int row, int col, const wxString& value )
 
116
void gqbGridOrderTable::SetValue( int row, int col, const wxString &value )
117
117
{
118
 
    if(col==1 && numberColumns==2)
119
 
    {
120
 
        if(value.Contains(wxT("ASC")))
121
 
        {
122
 
            kindOfOrder->Item(row)='A';
123
 
        }
124
 
        else
125
 
        {
126
 
            kindOfOrder->Item(row)='D';
127
 
        }
128
 
    }
 
118
        if(col == 1 && numberColumns == 2)
 
119
        {
 
120
                if(value.Contains(wxT("ASC")))
 
121
                {
 
122
                        kindOfOrder->Item(row) = 'A';
 
123
                }
 
124
                else
 
125
                {
 
126
                        kindOfOrder->Item(row) = 'D';
 
127
                }
 
128
        }
129
129
}
130
130
 
131
131
 
132
132
void gqbGridOrderTable::AppendItem(gqbColumn *column, gqbQueryObject *parent, char kindOrder)
133
133
{
134
 
    columns->Add(column);
135
 
    colsParents->Add(parent);
136
 
    if(numberColumns==2)
137
 
    {
138
 
        kindOfOrder->Add(kindOrder);
139
 
    }
 
134
        columns->Add(column);
 
135
        colsParents->Add(parent);
 
136
        if(numberColumns == 2)
 
137
        {
 
138
                kindOfOrder->Add(kindOrder);
 
139
        }
140
140
 
141
 
    if (GetView() )
142
 
    {
143
 
        wxGridTableMessage msg( this,
144
 
            wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
145
 
            (columns->GetCount()-1),
146
 
            1 );
147
 
        GetView()->ProcessTableMessage( msg );
148
 
    }
 
141
        if (GetView() )
 
142
        {
 
143
                wxGridTableMessage msg( this,
 
144
                                        wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
 
145
                                        (columns->GetCount() - 1),
 
146
                                        1 );
 
147
                GetView()->ProcessTableMessage( msg );
 
148
        }
149
149
}
150
150
 
151
151
 
152
152
bool gqbGridOrderTable::removeFirstRow(gqbObject *itemTable)
153
153
{
154
 
    bool found=false;
155
 
    int i,size=colsParents->GetCount();
156
 
 
157
 
    for(i=0;i<size;i++)
158
 
    {
159
 
        if (colsParents->Item(i)==itemTable)
160
 
        {
161
 
            found=true;
162
 
            break;
163
 
        }
164
 
    }
165
 
 
166
 
    if(found)
167
 
    {
168
 
        columns->RemoveAt(i);
169
 
        colsParents->RemoveAt(i);
170
 
        if(numberColumns==2)
171
 
        {
172
 
            kindOfOrder->RemoveAt(i);
173
 
        }
174
 
        if ( GetView() )                          // Notify Grid about the change
175
 
        {
176
 
            wxGridTableMessage msg( this,
177
 
                wxGRIDTABLE_NOTIFY_ROWS_DELETED,
178
 
                i+1,
179
 
                1 );
180
 
            GetView()->ProcessTableMessage( msg );
181
 
        }
182
 
    }
183
 
 
184
 
    return found;
 
154
        bool found = false;
 
155
        int i, size = colsParents->GetCount();
 
156
 
 
157
        for(i = 0; i < size; i++)
 
158
        {
 
159
                if (colsParents->Item(i) == itemTable)
 
160
                {
 
161
                        found = true;
 
162
                        break;
 
163
                }
 
164
        }
 
165
 
 
166
        if(found)
 
167
        {
 
168
                columns->RemoveAt(i);
 
169
                colsParents->RemoveAt(i);
 
170
                if(numberColumns == 2)
 
171
                {
 
172
                        kindOfOrder->RemoveAt(i);
 
173
                }
 
174
                if ( GetView() )                          // Notify Grid about the change
 
175
                {
 
176
                        wxGridTableMessage msg( this,
 
177
                                                wxGRIDTABLE_NOTIFY_ROWS_DELETED,
 
178
                                                i + 1,
 
179
                                                1 );
 
180
                        GetView()->ProcessTableMessage( msg );
 
181
                }
 
182
        }
 
183
 
 
184
        return found;
185
185
}
186
186
 
187
187
 
188
188
void gqbGridOrderTable::emptyTableData(gqbQueryObject *object)
189
189
{
190
 
    // Because items positions on array changes when I delete one, I have to do the remove in this way
191
 
    while(removeFirstRow(object));
 
190
        // Because items positions on array changes when I delete one, I have to do the remove in this way
 
191
        while(removeFirstRow(object));
192
192
}
193
193
 
194
194
 
195
195
void gqbGridOrderTable::removeRowAt(int i)
196
196
{
197
 
    columns->RemoveAt(i);
198
 
    colsParents->RemoveAt(i);
199
 
    if(numberColumns==2)
200
 
    {
201
 
        kindOfOrder->RemoveAt(i);
202
 
    }
203
 
    // Notify Grid about the change
204
 
        if ( GetView() )                              
205
 
    {
206
 
        wxGridTableMessage msg( this,
207
 
            wxGRIDTABLE_NOTIFY_ROWS_DELETED,
208
 
            i+1,
209
 
            1 );
210
 
        GetView()->ProcessTableMessage( msg );
211
 
    }
 
197
        columns->RemoveAt(i);
 
198
        colsParents->RemoveAt(i);
 
199
        if(numberColumns == 2)
 
200
        {
 
201
                kindOfOrder->RemoveAt(i);
 
202
        }
 
203
        // Notify Grid about the change
 
204
        if ( GetView() )
 
205
        {
 
206
                wxGridTableMessage msg( this,
 
207
                                        wxGRIDTABLE_NOTIFY_ROWS_DELETED,
 
208
                                        i + 1,
 
209
                                        1 );
 
210
                GetView()->ProcessTableMessage( msg );
 
211
        }
212
212
}
213
213
 
214
214
 
215
 
gqbObject* gqbGridOrderTable::getObjectAt(int pos, int col)
 
215
gqbObject *gqbGridOrderTable::getObjectAt(int pos, int col)
216
216
{
217
 
    gqbObject *value = NULL;
218
 
    switch(col)
219
 
    {
220
 
        case 0:
221
 
            value=columns->Item(pos);
222
 
            break;
223
 
        case 1:
224
 
            value=colsParents->Item(pos);
225
 
            break;
226
 
    };
227
 
    return value;
 
217
        gqbObject *value = NULL;
 
218
        switch(col)
 
219
        {
 
220
                case 0:
 
221
                        value = columns->Item(pos);
 
222
                        break;
 
223
                case 1:
 
224
                        value = colsParents->Item(pos);
 
225
                        break;
 
226
        };
 
227
        return value;
228
228
}
229
229
 
230
230
 
231
231
void gqbGridOrderTable::changesPositions(int sPos, int dPos)
232
232
{
233
233
 
234
 
    int size=columns->GetCount();
235
 
    gqbObject *tmpTable=NULL, *tmpColumn=NULL;
236
 
    char tmpKind = 'N';
237
 
 
238
 
    if( (sPos>=0 && sPos < size) && (dPos>=0 && dPos < size) )
239
 
    {
240
 
        tmpTable=colsParents->Item(sPos);
241
 
        tmpColumn=columns->Item(sPos);
242
 
        tmpKind=kindOfOrder->Item(sPos);
243
 
 
244
 
        colsParents->Item(sPos)=colsParents->Item(dPos);
245
 
        columns->Item(sPos)=columns->Item(dPos);
246
 
        kindOfOrder->Item(sPos)=kindOfOrder->Item(dPos);
247
 
        colsParents->Item(dPos)=tmpTable;
248
 
        columns->Item(dPos)=tmpColumn;
249
 
        kindOfOrder->Item(dPos)=tmpKind;
250
 
    }
251
 
 
252
 
    wxGridTableMessage msg( this,
253
 
        wxGRIDTABLE_REQUEST_VIEW_GET_VALUES,
254
 
        sPos,
255
 
        1 );
256
 
    GetView()->ProcessTableMessage( msg );
 
234
        int size = columns->GetCount();
 
235
        gqbObject *tmpTable = NULL, *tmpColumn = NULL;
 
236
        char tmpKind = 'N';
 
237
 
 
238
        if( (sPos >= 0 && sPos < size) && (dPos >= 0 && dPos < size) )
 
239
        {
 
240
                tmpTable = colsParents->Item(sPos);
 
241
                tmpColumn = columns->Item(sPos);
 
242
                tmpKind = kindOfOrder->Item(sPos);
 
243
 
 
244
                colsParents->Item(sPos) = colsParents->Item(dPos);
 
245
                columns->Item(sPos) = columns->Item(dPos);
 
246
                kindOfOrder->Item(sPos) = kindOfOrder->Item(dPos);
 
247
                colsParents->Item(dPos) = tmpTable;
 
248
                columns->Item(dPos) = tmpColumn;
 
249
                kindOfOrder->Item(dPos) = tmpKind;
 
250
        }
 
251
 
 
252
        wxGridTableMessage msg( this,
 
253
                                wxGRIDTABLE_REQUEST_VIEW_GET_VALUES,
 
254
                                sPos,
 
255
                                1 );
 
256
        GetView()->ProcessTableMessage( msg );
257
257
 
258
258
}
259
259
 
262
262
// Change a single row or a range to one pos up or down (but no more than one position)
263
263
void gqbGridOrderTable::changesRangeOnePos(int topPos, int bottomPos, int newTop)
264
264
{
265
 
    // Eliminate side effect of zero base array on calculations, but carefull newTop still it's zero based
266
 
    topPos++;
267
 
    bottomPos++;
268
 
    int sizeRange=bottomPos-(topPos-1), size=GetNumberRows();
269
 
    if(topPos>newTop)                             // Go Down
270
 
    {
271
 
        // Only if the movement don't create an overflow
272
 
        if( (topPos > 1) && ((newTop+sizeRange) <  size)  )
273
 
        {
274
 
            for(int i=newTop ; i < (newTop+sizeRange) ; i++)
275
 
            {
276
 
                changesPositions(i,i+1);
277
 
            }
278
 
        }
 
265
        // Eliminate side effect of zero base array on calculations, but carefull newTop still it's zero based
 
266
        topPos++;
 
267
        bottomPos++;
 
268
        int sizeRange = bottomPos - (topPos - 1), size = GetNumberRows();
 
269
        if(topPos > newTop)                           // Go Down
 
270
        {
 
271
                // Only if the movement don't create an overflow
 
272
                if( (topPos > 1) && ((newTop + sizeRange) <  size)  )
 
273
                {
 
274
                        for(int i = newTop ; i < (newTop + sizeRange) ; i++)
 
275
                        {
 
276
                                changesPositions(i, i + 1);
 
277
                        }
 
278
                }
279
279
 
280
 
    }                                             // Go Up
281
 
    else
282
 
    {
283
 
        // Only if the movement don't create an overflow
284
 
        if( (bottomPos < size) && ((newTop+sizeRange) <=  size)  )
285
 
        {
286
 
                                                  // Go Up Down
287
 
            for(int i=(newTop+sizeRange-1) ; i >= newTop  ; i--)
288
 
            {
289
 
                changesPositions(i-1,i);
290
 
            }
291
 
        }
292
 
    }
 
280
        }                                             // Go Up
 
281
        else
 
282
        {
 
283
                // Only if the movement don't create an overflow
 
284
                if( (bottomPos < size) && ((newTop + sizeRange) <=  size)  )
 
285
                {
 
286
                        // Go Up Down
 
287
                        for(int i = (newTop + sizeRange - 1) ; i >= newTop  ; i--)
 
288
                        {
 
289
                                changesPositions(i - 1, i);
 
290
                        }
 
291
                }
 
292
        }
293
293
}