KD Chart 2  [rev.2.7]
kdgantttreeviewrowcontroller.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
24 #include "kdgantttreeviewrowcontroller_p.h"
25 
26 #include <QAbstractProxyModel>
27 #include <QHeaderView>
28 #include <QScrollBar>
29 
30 #include <cassert>
31 
32 using namespace KDGantt;
33 
40  QAbstractProxyModel* proxy )
41  : _d( new Private )
42 {
43  _d->treeview = static_cast<Private::HackTreeView*>(tv);
44  _d->proxy = proxy;
45 }
46 
48 {
49  delete _d; _d=0;
50 }
51 
52 #define d d_func()
53 
55 {
56  //return d->treeview->header()->sizeHint().height();
57  return d->treeview->viewport()->y()-d->treeview->frameWidth();
58 }
59 
61 {
62  return d->treeview->fontMetrics().height();
63 }
64 
66 {
67  return d->treeview->verticalScrollBar()->maximum()+d->treeview->viewport()->height();
68 }
69 
70 bool TreeViewRowController::isRowVisible( const QModelIndex& _idx ) const
71 {
72  //qDebug() << _idx.model()<<d->proxy << d->treeview->model();
73  const QModelIndex idx = d->proxy->mapToSource( _idx );
74  assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
75  return d->treeview->visualRect(idx).isValid();
76 }
77 
78 bool TreeViewRowController::isRowExpanded( const QModelIndex& _idx ) const
79 {
80  const QModelIndex idx = d->proxy->mapToSource( _idx );
81  assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
82  return d->treeview->isExpanded( idx );
83 }
84 
85 Span TreeViewRowController::rowGeometry( const QModelIndex& _idx ) const
86 {
87  const QModelIndex idx = d->proxy->mapToSource( _idx );
88  assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
89  QRect r = d->treeview->visualRect(idx).translated( QPoint( 0, d->treeview->verticalOffset() ) );
90  return Span( r.y(), r.height() );
91 }
92 
93 QModelIndex TreeViewRowController::indexAt( int height ) const
94 {
95  /* using indexAt( QPoint ) wont work here, since it does hit detection
96  * against the actual item text/icon, so we would return wrong values
97  * for items with no text etc.
98  *
99  * The code below could cache for performance, but currently it doesn't
100  * seem to be the performance bottleneck at all.
101  */
102  if ( !d->treeview->model() ) return QModelIndex();
103  int y = d->treeview->verticalOffset();
104  QModelIndex idx = d->treeview->model()->index( 0, 0, d->treeview->rootIndex() );
105  do {
106  if ( y >= height ) break;
107 #if QT_VERSION >= 0x040300
108  y += d->treeview->rowHeight( idx );
109 #else
110  // Since TreeViewRowController is NOT using uniform row height
111  // we can use this:
112  y += d->treeview->indexRowSizeHint( idx );
113 #endif
114  idx = d->treeview->indexBelow( idx );
115  } while ( idx.isValid() );
116  return d->proxy->mapFromSource( idx );
117 }
118 
119 QModelIndex TreeViewRowController::indexAbove( const QModelIndex& _idx ) const
120 {
121  const QModelIndex idx = d->proxy->mapToSource( _idx );
122  return d->proxy->mapFromSource( d->treeview->indexAbove( idx ) );
123 }
124 
125 QModelIndex TreeViewRowController::indexBelow( const QModelIndex& _idx ) const
126 {
127  const QModelIndex idx = d->proxy->mapToSource( _idx );
128  return d->proxy->mapFromSource( d->treeview->indexBelow( idx ) );
129 }
QModelIndex indexAt(int height) const override
QModelIndex indexAbove(const QModelIndex &idx) const override
A class representing a start point and a length.
Class only listed here to document inheritance of some KDChart classes.
bool isRowVisible(const QModelIndex &idx) const override
TreeViewRowController(QTreeView *tv, QAbstractProxyModel *proxy)
Span rowGeometry(const QModelIndex &idx) const override
QModelIndex indexBelow(const QModelIndex &idx) const override
bool isRowExpanded(const QModelIndex &idx) const override

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/