forked from GLDsuh-a/qt-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQtCheckHeaderView.h
87 lines (68 loc) · 2.42 KB
/
QtCheckHeaderView.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef QTCHECKHEADERVIEW_H
#define QTCHECKHEADERVIEW_H
#include <QHeaderView>
#include <QList>
#include <QMap>
class QAbstractItemModel;
class QtCheckHeaderView: public QHeaderView
{
Q_OBJECT
public:
explicit QtCheckHeaderView(Qt::Orientation orientation, QWidget *parent = 0);
virtual ~QtCheckHeaderView();
QList<int> checkableIndexes() const
{
return mCheckableIndexes;
}
bool addCheckable(int logicalIndex)
{
if (model() && !mCheckableIndexes.contains(logicalIndex))
{
mCheckableIndexes.append(logicalIndex);
mCheckStates.insert(logicalIndex, Qt::Unchecked);
updateCheckbox(logicalIndex);
return true;
}
return false;
}
void removeCheckable(int logicalIndex)
{
mCheckableIndexes.removeOne(logicalIndex);
mCheckStates.remove(logicalIndex);
}
void setModel(QAbstractItemModel* model);
protected slots:
virtual void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
protected:
void mousePressEvent(QMouseEvent* event);
void paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const;
QList<int> mCheckableIndexes;
QMap<int, Qt::CheckState> mCheckStates;
bool blockDataChanged;
mutable QMap<int, QRect> mSectionRects;
void updateCheckbox(int logicalIndex);
void updateModel(int logicalIndex);
QRect checkRect(const QStyleOptionHeader& option, const QRect& bounding) const;
inline bool rowIntersectsSelection(int row) const
{
return (selectionModel() ? selectionModel()->rowIntersectsSelection(row, rootIndex()) : false);
}
inline bool columnIntersectsSelection(int column) const
{
return (selectionModel() ? selectionModel()->columnIntersectsSelection(column, rootIndex()) : false);
}
inline bool sectionIntersectsSelection(int logical) const
{
return (orientation() == Qt::Horizontal ? columnIntersectsSelection(logical) : rowIntersectsSelection(
logical));
}
inline bool isRowSelected(int row) const
{
return (selectionModel() ? selectionModel()->isRowSelected(row, rootIndex()) : false);
}
inline bool isColumnSelected(int column) const
{
return (selectionModel() ? selectionModel()->isColumnSelected(column, rootIndex()) : false);
}
};
#endif // QTCHECKHEADERVIEW_H