-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFilterHorizontalHeaderView.h
97 lines (86 loc) · 2.49 KB
/
FilterHorizontalHeaderView.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
88
89
90
91
92
93
94
95
96
97
#ifndef FILTERHORIZONTALHEADERVIEW_H
#define FILTERHORIZONTALHEADERVIEW_H
#include <cassert>
#include <iostream>
#include <QHeaderView>
#include <QTableView>
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QMouseEvent>
#include <QLineEdit>
#include <QSpinBox>
#include <QAction>
#include <QMenu>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QFileInfo>
#include <QMessageBox>
#include "SortMultiFilterProxyModel.h"
class FilterHorizontalHeaderView : public QHeaderView
{
Q_OBJECT
public:
enum WidgetType {wtString, wtInt, wtDouble, wtNone};
explicit FilterHorizontalHeaderView(SortMultiFilterProxyModel* model, QTableView *parent = 0);
QSize sizeHint() const;
void addPreset(const QVariantMap& p, const QString& name)
{
_presets.push_back(p);
QAction *act=new QAction(name,this);
int i=_presets.count()-1;
connect(act,&QAction::triggered,[=](){
activatePreset(i);
});
contextMenu.addAction(act);
}
void setPreset(const QVariantMap& p);
QVariantMap preset() const;
signals:
void presetSaved(QVariantMap, QString);
protected:
virtual bool event( QEvent *event );
virtual QSize sectionSizeFromContents(int logicalIndex) const;
virtual void contextMenuEvent(QContextMenuEvent *event)
{
contextMenu.exec(event->globalPos());
}
private slots:
void setSortIndicator(int col, const Qt::SortOrder &order);
void updateWidgetPositions() const;
void updateHeaderData(int first, int last);
void savePreset();
void activatePreset(int i);
void clearAllFilters();
void applyFilters();
private:
void updateGeometry(int logical) const;
void updateHeaderData(int col);
void makeWidget(int col);
void insertColumns(int first, int last);
protected:
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
private:
QTimer timer;
int lastSortSection=0;
int _height=10;
QAction saveAct{tr("save preset"),this};
QAction clearAct{tr("clear filters"),this};
QMenu contextMenu{this};
QVector<QVariantMap> _presets;
SortMultiFilterProxyModel* _model=nullptr;
QMap<int,QWidget*> headerWidgets;
QMap<int,QLabel*> headerNames;
QMap<int,QLabel*> headerSortIndicators;
QMap<int,QLineEdit*> matchEdits;
QMap<int,QLineEdit*> notMatchEdits;
QMap<int,QSpinBox*> minIntEdits;
QMap<int,QSpinBox*> maxIntEdits;
QMap<int,QDoubleSpinBox*> minDoubleEdits;
QMap<int,QDoubleSpinBox*> maxDoubleEdits;
bool frame=true;
int inputHeight=QFontMetrics(QFont("sans",11)).height();
};
#endif // FILTERHORIZONTALHEADERVIEW_H