From: <vo...@us...> - 2012-08-23 19:26:56
|
Revision: 2913 http://moneymanagerex.svn.sourceforge.net/moneymanagerex/?rev=2913&view=rev Author: vomikan Date: 2012-08-23 19:26:49 +0000 (Thu, 23 Aug 2012) Log Message: ----------- sort order for columns Modified Paths: -------------- branches/0.9.9.0/mmex/src/stockspanel.cpp branches/0.9.9.0/mmex/src/stockspanel.h Modified: branches/0.9.9.0/mmex/src/stockspanel.cpp =================================================================== --- branches/0.9.9.0/mmex/src/stockspanel.cpp 2012-08-23 13:06:44 UTC (rev 2912) +++ branches/0.9.9.0/mmex/src/stockspanel.cpp 2012-08-23 19:26:49 UTC (rev 2913) @@ -59,8 +59,9 @@ EVT_LIST_ITEM_ACTIVATED(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnListItemActivated) EVT_LIST_ITEM_RIGHT_CLICK(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnItemRightClick) EVT_LIST_ITEM_SELECTED(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnListItemSelected) - EVT_LIST_ITEM_DESELECTED(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnListItemDeselected) - EVT_LIST_COL_END_DRAG(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnItemResize) + EVT_LIST_ITEM_DESELECTED(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnListItemDeselected) + EVT_LIST_COL_END_DRAG(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnItemResize) + EVT_LIST_COL_CLICK(ID_PANEL_STOCKS_LISTCTRL, stocksListCtrl::OnColClick) EVT_MENU(MENU_TREEPOPUP_NEW, stocksListCtrl::OnNewStocks) EVT_MENU(MENU_TREEPOPUP_EDIT, stocksListCtrl::OnEditStocks) @@ -79,6 +80,12 @@ Create(parent, winid, pos, size, style, name); } +void stocksListCtrl::InitVariables() +{ + m_selected_col = 0; + m_asc = true; +} + bool mmStocksPanel::Create(wxWindow *parent, wxWindowID winid, const wxPoint& pos, const wxSize& size,long style, const wxString& name) @@ -92,6 +99,7 @@ GetSizer()->Fit(this); GetSizer()->SetSizeHints(this); + listCtrlAccount_->InitVariables(); initVirtualListControl(); if (trans_.size() > 1) listCtrlAccount_->EnsureVisible(((int)trans_.size()) - 1); @@ -178,8 +186,10 @@ wxSize imageSize(16, 16); m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); - m_imageList->Add(wxBitmap(uparrow_xpm)); - m_imageList->Add(wxBitmap(downarrow_red_xpm)); + m_imageList->Add(wxBitmap(wxImage(uparrow_xpm).Scale(16, 16))); + m_imageList->Add(wxBitmap(wxImage(downarrow_red_xpm).Scale(16, 16))); + m_imageList->Add(wxBitmap(wxImage(uparrow_xpm).Scale(16, 16))); + m_imageList->Add(wxBitmap(wxImage(downarrow_xpm).Scale(16, 16))); listCtrlAccount_ = new stocksListCtrl(this, itemSplitterWindow10, ID_PANEL_STOCKS_LISTCTRL, wxDefaultPosition, wxDefaultSize, @@ -254,7 +264,7 @@ updateExtraStocksData(-1); } -void mmStocksPanel::initVirtualListControl() +void mmStocksPanel::initVirtualListControl(int col, bool asc) { /* Clear all the records */ trans_.clear(); @@ -305,43 +315,51 @@ header->SetLabel(lbl); - char sql[] = - "select S.STOCKID, S.HELDAT, S.STOCKNAME, UPPER(S.SYMBOL) SYMBOL, " - "S.NUMSHARES as NUMSHARES, t.TOTAL_NUMSHARES, T.PURCHASEDTIME, " - "T.AVG_PURCHASEPRICE as AVG_PURCHASEPRICE, " - "S.PURCHASEPRICE as PURCHASEPRICE, " - "S.CURRENTPRICE as CURRENTPRICE, " - "S.VALUE as VALUE, S.COMMISSION as COMMISSION, " - "ifnull (strftime(INFOVALUE, S.PURCHASEDATE),strftime(replace (i.infovalue, '%y', SubStr (strftime('%Y', S.PURCHASEDATE),3,2)),S.PURCHASEDATE)) as PURCHDATE, " - "S.PURCHASEDATE as PURCHASEDATE, " - "julianday('now', 'localtime')-julianday (S.PURCHASEDATE, 'localtime') as DAYSOWN, " - "S.NOTES " - "from STOCK_V1 S " - "left join infotable_v1 i on i.INFONAME='DATEFORMAT' " - "left join ( " - "select count (UPPER (SYMBOL)) as PURCHASEDTIME, " - "HELDAT, UPPER (SYMBOL) as SYMBOL, " - "total (NUMSHARES) as TOTAL_NUMSHARES, " - "total(PURCHASEPRICE*NUMSHARES)/total(NUMSHARES) as AVG_PURCHASEPRICE " - "from STOCK_V1 " - "left join infotable_v1 i on i.INFONAME='DATEFORMAT' " - "group by HELDAT, UPPER (SYMBOL) " - "order by julianday(min (PURCHASEDATE),'localtime'), SYMBOL, STOCKNAME " - ") T on UPPER (T.SYMBOL)=UPPER (S.SYMBOL) and T.HELDAT=S.HELDAT " - "where S.HELDAT = ? " - "order by julianday((S.PURCHASEDATE),'localtime'), S.SYMBOL, S.STOCKNAME "; + wxString sql = + wxT("select \ + S.PURCHASEDATE as PURCHASEDATE, \ + S.STOCKNAME, \ + S.NUMSHARES as NUMSHARES, \ + S.VALUE as VALUE, \ + (S.VALUE - (S.NUMSHARES*S.PURCHASEPRICE + S.COMMISSION)) as GAIN_LOSS, \ + S.CURRENTPRICE as CURRENTPRICE, \ + S.NOTES, \ + T.AVG_PURCHASEPRICE as AVG_PURCHASEPRICE, \ + S.PURCHASEPRICE as PURCHASEPRICE, \ + S.STOCKID, S.HELDAT, UPPER(S.SYMBOL) SYMBOL, \ + S.COMMISSION as COMMISSION, \ + julianday('now', 'localtime')-julianday (S.PURCHASEDATE, 'localtime') as DAYSOWN, \ + t.TOTAL_NUMSHARES, T.PURCHASEDTIME, \ + ifnull (strftime(INFOVALUE, S.PURCHASEDATE),strftime(replace (i.infovalue, '%y', SubStr (strftime('%Y', S.PURCHASEDATE),3,2)),S.PURCHASEDATE)) as PURCHDATE \ + from STOCK_V1 S \ + left join infotable_v1 i on i.INFONAME='DATEFORMAT' \ + left join ( \ + select count (UPPER (SYMBOL)) as PURCHASEDTIME, \ + HELDAT, UPPER (SYMBOL) as SYMBOL, \ + total (NUMSHARES) as TOTAL_NUMSHARES, \ + total(PURCHASEPRICE*NUMSHARES)/total(NUMSHARES) as AVG_PURCHASEPRICE \ + from STOCK_V1 \ + left join infotable_v1 i on i.INFONAME='DATEFORMAT' \ + group by HELDAT, UPPER (SYMBOL) \ + order by julianday(min (PURCHASEDATE),'localtime'), SYMBOL, STOCKNAME \ + ) T on UPPER (T.SYMBOL)=UPPER (S.SYMBOL) and T.HELDAT=S.HELDAT \ + where S.HELDAT = ? "); + //"order by julianday((S.PURCHASEDATE),'localtime'), S.SYMBOL, S.STOCKNAME "; + sql << wxString::Format(wxT("order by %d "), col+1); + if (!asc) sql << wxT(" desc"); + wxSQLite3Statement st = db_->PrepareStatement(sql); st.Bind(1, accountID_); + wxSQLite3ResultSet q1 = st.ExecuteQuery(); - wxSQLite3ResultSet q1 = st.ExecuteQuery(); int cnt = 0; for ( ; q1.NextRow(); ++cnt) { mmStockTransactionHolder th; - th.id_ = q1.GetInt(wxT("STOCKID")); + th.id_ = q1.GetInt(wxT("STOCKID")); th.stockPDate_ = q1.GetString(wxT("PURCHDATE")); int accountID = q1.GetInt(wxT("HELDAT")); th.stockSymbol_ = q1.GetString (wxT ("SYMBOL")); @@ -876,3 +894,26 @@ cp_->updateExtraStocksData(selectedIndex_); } } + +void stocksListCtrl::OnColClick(wxListEvent& event) +{ + if(0 > event.GetColumn() || event.GetColumn() >= COL_MAX) return; + + if (m_selected_col == event.GetColumn()) m_asc = !m_asc; + + wxListItem item; + item.SetMask(wxLIST_MASK_IMAGE); + item.SetImage(-1); + cp_->listCtrlAccount_->SetColumn(m_selected_col, item); + + m_selected_col = event.GetColumn(); + + item.SetImage(m_asc ? 3 : 2); + SetColumn(m_selected_col, item); + + //doRefreshItems(); + cp_->initVirtualListControl(m_selected_col, m_asc); + long cnt = static_cast<long>(cp_->trans_.size()); + RefreshItems(0, cnt > 0 ? --cnt : 0); + cp_->updateExtraStocksData(-1); +} Modified: branches/0.9.9.0/mmex/src/stockspanel.h =================================================================== --- branches/0.9.9.0/mmex/src/stockspanel.h 2012-08-23 13:06:44 UTC (rev 2912) +++ branches/0.9.9.0/mmex/src/stockspanel.h 2012-08-23 19:26:49 UTC (rev 2913) @@ -5,12 +5,12 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -54,6 +54,7 @@ void OnItemRightClick(wxListEvent& event); void OnListItemActivated(wxListEvent& event); + void OnColClick(wxListEvent& event); void OnMarkTransaction(wxCommandEvent& event); void OnMarkAllTransactions(wxCommandEvent& event); void OnListKeyDown(wxListEvent& event); @@ -65,12 +66,15 @@ void OnDeleteStocks(wxCommandEvent& event); void OnEditStocks(wxCommandEvent& event); wxStaticText* stock_details_short_; + void InitVariables(); private: wxListItemAttr attr1_; // style1 wxListItemAttr attr2_; // style2 mmStocksPanel* cp_; long selectedIndex_; + int m_selected_col; + bool m_asc; }; /* Holds a single transaction */ @@ -126,7 +130,7 @@ void CreateControls(); /* updates thstockide checking panel data */ - void initVirtualListControl(); + void initVirtualListControl(int col = 0, bool asc = true); /* Getter for Virtual List Control */ wxString getItem(long item, long column); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |