KGantt

kganttlistviewrowcontroller.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 "kganttlistviewrowcontroller.h"
10 #include "kganttlistviewrowcontroller_p.h"
11 
12 #include <QAbstractProxyModel>
13 #include <QScrollBar>
14 
15 #include <cassert>
16 
17 using namespace KGantt;
18 
19 
20 
21 ListViewRowController::ListViewRowController( QListView* lv, QAbstractProxyModel* proxy )
22  : _d( new Private(lv,proxy) )
23 {
24 }
25 
26 ListViewRowController::~ListViewRowController()
27 {
28  delete _d; _d = nullptr;
29 }
30 
31 #define d d_func()
32 
34 {
35  return d->listview->viewport()->y()-d->listview->frameWidth();
36 }
37 
38 int ListViewRowController::maximumItemHeight() const
39 {
40  return d->listview->fontMetrics().height();
41 }
42 
44 {
45  return d->listview->verticalScrollBar()->maximum()+d->listview->viewport()->height();
46 }
47 
49 {
50  const QModelIndex idx = d->proxy->mapToSource( _idx );
51  assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) );
52  return d->listview->visualRect(idx).isValid();
53 }
54 
55 bool ListViewRowController::isRowExpanded( const QModelIndex& _idx ) const
56 {
57  Q_UNUSED(_idx);
58 
59  return false;
60 }
61 
63 {
64  const QModelIndex idx = d->proxy->mapToSource( _idx );
65  assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) );
66  QRect r = d->listview->visualRect(idx).translated( QPoint( 0,
67  static_cast<Private::HackListView*>(d->listview)->verticalOffset() ) );
68  return Span( r.y(), r.height() );
69 }
70 
71 QModelIndex ListViewRowController::indexAt( int height ) const
72 {
73  return d->proxy->mapFromSource( d->listview->indexAt( QPoint( 1,height ) ) );
74 }
75 
77 {
78  const QModelIndex idx = d->proxy->mapToSource( _idx );
79  return d->proxy->mapFromSource( idx.sibling( idx.row()-1, idx.column()) );
80 }
81 
83 {
84  const QModelIndex idx = d->proxy->mapToSource( _idx );
85  if ( !idx.isValid() || idx.column()!=0 ) return QModelIndex();
86  if ( idx.model()->rowCount(idx.parent())<idx.row()+1 ) return QModelIndex();
87  return d->proxy->mapFromSource( idx.sibling( idx.row()+1, idx.column()) );
88 }
89 
virtual int rowCount(const QModelIndex &parent) const const =0
QModelIndex indexBelow(const QModelIndex &idx) const override
Span rowGeometry(const QModelIndex &idx) const override
bool isValid() const const
int row() const const
Global namespace.
QModelIndex parent() const const
bool isRowVisible(const QModelIndex &idx) const override
const QAbstractItemModel * model() const const
QModelIndex sibling(int row, int column) const const
int column() const const
QModelIndex indexAbove(const QModelIndex &idx) const override
A class representing a start point and a length.
Definition: kganttglobal.h:240
int height() const const
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.