File indexing completed on 2024-04-28 04:37:47
0001 /* 0002 SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de> 0003 SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KDEVPLATFORM_VCSREVISION_H 0009 #define KDEVPLATFORM_VCSREVISION_H 0010 0011 #include "vcsexport.h" 0012 #include <QVariant> 0013 #include <QSharedDataPointer> 0014 class QStringList; 0015 class QString; 0016 0017 namespace KDevelop 0018 { 0019 0020 /** 0021 * Encapsulates a vcs revision number, date or range of revisions. 0022 * 0023 * The type of the QVariant value depends on the type of the revision, 0024 * the following table lists the standard types and the according datatype 0025 * in the QVariant: 0026 * 0027 * <table> 0028 * <tr><th>Revision type</th><th>QVariant type</th></tr> 0029 * <tr><td>GlobalNumber</td><td>qlonglong/QString</td></tr> 0030 * <tr><td>FileNumber</td><td>qlonglong/QString</td></tr> 0031 * <tr><td>Date</td><td>QDateTime</td></tr> 0032 * <tr><td>Special</td><td>KDevelop::VcsRevision::RevisionSpecialType or int, see explanation below</td></tr> 0033 * </table> 0034 * 0035 * The vcs plugins need to register the Revision and RevisionSpecialType with 0036 * qRegisterMetaType. 0037 * 0038 * Also Users of this class should set RevisionSpecialType QVariant values via 0039 * @code 0040 * setRevisionValue(QVariant::fromValue<KDevelop::VcsRevision::RevisionSpecialType>(val), KDevelop::VcsRevision::Special); 0041 * @endcode 0042 * instead of 0043 * @code 0044 * setRevisionValue(QVariant::fromValue(val), KDevelop::VcsRevision::Special); 0045 * @endcode 0046 * 0047 * If the latter method is used the QVariant will be an Integer, which might not 0048 * be handled by the vcs plugin and is possibly ambiguous with the qlonglong 0049 * parameters. 0050 * 0051 */ 0052 class KDEVPLATFORMVCS_EXPORT VcsRevision 0053 { 0054 public: 0055 0056 /** 0057 * @note Not all VCS's support both FileNumber and GlobalNumber. For those 0058 * that don't, asking for one may give you the other, therefore you should 0059 * check which is returned. For example, CVS does not support GlobalNumber, 0060 * and Subversion does not support FileNumber, while Perforce supports both. 0061 */ 0062 enum RevisionType 0063 { 0064 Special = 0 /**< One of the special versions in RevisionSpecialType. */, 0065 GlobalNumber = 1 /**< Global repository version when item was last changed. */, 0066 FileNumber = 2 /**< Item's independent version number. */, 0067 Date = 3, /**< The date of the revision to check out */ 0068 Invalid = 4 /**< The type is not set, this is an invalid revision. */, 0069 UserType = 1000 /**< This should be used by subclasses as base for their own types. */ 0070 }; 0071 enum RevisionSpecialType 0072 { 0073 Head = 0 /**< Latest revision in the repository. */, 0074 Working = 1 /**< The local copy (including any changes made). */, 0075 Base = 2 /**< The repository source of the local copy. */, 0076 Previous = 3 /**< The version prior the other one (only valid in functions that take two revisions). */, 0077 Start = 4, /**< The first commit in a repository. */ 0078 UserSpecialType = 1000 /**< This should be used by subclasses as base for their own special types. */ 0079 }; 0080 0081 /** 0082 * Creates an invalid revision. 0083 */ 0084 VcsRevision(); 0085 virtual ~VcsRevision(); 0086 0087 VcsRevision( const VcsRevision& ); 0088 0089 VcsRevision& operator=( const VcsRevision& ); 0090 0091 /** 0092 * Set the value of this revision 0093 */ 0094 void setRevisionValue( const QVariant& rev, RevisionType type ); 0095 0096 /** 0097 * returns the type of the revision 0098 */ 0099 RevisionType revisionType() const; 0100 0101 RevisionSpecialType specialType() const; 0102 0103 /** 0104 * Return the value of this revision. 0105 * 0106 * See the class documentation for the different QVariant types 0107 */ 0108 QVariant revisionValue() const; 0109 0110 /** 0111 * This returns the value of the revision, suitable for displaying to the 0112 * user. For numbers it just returns the number converted to a string, for 0113 * the special types it returns the literal value of the special type and 0114 * for a datetime value it returns a localized string of the datetime value. 0115 */ 0116 QString prettyValue() const; 0117 0118 bool operator==( const KDevelop::VcsRevision&) const; 0119 0120 /** 0121 * Helper function to create a vcs revision for one of the special types 0122 */ 0123 static VcsRevision createSpecialRevision( KDevelop::VcsRevision::RevisionSpecialType type ); 0124 protected: 0125 /** 0126 * Get the keys that make up the internal data of this revision instance 0127 */ 0128 QStringList keys() const; 0129 /** 0130 * get the value for a given key, this retrieves internal data and is 0131 * meant to be used by subclasses 0132 */ 0133 QVariant value(const QString& key) const; 0134 /** 0135 * change the value of the given internal data 0136 */ 0137 void setValue( const QString& key, const QVariant& value ); 0138 0139 /** 0140 * write methods for subclasses to easily set the type and value 0141 */ 0142 void setType( RevisionType t); 0143 void setSpecialType( RevisionSpecialType t); 0144 void setValue( const QVariant& ); 0145 0146 0147 private: 0148 QSharedDataPointer<class VcsRevisionPrivate> d; 0149 }; 0150 0151 KDEVPLATFORMVCS_EXPORT uint qHash( const KDevelop::VcsRevision& rev); 0152 0153 } 0154 0155 Q_DECLARE_METATYPE(KDevelop::VcsRevision) 0156 Q_DECLARE_TYPEINFO(KDevelop::VcsRevision, Q_MOVABLE_TYPE); 0157 Q_DECLARE_METATYPE(KDevelop::VcsRevision::RevisionSpecialType) 0158 0159 0160 0161 #endif 0162