kdgantt
kdganttlistviewrowcontroller.cpp
Go to the documentation of this file.00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Gantt library. 00005 ** 00006 ** This file may be used under the terms of the GNU General Public 00007 ** License versions 2.0 or 3.0 as published by the Free Software 00008 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 00009 ** included in the packaging of this file. Alternatively you may (at 00010 ** your option) use any later version of the GNU General Public 00011 ** License if such license has been publicly approved by 00012 ** Klarälvdalens Datakonsult AB (or its successors, if any). 00013 ** 00014 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, 00015 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR 00016 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights 00017 ** not expressly granted herein. 00018 ** 00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00021 ** 00022 **********************************************************************/ 00023 #include "kdganttlistviewrowcontroller.h" 00024 #include "kdganttlistviewrowcontroller_p.h" 00025 00026 #include <QAbstractProxyModel> 00027 #include <QDebug> 00028 00029 #include <cassert> 00030 00031 using namespace KDGantt; 00032 00040 ListViewRowController::ListViewRowController( QListView* lv, QAbstractProxyModel* proxy ) 00041 : _d( new Private(lv,proxy) ) 00042 { 00043 } 00044 00045 ListViewRowController::~ListViewRowController() 00046 { 00047 delete _d; _d = 0; 00048 } 00049 00050 #define d d_func() 00051 00052 int ListViewRowController::headerHeight() const 00053 { 00054 return d->listview->viewport()->y()-d->listview->frameWidth(); 00055 } 00056 00057 int ListViewRowController::maximumItemHeight() const 00058 { 00059 return d->listview->fontMetrics().height(); 00060 } 00061 00062 bool ListViewRowController::isRowVisible( const QModelIndex& _idx ) const 00063 { 00064 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00065 assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) ); 00066 return d->listview->visualRect(idx).isValid(); 00067 } 00068 00069 Span ListViewRowController::rowGeometry( const QModelIndex& _idx ) const 00070 { 00071 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00072 assert( idx.isValid() ? ( idx.model() == d->listview->model() ):( true ) ); 00073 QRect r = d->listview->visualRect(idx).translated( QPoint( 0, 00074 static_cast<Private::HackListView*>(d->listview)->verticalOffset() ) ); 00075 return Span( r.y(), r.height() ); 00076 } 00077 00078 QModelIndex ListViewRowController::indexAt( int height ) const 00079 { 00080 return d->proxy->mapFromSource( d->listview->indexAt( QPoint( 1,height ) ) ); 00081 } 00082 00083 QModelIndex ListViewRowController::indexAbove( const QModelIndex& _idx ) const 00084 { 00085 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00086 return d->proxy->mapFromSource( idx.sibling( idx.row()-1, idx.column()) ); 00087 } 00088 00089 QModelIndex ListViewRowController::indexBelow( const QModelIndex& _idx ) const 00090 { 00091 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00092 if( !idx.isValid() || idx.column()!=0 ) return QModelIndex(); 00093 if( idx.model()->rowCount(idx.parent())<idx.row()+1 ) return QModelIndex(); 00094 return d->proxy->mapFromSource( idx.sibling( idx.row()+1, idx.column()) ); 00095 } 00096
KDE 4.2 API Reference