-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtableviewheadersection.h
executable file
·151 lines (117 loc) · 5.25 KB
/
tableviewheadersection.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef TABLEVIEWHEADERSECTION
#define TABLEVIEWHEADERSECTION
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QWidget>
#include <QHeaderView>
#include <QPointer>
#include <QPainter>
class TableViewHeaderWidget : public QWidget
{
public:
QLabel *headerLable;
QLineEdit *headerLE;
QComboBox *headerCB;
TableViewHeaderWidget(QWidget *parent = 0) : QWidget(parent)
{
headerLable = new QLabel(this);
headerLE = new QLineEdit(this);
headerCB = new QComboBox(this);
QVBoxLayout *vl = new QVBoxLayout(this);
vl->addWidget(headerLable, 1, Qt::AlignCenter);
vl->addWidget(headerLE);
vl->addWidget(headerCB);
setLayout(vl);
}
};
class TableViewHeaderSection : public QHeaderView
{
Q_OBJECT
public:
explicit TableViewHeaderSection(int colCount, QWidget* parent):QHeaderView(Qt::Horizontal, parent)
{
columnCount = colCount;
for(int i = 0; i < columnCount; i++)
{
headerSections.insert(i,new TableViewHeaderWidget(this));
headerSections[i]->headerCB->setFixedHeight(30);
headerSections[i]->headerLE->setFixedHeight(30);
connect(headerSections[i]->headerLE, SIGNAL(textChanged(QString)),this,SIGNAL(sectionsWidgetsSignal()) );
connect(headerSections[i]->headerCB, SIGNAL(currentIndexChanged(int)),this, SIGNAL(sectionsWidgetsSignal()));
}
}
void setHeaderSectionLable(int section, QString label)
{
headerSections[section]->headerLable->setText(label);
}
void setSectionWidth(int section, int width)
{
headerSections[section]->headerLable->setFixedWidth(width);
headerSections[section]->headerCB->setFixedWidth(width);
}
void HideHeaderSectionWidgets(int section)
{
headerSections[section]->headerLable->setEnabled(false);
headerSections[section]->headerLable->hide();
headerSections[section]->headerCB->setEnabled(false);
headerSections[section]->headerCB->hide();
headerSections[section]->headerLE->setEnabled(false);
headerSections[section]->headerLE->hide();
}
void hideHeaderSectionLabel(int section){headerSections[section]->headerLable->setEnabled(false);headerSections[section]->headerLable->hide();}
void hideHeaderSectionLE(int section){headerSections[section]->headerLE->setEnabled(false);headerSections[section]->headerLE->hide();}
void hideHeaderSectionCB(int section){headerSections[section]->headerCB->setEnabled(false);headerSections[section]->headerCB->hide();}
void resetHeaderWidgets()
{
for(int i =0; i < columnCount; i++)
{
headerSections[i]->headerLE->clear();
headerSections[i]->headerCB->setCurrentIndex(headerSections[i]->headerCB->findData(0));
}
}
QString getHeaderLEText(int section){return headerSections[section]->headerLE->text();}
QVariant getHeaderCBCurrentData(int section){return headerSections[section]->headerCB->currentData();}
QString getHeaderCBCurrentText(int section)
{
if(headerSections[section]->headerCB->currentData().toInt() == 0)//all
return "";
else
return headerSections[section]->headerCB->currentText();
}
void showHeaderSectionLabel(int section){headerSections[section]->headerLable->setEnabled(true);headerSections[section]->headerLable->show();}
void showHeaderSectionLE(int section){headerSections[section]->headerCB->setEnabled(true);headerSections[section]->headerCB->show();}
void showHeaderSectionCB(int section){headerSections[section]->headerLE->setEnabled(true);headerSections[section]->headerLE->show();}
void setLEAlignment(int section, Qt::Alignment alignment){headerSections[section]->headerLE->setAlignment(alignment);}
void setLEPlaceHolder(int section, QString PH){headerSections[section]->headerLE->setPlaceholderText(PH);}
void setLEText(int section, QString data){headerSections[section]->headerLE->setText(data);}
void setCBCurrentData(int section, QVariant data){headerSections[section]->headerCB->setCurrentIndex(headerSections[section]->headerCB->findData(data));}
void addCBItem(int section, const QString text, const QVariant data){headerSections[section]->headerCB->addItem(text, data);}
void setCBLayoutDirection(int section, Qt::LayoutDirection direction){headerSections[section]->headerCB->setLayoutDirection(direction);}
QSize sizeHint() const
{
QSize s = size();
s.setHeight(headerSections[4]->minimumSizeHint().height()+5);
s.setWidth(headerSections[4]->minimumSizeHint().width()+5);
return s;
}
signals:
void sectionsWidgetsSignal();
protected:
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
QPainterPath path;
path.addRect(rect);
painter->fillPath(path,QBrush(QColor(220,220,230)));
painter->drawRect(rect);
if (!rect.isValid())
return;
headerSections[logicalIndex]->setGeometry(rect);
headerSections[logicalIndex]->show();
}
private:
QVector< QPointer<TableViewHeaderWidget> > headerSections; //vector of pointers to our widgets
int columnCount;
};
#endif // TABLEVIEWHEADERSECTION