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

vcs

vcsrevision.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 "vcsrevision.h"
00022 
00023 #include <QtCore/QString>
00024 #include <QtCore/QStringList>
00025 #include <QtCore/QMap>
00026 #include <QtCore/QDateTime>
00027 
00028 #include <kdebug.h>
00029 
00030 namespace KDevelop
00031 {
00032 
00033 VcsRevision VcsRevision::createSpecialRevision( KDevelop::VcsRevision::RevisionSpecialType _type )
00034 {
00035     VcsRevision rev;
00036     rev.setRevisionValue( QVariant::fromValue<KDevelop::VcsRevision::RevisionSpecialType>( _type ), VcsRevision::Special );
00037     return rev;
00038 }
00039 
00040 class VcsRevisionPrivate
00041 {
00042     public:
00043         QVariant value;
00044         VcsRevision::RevisionType type;
00045         QMap<QString,QVariant> internalValues;
00046 };
00047 
00048 VcsRevision::VcsRevision()
00049     : d(new VcsRevisionPrivate)
00050 {
00051     d->type = VcsRevision::Invalid;
00052 }
00053 
00054 VcsRevision::VcsRevision( const VcsRevision& rhs )
00055     : d(new VcsRevisionPrivate)
00056 {
00057     d->value = rhs.d->value;
00058     d->internalValues = rhs.d->internalValues;
00059     d->type = rhs.d->type;
00060 }
00061 
00062 VcsRevision::~VcsRevision()
00063 {
00064     delete d;
00065 }
00066 
00067 VcsRevision& VcsRevision::operator=( const VcsRevision& rhs)
00068 {
00069     if(this == &rhs)
00070         return *this;
00071     d->value = rhs.d->value;
00072     d->type = rhs.d->type;
00073     d->internalValues = rhs.d->internalValues;
00074     return *this;
00075 }
00076 
00077 void VcsRevision::setRevisionValue( const QVariant& rev, VcsRevision::RevisionType type )
00078 {
00079     d->value = rev;
00080     d->type = type;
00081 }
00082 
00083 VcsRevision::RevisionType VcsRevision::revisionType() const
00084 {
00085     return d->type;
00086 }
00087 
00088 QVariant VcsRevision::revisionValue() const
00089 {
00090     return d->value;
00091 }
00092 
00093 QStringList VcsRevision::keys() const
00094 {
00095     return d->internalValues.keys();
00096 }
00097 
00098 QVariant VcsRevision::getValue( const QString& key ) const
00099 {
00100     if( d->internalValues.contains(key) )
00101     {
00102         return d->internalValues[key];
00103     }
00104     return QVariant();
00105 }
00106 
00107 void VcsRevision::setValue( const QString& key, const QVariant& value )
00108 {
00109     d->internalValues[key] = value;
00110 }
00111 
00112 void VcsRevision::setType( RevisionType t)
00113 {
00114     d->type = t;
00115 }
00116 
00117 void VcsRevision::setSpecialType( RevisionSpecialType t)
00118 {
00119     d->value = QVariant(t);
00120 }
00121 
00122 void VcsRevision::setValue( const QVariant& v )
00123 {
00124     d->value = v;
00125 }
00126 
00127 bool VcsRevision::operator==( const KDevelop::VcsRevision& rhs ) const
00128 {
00129     return ( d->type == rhs.d->type && d->value == rhs.d->value && d->internalValues == rhs.d->internalValues );
00130 }
00131 
00132 QString VcsRevision::prettyValue() const
00133 {
00134     switch( revisionType() )
00135     {
00136         case GlobalNumber:
00137         case FileNumber:
00138             return QString::number( revisionValue().toLongLong() );
00139             break;
00140         case Special:
00141             switch( revisionValue().value<KDevelop::VcsRevision::RevisionSpecialType>(  ) )
00142             {
00143                 case VcsRevision::Head:
00144                     return "Head";
00145                     break;
00146                 case VcsRevision::Base:
00147                     return "Base";
00148                     break;
00149                 case VcsRevision::Working:
00150                     return "Working";
00151                     break;
00152                 case VcsRevision::Previous:
00153                     return "Previous";
00154                     break;
00155                 case VcsRevision::Start:
00156                     return "Start";
00157                     break;
00158                 default:
00159                     return "User";
00160                     break;
00161             }
00162             break;
00163         case Date:
00164             return revisionValue().toDateTime().toString( Qt::LocalDate );
00165             break;
00166         default:
00167             return revisionValue().toString();
00168             break;
00169     }
00170 }
00171 
00172 }
00173 
00174 uint KDevelop::qHash( const KDevelop::VcsRevision& rev)
00175 {
00176     return rev.revisionValue().toULongLong();
00177 }
00178 

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