Menu

[b73cc1]: / cnamemagview.h  Maximize  Restore  History

Download this file

64 lines (51 with data), 1.5 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
58
59
60
61
62
63
#ifndef CNAMEMAGVIEW_H
#define CNAMEMAGVIEW_H
#include <QTreeView>
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
class CProxyNameMagModel: public QSortFilterProxyModel
{
protected:
bool lessThan(const QModelIndex& left, const QModelIndex& right) const
{
if (sortColumn() == 1)
{
return (left.data(Qt::UserRole + 1).toDouble() < right.data(Qt::UserRole + 1).toDouble());
}
QString leftData = sourceModel()->data(left).toString();
QString rightData = sourceModel()->data(right).toString();
if (leftData.startsWith("("))
{
int index = leftData.indexOf(")");
if (index > 0)
{
leftData.remove(0, index);
}
}
if (rightData.startsWith("("))
{
int index = rightData.indexOf(")");
if (index > 0)
{
rightData.remove(0, index);
}
}
return QString::localeAwareCompare(leftData, rightData) < 0;
}
};
class CNameMagView : public QTreeView
{
Q_OBJECT
public:
explicit CNameMagView(QWidget *parent = 0);
void addRow(const QString &name, double mag, const QVariant &data = 0, bool boldFont = false, const QVariant &data2 = 0);
void setHeaderSize(int c1 = 100, int c2 = 100);
QSortFilterProxyModel *getModel() { return m_proxy; }
QVariant getSelectedData(int dataIndex = 1);
signals:
public slots:
protected:
QStandardItemModel *m_model;
CProxyNameMagModel *m_proxy;
};
#endif // CNAMEMAGVIEW_H