diff --git a/uppsrc/GridCtrl/GridCtrl.cpp b/uppsrc/GridCtrl/GridCtrl.cpp index 2755a261d..b18fea67b 100644 --- a/uppsrc/GridCtrl/GridCtrl.cpp +++ b/uppsrc/GridCtrl/GridCtrl.cpp @@ -2099,12 +2099,6 @@ void GridCtrl::LeftUp(Point p, dword keyflags) if(sorting_multicol && (keyflags & K_CTRL)) { - if(sortCol >= 0) - { - sortOrder.Add(sortCol); - sortCol = -1; - } - int colidx = InMultisort(newSortCol); if(colidx < 0) @@ -2149,7 +2143,7 @@ void GridCtrl::LeftUp(Point p, dword keyflags) hitems[idx].sortmode = 0; } - ClearMultisort(); + ClearMultisort(1); hitems[j].ChangeSortMode(); hitems[j].sortcol = 1; @@ -2158,7 +2152,7 @@ void GridCtrl::LeftUp(Point p, dword keyflags) else sortCol = newSortCol; - sortOrder.Clear(); + sortOrder.Add(newSortCol); if(WhenSort) WhenSort(); @@ -4591,20 +4585,22 @@ void GridCtrl::SyncSummary() else { int n = 0; + for(int j = fixed_rows; j < total_rows; j++) { + if(vitems[j].IsHidden()) + continue; + int idy = vitems[j].id; - + Value v = items[idy][idx].val; if(IsNull(v)) continue; - - ++n; - + ProcessSummaryValue(v); - if(j == fixed_rows && (sop == SOP_MIN || sop == SOP_MAX)) + if(n == 0 && (sop == SOP_MIN || sop == SOP_MAX)) t = v; if(IsNumber(v)) @@ -4624,9 +4620,33 @@ void GridCtrl::SyncSummary() t = double(t) + double(v); } } + else if(IsType(v)) + { + switch(sop) + { + case SOP_MIN: + if((Date) v < (Date) t) + t = v; + break; + case SOP_MAX: + if((Date) v > (Date) t) + t = v; + break; + case SOP_SUM: + case SOP_AVG: + t = v; + break; + } + } + + ++n; } + if(sop == SOP_AVG) - t = double(t) / double(n); + { + if(IsNumber(t)) + t = double(t) / double(n); + } } summary[idx].val = t; diff --git a/uppsrc/GridCtrl/GridCtrl.h b/uppsrc/GridCtrl/GridCtrl.h index 2c7c47020..a2cc89a76 100644 --- a/uppsrc/GridCtrl/GridCtrl.h +++ b/uppsrc/GridCtrl/GridCtrl.h @@ -1641,8 +1641,7 @@ class GridCtrl : public Ctrl void GSort(int col, int order, int from, int count = -1); void Multisort(); int InMultisort(int col); - bool ClearMultisort(); - bool ClearSorted(); + void ClearMultisort(int n = 0); bool IsSorted(); void MarkSort(int col, int sort_mode, bool refresh); diff --git a/uppsrc/GridCtrl/GridSort.cpp b/uppsrc/GridCtrl/GridSort.cpp index 89fa48f42..028c4a80d 100644 --- a/uppsrc/GridCtrl/GridSort.cpp +++ b/uppsrc/GridCtrl/GridSort.cpp @@ -119,32 +119,20 @@ int GridCtrl::InMultisort(int col) return -1; } -bool GridCtrl::ClearMultisort() +void GridCtrl::ClearMultisort(int n) { - if(sortOrder.IsEmpty()) - return false; - - return ClearSorted(); -} - -bool GridCtrl::ClearSorted() -{ - bool sorted = false; - - for(int i = 0; i < total_cols; i++) + for(int i = n; i < sortOrder.GetCount(); i++) { - if(hitems[i].sortMode > 0) - sorted = true; - hitems[i].sortmode = 0; - hitems[i].sortcol = 0; + int c = GetIdCol(sortOrder[i], true); + hitems[c].sortmode = 0; + hitems[c].sortcol = 0; } - - return sorted; + sortOrder.Clear(); } bool GridCtrl::IsSorted() { - return sortOrder.GetCount() > 0 || sortCol >= 0; + return sortOrder.GetCount() > 0; } void GridCtrl::MarkSort(int col, int sort_mode, bool refresh) @@ -174,10 +162,7 @@ GridCtrl& GridCtrl::Sort(int sort_col, int sort_mode, bool multisort, bool repai return *this; if(!multisort) - { - sortOrder.Clear(); - ClearSorted(); - } + ClearMultisort(); sortOrder.Add(col); @@ -228,27 +213,17 @@ Vector GridCtrl::GetSortOrderId() const Vector GridCtrl::GetSortOrder() const { Vector v; - if(sortOrder.GetCount() > 0) + + for(int i = 0; i < sortOrder.GetCount(); i++) { - for(int i = 0; i < sortOrder.GetCount(); i++) - { - int c = sortOrder[i]; - SortOrder& s = v.Add(); - s.id = c; - s.name = aliases.GetKey(c); - s.ascending = hitems[c].IsSortAsc(); - s.descending = hitems[c].IsSortDsc(); - } - } - else if(sortCol >= 0) - { - int c = sortCol; + int c = sortOrder[i]; SortOrder& s = v.Add(); s.id = c; s.name = aliases.GetKey(c); s.ascending = hitems[c].IsSortAsc(); s.descending = hitems[c].IsSortDsc(); } + return v; }