Debian Codegraph @

hiro/qt/widget/table-view-column.cpp

raw
1 #if defined(Hiro_TableView)
2
3 namespace hiro {
4
5 auto pTableViewColumn::construct() -> void {
6 if(auto parent = _parent()) {
7 auto lock = parent->acquire();
8 //parent->qtTableView->setAlternatingRowColors(parent->self().columnCount() >= 2);
9 parent->qtTableView->setColumnCount(parent->self().columnCount());
10 for(auto& column : parent->state().columns) {
11 if(auto delegate = column->self()) {
12 delegate->setIcon(delegate->state().icon);
13 delegate->setText(delegate->state().text); //also handles setSorting();
14 delegate->_setState();
15 }
16 }
17 }
18 }
19
20 auto pTableViewColumn::destruct() -> void {
21 }
22
23 auto pTableViewColumn::setActive() -> void {
24 //unsupported
25 }
26
27 auto pTableViewColumn::setAlignment(Alignment alignment) -> void {
28 _setState();
29 }
30
31 auto pTableViewColumn::setBackgroundColor(Color color) -> void {
32 _setState();
33 }
34
35 auto pTableViewColumn::setEditable(bool editable) -> void {
36 //unsupported
37 }
38
39 auto pTableViewColumn::setExpandable(bool expandable) -> void {
40 _setState();
41 }
42
43 auto pTableViewColumn::setFont(const Font& font) -> void {
44 _setState();
45 }
46
47 auto pTableViewColumn::setForegroundColor(Color color) -> void {
48 _setState();
49 }
50
51 auto pTableViewColumn::setHorizontalAlignment(double alignment) -> void {
52 _setState();
53 }
54
55 auto pTableViewColumn::setIcon(const image& icon) -> void {
56 if(auto parent = _parent()) {
57 parent->qtTableView->headerItem()->setIcon(self().offset(), CreateIcon(icon));
58 }
59 }
60
61 auto pTableViewColumn::setResizable(bool resizable) -> void {
62 _setState();
63 }
64
65 auto pTableViewColumn::setSorting(Sort) -> void {
66 if(auto parent = _parent()) {
67 string label = state().text;
68 if(state().sorting == Sort::Ascending ) label.append(" \u25b4");
69 if(state().sorting == Sort::Descending) label.append(" \u25be");
70 parent->qtTableView->headerItem()->setText(self().offset(), QString::fromUtf8(label));
71 }
72 }
73
74 auto pTableViewColumn::setText(const string&) -> void {
75 if(auto parent = _parent()) {
76 string label = state().text;
77 if(state().sorting == Sort::Ascending ) label.append(" \u25b4");
78 if(state().sorting == Sort::Descending) label.append(" \u25be");
79 parent->qtTableView->headerItem()->setText(self().offset(), QString::fromUtf8(label));
80 }
81 }
82
83 auto pTableViewColumn::setVerticalAlignment(double alignment) -> void {
84 _setState();
85 }
86
87 auto pTableViewColumn::setVisible(bool visible) -> void {
88 _setState();
89 }
90
91 auto pTableViewColumn::setWidth(s32 width) -> void {
92 _setState();
93 }
94
95 auto pTableViewColumn::_parent() -> maybe<pTableView&> {
96 if(auto parent = self().parentTableView()) {
97 if(auto delegate = parent->self()) return *delegate;
98 }
99 return {};
100 }
101
102 auto pTableViewColumn::_setState() -> void {
103 if(auto parent = _parent()) {
104 auto lock = parent->acquire();
105 parent->qtTableView->header()->setSectionResizeMode(self().offset(), state().resizable ? QHeaderView::Interactive : QHeaderView::Fixed);
106 parent->qtTableView->setColumnHidden(self().offset(), !self().visible());
107
108 for(auto& item : parent->state().items) {
109 if(auto cell = item->cell(self().offset())) {
110 if(auto self = cell->self()) self->_setState();
111 }
112 }
113 }
114 }
115
116 }
117
118 #endif