10 #include <QAbstractItemModel>
11 #include <QHeaderView>
16 QWidget* parentObject)
17 : Superclass(orientation, parentObject) {
22 this, &QHeaderView::sectionResized,
23 [
this](
int logicalIndex,
int,
int) {
25 this->sectionSpan(this->visualIndex(logicalIndex));
26 if (span.first != span.second) {
28 QPair<int, int>(this->logicalIndex(span.first),
29 this->logicalIndex(span.second));
30 int start = this->sectionViewportPosition(lspan.first);
31 int end = this->sectionViewportPosition(lspan.second) +
32 this->sectionSize(lspan.second);
33 auto viewport = this->viewport();
34 if (this->orientation() == Qt::Horizontal &&
35 viewport !=
nullptr) {
36 viewport->update(start, 0, end, viewport->height());
38 viewport->update(0, start, viewport->width(), end);
48 QString cvMultiColumnHeaderView::sectionDisplayText(
int logicalIndex)
const {
49 auto amodel = this->model();
52 ->headerData(logicalIndex, this->orientation(), Qt::DisplayRole)
59 QPair<int, int> cvMultiColumnHeaderView::sectionSpan(
int visual)
const {
60 QPair<int, int> vrange(visual, visual);
61 const int logical = this->logicalIndex(visual);
62 const auto vlabel = this->sectionDisplayText(logical);
68 for (
int cc = vrange.first - 1; cc >= 0; --cc) {
69 const int clogical = this->logicalIndex(cc);
70 if (this->sectionDisplayText(clogical) ==
vlabel) {
78 for (
int cc = vrange.second + 1, max = this->count(); cc < max; ++cc) {
79 const int clogical = this->logicalIndex(cc);
80 if (this->sectionDisplayText(clogical) ==
vlabel) {
92 int logicalIndex)
const {
93 if (!rect.isValid()) {
97 const int visual = this->visualIndex(logicalIndex);
98 const auto span = this->sectionSpan(visual);
99 if (span.first == span.second) {
101 this->Superclass::paintSection(painter, rect, logicalIndex);
104 if (this->isSortIndicatorShown()) {
112 const int vSortIndicatorShown =
113 this->visualIndex(this->sortIndicatorSection());
114 if (span.first <= vSortIndicatorShown &&
115 span.second >= vSortIndicatorShown) {
116 logicalIndex = this->sortIndicatorSection();
122 for (
int cc = span.first; cc < visual; ++cc) {
123 const int cc_size = this->sectionSize(this->logicalIndex(cc));
124 newrect.adjust(-cc_size, 0, 0, 0);
127 for (
int cc = visual + 1; cc <= span.second; ++cc) {
128 const int cc_size = this->sectionSize(this->logicalIndex(cc));
129 newrect.adjust(0, 0, cc_size, 0);
133 this->Superclass::paintSection(painter, newrect, logicalIndex);
cvMultiColumnHeaderView(Qt::Orientation orientation, QWidget *parent=nullptr)
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const override
~cvMultiColumnHeaderView() override