#include <kdganttconstraintmodel.h>
Definition at line 35 of file kdganttconstraintmodel.h.
Signals | |
void | constraintAdded (const KDGantt::Constraint &) |
void | constraintRemoved (const KDGantt::Constraint &) |
Public Member Functions | |
void | addConstraint (const Constraint &c) |
void | cleanup () |
void | clear () |
ConstraintModel (QObject *parent=0) | |
QList< Constraint > | constraints () const |
QList< Constraint > | constraintsForIndex (const QModelIndex &) const |
bool | hasConstraint (const QModelIndex &s, const QModelIndex &e) const |
bool | hasConstraint (const Constraint &c) const |
bool | removeConstraint (const Constraint &c) |
virtual | ~ConstraintModel () |
ConstraintModel::ConstraintModel | ( | QObject * | parent = 0 |
) | [explicit] |
Constructor. Creates an empty ConstraintModel with parent parent
Definition at line 72 of file kdganttconstraintmodel.cpp.
References StockDiagram::init().
ConstraintModel::~ConstraintModel | ( | ) | [virtual] |
void ConstraintModel::addConstraint | ( | const Constraint & | c | ) |
Adds the constraint c to this ConstraintModel If the Constraint c is already in this ConstraintModel, nothing happens.
Definition at line 101 of file kdganttconstraintmodel.cpp.
References constraintAdded(), d, KDGantt::Constraint::endIndex(), hasConstraint(), and KDGantt::Constraint::startIndex().
Referenced by KDGantt::GraphicsView::addConstraint(), and KDAB_SCOPED_UNITTEST_SIMPLE().
00102 { 00103 //int size = d->constraints.size(); 00104 bool hasConstraint = d->constraints.contains( c ); 00105 //d->constraints.insert( c ); 00106 //if ( size != d->constraints.size() ) { 00107 if ( !hasConstraint ) { 00108 d->constraints.push_back( c ); 00109 d->addConstraintToIndex( c.startIndex(), c ); 00110 d->addConstraintToIndex( c.endIndex(), c ); 00111 emit constraintAdded( c ); 00112 } 00113 }
void ConstraintModel::cleanup | ( | ) |
Not used
Definition at line 148 of file kdganttconstraintmodel.cpp.
References d, KDGantt::Constraint::endIndex(), and KDGantt::Constraint::startIndex().
00149 { 00150 #if 0 00151 QSet<Constraint> orphans; 00152 Q_FOREACH( const Constraint& c, d->constraints ) { 00153 if ( !c.startIndex().isValid() || !c.endIndex().isValid() ) orphans.insert( c ); 00154 } 00155 //qDebug() << "Constraint::cleanup() found" << orphans << "orphans"; 00156 d->constraints.subtract( orphans ); 00157 #endif 00158 }
void ConstraintModel::clear | ( | ) |
Removes all Constraints from this model The signal constraintRemoved(const Constraint&) is emitted for every Constraint that is removed.
Definition at line 139 of file kdganttconstraintmodel.cpp.
References constraints(), and removeConstraint().
00140 { 00141 QList<Constraint> lst = constraints(); 00142 Q_FOREACH( const Constraint& c, lst ) { 00143 removeConstraint( c ); 00144 } 00145 }
void KDGantt::ConstraintModel::constraintAdded | ( | const KDGantt::Constraint & | ) | [signal] |
Referenced by addConstraint().
void KDGantt::ConstraintModel::constraintRemoved | ( | const KDGantt::Constraint & | ) | [signal] |
Referenced by removeConstraint().
QList< Constraint > ConstraintModel::constraints | ( | ) | const |
Definition at line 163 of file kdganttconstraintmodel.cpp.
References d.
Referenced by clear(), KDAB_SCOPED_UNITTEST_SIMPLE(), and operator<<().
00164 { 00165 //return d->constraints.toList(); 00166 return d->constraints; 00167 }
QList< Constraint > ConstraintModel::constraintsForIndex | ( | const QModelIndex & | idx | ) | const |
Definition at line 172 of file kdganttconstraintmodel.cpp.
References d, KDGantt::Constraint::endIndex(), and KDGantt::Constraint::startIndex().
Referenced by KDAB_SCOPED_UNITTEST_SIMPLE().
00173 { 00174 // TODO: @Steffen: Please comment on this assert, it's long and not obvious (Johannes) 00175 assert( !idx.isValid() || d->indexMap.isEmpty() || !d->indexMap.keys().front().model() || idx.model() == d->indexMap.keys().front().model() ); 00176 if ( !idx.isValid() ) { 00177 // Because of a Qt bug we need to treat this as a special case 00178 QSet<Constraint> result; 00179 Q_FOREACH( Constraint c, d->constraints ) { 00180 if ( !c.startIndex().isValid() || !c.endIndex().isValid() ) result.insert( c ); 00181 } 00182 return result.toList(); 00183 } else { 00184 QList<Constraint> result; 00185 Q_FOREACH( Constraint c, d->constraints ) { 00186 if ( c.startIndex() == idx || c.endIndex() == idx ) result.push_back( c ); 00187 } 00188 return result; 00189 } 00190 00191 //return d->indexMap.values( idx ); 00192 }
bool KDGantt::ConstraintModel::hasConstraint | ( | const QModelIndex & | s, | |
const QModelIndex & | e | |||
) | const |
Definition at line 66 of file kdganttconstraintmodel.h.
References hasConstraint().
00066 { 00067 return hasConstraint( Constraint( s, e ) ); 00068 }
bool ConstraintModel::hasConstraint | ( | const Constraint & | c | ) | const |
Returns true if a Constraint with start s and end e exists, otherwise false.
Definition at line 197 of file kdganttconstraintmodel.cpp.
References d.
Referenced by KDGantt::GraphicsView::addConstraint(), addConstraint(), hasConstraint(), and KDAB_SCOPED_UNITTEST_SIMPLE().
00198 { 00199 /* 00200 // Because of a Qt bug we have to search like this 00201 Q_FOREACH( Constraint c2, d->constraints ) { 00202 if ( c==c2 ) return true; 00203 } 00204 return false; 00205 */ 00206 return d->constraints.contains( c ); 00207 }
bool ConstraintModel::removeConstraint | ( | const Constraint & | c | ) |
Removes the Constraint c from this ConstraintModel. If c was found and removed, the signal constraintRemoved(const Constraint&) is emitted.
Definition at line 122 of file kdganttconstraintmodel.cpp.
References constraintRemoved(), d, KDGantt::Constraint::endIndex(), and KDGantt::Constraint::startIndex().
Referenced by KDGantt::GraphicsView::addConstraint(), clear(), and KDAB_SCOPED_UNITTEST_SIMPLE().
00123 { 00124 //qDebug() << "ConstraintModel::removeConstraint("<<c<<") from "<< d->constraints; 00125 bool rc = d->constraints.removeAll( c ); 00126 //bool rc = d->constraints.remove( c ); 00127 if ( rc ) { 00128 d->removeConstraintFromIndex( c.startIndex(), c ); 00129 d->removeConstraintFromIndex( c.endIndex(), c ); 00130 emit constraintRemoved( c ); 00131 } 00132 return rc; 00133 }