2017-12-31 02:43:56 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QTableWidgetItem>
|
|
|
|
|
|
|
|
|
|
class custom_table_widget_item : public QTableWidgetItem
|
|
|
|
|
{
|
2018-04-07 19:52:42 +02:00
|
|
|
private:
|
|
|
|
|
int m_sort_role = Qt::DisplayRole;
|
|
|
|
|
|
2017-12-31 02:43:56 +01:00
|
|
|
public:
|
2018-05-02 17:22:21 +02:00
|
|
|
custom_table_widget_item(){}
|
2018-05-17 22:36:31 +02:00
|
|
|
custom_table_widget_item(const std::string& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0)
|
|
|
|
|
: QTableWidgetItem(QString::fromStdString(text).simplified()) // simplified() forces single line text
|
2018-05-02 17:22:21 +02:00
|
|
|
{
|
|
|
|
|
if (sort_role != Qt::DisplayRole)
|
|
|
|
|
{
|
2018-05-17 22:36:31 +02:00
|
|
|
setData(sort_role, sort_value, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
custom_table_widget_item(const QString& text, int sort_role = Qt::DisplayRole, const QVariant& sort_value = 0)
|
|
|
|
|
: QTableWidgetItem(text.simplified()) // simplified() forces single line text
|
|
|
|
|
{
|
|
|
|
|
if (sort_role != Qt::DisplayRole)
|
|
|
|
|
{
|
|
|
|
|
setData(sort_role, sort_value, true);
|
2018-05-02 17:22:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-31 02:43:56 +01:00
|
|
|
bool operator <(const QTableWidgetItem &other) const
|
|
|
|
|
{
|
2018-04-07 19:52:42 +02:00
|
|
|
return data(m_sort_role) < other.data(m_sort_role);
|
|
|
|
|
}
|
2018-05-02 17:22:21 +02:00
|
|
|
|
2018-04-07 19:52:42 +02:00
|
|
|
void setData(int role, const QVariant &value, bool assign_sort_role = false)
|
|
|
|
|
{
|
|
|
|
|
if (assign_sort_role)
|
|
|
|
|
{
|
|
|
|
|
m_sort_role = role;
|
|
|
|
|
}
|
|
|
|
|
QTableWidgetItem::setData(role, value);
|
2017-12-31 02:43:56 +01:00
|
|
|
}
|
|
|
|
|
};
|