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 
18 using namespace KGantt;
19 
20 
21 
22 TreeViewRowController::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 
30 TreeViewRowController::~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 
43 int 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 
61 bool 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 
76 QModelIndex 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 }
bool isRowVisible(const QModelIndex &idx) const override
QModelIndex indexBelow(const QModelIndex &idx) const override
bool isValid() const const
QModelIndex indexAbove(const QModelIndex &idx) const override
Span rowGeometry(const QModelIndex &idx) const override
Global namespace.
const QAbstractItemModel * model() const const
A class representing a start point and a length.
Definition: kganttglobal.h:240
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 22:32:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.