File indexing completed on 2024-05-12 04:20:39
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KGANTTCONSTRAINT_H 0010 #define KGANTTCONSTRAINT_H 0011 0012 #include <QMap> 0013 #include <QModelIndex> 0014 #include <QObject> 0015 #include <QSharedDataPointer> 0016 #include <QVariant> 0017 0018 #include "kganttglobal.h" 0019 #ifndef QT_NO_DEBUG_STREAM 0020 #include <QDebug> 0021 #endif 0022 0023 namespace KGantt { 0024 0025 0026 /*!\class KGantt::Constraint 0027 *\ingroup KGantt 0028 * \brief A class used to represent a dependency. 0029 * 0030 * Instances of this class represent a dependency between the 0031 * data items pointed to by a start-QModelIndex and an 0032 * end-QModelIndex. 0033 */ 0034 class KGANTT_EXPORT Constraint { 0035 class Private; 0036 public: 0037 /*!\enum KGantt::Constraint::Type 0038 * This enum is unused for now. 0039 */ 0040 enum Type 0041 { 0042 TypeSoft = 0, 0043 TypeHard = 1 0044 }; 0045 enum RelationType 0046 { 0047 FinishStart = 0, 0048 FinishFinish = 1, 0049 StartStart = 2, 0050 StartFinish = 3 0051 }; 0052 0053 /*!\enum KGantt::Constraint::ConstraintDataRole 0054 * Data roles used when specifying the pen to draw constraints with. 0055 * \sa setData 0056 */ 0057 enum ConstraintDataRole 0058 { 0059 ValidConstraintPen = Qt::UserRole, 0060 InvalidConstraintPen 0061 }; 0062 0063 typedef QMap<int, QVariant> DataMap; 0064 0065 /*! Default constructor, created an invalid constraint. */ 0066 Constraint(); 0067 0068 /*! Constructor. Creates a dependency for \a idx2 on \a idx1. 0069 * \param type controls if the constraint is a soft one that 0070 * is allowed to be broken (ie, go backwards in time) or a hard 0071 * constraint that will not allow the user to move an item so 0072 * that the constraint would have to go backwards. The default is 0073 * TypeSoft. 0074 * 0075 * Actually enforcing hard constraints is the responsibility of 0076 * the AbstractGrid subclass used in the view. 0077 * 0078 * \param relationType defines how the tasks depends on each other. 0079 * relationType can be FinishStart (default), FinishFinish, StartStart or StartFinish. 0080 */ 0081 Constraint( const QModelIndex& idx1, 0082 const QModelIndex& idx2, 0083 Type type=TypeSoft, 0084 RelationType relType=FinishStart, 0085 const DataMap& datamap=DataMap() ); 0086 0087 /*! Copy-Constructor. */ 0088 Constraint( const Constraint& other); 0089 0090 0091 /*! Destructor */ 0092 ~Constraint(); 0093 0094 /*! This is unused for now. */ 0095 Type type() const; 0096 0097 /*! This is unused for now. */ 0098 RelationType relationType() const; 0099 0100 /*! \returns The dependency index */ 0101 QModelIndex startIndex() const; 0102 0103 /*! \returns The constrained index */ 0104 QModelIndex endIndex() const; 0105 0106 /*! Set data on this index for the specified role. 0107 * \param role The role to set the data for. 0108 * \param value The data to set on the index. 0109 * \sa ConstraintDataRole 0110 */ 0111 void setData( int role, const QVariant& value ); 0112 0113 /*! \returns The data associated with this index for the specified role. 0114 * \param role The role to fetch the data for. 0115 * \sa ConstraintDataRole 0116 */ 0117 QVariant data( int role ) const; 0118 0119 /*! Set data on this constraint to the keys/values in \a datamap. 0120 * Clears any existing data from the constraint. 0121 */ 0122 void setDataMap( const QMap< int, QVariant >& datamap ); 0123 0124 /*! \returns all the data set on this constraint. \see setDataMap 0125 */ 0126 QMap< int, QVariant > dataMap() const; 0127 0128 bool compareIndexes(const Constraint& other) const; 0129 0130 /*! Assignment operator. */ 0131 Constraint& operator=( const Constraint& other ); 0132 0133 /*! Compare two Constraint objects. Two Constraints are equal 0134 * if the have the same start and end indexes 0135 */ 0136 bool operator==( const Constraint& other ) const; 0137 0138 inline bool operator!=( const Constraint& other ) const { 0139 return !operator==( other ); 0140 } 0141 0142 /*!\internal*/ 0143 uint hash() const; 0144 #ifndef QT_NO_DEBUG_STREAM 0145 QDebug debug( QDebug dbg) const; 0146 #endif 0147 0148 private: 0149 QSharedDataPointer<Private> d; 0150 }; 0151 0152 inline uint qHash( const Constraint& c ) {return c.hash();} 0153 } 0154 0155 #ifndef QT_NO_DEBUG_STREAM 0156 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::Constraint& c ); 0157 #endif /* QT_NO_DEBUG_STREAM */ 0158 0159 #endif /* KGANTTCONSTRAINT_H */ 0160