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 KGANTTCONSTRAINTMODEL_H 0010 #define KGANTTCONSTRAINTMODEL_H 0011 0012 #include <QModelIndex> 0013 #include <QDebug> 0014 0015 #include "kganttglobal.h" 0016 #include "kganttconstraint.h" 0017 0018 namespace KGantt { 0019 0020 0021 /*!\class KGantt::ConstraintModel 0022 *\ingroup KGantt 0023 * The ConstraintModel keeps track of the 0024 * interdependencies between gantt items in 0025 * a View. 0026 * 0027 */ 0028 class KGANTT_EXPORT ConstraintModel : public QObject { 0029 Q_OBJECT 0030 KGANTT_DECLARE_PRIVATE_DERIVED_PARENT( ConstraintModel, QObject* ) 0031 public: 0032 0033 0034 /*! Constructor. Creates an empty ConstraintModel with parent \a parent 0035 */ 0036 explicit ConstraintModel( QObject* parent = nullptr ); 0037 0038 0039 /*! Destroys this ConstraintModel */ 0040 ~ConstraintModel() override; 0041 0042 /*! Adds the constraint \a c to this ConstraintModel 0043 * If the Constraint \a c is already in this ConstraintModel, 0044 * nothing happens. 0045 * 0046 * Subclassing ConstraintModel and overriding addConstraint() and removeConstraint() can provide 0047 * re-entrancy issues in the ConstraintModel<->ConstraintProxy interaction. Therefore it is recommended 0048 * to better subclass GraphicsView and override addConstraint() there. 0049 */ 0050 virtual void addConstraint( const Constraint& c ); 0051 0052 /*! Removes the Constraint \a c from this 0053 * ConstraintModel. If \a c was found and removed, 0054 * the signal constraintRemoved(const Constraint&) is emitted. 0055 * 0056 * \returns If \a c was found and removed, it returns true, 0057 * otherwise it returns false. 0058 */ 0059 virtual bool removeConstraint( const Constraint& c ); 0060 0061 /*! Removes all Constraints from this model 0062 * The signal constraintRemoved(const Constraint&) is emitted 0063 * for every Constraint that is removed. 0064 */ 0065 void clear(); 0066 0067 /*! Not used */ 0068 void cleanup(); 0069 0070 /*! \returns A list of all Constraints in this 0071 * ConstraintModel. 0072 */ 0073 QList<Constraint> constraints() const; 0074 0075 /*! Returns true if a Constraint with start \a s and end \a e 0076 * exists, otherwise false. 0077 */ 0078 bool hasConstraint( const Constraint& c ) const; 0079 inline bool hasConstraint( const QModelIndex& s, 0080 const QModelIndex& e ) const; 0081 0082 0083 /*! \returns A list of all Constraints in this ConstraintModel 0084 * that have an endpoint at \a idx. 0085 */ 0086 QList<Constraint> constraintsForIndex( const QModelIndex& ) const; 0087 0088 Q_SIGNALS: 0089 void constraintAdded(const KGantt::Constraint&); 0090 void constraintRemoved(const KGantt::Constraint&); 0091 0092 private: 0093 Private* _d; 0094 }; 0095 0096 inline const ConstraintModel::Private* ConstraintModel::d_func() const { return _d; } 0097 inline ConstraintModel::Private* ConstraintModel::d_func() { return _d; } 0098 inline bool ConstraintModel::hasConstraint( const QModelIndex& s, const QModelIndex& e ) const { 0099 return hasConstraint( Constraint( s, e ) ); 0100 } 0101 } 0102 0103 #ifndef QT_NO_DEBUG_STREAM 0104 0105 QDebug KGANTT_EXPORT operator<<( QDebug dbg, const KGantt::ConstraintModel& model ); 0106 inline QDebug operator<<( QDebug dbg, KGantt::ConstraintModel* model ) 0107 { 0108 return operator<<(dbg,*model); 0109 } 0110 0111 #endif /* QT_NO_DEBUG_STREAM */ 0112 0113 #endif /* KGANTTCONSTRAINTMODEL_H */ 0114