24 #include "kdganttconstraintmodel_p.h" 42 ConstraintModel::Private::Private()
46 void ConstraintModel::Private::addConstraintToIndex(
const QModelIndex& idx,
const Constraint& c )
48 IndexType::iterator it = indexMap.find(idx);
49 while (it != indexMap.end() && it.key() == idx) {
51 if ( *it == c )
return;
55 indexMap.insert( idx, c );
58 void ConstraintModel::Private::removeConstraintFromIndex(
const QModelIndex& idx,
const Constraint& c )
60 IndexType::iterator it = indexMap.find(idx);
61 while (it != indexMap.end() && it.key() == idx) {
63 it =indexMap.erase( it );
73 :
QObject( parent ), _d( new Private )
80 :
QObject( parent ), _d( d_ptr )
93 void ConstraintModel::init()
98 struct compare_constraint_indexes_to :
public std::unary_function<bool,Constraint> {
99 compare_constraint_indexes_to(
const Constraint& c )
104 return m_c.compareIndexes( c );
119 d->constraints.end(),
120 compare_constraint_indexes_to(c) );
122 if ( it ==
d->constraints.end() ) {
123 d->constraints.push_back( c );
125 d->addConstraintToIndex( c.
endIndex(), c );
127 }
else if ( ( *it ).dataMap() != c.
dataMap() ) {
130 d->constraints.push_back( c );
132 d->addConstraintToIndex( c.
endIndex(), c );
148 for (
int i = 0; i <
d->constraints.count(); i++)
152 d->constraints.removeAt(i);
159 d->removeConstraintFromIndex( c.
endIndex(), c );
182 QSet<Constraint> orphans;
187 d->constraints.subtract( orphans );
197 return d->constraints;
206 assert( !idx.isValid() ||
d->indexMap.isEmpty() || !
d->indexMap.keys().front().model() || idx.model() ==
d->indexMap.keys().front().model() );
207 if ( !idx.isValid() ) {
209 QSet<Constraint> result;
213 return result.toList();
239 for (
int i = 0; i <
d->constraints.count(); i++)
246 #ifndef QT_NO_DEBUG_STREAM 250 dbg <<
"KDGantt::ConstraintModel[ " <<
static_cast<const QObject*
>( &model ) <<
": [\n";
252 dbg <<
"\t" << c <<
"\n";
262 #ifndef KDAB_NO_UNIT_TESTS 264 #include <QStandardItemModel> 268 std::ostream&
operator<<( std::ostream& os,
const QModelIndex& idx )
273 os<<str.toLatin1().constData();
275 os<<str.toStdString();
282 QStandardItemModel dummyModel( 100, 100 );
285 QModelIndex invalidIndex;
296 QPersistentModelIndex idx1 = dummyModel.index( 7, 17, QModelIndex() );
297 QPersistentModelIndex idx2 = dummyModel.index( 42, 17, QModelIndex() );
319 dummyModel.removeRow( 8 );
321 dummyModel.removeRow( 7 );
327 #include "moc_kdganttconstraintmodel.cpp" bool hasConstraint(const Constraint &c) const
A class used to represent a dependency.
virtual bool removeConstraint(const Constraint &c)
virtual void addConstraint(const Constraint &c)
Subclassing ConstraintModel and overriding addConstraint() and removeConstraint() can provide re-entr...
ConstraintModel(QObject *parent=0)
void constraintAdded(const KDGantt::Constraint &)
QList< Constraint > constraintsForIndex(const QModelIndex &) const
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, ConstraintModel,"test")
QDebug operator<<(QDebug dbg, const KDGantt::ConstraintModel &model)
QList< Constraint > constraints() const
QModelIndex endIndex() const
void constraintRemoved(const KDGantt::Constraint &)
Class only listed here to document inheritance of some KDChart classes.
QMap< int, QVariant > dataMap() const
~ConstraintModel() override
bool compareIndexes(const Constraint &other) const
QModelIndex startIndex() const
#define assertEqual(x, y)