1 /***************************************************************************
2 * This file is part of KDevelop *
3 * Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
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. *
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. *
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>
33 VcsRevision
VcsRevision::createSpecialRevision( KDevelop::VcsRevision::RevisionSpecialType _type
)
36 rev
.setRevisionValue( QVariant::fromValue
<KDevelop::VcsRevision::RevisionSpecialType
>( _type
), VcsRevision::Special
);
40 class VcsRevisionPrivate
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()
67 VcsRevision
& VcsRevision::operator=( const VcsRevision
& rhs
)
71 d
->value
= rhs
.d
->value
;
72 d
->type
= rhs
.d
->type
;
73 d
->internalValues
= rhs
.d
->internalValues
;
77 void VcsRevision::setRevisionValue( const QVariant
& rev
, VcsRevision::RevisionType type
)
83 VcsRevision::RevisionType
VcsRevision::revisionType() const
88 QVariant
VcsRevision::revisionValue() const
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
];
107 void VcsRevision::setValue( const QString
& key
, const QVariant
& value
)
109 d
->internalValues
[key
] = value
;
112 void VcsRevision::setType( RevisionType t
)
117 void VcsRevision::setSpecialType( RevisionSpecialType t
)
119 d
->value
= QVariant(t
);
122 void VcsRevision::setValue( const QVariant
& 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() )
138 return QString::number( revisionValue().toLongLong() );
141 switch( revisionValue().value
<KDevelop::VcsRevision::RevisionSpecialType
>( ) )
143 case VcsRevision::Head
:
146 case VcsRevision::Base
:
149 case VcsRevision::Working
:
152 case VcsRevision::Previous
:
155 case VcsRevision::Start
:
164 return revisionValue().toDateTime().toString( Qt::LocalDate
);
167 return revisionValue().toString();
174 uint
KDevelop::qHash( const KDevelop::VcsRevision
& rev
)
176 return rev
.revisionValue().toULongLong();