File indexing completed on 2024-05-12 15:54:22
0001 /* 0002 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KGantt library. 0005 * 0006 * This program is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef KGANTTCONSTRAINTMODEL_H 0021 #define KGANTTCONSTRAINTMODEL_H 0022 0023 #include <QModelIndex> 0024 #include <QDebug> 0025 0026 #include "kganttglobal.h" 0027 #include "kganttconstraint.h" 0028 0029 namespace KGantt { 0030 0031 0032 /*!\class KGantt::ConstraintModel 0033 *\ingroup KGantt 0034 * The ConstraintModel keeps track of the 0035 * interdependencies between gantt items in 0036 * a View. 0037 * 0038 */ 0039 class KGANTT_EXPORT ConstraintModel : public QObject { 0040 Q_OBJECT 0041 KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( ConstraintModel, QObject* ) 0042 public: 0043 0044 0045 /*! Constructor. Creates an empty ConstraintModel with parent \a parent 0046 */ 0047 explicit ConstraintModel( QObject* parent = nullptr ); 0048 0049 0050 /*! Destroys this ConstraintModel */ 0051 virtual ~ConstraintModel(); 0052 0053 /*! Adds the constraint \a c to this ConstraintModel 0054 * If the Constraint \a c is already in this ConstraintModel, 0055 * nothing happens. 0056 * 0057 * Subclassing ConstraintModel and overriding addConstraint() and removeConstraint() can provide 0058 * re-entrancy issues in the ConstraintModel<->ConstraintProxy interaction. Therefore it is recommed 0059 * to better subclass GraphicsView and override addConstraint() there. 0060 */ 0061 virtual void addConstraint( const Constraint& c ); 0062 0063 /*! Removes the Constraint \a c from this 0064 * ConstraintModel. If \a c was found and removed, 0065 * the signal constraintRemoved(const Constraint&) is emitted. 0066 * 0067 * \returns If \a c was found and removed, it returns true, 0068 * otherwise it returns false. 0069 */ 0070 virtual bool removeConstraint( const Constraint& c ); 0071 0072 /*! Removes all Constraints from this model 0073 * The signal constraintRemoved(const Constraint&) is emitted 0074 * for every Constraint that is removed. 0075 */ 0076 void clear(); 0077 0078 /*! Not used */ 0079 void cleanup(); 0080 0081 /*! \returns A list of all Constraints in this 0082 * ConstraintModel. 0083 */ 0084 QList<Constraint> constraints() const; 0085 0086 /*! Returns true if a Constraint with start \a s and end \a e 0087 * exists, otherwise false. 0088 */ 0089 bool hasConstraint( const Constraint& c ) const; 0090 inline bool hasConstraint( const QModelIndex& s, 0091 const QModelIndex& e ) const; 0092 0093 0094 /*! \returns A list of all Constraints in this ConstraintModel 0095 * that have an endpoint at \a idx. 0096 */ 0097 QList<Constraint> constraintsForIndex( const QModelIndex& ) const; 0098 0099 Q_SIGNALS: 0100 void constraintAdded(const KGantt::Constraint&); 0101 void constraintRemoved(const KGantt::Constraint&); 0102 0103 private: 0104 Private* _d; 0105 }; 0106 0107 inline const ConstraintModel::Private* ConstraintModel::d_func() const { return _d; } 0108 inline ConstraintModel::Private* ConstraintModel::d_func() { return _d; } 0109 inline bool ConstraintModel::hasConstraint( const QModelIndex& s, const QModelIndex& e ) const { 0110 return hasConstraint( Constraint( s, e ) ); 0111 } 0112 } 0113 0114 #ifndef QT_NO_DEBUG_STREAM 0115 0116 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::ConstraintModel& model ); 0117 inline QDebug operator<<( QDebug dbg, KGantt::ConstraintModel* model ) 0118 { 0119 return operator<<(dbg,*model); 0120 } 0121 0122 #endif /* QT_NO_DEBUG_STREAM */ 0123 0124 #endif /* KGANTTCONSTRAINTMODEL_H */ 0125