kdgantt
kdgantttreeviewrowcontroller.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 "kdgantttreeviewrowcontroller.h" 00024 #include "kdgantttreeviewrowcontroller_p.h" 00025 00026 #include <QAbstractProxyModel> 00027 #include <QHeaderView> 00028 00029 #include <cassert> 00030 00031 using namespace KDGantt; 00032 00038 TreeViewRowController::TreeViewRowController( QTreeView* tv, 00039 QAbstractProxyModel* proxy ) 00040 : _d( new Private ) 00041 { 00042 _d->treeview = static_cast<Private::HackTreeView*>(tv); 00043 _d->proxy = proxy; 00044 } 00045 00046 TreeViewRowController::~TreeViewRowController() 00047 { 00048 delete _d; _d=0; 00049 } 00050 00051 #define d d_func() 00052 00053 int TreeViewRowController::headerHeight() const 00054 { 00055 //return d->treeview->header()->sizeHint().height(); 00056 return d->treeview->viewport()->y()-d->treeview->frameWidth(); 00057 } 00058 00059 int TreeViewRowController::maximumItemHeight() const 00060 { 00061 return d->treeview->fontMetrics().height(); 00062 } 00063 00064 bool TreeViewRowController::isRowVisible( const QModelIndex& _idx ) const 00065 { 00066 //qDebug() << _idx.model()<<d->proxy << d->treeview->model(); 00067 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00068 assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) ); 00069 return d->treeview->visualRect(idx).isValid(); 00070 } 00071 00072 Span TreeViewRowController::rowGeometry( const QModelIndex& _idx ) const 00073 { 00074 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00075 assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) ); 00076 QRect r = d->treeview->visualRect(idx).translated( QPoint( 0, d->treeview->verticalOffset() ) ); 00077 return Span( r.y(), r.height() ); 00078 } 00079 00080 QModelIndex TreeViewRowController::indexAt( int height ) const 00081 { 00082 return d->proxy->mapFromSource( d->treeview->indexAt( QPoint( 1,height ) ) ); 00083 } 00084 00085 QModelIndex TreeViewRowController::indexAbove( const QModelIndex& _idx ) const 00086 { 00087 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00088 return d->proxy->mapFromSource( d->treeview->indexAbove( idx ) ); 00089 } 00090 00091 QModelIndex TreeViewRowController::indexBelow( const QModelIndex& _idx ) const 00092 { 00093 const QModelIndex idx = d->proxy->mapToSource( _idx ); 00094 return d->proxy->mapFromSource( d->treeview->indexBelow( idx ) ); 00095 }
KDE 4.2 API Reference