-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattributetableview.cpp
More file actions
57 lines (50 loc) · 1.94 KB
/
attributetableview.cpp
File metadata and controls
57 lines (50 loc) · 1.94 KB
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
47
48
49
50
51
52
53
54
55
56
57
// SPDX-FileCopyrightText: 2017 Christian Sailer
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "attributetableview.hpp"
AttributeTableView::AttributeTableView(const AttributeTable &tableIn)
: table(tableIn), m_index(), m_displayColumn(-1), _padding0(0) {}
void AttributeTableView::setDisplayColIndex(int columnIndex) {
if (columnIndex < -1) {
m_displayColumn = -2;
m_index.clear();
return;
}
// recalculate the index even if it's the same column in case stuff has
// changed
m_index = makeAttributeIndex(table, columnIndex);
m_displayColumn = columnIndex;
}
float AttributeTableView::getNormalisedValue(const AttributeKey &key,
const AttributeRow &row) const {
if (m_displayColumn < 0) {
auto endIter = table.end();
--endIter;
return static_cast<float>(key.value) / static_cast<float>(endIter->getKey().value);
}
return row.getNormalisedValue(static_cast<size_t>(m_displayColumn));
}
const DisplayParams &AttributeTableView::getDisplayParams() const {
if (m_displayColumn < 0) {
return table.getDisplayParams();
}
return table.getColumn(static_cast<size_t>(m_displayColumn)).getDisplayParams();
}
void AttributeTableHandle::setDisplayColIndex(int columnIndex) {
if (columnIndex < -1) {
m_mutableIndex.clear();
} else {
// recalculate the index even if it's the same column in case stuff has
// changed
m_mutableIndex = makeAttributeIndex(m_mutableTable, columnIndex);
}
AttributeTableView::setDisplayColIndex(columnIndex);
}
AttributeTableHandle::Index::iterator::difference_type
AttributeTableHandle::findInIndex(const AttributeKey &key) {
auto iter = std::find_if(m_mutableIndex.begin(), m_mutableIndex.end(), index_item_key(key));
if (iter != m_mutableIndex.end()) {
return (std::distance(m_mutableIndex.begin(), iter));
}
return -1;
}