KGantt

kgantttreeviewrowcontroller.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "kgantttreeviewrowcontroller.h"
10#include "kgantttreeviewrowcontroller_p.h"
11
12#include <QAbstractProxyModel>
13#include <QHeaderView>
14#include <QScrollBar>
15
16#include <cassert>
17
18using namespace KGantt;
19
20
21
22TreeViewRowController::TreeViewRowController( QTreeView* tv,
23 QAbstractProxyModel* proxy )
24 : _d( new Private )
25{
26 _d->treeview = static_cast<Private::HackTreeView*>(tv);
27 _d->proxy = proxy;
28}
29
30TreeViewRowController::~TreeViewRowController()
31{
32 delete _d; _d = nullptr;
33}
34
35#define d d_func()
36
38{
39 //return d->treeview->header()->sizeHint().height();
40 return d->treeview->viewport()->y()-d->treeview->frameWidth();
41}
42
43int TreeViewRowController::maximumItemHeight() const
44{
45 return d->treeview->fontMetrics().height();
46}
47
49{
50 return d->treeview->verticalScrollBar()->maximum()+d->treeview->viewport()->height();
51}
52
54{
55 //qDebug() << _idx.model()<<d->proxy << d->treeview->model();
56 const QModelIndex idx = d->proxy->mapToSource( _idx );
57 assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
58 return d->treeview->visualRect(idx).isValid();
59}
60
61bool TreeViewRowController::isRowExpanded( const QModelIndex& _idx ) const
62{
63 const QModelIndex idx = d->proxy->mapToSource( _idx );
64 assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
65 return d->treeview->isExpanded( idx );
66}
67
69{
70 const QModelIndex idx = d->proxy->mapToSource( _idx );
71 assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
72 QRect r = d->treeview->visualRect(idx).translated( QPoint( 0, d->treeview->verticalOffset() ) );
73 return Span( r.y(), r.height() );
74}
75
76QModelIndex TreeViewRowController::indexAt( int height ) const
77{
78 /* using indexAt( QPoint ) won't work here, since it does hit detection
79 * against the actual item text/icon, so we would return wrong values
80 * for items with no text etc.
81 *
82 * The code below could cache for performance, but currently it doesn't
83 * seem to be the performance bottleneck at all.
84 */
85 if ( !d->treeview->model() ) return QModelIndex();
86 int y = d->treeview->verticalOffset();
87 QModelIndex idx = d->treeview->model()->index( 0, 0, d->treeview->rootIndex() );
88 do {
89 if ( y >= height ) break;
90 y += d->treeview->rowHeight( idx );
91 idx = d->treeview->indexBelow( idx );
92 } while ( idx.isValid() );
93 return d->proxy->mapFromSource( idx );
94}
95
97{
98 const QModelIndex idx = d->proxy->mapToSource( _idx );
99 return d->proxy->mapFromSource( d->treeview->indexAbove( idx ) );
100}
101
103{
104 const QModelIndex idx = d->proxy->mapToSource( _idx );
105 return d->proxy->mapFromSource( d->treeview->indexBelow( idx ) );
106}
A class representing a start point and a length.
QModelIndex indexBelow(const QModelIndex &idx) const override
bool isRowVisible(const QModelIndex &idx) const override
QModelIndex indexAbove(const QModelIndex &idx) const override
Span rowGeometry(const QModelIndex &idx) const override
Global namespace.
bool isValid() const const
const QAbstractItemModel * model() const const
int height() const const
int y() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Sep 27 2024 11:49:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.