1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/***************************************************************************
* This file is part of KDevelop *
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "vcsrevision.h"
#include <QString>
#include <QStringList>
#include <QMap>
#include <QDateTime>
#include <QLocale>
namespace KDevelop
{
VcsRevision VcsRevision::createSpecialRevision( KDevelop::VcsRevision::RevisionSpecialType _type )
{
VcsRevision rev;
rev.setRevisionValue( QVariant::fromValue<KDevelop::VcsRevision::RevisionSpecialType>( _type ), VcsRevision::Special );
return rev;
}
class VcsRevisionPrivate : public QSharedData
{
public:
QVariant value;
VcsRevision::RevisionType type;
QMap<QString,QVariant> internalValues;
};
VcsRevision::VcsRevision()
: d(new VcsRevisionPrivate)
{
d->type = VcsRevision::Invalid;
}
VcsRevision::VcsRevision( const VcsRevision& rhs )
: d(rhs.d)
{
}
VcsRevision::~VcsRevision() = default;
VcsRevision& VcsRevision::operator=( const VcsRevision& rhs)
{
d = rhs.d;
return *this;
}
void VcsRevision::setRevisionValue( const QVariant& rev, VcsRevision::RevisionType type )
{
d->value = rev;
d->type = type;
}
VcsRevision::RevisionType VcsRevision::revisionType() const
{
return d->type;
}
VcsRevision::RevisionSpecialType VcsRevision::specialType() const
{
Q_ASSERT(d->type==Special);
return d->value.value<RevisionSpecialType>();
}
QVariant VcsRevision::revisionValue() const
{
return d->value;
}
QStringList VcsRevision::keys() const
{
return d->internalValues.keys();
}
QVariant VcsRevision::value(const QString& key) const
{
const auto valueIt = d->internalValues.constFind(key);
if (valueIt != d->internalValues.constEnd()) {
return *valueIt;
}
return QVariant();
}
void VcsRevision::setValue( const QString& key, const QVariant& value )
{
d->internalValues[key] = value;
}
void VcsRevision::setType( RevisionType t)
{
d->type = t;
}
void VcsRevision::setSpecialType( RevisionSpecialType t)
{
d->value = QVariant(t);
}
void VcsRevision::setValue( const QVariant& v )
{
d->value = v;
}
bool VcsRevision::operator==( const KDevelop::VcsRevision& rhs ) const
{
return ( d->type == rhs.d->type && d->value == rhs.d->value && d->internalValues == rhs.d->internalValues );
}
QString VcsRevision::prettyValue() const
{
switch( revisionType() )
{
case GlobalNumber:
case FileNumber:
return (revisionValue().type() == QVariant::String ? revisionValue().toString() : QString::number(revisionValue().toLongLong()));
case Special:
switch( revisionValue().value<KDevelop::VcsRevision::RevisionSpecialType>( ) )
{
case VcsRevision::Head:
return QStringLiteral("Head");
case VcsRevision::Base:
return QStringLiteral("Base");
case VcsRevision::Working:
return QStringLiteral("Working");
case VcsRevision::Previous:
return QStringLiteral("Previous");
case VcsRevision::Start:
return QStringLiteral("Start");
default:
return QStringLiteral("User");
}
case Date:
return QLocale().toString(revisionValue().toDateTime(), QLocale::ShortFormat);
default:
return revisionValue().toString();
}
}
}
uint KDevelop::qHash( const KDevelop::VcsRevision& rev)
{
const auto revisionValue = rev.revisionValue();
switch (rev.revisionType()) {
case VcsRevision::GlobalNumber:
case VcsRevision::FileNumber:
return (revisionValue.type() == QVariant::String ? ::qHash(revisionValue.toString()) :
::qHash(revisionValue.toULongLong()));
case VcsRevision::Special:
return ::qHash(static_cast<int>(revisionValue.value<KDevelop::VcsRevision::RevisionSpecialType>()));
case VcsRevision::Date:
return ::qHash(revisionValue.toDateTime());
default:
return ::qHash(revisionValue.toString());
}
}
|