NCBI C++ ToolKit
seq_table_grid.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: seq_table_grid.hpp 43833 2019-09-09 17:38:14Z filippov $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Colleen Bollin
27  */
28 #ifndef _SEQ_TABLE_GRID_H_
29 #define _SEQ_TABLE_GRID_H_
30 
31 #include <corelib/ncbistd.hpp>
39 
40 /*!
41  * Includes
42  */
43 
44 // For compilers that support precompilation, includes "wx/wx.h".
45 #include "wx/wxprec.h"
46 
47 #ifdef __BORLANDC__
48 #pragma hdrstop
49 #endif
50 
51 #ifndef WX_PRECOMP
52 #include "wx/wx.h"
53 #endif
54 
55 ////@begin includes
56 #include "wx/grid.h"
57 #include <wx/textwrapper.h>
58 ////@end includes
59 
60 
61 /*!
62  * Forward declarations
63  */
64 
65 ////@begin forward declarations
66 ////@end forward declarations
67 
69 
70 
71 static const int kSkipColumns = 1;
72 
73 class CSeqGridCellAttrProvider : public wxGridCellAttrProvider
74 {
75 public:
77  virtual ~CSeqGridCellAttrProvider();
78 
79  virtual wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind = wxGridCellAttr::Any) const wxOVERRIDE;
80  virtual void SetAttr(wxGridCellAttr *attr, int row, int col) wxOVERRIDE;
81 
82 private:
83 
84 // http://stackoverflow.com/questions/32685540/c-unordered-map-with-pair-as-key-not-compiling
85  struct pair_hash
86  {
87  template <class T1, class T2>
88  std::size_t operator () (const std::pair<T1,T2> &p) const
89  {
90  auto h1 = std::hash<T1>{}(p.first);
91  auto h2 = std::hash<T2>{}(p.second);
92 // return h1 ^ h2;
93  return (h1 ^ (h2 + 0x9e3779b9 + (h1<<6) + (h1>>2))); // http://www.boost.org/doc/libs/1_59_0/boost/functional/hash/hash.hpp
94  }
95  };
96  unordered_map< pair<int, int>, wxGridCellAttr*, pair_hash> m_cache;
97 };
98 
99 class CCollapsibleGrid : public wxGrid
100 {
102 public:
104  CCollapsibleGrid(wxWindow *parent,
105  wxWindowID id,
106  const wxPoint& pos = wxDefaultPosition,
107  const wxSize& size = wxDefaultSize,
108  long style = wxWANTS_CHARS,
109  const wxString& name = wxGridNameStr);
110  virtual ~CCollapsibleGrid() {}
111 
112  void x_InitRowHeights();
113  void FastSetRowSize(int row, int height);
114  void UpdateRowBottoms();
115 
116 private:
117  int UpdateRowOrColSize(int& sizeCurrent, int sizeNew);
118  vector<int> m_diffs;
119 };
120 
121 class CGridCellWrapStringRenderer : public wxGridCellRenderer
122 {
123 public:
124  CGridCellWrapStringRenderer() : wxGridCellRenderer() { }
125 
126  virtual void Draw(wxGrid& grid,
127  wxGridCellAttr& attr,
128  wxDC& dc,
129  const wxRect& rect,
130  int row, int col,
131  bool isSelected) wxOVERRIDE;
132 
133  virtual wxSize GetBestSize(wxGrid& grid,
134  wxGridCellAttr& attr,
135  wxDC& dc,
136  int row, int col) wxOVERRIDE;
137 
138  virtual wxGridCellRenderer *Clone() const wxOVERRIDE
139  { return new CGridCellWrapStringRenderer; }
140 
141 private:
142  void SetTextColoursAndFont(const wxGrid& grid, const wxGridCellAttr& attr, wxDC& dc, bool isSelected);
143  wxString BreakLines(const wxString &text);
144 };
145 
146 class CSeqTableGrid : public wxGridTableBase
147 {
148 public:
150  virtual ~CSeqTableGrid() {}
151 
152  virtual int GetNumberRows();
153  virtual int GetNumberCols();
154  virtual bool IsEmptyCell(int row, int col);
155 
156  virtual wxString GetValue(int row, int col);
157  virtual void SetValue(int vis_row, int vis_col, const wxString& value);
158 
159 /*
160  // Overriding these is optional
161  //
162  virtual void SetView( wxGrid *grid ) { m_view = grid; }
163  virtual wxGrid * GetView() const { return m_view; }
164 
165  virtual void Clear() {}
166  virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 );
167  virtual bool AppendRows( size_t numRows = 1 );
168  virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 );
169 */
170  virtual bool InsertCols(size_t pos = 0, size_t numCols = 1);
171  virtual bool AppendCols(size_t numCols = 1);
172  virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1);
173 
174  virtual wxString GetRowLabelValue(int row);
175  virtual wxString GetColLabelValue(int col);
176 
177  virtual void SetColLabelValue(int col, const wxString& label);
178 
181 
182 
183 private:
185 };
186 
187 
188 /*!
189  * Control identifiers
190  */
191 
192 ////@begin control identifiers
193 #define ID_CSEQTABLEGRID 10078
194 #define ID_GRID 10012
195 #define SYMBOL_CSEQTABLEGRIDPANEL_STYLE wxTAB_TRAVERSAL
196 #define SYMBOL_CSEQTABLEGRIDPANEL_TITLE _("SeqTableGrid")
197 #define SYMBOL_CSEQTABLEGRIDPANEL_IDNAME ID_CSEQTABLEGRID
198 #define SYMBOL_CSEQTABLEGRIDPANEL_SIZE wxSize(400, 300)
199 #define SYMBOL_CSEQTABLEGRIDPANEL_POSITION wxDefaultPosition
200 ////@end control identifiers
201 
202 enum
203 {
213 };
214 
215 class SrcEditDialog;
216 /*!
217  * CSeqTableGridPanel class declaration
218  */
219 
220 class CSeqTableGridPanel: public wxPanel
221 {
222  DECLARE_DYNAMIC_CLASS( CSeqTableGridPanel )
223  DECLARE_EVENT_TABLE()
224 
225 public:
226  /// Constructors
228  CSeqTableGridPanel( wxWindow* parent, CRef<objects::CSeq_table> values, CRef<objects::CSeq_table> choices, int glyph_col = -1,
230 
231  /// Creation
232  bool Create( wxWindow* parent, wxWindowID id = SYMBOL_CSEQTABLEGRIDPANEL_IDNAME, const wxPoint& pos = SYMBOL_CSEQTABLEGRIDPANEL_POSITION, const wxSize& size = SYMBOL_CSEQTABLEGRIDPANEL_SIZE, long style = SYMBOL_CSEQTABLEGRIDPANEL_STYLE );
233 
234  /// Destructor
236 
237  /// Initialises member variables
238  void Init();
239 
240  /// Creates the controls and sizers
241  void CreateControls();
242 
243 ////@begin CSeqTableGridPanel event handler declarations
244 
245  /// wxEVT_GRID_CELL_RIGHT_CLICK event handler for ID_GRID
246  void OnCellRightClick( wxGridEvent& event );
247 
248  /// wxEVT_GRID_LABEL_RIGHT_CLICK event handler for ID_GRID
249  void OnLabelRightClick( wxGridEvent& event );
250 
251 ////@end CSeqTableGridPanel event handler declarations
252 
253  void OnCopyCells( wxCommandEvent& event );
254  void OnPasteCells( wxCommandEvent& event );
255  void OnPasteAppendCells( wxCommandEvent& event );
256  void OnCopyCellsFromId( wxCommandEvent& event );
257  void OnSearchTable( wxCommandEvent& event );
258  void OnSortTableByColumn( wxGridEvent& event );
259  void OnLabelLeftClick( wxGridEvent& event );
260  void OnLabelLeftDClick( wxGridEvent& event );
261  void OnCellLeftClick( wxGridEvent& event );
262  void OnCellDoubleLeftClick( wxGridEvent& event );
263  void OnCellDoubleLeftClick2( wxMouseEvent& event );
264  void OnDeleteColumn( wxCommandEvent& event );
265  void OnRenameColumn( wxCommandEvent& event );
266  void OnCollapseColumn( wxCommandEvent& event );
267  void OnExpandColumn( wxCommandEvent& event );
268 
269 ////@begin CSeqTableGridPanel member function declarations
270 
271  /// Retrieves bitmap resources
272  wxBitmap GetBitmapResource( const wxString& name );
273 
274  /// Retrieves icon resources
275  wxIcon GetIconResource( const wxString& name );
276 ////@end CSeqTableGridPanel member function declarations
277 
278  /// Should we show tooltips?
279  static bool ShowToolTips();
280 
281 ////@begin CSeqTableGridPanel member variables
282 ////@end CSeqTableGridPanel member variables
283  wxGrid* GetGrid(void) {return m_Grid;}
286  void CopyPasteDataByKeyboard(wxKeyEvent& event);
287 
288  void UpdateColumnLabelHeight ();
289  int GetBestTableWidth();
290  void SetBestTableWidth();
291  void MakeColumnReadOnly(int pos, bool val = true);
292  void MakeColumnReadOnly(string name, bool val = true);
293  void MakeAllColumnsReadOnly();
295  void UpdateColumnChoices(int pos, vector<string> choices);
296  void InitColumnCollapse(int col);
297  bool GetModified() {return m_Modified;}
298  int GetCollapseColAndExpand(void);
299  void CollapseByCol(int col);
300  int GetRowIndex(int row);
301 private:
307  unordered_map<string,int> m_MapRowLabelToIndex;
308  wxString m_FindStr;
309  void InitMapRowLabelToIndex();
310  void x_SortByRowLabel();
311  void x_SetUpMenu();
312  void x_CreateMenu(wxGridEvent& evt);
313  void x_PasteCells(CRef<objects::CSeq_table> copied, bool append = false, string delim = ";");
314 
316  void x_OnCopyCells();
317  void x_OnPasteCells();
321  void x_CollapseTableByColumn(bool initialize = false);
322  void x_ExpandTableByColumn(void);
323  void x_UpdateCollapsedRow(unsigned int num_cols, int expand_row, vector<bool> &all_present, vector<bool> &all_same, vector<wxString> &values);
324  void x_ExpandTable();
325  void x_SortTableByColumn(int col, bool ascend);
326  void x_UpdateCountSelectedDisplay(void);
327  void x_SelectHiddenRows(int row);
328 
329  unordered_map<int, int> m_CollapseCell;
338 };
339 
340 
341 
343 
344 #endif
345  // _SEQ_TABLE_GRID_H_
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
wxDECLARE_NO_COPY_CLASS(CCollapsibleGrid)
vector< int > m_diffs
int UpdateRowOrColSize(int &sizeCurrent, int sizeNew)
virtual ~CCollapsibleGrid()
void FastSetRowSize(int row, int height)
CConstRef –.
Definition: ncbiobj.hpp:1266
wxString BreakLines(const wxString &text)
virtual wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) wxOVERRIDE
virtual void Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) wxOVERRIDE
virtual wxGridCellRenderer * Clone() const wxOVERRIDE
void SetTextColoursAndFont(const wxGrid &grid, const wxGridCellAttr &attr, wxDC &dc, bool isSelected)
virtual void SetAttr(wxGridCellAttr *attr, int row, int col) wxOVERRIDE
virtual wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind=wxGridCellAttr::Any) const wxOVERRIDE
unordered_map< pair< int, int >, wxGridCellAttr *, pair_hash > m_cache
void MakeColumnReadOnly(int pos, bool val=true)
CSeqTableGridPanel()
Constructors.
void OnCellRightClick(wxGridEvent &event)
wxEVT_GRID_CELL_RIGHT_CLICK event handler for ID_GRID
void x_CollapseTableByColumn(bool initialize=false)
void CollapseByCol(int col)
int GetCollapseColAndExpand(void)
void UpdateColumnChoices(int pos, vector< string > choices)
void x_SelectHiddenRows(int row)
void CreateControls()
Creates the controls and sizers.
static bool ShowToolTips()
Should we show tooltips?
wxGrid * GetGrid(void)
void x_UpdateCountSelectedDisplay(void)
CRef< objects::CSeq_table > m_Table
map< pair< int, int >, wxString > m_CollapseCache
void OnCellDoubleLeftClick2(wxMouseEvent &event)
~CSeqTableGridPanel()
Destructor.
void OnCopyCellsFromId(wxCommandEvent &event)
void OnCellDoubleLeftClick(wxGridEvent &event)
void x_SortTableByColumn(int col, bool ascend)
unordered_map< string, int > m_MapRowLabelToIndex
set< int > m_SetOfReadOnlyCols
unordered_map< int, int > m_CollapseCell
void OnCopyCells(wxCommandEvent &event)
void OnLabelRightClick(wxGridEvent &event)
wxEVT_GRID_LABEL_RIGHT_CLICK event handler for ID_GRID
void x_CreateMenu(wxGridEvent &evt)
void OnRenameColumn(wxCommandEvent &event)
void InitColumnCollapse(int col)
void OnExpandColumn(wxCommandEvent &event)
void x_MakeProblemsColumnReadOnly()
void OnPasteAppendCells(wxCommandEvent &event)
void OnLabelLeftClick(wxGridEvent &event)
void OnDeleteColumn(wxCommandEvent &event)
CSeqGridTableNav * x_GetSeqGridTableNav()
void x_UpdateCollapsedRow(unsigned int num_cols, int expand_row, vector< bool > &all_present, vector< bool > &all_same, vector< wxString > &values)
bool x_ValuesOkForNewColumn(CConstRef< objects::CSeqTable_column > values, int col_pos)
void OnSearchTable(wxCommandEvent &event)
SrcEditDialog * x_GetParent()
CRef< objects::CSeq_table > m_Choices
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
int GetRowIndex(int row)
void SetValuesTable(CRef< objects::CSeq_table > table)
void x_PasteCells(CRef< objects::CSeq_table > copied, bool append=false, string delim=";")
void OnCollapseColumn(wxCommandEvent &event)
CCollapsibleGrid * m_Grid
void CopyPasteDataByKeyboard(wxKeyEvent &event)
bool Create(wxWindow *parent, wxWindowID id=10078, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
Creation.
CSeqTableGridPanel(wxWindow *parent, CRef< objects::CSeq_table > values, CRef< objects::CSeq_table > choices, int glyph_col=-1, wxWindowID id=10078, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
void x_ExpandTableByColumn(void)
void OnSortTableByColumn(wxGridEvent &event)
CRef< objects::CSeq_table > m_Copied
CRef< objects::CSeq_table > GetValuesTable()
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void OnLabelLeftDClick(wxGridEvent &event)
void OnCellLeftClick(wxGridEvent &event)
void Init()
Initialises member variables.
void OnPasteCells(wxCommandEvent &event)
virtual bool IsEmptyCell(int row, int col)
virtual void SetColLabelValue(int col, const wxString &label)
CConstRef< objects::CSeq_table > GetValuesTable(void) const
virtual wxString GetValue(int row, int col)
virtual int GetNumberRows()
virtual bool DeleteCols(size_t pos=0, size_t numCols=1)
CSeqTableGrid(CRef< objects::CSeq_table > values_table)
virtual void SetValue(int vis_row, int vis_col, const wxString &value)
virtual wxString GetColLabelValue(int col)
virtual wxString GetRowLabelValue(int row)
virtual ~CSeqTableGrid()
CRef< objects::CSeq_table > GetValuesTable(void)
CRef< objects::CSeq_table > m_ValuesTable
virtual int GetNumberCols()
virtual bool InsertCols(size_t pos=0, size_t numCols=1)
virtual bool AppendCols(size_t numCols=1)
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
static void DLIST_NAME() append(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:78
static void Init(void)
Definition: cursor6.c:76
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static const char label[]
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
static void text(MDB_val *v)
Definition: mdb_dump.c:62
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
@ eCmdCollapseTableCol
@ eCmdRenameTableCol
@ eCmdPasteTableValues
@ eCmdAppendTableValues
@ eCmdSearchTable
@ eCmdExpandTableCol
@ eCmdCopyTableValues
@ eCmdDeleteTableCol
@ eCmdCopyTableValuesFromId
#define SYMBOL_CSEQTABLEGRIDPANEL_STYLE
static const int kSkipColumns
#define SYMBOL_CSEQTABLEGRIDPANEL_SIZE
#define SYMBOL_CSEQTABLEGRIDPANEL_IDNAME
#define SYMBOL_CSEQTABLEGRIDPANEL_POSITION
#define row(bind, expected)
Definition: string_bind.c:73
std::size_t operator()(const std::pair< T1, T2 > &p) const
#define const
Definition: zconf.h:232
Modified on Thu May 23 12:34:15 2024 by modify_doxy.py rev. 669887