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_FORM_DELEGATE_H_ 8 #define WT_FORM_FORM_DELEGATE_H_ 9 10 #include <Wt/Form/WAbstractFormDelegate.h> 11 12 namespace Wt { 13 namespace Form { 14 15 template<typename T, class Enable = void> 16 class WFormDelegate; 17 18 /*! \brief %Form delegate class for WString 19 * 20 * This will create a WLineEdit to display the WString value 21 * in the View 22 * 23 * \ingroup form 24 */ 25 template<> 26 class WT_API WFormDelegate<Wt::WString, void> : public WAbstractFormDelegate 27 { 28 public: 29 /*! \brief Create a form delegate 30 */ 31 WFormDelegate(); 32 33 /*! \brief Create WLineEdit to be used in the View 34 */ 35 std::unique_ptr<Wt::WWidget> createFormWidget() override; 36 }; 37 38 /*! \brief %Form delegate class for std::string 39 * 40 * This will create a WLineEdit to display the std::string value 41 * in the View 42 * 43 * \ingroup form 44 */ 45 template<> 46 class WT_API WFormDelegate<std::string, void> : public WAbstractFormDelegate 47 { 48 public: 49 /*! \brief Create a form delegate 50 */ 51 WFormDelegate(); 52 53 /*! \brief Create WLineEdit to be used in the View 54 */ 55 std::unique_ptr<Wt::WWidget> createFormWidget() override; 56 57 /*! \brief Update the value in the Model 58 */ 59 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 60 }; 61 62 /*! \brief %Form delegate class for WDate 63 * 64 * This will create a WDateEdit to display the WDate value in the 65 * View 66 * 67 * \ingroup form 68 */ 69 template<> 70 class WT_API WFormDelegate<Wt::WDate, void> : public WAbstractFormDelegate 71 { 72 public: 73 /*! \brief Create a form delegate 74 */ 75 WFormDelegate(); 76 77 /*! \brief Create WDateEdit to be used in the View 78 */ 79 std::unique_ptr<Wt::WWidget> createFormWidget() override; 80 81 /*! \brief Create WDateValidator 82 */ 83 std::shared_ptr<Wt::WValidator> createValidator() override; 84 85 /*! \brief Update the value in the Model 86 */ 87 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 88 }; 89 90 /*! \brief %Form delegate class for WTime 91 * 92 * This will create a WTimeEdit to display the WTime value in the 93 * View 94 * 95 * \ingroup form 96 */ 97 template<> 98 class WT_API WFormDelegate<Wt::WTime, void> : public WAbstractFormDelegate 99 { 100 public: 101 /*! \brief Create a form delegate 102 */ 103 WFormDelegate(); 104 105 /*! \brief Create WTimeEdit to be used in the View 106 */ 107 std::unique_ptr<Wt::WWidget> createFormWidget() override; 108 109 /*! \brief Create WTimeValidator 110 */ 111 std::shared_ptr<Wt::WValidator> createValidator() override; 112 113 /*! \brief Update the value in the Model 114 */ 115 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 116 }; 117 118 /*! \brief %Form delegate class for WDateTime 119 * 120 * This will create a WLineEdit to display the WDateTime value 121 * in the View 122 * 123 * In the future this implementation will change to return a dedicated widget 124 * for WDateTime objects. 125 * 126 * \ingroup form 127 */ 128 template<> 129 class WT_API WFormDelegate<Wt::WDateTime, void> : public WAbstractFormDelegate 130 { 131 public: 132 /*! \brief Create a form delegate 133 */ 134 WFormDelegate(); 135 136 /*! \brief Create a WLineEdit to be used in the View 137 */ 138 std::unique_ptr<Wt::WWidget> createFormWidget() override; 139 140 /*! \brief Update the value in the Model 141 */ 142 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 143 }; 144 145 /*! \brief %Form delegate class for boolean 146 * 147 * This will create a WCheckBox to display the boolean value 148 * in the view 149 * 150 * \ingroup form 151 */ 152 template<> 153 class WT_API WFormDelegate<bool, void> : public WAbstractFormDelegate 154 { 155 public: 156 /*! \brief Create a form delegate 157 */ 158 WFormDelegate(); 159 160 /*! \brief Create WCheckBox to be used in the View 161 */ 162 std::unique_ptr<Wt::WWidget> createFormWidget() override; 163 164 /*! \brief Update the value in the Model 165 */ 166 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 167 168 /*! \brief Update the value in the View 169 */ 170 void updateViewValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 171 }; 172 173 /*! \brief %Form delegate class for integer 174 * 175 * This will create a WLineEdit to display the integer value 176 * in the View. Additionally the delegate will also initialize 177 * the WIntValidator for validation. 178 * 179 * \ingroup form 180 */ 181 template<> 182 class WT_API WFormDelegate<int, void> : public WAbstractFormDelegate 183 { 184 public: 185 /*! \brief Create a form delegate 186 */ 187 WFormDelegate(); 188 189 /*! \brief Create WLineEdit to be used in the View 190 */ 191 std::unique_ptr<Wt::WWidget> createFormWidget() override; 192 193 /*! \brief Create WIntValidator for validation 194 */ 195 std::shared_ptr<Wt::WValidator> createValidator() override; 196 197 /*! \brief Update the value in the Model 198 */ 199 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 200 201 /*! \brief Update the value in the View 202 */ 203 void updateViewValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 204 }; 205 206 /*! \brief %Form delegate for double 207 * 208 * This will create a WLineEdit to display the double value 209 * in the View. Additionally the delegate will also initialize 210 * the WDoubleValidator for validation. 211 * 212 * \ingroup form 213 */ 214 template<> 215 class WT_API WFormDelegate<double, void> : public WAbstractFormDelegate 216 { 217 public: 218 /*! \brief Create a form delegate 219 */ 220 WFormDelegate(); 221 222 /*! \brief Create WLineEdit to be used in the View 223 */ 224 std::unique_ptr<Wt::WWidget> createFormWidget() override; 225 226 /*! \brief Create WDoubleValidator for validation 227 */ 228 std::shared_ptr<Wt::WValidator> createValidator() override; 229 230 /*! \brief Update the value in the model 231 */ 232 void updateModelValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 233 234 /*! \brief Update the value in the View 235 */ 236 void updateViewValue(Wt::WFormModel *model, Wt::WFormModel::Field field, Wt::WFormWidget *edit) override; 237 }; 238 } 239 } 240 241 #endif // WT_FORM_FORM_DELEGATE 242