Wtx ~ Wt Extension Library
WtxLib
TableView.h
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 #ifndef __WTX_DBO_TABLEVIEW_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
46 #define __WTX_DBO_TABLEVIEW_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
47 
48 #include <Wtx/Core/Core.h>
49 #include <Wt/Dbo/Query.h>
50 #include "QueryModel.h"
51 
52 #include <Wtx/Dbo/Session.h>
53 #include <Wtx/Dbo/TableDef.h>
54 #include <Wtx/TableView.h>
55 #include <Wtx/TableViewDef.h>
56 
57 
58 
59 namespace Wtx {
60  namespace Dbo {
61 
67 template <class C>
68 class TableView
69 : public Wtx::TableView
70 {
71  public:
72 
73  virtual ~TableView();
75  TableView( const std::string & viewDefName, Wtx::Dbo::Session * s );
77  TableView( const std::string & viewDefName, const Wtx::TableViewDef::ViewDef & viewDef, Wtx::Dbo::Session * s );
78 
79  bool loadLayout( const std::string & name );
80  void saveLayout( const std::string & name );
81 
82  Wtx::Dbo::Session * session() const { return m_session; }
83 
84  const std::shared_ptr< Wtx::Dbo::QueryModel< Wt::Dbo::ptr<C> > > & model() const
85  {
86  return m_model;
87  }
88 
89  virtual void showHeaderPopup( const Wt::WMouseEvent & event );
90  std::string layoutName( const std::string & name ) const;
91 
92  void refresh();
93  void refreshSelected();
94 
95  const std::string & filter() const;
96  void setFilter();
97  void setFilter( const std::string & filter );
98  void setSearch( const std::string & search );
99  void setSubFilter( const std::string & filter );
100 
101  const std::string & queryValue() const;
102  void setQuery( const std::string & search = "" );
103 
104  void setupLayout();
105 
106  int queryRowCount() const
107  {
108  return m_queryRowCount;
109  }
110 
111  int totalRowCount()
112  {
113  Wt::Dbo::Transaction t(*session());
114 
115  std::string filter;
116  filter =
117  "SELECT COUNT(id) FROM \""
118  + std::string( session()-> template tableName<C>() ) + "\""
119  ;
120 
121  if( viewDef().m_def.filter != "" )
122  filter += " WHERE " + viewDef().m_def.filter;
123 
124 // std::cout << __FILE__ << ":" << __LINE__ << " " << filter << std::endl;
125 
126  int totalRows = -1;
127  totalRows =
128  session()->
129  template query<int>( filter );
130 
131  return totalRows;
132  }
133 
134  Wt::Dbo::ptr<C> item( Wt::WModelIndex index )
135  {
136  Wt::Dbo::ptr<C> retVal;
137 
138  if( index.isValid() )
139  {
140  retVal = model()-> stableResultRow( index.row() );
141  }
142 
143  return retVal;
144 
145  }
146 
147  void selectItem( Wt::Dbo::ptr<C> item );
148 
149  Wt::Dbo::ptr<C> selectedItem();
150 
151  private:
152 
153  void on_keyPressed( Wt::WKeyEvent keyEvent );
154 
155  void init();
156  void setLayout();
157 
158  std::string m_filterValue;
159  std::string m_subFilterValue;
160  std::string m_queryValue;
161  bool colsSet = false;
162  Wtx::Dbo::Session * m_session = nullptr;
163  std::shared_ptr< Wtx::Dbo::QueryModel< Wt::Dbo::ptr<C> > > m_model;
164  int m_queryRowCount = -1;
165 
166 }; // endclass TableView
167 
168  } // endnamespace Dbo
169 } // endnamespace Wtx
170 
171 #include "TableView_imp.h"
172 
173 #endif // __WTX_DBO_TABLEVIEW_H___
174 
void setQuery(const std::string &search="")
Table View.
Definition: TableView.h:65
Table View Definition.
Definition: TableViewDef.h:171
witty extension library
Definition: Activity.h:51
Dbo Table View.
Definition: TableView.h:68