• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDevelop Platform Libraries
  • Sitemap
  • Contact Us
 

vcs

vcseventmodel.cpp

00001 /***************************************************************************
00002  *   This file is part of KDevelop                                         *
00003  *   Copyright 2007 Andreas Pakulat <apaku@gmx.de>                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
00019  ***************************************************************************/
00020 
00021 #include "vcseventmodel.h"
00022 
00023 #include <QModelIndex>
00024 #include <QVariant>
00025 #include <QDateTime>
00026 #include <QList>
00027 
00028 #include <klocale.h>
00029 
00030 #include "../vcsevent.h"
00031 #include "../vcsrevision.h"
00032 
00033 namespace KDevelop
00034 {
00035 
00036 class VcsEventModelPrivate
00037 {
00038 public:
00039     QList<KDevelop::VcsEvent> m_events;
00040 };
00041 
00042 VcsEventModel::VcsEventModel( QObject* parent )
00043     : QAbstractTableModel( parent ), d(new VcsEventModelPrivate)
00044 {
00045 }
00046 
00047 VcsEventModel::~VcsEventModel()
00048 {
00049     delete d;
00050 }
00051 
00052 int VcsEventModel::rowCount( const QModelIndex& ) const
00053 {
00054     return d->m_events.count();
00055 }
00056 
00057 int VcsEventModel::columnCount( const QModelIndex& ) const
00058 {
00059     return 4;
00060 }
00061 
00062 QVariant VcsEventModel::data( const QModelIndex& idx, int role ) const
00063 {
00064     if( !idx.isValid() || role != Qt::DisplayRole )
00065         return QVariant();
00066 
00067     if( idx.row() < 0 || idx.row() >= rowCount() || idx.column() < 0 || idx.column() >= columnCount() )
00068         return QVariant();
00069 
00070     KDevelop::VcsEvent ev = d->m_events.at( idx.row() );
00071     switch( idx.column() )
00072     {
00073         case 0:
00074             return QVariant( ev.revision().revisionValue() );
00075             break;
00076         case 1:
00077             return QVariant( ev.author() );
00078             break;
00079         case 2:
00080             return QVariant( ev.date() );
00081             break;
00082         case 3:
00083             return QVariant( ev.message() );
00084             break;
00085         default:
00086             break;
00087     }
00088     return QVariant();
00089 }
00090 
00091 QVariant VcsEventModel::headerData( int section, Qt::Orientation orientation, int role ) const
00092 {
00093     if( section < 0 || section >= columnCount() || orientation != Qt::Horizontal || role != Qt::DisplayRole )
00094         return QVariant();
00095     switch( section )
00096     {
00097         case 0:
00098             return QVariant( i18n("Revision") );
00099             break;
00100         case 1:
00101             return QVariant( i18n("Author") );
00102             break;
00103         case 2:
00104             return QVariant( i18n("Date") );
00105             break;
00106         case 3:
00107             return QVariant( i18n("Message") );
00108             break;
00109         default:
00110             break;
00111     }
00112     return QVariant();
00113 }
00114 
00115 void VcsEventModel::addEvents( const QList<KDevelop::VcsEvent>& list )
00116 {
00117     if( list.isEmpty() )
00118         return;
00119     if( rowCount() > 0 )
00120         beginInsertRows( QModelIndex(), rowCount(), rowCount()+list.count()-1 );
00121     else
00122         beginInsertRows( QModelIndex(), rowCount(), list.count() );
00123     d->m_events += list;
00124     endInsertRows();
00125 }
00126 
00127 KDevelop::VcsEvent VcsEventModel::eventForIndex( const QModelIndex& idx ) const
00128 {
00129     if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() )
00130     {
00131         return KDevelop::VcsEvent();
00132     }
00133     return d->m_events.at( idx.row() );
00134 }
00135 
00136 void VcsEventModel::clear()
00137 {
00138     if( rowCount() == 0 )
00139         beginRemoveRows( QModelIndex(), 0, 0 );
00140     else
00141         beginRemoveRows( QModelIndex(), 0, rowCount()-1 );
00142     d->m_events.clear();
00143     endRemoveRows();
00144 }
00145 
00146 }
00147 
00148 #include "vcseventmodel.moc"

vcs

Skip menu "vcs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

KDevelop Platform Libraries

Skip menu "KDevelop Platform Libraries"
  • interfaces
  • language
  •   codegen
  •   duchain
  •   editor
  • outputview
  •     interfaces
  • project
  • shell
  • sublime
  • util
  • vcs
Generated for KDevelop Platform Libraries 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