SWMMVis  6.0.0-alpha.4
Qt6/C++ GIS-based graphical user interface for the SWMMVis engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
numerictablewidgetitem.h
Go to the documentation of this file.
1
10#ifndef OPENSWMMVIS_NUMERICTABLEWIDGETITEM_H
11#define OPENSWMMVIS_NUMERICTABLEWIDGETITEM_H
12
13#include <QTableWidgetItem>
14#include <cmath>
15
16namespace openswmmvis::ui
17{
18
19// Preserve display formatting while ordering numeric cells by value.
20class NumericTableWidgetItem : public QTableWidgetItem
21{
22public:
23 using QTableWidgetItem::QTableWidgetItem;
24 static constexpr int SortKeyRole = Qt::UserRole + 1;
30 bool operator<(const QTableWidgetItem &other) const override
31 {
32 bool leftOk = false, rightOk = false;
33 const QVariant leftKey = data(SortKeyRole);
34 const QVariant rightKey = other.data(SortKeyRole);
35 const double left = (leftKey.isValid() ? leftKey : QVariant(text())).toDouble(&leftOk);
36 const double right =
37 (rightKey.isValid() ? rightKey : QVariant(other.text())).toDouble(&rightOk);
38 leftOk = leftOk && std::isfinite(left);
39 rightOk = rightOk && std::isfinite(right);
40 if (leftOk != rightOk)
41 return leftOk;
42 if (leftOk)
43 return left < right;
44 return QTableWidgetItem::operator<(other);
45 }
46};
47
48} // namespace openswmmvis::ui
49#endif
Definition numerictablewidgetitem.h:21
bool operator<(const QTableWidgetItem &other) const override
Sort finite numeric keys before unavailable/text values while preserving formatted display text.
Definition numerictablewidgetitem.h:30
static constexpr int SortKeyRole
Definition numerictablewidgetitem.h:24
Definition openswmmvislayer.h:46
int right
Definition constraintaudit.cpp:162
int left
Definition constraintaudit.cpp:162
QString text
Definition queryparser.cpp:54