kdgantttreeviewrowcontroller.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "kdgantttreeviewrowcontroller.h"
00024 #include "kdgantttreeviewrowcontroller_p.h"
00025 
00026 #include <QAbstractProxyModel>
00027 #include <QHeaderView>
00028 #include <QScrollBar>
00029 
00030 #include <cassert>
00031 
00032 using namespace KDGantt;
00033 
00039 TreeViewRowController::TreeViewRowController( QTreeView* tv,
00040                                               QAbstractProxyModel* proxy )
00041   : _d( new Private )
00042 {
00043     _d->treeview = static_cast<Private::HackTreeView*>(tv);
00044     _d->proxy = proxy;
00045 }
00046 
00047 TreeViewRowController::~TreeViewRowController()
00048 {
00049     delete _d; _d=0;
00050 }
00051 
00052 #define d d_func()
00053 
00054 int TreeViewRowController::headerHeight() const
00055 {
00056   //return d->treeview->header()->sizeHint().height();
00057     return d->treeview->viewport()->y()-d->treeview->frameWidth();
00058 }
00059 
00060 int TreeViewRowController::maximumItemHeight() const
00061 {
00062     return d->treeview->fontMetrics().height();
00063 }
00064 
00065 int TreeViewRowController::totalHeight() const
00066 {
00067     return d->treeview->verticalScrollBar()->maximum()+d->treeview->viewport()->height();
00068 }
00069 
00070 bool TreeViewRowController::isRowVisible( const QModelIndex& _idx ) const
00071 {
00072   //qDebug() << _idx.model()<<d->proxy << d->treeview->model();
00073     const QModelIndex idx = d->proxy->mapToSource( _idx );
00074     assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
00075     return d->treeview->visualRect(idx).isValid();
00076 }
00077 
00078 bool TreeViewRowController::isRowExpanded( const QModelIndex& _idx ) const
00079 {
00080     const QModelIndex idx = d->proxy->mapToSource( _idx );
00081     assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
00082     return d->treeview->isExpanded( idx );
00083 }
00084 
00085 Span TreeViewRowController::rowGeometry( const QModelIndex& _idx ) const
00086 {
00087     const QModelIndex idx = d->proxy->mapToSource( _idx );
00088     assert( idx.isValid() ? ( idx.model() == d->treeview->model() ):( true ) );
00089     QRect r = d->treeview->visualRect(idx).translated( QPoint( 0, d->treeview->verticalOffset() ) );
00090     return Span( r.y(), r.height() );
00091 }
00092 
00093 QModelIndex TreeViewRowController::indexAt( int height ) const
00094 {
00095   /* using indexAt( QPoint ) wont work here, since it does hit detection
00096    *   against the actual item text/icon, so we would return wrong values
00097    *   for items with no text etc.
00098    *
00099    *   The code below could cache for performance, but currently it doesn't
00100    *   seem to be the performance bottleneck at all.
00101    */
00102     if ( !d->treeview->model() ) return QModelIndex();
00103     int y = d->treeview->verticalOffset();
00104     QModelIndex idx = d->treeview->model()->index( 0, 0, d->treeview->rootIndex() );
00105     do {
00106         if ( y >= height ) break;
00107 #if QT_VERSION >= 0x040300
00108         y += d->treeview->rowHeight( idx );
00109 #else
00110         // Since TreeViewRowController is NOT using uniform row height
00111         // we can use this:
00112         y += d->treeview->indexRowSizeHint( idx );
00113 #endif
00114         idx = d->treeview->indexBelow( idx );
00115     } while ( idx.isValid() );
00116     return d->proxy->mapFromSource( idx );
00117 }
00118 
00119 QModelIndex TreeViewRowController::indexAbove( const QModelIndex& _idx ) const
00120 {
00121     const QModelIndex idx = d->proxy->mapToSource( _idx );
00122     return d->proxy->mapFromSource( d->treeview->indexAbove( idx ) );
00123 }
00124 
00125 QModelIndex TreeViewRowController::indexBelow( const QModelIndex& _idx ) const
00126 {
00127     const QModelIndex idx = d->proxy->mapToSource( _idx );
00128     return d->proxy->mapFromSource( d->treeview->indexBelow( idx ) );
00129 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/