Fix no newlines warnings. Patch by Peter Oberndorfer
[kdevelopdvcssupport.git] / vcs / vcsrevision.cpp
blob7cf32376c30b65f5112d74593a743022f2d064ef
1 /***************************************************************************
2 * This file is part of KDevelop *
3 * Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "vcsrevision.h"
23 #include <QtCore/QString>
24 #include <QtCore/QStringList>
25 #include <QtCore/QMap>
26 #include <QtCore/QDateTime>
28 #include <kdebug.h>
30 namespace KDevelop
33 VcsRevision VcsRevision::createSpecialRevision( KDevelop::VcsRevision::RevisionSpecialType _type )
35 VcsRevision rev;
36 rev.setRevisionValue( QVariant::fromValue<KDevelop::VcsRevision::RevisionSpecialType>( _type ), VcsRevision::Special );
37 return rev;
40 class VcsRevisionPrivate
42 public:
43 QVariant value;
44 VcsRevision::RevisionType type;
45 QMap<QString,QVariant> internalValues;
48 VcsRevision::VcsRevision()
49 : d(new VcsRevisionPrivate)
51 d->type = VcsRevision::Invalid;
54 VcsRevision::VcsRevision( const VcsRevision& rhs )
55 : d(new VcsRevisionPrivate)
57 d->value = rhs.d->value;
58 d->internalValues = rhs.d->internalValues;
59 d->type = rhs.d->type;
62 VcsRevision::~VcsRevision()
64 delete d;
67 VcsRevision& VcsRevision::operator=( const VcsRevision& rhs)
69 if(this == &rhs)
70 return *this;
71 d->value = rhs.d->value;
72 d->type = rhs.d->type;
73 d->internalValues = rhs.d->internalValues;
74 return *this;
77 void VcsRevision::setRevisionValue( const QVariant& rev, VcsRevision::RevisionType type )
79 d->value = rev;
80 d->type = type;
83 VcsRevision::RevisionType VcsRevision::revisionType() const
85 return d->type;
88 QVariant VcsRevision::revisionValue() const
90 return d->value;
93 QStringList VcsRevision::keys() const
95 return d->internalValues.keys();
98 QVariant VcsRevision::getValue( const QString& key ) const
100 if( d->internalValues.contains(key) )
102 return d->internalValues[key];
104 return QVariant();
107 void VcsRevision::setValue( const QString& key, const QVariant& value )
109 d->internalValues[key] = value;
112 void VcsRevision::setType( RevisionType t)
114 d->type = t;
117 void VcsRevision::setSpecialType( RevisionSpecialType t)
119 d->value = QVariant(t);
122 void VcsRevision::setValue( const QVariant& v )
124 d->value = v;
127 bool VcsRevision::operator==( const KDevelop::VcsRevision& rhs ) const
129 return ( d->type == rhs.d->type && d->value == rhs.d->value && d->internalValues == rhs.d->internalValues );
132 QString VcsRevision::prettyValue() const
134 switch( revisionType() )
136 case GlobalNumber:
137 case FileNumber:
138 return QString::number( revisionValue().toLongLong() );
139 break;
140 case Special:
141 switch( revisionValue().value<KDevelop::VcsRevision::RevisionSpecialType>( ) )
143 case VcsRevision::Head:
144 return "Head";
145 break;
146 case VcsRevision::Base:
147 return "Base";
148 break;
149 case VcsRevision::Working:
150 return "Working";
151 break;
152 case VcsRevision::Previous:
153 return "Previous";
154 break;
155 case VcsRevision::Start:
156 return "Start";
157 break;
158 default:
159 return "User";
160 break;
162 break;
163 case Date:
164 return revisionValue().toDateTime().toString( Qt::LocalDate );
165 break;
166 default:
167 return revisionValue().toString();
168 break;
174 uint KDevelop::qHash( const KDevelop::VcsRevision& rev)
176 return rev.revisionValue().toULongLong();