• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kdgantt

kdganttproxymodel.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 "kdganttproxymodel.h"
00024 #include "kdganttproxymodel_p.h"
00025 
00026 
00027 using namespace KDGantt;
00028 
00029 typedef ForwardingProxyModel BASE;
00030 
00031 ProxyModel::Private::Private( ProxyModel* _q )
00032 #if 0
00033     : calendarMode( false )
00034 #endif
00035 {
00036     Q_UNUSED( _q ); // for now
00037 
00038     columnMap[Qt::DisplayRole]    = 0;
00039     columnMap[ItemTypeRole]       = 1;
00040     columnMap[StartTimeRole]      = 2;
00041     columnMap[EndTimeRole]        = 3;
00042     columnMap[TaskCompletionRole] = 4;
00043     columnMap[LegendRole]         = 5;
00044 
00045     roleMap[Qt::DisplayRole]    = Qt::DisplayRole;
00046     roleMap[ItemTypeRole]       = Qt::DisplayRole;
00047     roleMap[StartTimeRole]      = Qt::DisplayRole;
00048     roleMap[EndTimeRole]        = Qt::DisplayRole;
00049     roleMap[TaskCompletionRole] = Qt::DisplayRole;
00050     roleMap[LegendRole]         = Qt::DisplayRole;
00051 }
00052 
00053 ProxyModel::ProxyModel( QObject* parent )
00054     : BASE( parent ), _d( new Private( this ) )
00055 {
00056     init();
00057 }
00058 
00059 ProxyModel::~ProxyModel()
00060 {
00061     delete _d; _d = 0;
00062 }
00063 
00064 #define d d_func()
00065 
00066 void ProxyModel::init()
00067 {
00068 }
00069 
00070 QModelIndex ProxyModel::mapFromSource( const QModelIndex& sourceIdx ) const
00071 {
00072     if( sourceIdx.isValid() ) {
00073 #if 0
00074         if ( calendarMode() ) {
00075             const QAbstractItemModel* model = sourceIdx.model();
00076             if ( model->hasChildren( sourceIdx ) ) {
00077                 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()));
00078             } else {
00079                 // Map children to columns
00080                 return BASE::mapFromSource( model->index( sourceIdx.row(),0,sourceIdx.parent()))
00081                     .child( 0, sourceIdx.column() );
00082             }
00083         }
00084 #endif
00085         return BASE::mapFromSource( sourceIdx.model()->index( sourceIdx.row(),0,sourceIdx.parent()));
00086     }
00087     else return QModelIndex();
00088 }
00089 
00090 QModelIndex ProxyModel::mapToSource( const QModelIndex& proxyIdx ) const
00091 {
00092     if( proxyIdx.isValid() ) {
00093 #if 0
00094         if ( calendarMode() && proxyIdx.column() > 0 ) {
00095             return BASE::mapToSource( proxyIdx.model()->index( proxyIdx.column(), 0, proxyIdx ) );
00096         }
00097 #endif
00098         return BASE::mapToSource( proxyIdx );
00099     }
00100     else return QModelIndex();
00101 }
00102 
00103 void ProxyModel::setColumn( int ganttrole, int col )
00104 {
00105     d->columnMap[ganttrole] = col;
00106 }
00107 
00108 int ProxyModel::column( int ganttrole ) const
00109 {
00110     return d->columnMap[ganttrole];
00111 }
00112 
00113 void ProxyModel::setRole( int ganttrole, int role )
00114 {
00115     d->roleMap[ganttrole] = role;
00116 }
00117 
00118 int ProxyModel::role( int ganttrole ) const
00119 {
00120     return d->roleMap[ganttrole];
00121 }
00122 
00123 #if 0
00124 void ProxyModel::setCalendarMode( bool enable )
00125 {
00126     if ( d->calendarMode != enable ) {
00127         d->calendarMode = enable;
00128         reset();
00129     }
00130 }
00131 
00132 bool ProxyModel::calendarMode() const
00133 {
00134     return d->calendarMode;
00135 }
00136 #endif
00137 
00138 int ProxyModel::rowCount( const QModelIndex& proxyIndex ) const
00139 {
00140     // TODO
00141     return BASE::rowCount( proxyIndex );
00142 }
00143 
00144 int ProxyModel::columnCount( const QModelIndex& proxyIndex ) const
00145 {
00146     return qMin( sourceModel()->columnCount( mapToSource( proxyIndex ) ), 1 );
00147 }
00148 
00149 QVariant ProxyModel::data( const QModelIndex& proxyIdx, int role ) const
00150 {
00151     int srole = role;
00152     int scol  = proxyIdx.column();
00153     QHash<int, int>::const_iterator it = d->roleMap.find( role );
00154     if ( it != d->roleMap.end() ) srole = *it;
00155     it = d->columnMap.find( role );
00156     if ( it != d->columnMap.end() ) scol = *it;
00157 
00158     //qDebug() << "mapping role"<<static_cast<ItemDataRole>(role)<<"to"<<static_cast<ItemDataRole>(srole);
00159     //qDebug() << "mapping column"<<proxyIdx.column()<<"to"<<scol;
00160 
00161     const QAbstractItemModel* model = sourceModel();
00162     return model->data( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), srole );
00163 }
00164 
00165 bool ProxyModel::setData( const QModelIndex& proxyIdx, const QVariant& value, int role )
00166 {
00167     int srole = role;
00168     int scol  = proxyIdx.column();
00169     QHash<int, int>::const_iterator it = d->roleMap.find( role );
00170     if ( it != d->roleMap.end() ) srole = *it;
00171     it = d->columnMap.find( role );
00172     if ( it != d->columnMap.end() ) scol = *it;
00173 
00174     QAbstractItemModel* model = sourceModel();
00175     return model->setData( model->index( proxyIdx.row(), scol, mapToSource( proxyIdx.parent() ) ), value, srole );
00176 }
00177 
00178 #include "moc_kdganttproxymodel.cpp"

kdgantt

Skip menu "kdgantt"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal