-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumericItem.h
More file actions
46 lines (39 loc) · 987 Bytes
/
NumericItem.h
File metadata and controls
46 lines (39 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <Wt/WStandardItemModel.h>
#include <Wt/WStandardItem.h>
#include <Wt/WTableView.h>
#include <Wt/WModelIndex.h>
using namespace Wt;
using namespace Wt::Chart;
namespace {
/*
* A standard item which converts text edits to numbers
*/
class NumericItem : public Wt::WStandardItem {
public:
virtual std::unique_ptr<Wt::WStandardItem> clone() const override {
return cpp14::make_unique<NumericItem>();
}
virtual void setData(const cpp17::any& data, ItemDataRole role = ItemDataRole::User) override {
cpp17::any dt;
if (role == ItemDataRole::Edit) {
std::string s = asString(data).toUTF8();
char* endptr;
double d = strtod(s.c_str(), &endptr);
if (*endptr == 0) {
dt = cpp17::any(d);
}
else {
unsigned long long ullV = strtoull(s.c_str(), &endptr, 10);
if (*endptr == 0) {
dt = cpp17::any(ullV);
}
else {
dt = data;
}
}
}
WStandardItem::setData(data, role);
}
};
}