Version: 0.6.0
tableview.h
1 /******************************************************************************
2  * Project: wxGIS (GIS Catalog)
3  * Purpose: wxGISTableView class.
4  * Author: Dmitry Baryshnikov (aka Bishop), polimax@mail.ru
5  ******************************************************************************
6 * Copyright (C) 2009-2011,2013,2014 Dmitry Baryshnikov
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  ****************************************************************************/
21 #pragma once
22 
23 #include <wx/colour.h>
24 #include <wx/settings.h>
25 #include <wx/string.h>
26 #include <wx/font.h>
27 #include <wx/grid.h>
28 #include <wx/gdicmn.h>
29 #include <wx/stattext.h>
30 #include <wx/bitmap.h>
31 #include <wx/image.h>
32 #include <wx/icon.h>
33 #include <wx/bmpbuttn.h>
34 #include <wx/button.h>
35 #include <wx/textctrl.h>
36 #include <wx/sizer.h>
37 #include <wx/panel.h>
38 #include <wx/statline.h>
39 
40 #include "wxgis/carto/carto.h"
41 #include "wxgis/datasource/table.h"
42 
43 #define GRID_ROW_SIZE 15
44 #define GRID_COL_SIZE 20
45 
46 WX_DECLARE_HASH_MAP(long, wxGISFeature, wxIntegerHash, wxIntegerEqual, wxGISFeatureMap);
47 
56 class WXDLLIMPEXP_GIS_CTU wxGISGridTable :
57  public wxGridTableBase
58 {
59  DECLARE_CLASS(wxGISGridTable)
60 public:
61  wxGISGridTable(wxGISDataset* pGISDataset);
62  virtual ~wxGISGridTable();
63 
64  //overrides
65  virtual int GetNumberRows();
66  virtual int GetNumberCols();
67  virtual bool IsEmptyCell(int row, int col);
68  virtual wxString GetValue(int row, int col);
69  virtual void SetValue(int row, int col, const wxString &value);
70  virtual wxString GetColLabelValue(int col);
71  virtual wxString GetRowLabelValue(int row);
72  virtual wxGISTable* GetDataset() const;
73  virtual void ClearFeatures(void);
74  virtual bool DeleteCols(size_t pos = 0, size_t numCols = 1);
75  virtual void SetEncoding(const wxFontEncoding &oEncoding);
76  virtual bool CanDeleteField(void) const;
77  virtual wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);
78 protected:
79  virtual void FillForPos(int nRow);
80 private:
81  wxGISTable* m_pGISDataset;
82  //wxString m_sFIDKeyName;
83  int m_nCols; // columns from dataSet
84  int m_nRows; // rows initially returned by dataSet
85  wxGISFeatureMap m_moFeatures;
86  std::map<int, int> m_mnAlign;
87 };
88 
97 class WXDLLIMPEXP_GIS_CTU wxGridCtrl:
98  public wxGrid
99 {
100  enum
101  {
102  ID_DELETE = wxID_HIGHEST + 5001,
103  ID_SORT_ASC,
104  ID_SORT_DESC,
105  ID_ADVANCED_SORTING,
106  ID_FIELD_CALCULATOR,
107  ID_CALCULATE_GEOMETRY,
108  ID_TURN_FIELD_OFF,
109  ID_FREESE_COLUMN,
110  ID_PROPERTIES,
111  ID_STATISTICS,
112  ID_MAX
113  };
114  DECLARE_DYNAMIC_CLASS(wxGridCtrl)
115 public:
116  wxGridCtrl();
117  virtual ~wxGridCtrl(void);
118  wxGridCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
119  virtual void SetEncoding(const wxFontEncoding &eEnc);
120 protected:
121  virtual void DrawRowLabel(wxDC& dc, int row);
122  virtual void OnLabelLeftClick(wxGridEvent& event);
123  virtual void OnLabelRightClick(wxGridEvent& event);
124  virtual void OnSelectCell(wxGridEvent& event);
125  virtual void OnMenu(wxCommandEvent& event);
126  virtual void OnMenuUpdateUI(wxUpdateUIEvent& event);
127  virtual void OnMouseMove(wxMouseEvent& event);
128  virtual void OnMouseWheel(wxMouseEvent& event);
129  virtual void OnCellClick(wxGridEvent& event);
130 protected:
131  wxMenu *m_pMenu;
132 private:
133  DECLARE_EVENT_TABLE();
134 };
135 
136 #ifdef __WXMSW__
137  #define WXGISBITBUTTONSIZE 18
138 #else
139  #define WXGISBITBUTTONSIZE 24
140 #endif
141 
142 class WXDLLIMPEXP_GIS_CTU wxGISTableView :
143  public wxPanel
144 {
145  enum
146  {
147  ID_FIRST = wxID_HIGHEST + 4001,
148  ID_PREV,
149  ID_NEXT,
150  ID_LAST,
151  ID_POS,
152  ID_ENCODING
153  };
154  DECLARE_CLASS(wxGISTableView)
155 public:
156  wxGISTableView(void);
157  wxGISTableView(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSTATIC_BORDER|wxTAB_TRAVERSAL);
158  virtual ~wxGISTableView(void);
159  bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSTATIC_BORDER|wxTAB_TRAVERSAL, const wxString& name = wxT("GISTableView"));
160  virtual void SetTable(wxGridTableBase* table, bool takeOwnership = false, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells);
161  virtual wxGridTableBase* GetTable(void) const;
162  virtual void SetReadOnly(bool bIsReadOnly){if(m_grid) m_grid->EnableEditing( bIsReadOnly );};
163  //events
164  void OnSelectCell(wxGridEvent& event);
165  void OnBtnFirst(wxCommandEvent& event);
166  void OnBtnNext(wxCommandEvent& event);
167  void OnBtnPrev(wxCommandEvent& event);
168  void OnBtnLast(wxCommandEvent& event);
169  void OnSetPos(wxCommandEvent& event);
170  void OnEncodingSelect(wxCommandEvent& event);
171 protected:
172  wxGridCtrl* m_grid;
173  wxStaticText* m_staticText1, *m_staticText2, *m_staticText3, *m_staticText4;
174  wxBitmapButton* m_bpFirst;
175  wxBitmapButton* m_bpPrev;
176  wxTextCtrl* m_position;
177  wxBitmapButton* m_bpNext;
178  wxBitmapButton* m_bpLast;
179  wxComboBox *m_pEncodingsCombo;
180  wxStaticLine *m_staticline1;
181  std::map<wxString, wxFontEncoding> m_mnEnc;
182 private:
183  DECLARE_EVENT_TABLE()
184 };
Definition: table.h:37
Definition: tableview.h:142
Definition: gdalinh.h:117
Definition: dataset.h:33
Definition: tableview.h:97
Definition: tableview.h:56