Skip to content

Commit e1472f5

Browse files
YoikaGRockinRoel
authored andcommitted
Custom model to keep track of database columns
In future commits I will be adding custom Dbo actions to be used with Dbo's persist method to create a link between the custom WFormModel and the database object. This base class will be used by that custom WFormModel and those actions to keep track of which database columns have been added to the model.
1 parent f6273ea commit e1472f5

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/Wt/Form/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
FILE(GLOB FORM_H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
22
INSTALL(FILES ${FORM_H_FILES}
33
DESTINATION include/Wt/Form)
4+
5+
ADD_SUBDIRECTORY(Dbo)

src/Wt/Form/Dbo/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FILE(GLOB FORM_DBO_H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.h")
2+
INSTALL(FILES ${FORM_DBO_H_FILES}
3+
DESTINATION include/Wt/Form/Dbo)

src/Wt/Form/Dbo/FormModelBase.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This may look like C code, but it's really -*- C++ -*-
2+
/*
3+
* Copyright (C) 2021 Emweb bv, Herent, Belgium.
4+
*
5+
* See the LICENSE file for terms of use.
6+
*/
7+
#ifndef WT_FORM_DBO_FORMMODELBASE_H_
8+
#define WT_FORM_DBO_FORMMODELBASE_H_
9+
10+
#include <Wt/WFormModel.h>
11+
12+
namespace Wt {
13+
namespace Form {
14+
namespace Dbo {
15+
/*! \brief A model class keeping information about database columns
16+
* that are to be used in the model/view logic.
17+
*/
18+
class FormModelBase : public Wt::WFormModel
19+
{
20+
public:
21+
FormModelBase()
22+
: Wt::WFormModel()
23+
{
24+
}
25+
26+
/*! \brief Returns the Dbo columns used in this model
27+
*/
28+
const std::vector<std::string>& dboFields() const { return dboFields_; }
29+
30+
protected:
31+
std::vector<std::string> dboFields_;
32+
33+
/*! \brief Adds a Dbo column as a field
34+
*/
35+
void insertDboField(Wt::WFormModel::Field field)
36+
{
37+
dboFields_.push_back(field);
38+
addField(field);
39+
}
40+
};
41+
}
42+
}
43+
}
44+
45+
#endif // WT_FORM_DBO_FORMMODELBASE

0 commit comments

Comments
 (0)