@@ -0,0 +1,51 | |||||
|
1 | #include "qtablewidgetintitem.h" | |||
|
2 | ||||
|
3 | QTableWidgetIntItem::QTableWidgetIntItem(const QString &text,int Type) | |||
|
4 | :QTableWidgetItem(text,Type) | |||
|
5 | { | |||
|
6 | } | |||
|
7 | ||||
|
8 | bool QTableWidgetIntItem::operator <(const QTableWidgetItem& other) const | |||
|
9 | { | |||
|
10 | return toInt() < toInt(other); | |||
|
11 | } | |||
|
12 | ||||
|
13 | bool QTableWidgetIntItem::operator >(const QTableWidgetItem &other) const | |||
|
14 | { | |||
|
15 | return toInt() > toInt(other); | |||
|
16 | } | |||
|
17 | ||||
|
18 | bool QTableWidgetIntItem::operator ==(const QTableWidgetItem &other) const | |||
|
19 | { | |||
|
20 | return toInt() == toInt(other); | |||
|
21 | } | |||
|
22 | ||||
|
23 | int QTableWidgetIntItem::toInt() const | |||
|
24 | { | |||
|
25 | bool ok=true; | |||
|
26 | if(type()==DecimalItem) | |||
|
27 | { | |||
|
28 | return text().toInt(); | |||
|
29 | } | |||
|
30 | else if(type()==HexaDecimalItem) | |||
|
31 | { | |||
|
32 | return text().replace("0x","").toInt(&ok,16); | |||
|
33 | } | |||
|
34 | return 0; | |||
|
35 | } | |||
|
36 | ||||
|
37 | int QTableWidgetIntItem::toInt(const QTableWidgetItem &item) const | |||
|
38 | { | |||
|
39 | bool ok=true; | |||
|
40 | if(item.type()==DecimalItem) | |||
|
41 | { | |||
|
42 | return item.text().toInt(); | |||
|
43 | } | |||
|
44 | else if(item.type()==HexaDecimalItem) | |||
|
45 | { | |||
|
46 | return item.text().replace("0x","").toInt(&ok,16); | |||
|
47 | } | |||
|
48 | return 0; | |||
|
49 | } | |||
|
50 | ||||
|
51 |
@@ -0,0 +1,22 | |||||
|
1 | #ifndef QTABLEWIDGETINTITEM_H | |||
|
2 | #define QTABLEWIDGETINTITEM_H | |||
|
3 | ||||
|
4 | #include <QTableWidgetItem> | |||
|
5 | ||||
|
6 | #define DecimalItem 0 | |||
|
7 | #define HexaDecimalItem 1 | |||
|
8 | ||||
|
9 | class QTableWidgetIntItem : public QTableWidgetItem | |||
|
10 | { | |||
|
11 | ||||
|
12 | public: | |||
|
13 | explicit QTableWidgetIntItem(const QString& text, int Type); | |||
|
14 | bool operator <(const QTableWidgetItem &other)const; | |||
|
15 | bool operator >(const QTableWidgetItem &other)const; | |||
|
16 | bool operator ==(const QTableWidgetItem &other)const; | |||
|
17 | int toInt() const; | |||
|
18 | int toInt(const QTableWidgetItem &item) const; | |||
|
19 | ||||
|
20 | }; | |||
|
21 | ||||
|
22 | #endif // QTABLEWIDGETINTITEM_H |
General Comments 0
You need to be logged in to leave comments.
Login now