# HG changeset patch # User Jeandet Alexis # Date 2014-06-17 22:24:12 # Node ID 792782cb7421744ce931903441bc006e6afe0114 # Parent acef0ecb71beb64a75c7184bad8b1943adbf88f4 Moved QTableWidgetIntItem. diff --git a/qtablewidgetintitem.cpp b/qtablewidgetintitem.cpp new file mode 100644 --- /dev/null +++ b/qtablewidgetintitem.cpp @@ -0,0 +1,51 @@ +#include "qtablewidgetintitem.h" + +QTableWidgetIntItem::QTableWidgetIntItem(const QString &text,int Type) + :QTableWidgetItem(text,Type) +{ +} + +bool QTableWidgetIntItem::operator <(const QTableWidgetItem& other) const +{ + return toInt() < toInt(other); +} + +bool QTableWidgetIntItem::operator >(const QTableWidgetItem &other) const +{ + return toInt() > toInt(other); +} + +bool QTableWidgetIntItem::operator ==(const QTableWidgetItem &other) const +{ + return toInt() == toInt(other); +} + +int QTableWidgetIntItem::toInt() const +{ + bool ok=true; + if(type()==DecimalItem) + { + return text().toInt(); + } + else if(type()==HexaDecimalItem) + { + return text().replace("0x","").toInt(&ok,16); + } + return 0; +} + +int QTableWidgetIntItem::toInt(const QTableWidgetItem &item) const +{ + bool ok=true; + if(item.type()==DecimalItem) + { + return item.text().toInt(); + } + else if(item.type()==HexaDecimalItem) + { + return item.text().replace("0x","").toInt(&ok,16); + } + return 0; +} + + diff --git a/qtablewidgetintitem.h b/qtablewidgetintitem.h new file mode 100644 --- /dev/null +++ b/qtablewidgetintitem.h @@ -0,0 +1,22 @@ +#ifndef QTABLEWIDGETINTITEM_H +#define QTABLEWIDGETINTITEM_H + +#include + +#define DecimalItem 0 +#define HexaDecimalItem 1 + +class QTableWidgetIntItem : public QTableWidgetItem +{ + +public: + explicit QTableWidgetIntItem(const QString& text, int Type); + bool operator <(const QTableWidgetItem &other)const; + bool operator >(const QTableWidgetItem &other)const; + bool operator ==(const QTableWidgetItem &other)const; + int toInt() const; + int toInt(const QTableWidgetItem &item) const; + +}; + +#endif // QTABLEWIDGETINTITEM_H