1 /* 2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 3 * 4 * This file is part of the KGantt library. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef KGANTTCONSTRAINT_H 21 #define KGANTTCONSTRAINT_H 22 23 #include <QMap> 24 #include <QModelIndex> 25 #include <QObject> 26 #include <QSharedDataPointer> 27 #include <QVariant> 28 29 #include "kganttglobal.h" 30 #ifndef QT_NO_DEBUG_STREAM 31 #include <QDebug> 32 #endif 33 34 namespace KGantt { 35 36 37 /*!\class KGantt::Constraint 38 *\ingroup KGantt 39 * \brief A class used to represent a dependency. 40 * 41 * Instances of this class represent a dependency between the 42 * data items pointed to by a start-QModelIndex and an 43 * end-QModelIndex. 44 */ 45 class KGANTT_EXPORT Constraint { 46 class Private; 47 public: 48 /*!\enum KGantt::Constraint::Type 49 * This enum is unused for now. 50 */ 51 enum Type 52 { 53 TypeSoft = 0, 54 TypeHard = 1 55 }; 56 enum RelationType 57 { 58 FinishStart = 0, 59 FinishFinish = 1, 60 StartStart = 2, 61 StartFinish = 3 62 }; 63 64 /*!\enum KGantt::Constraint::ConstraintDataRole 65 * Data roles used when specifying the pen to draw constraints with. 66 * \sa setData 67 */ 68 enum ConstraintDataRole 69 { 70 ValidConstraintPen = Qt::UserRole, 71 InvalidConstraintPen 72 }; 73 74 typedef QMap<int, QVariant> DataMap; 75 76 /*! Default constructor, created an invalid constraint. */ 77 Constraint(); 78 79 /*! Constructor. Creates a dependency for \a idx2 on \a idx1. 80 * \param type controls if the constraint is a soft one that 81 * is allowed to be broken (ie, go backwards in time) or a hard 82 * constraint that will not allow the user to move an item so 83 * that the constraint would have to go backwards. The default is 84 * TypeSoft. 85 * 86 * Actually enforcing hard constraints is the responsibility of 87 * the AbstractGrid subclass used in the view. 88 * 89 * \param relationType defines how the tasks depends on each other. 90 * relationType can be FinishStart (default), FinishFinish, StartStart or StartFinish. 91 */ 92 Constraint( const QModelIndex& idx1, 93 const QModelIndex& idx2, 94 Type type=TypeSoft, 95 RelationType relType=FinishStart, 96 const DataMap& datamap=DataMap() ); 97 98 /*! Copy-Constructor. */ 99 Constraint( const Constraint& other); 100 101 102 /*! Destructor */ 103 ~Constraint(); 104 105 /*! This is unused for now. */ 106 Type type() const; 107 108 /*! This is unused for now. */ 109 RelationType relationType() const; 110 111 /*! \returns The dependency index */ 112 QModelIndex startIndex() const; 113 114 /*! \returns The constrained index */ 115 QModelIndex endIndex() const; 116 117 /*! Set data on this index for the specified role. 118 * \param role The role to set the data for. 119 * \param value The data to set on the index. 120 * \sa ConstraintDataRole 121 */ 122 void setData( int role, const QVariant& value ); 123 124 /*! \returns The data associated with this index for the specified role. 125 * \param role The role to fetch the data for. 126 * \sa ConstraintDataRole 127 */ 128 QVariant data( int role ) const; 129 130 /*! Set data on this constraint to the keys/values in \a datamap. 131 * Clears any existing data from the constraint. 132 */ 133 void setDataMap( const QMap< int, QVariant >& datamap ); 134 135 /*! \returns all the data set on this constraint. \see setDataMap 136 */ 137 QMap< int, QVariant > dataMap() const; 138 139 bool compareIndexes(const Constraint& other) const; 140 141 /*! Assignment operator. */ 142 Constraint& operator=( const Constraint& other ); 143 144 /*! Compare two Constraint objects. Two Constraints are equal 145 * if the have the same start and end indexes 146 */ 147 bool operator==( const Constraint& other ) const; 148 149 inline bool operator!=( const Constraint& other ) const { 150 return !operator==( other ); 151 } 152 153 /*!\internal*/ 154 uint hash() const; 155 #ifndef QT_NO_DEBUG_STREAM 156 QDebug debug( QDebug dbg) const; 157 #endif 158 159 private: 160 QSharedDataPointer<Private> d; 161 }; 162 qHash(const Constraint & c)163 inline uint qHash( const Constraint& c ) {return c.hash();} 164 } 165 166 #ifndef QT_NO_DEBUG_STREAM 167 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::Constraint& c ); 168 #endif /* QT_NO_DEBUG_STREAM */ 169 170 #endif /* KGANTTCONSTRAINT_H */ 171 172