12#include "kdganttconstraintmodel_p.h"
30ConstraintModel::Private::Private()
36 IndexType::iterator it = indexMap.find(idx);
37 while (it != indexMap.end() && it.key() == idx) {
44 indexMap.insert(idx, c);
49 IndexType::iterator it = indexMap.find(idx);
50 while (it != indexMap.end() && it.key() == idx) {
52 it = indexMap.erase(it);
84void ConstraintModel::init()
89struct compare_constraint_indexes_to
91 compare_constraint_indexes_to(
const Constraint &c)
97 return m_c.compareIndexes(c);
112 d->constraints.end(),
113 compare_constraint_indexes_to(c));
115 if (
it ==
d->constraints.end()) {
116 d->constraints.push_back(c);
118 d->addConstraintToIndex(c.
endIndex(), c);
120 }
else if ((*it).dataMap() != c.
dataMap()) {
123 d->constraints.push_back(c);
125 d->addConstraintToIndex(c.
endIndex(), c);
141 for (
int i = 0;
i <
d->constraints.count();
i++) {
143 d->constraints.removeAt(
i);
150 d->removeConstraintFromIndex(c.
endIndex(), c);
188 return d->constraints;
197 assert(!
idx.isValid() ||
d->indexMap.isEmpty() || !
d->indexMap.keys().front().model() ||
idx.model() ==
d->indexMap.keys().front().model());
198 if (!
idx.isValid()) {
233 for (
int i = 0;
i <
d->constraints.count();
i++)
240#ifndef QT_NO_DEBUG_STREAM
244 dbg <<
"KDGantt::ConstraintModel[ " <<
static_cast<const QObject *
>(&model) <<
": [\n";
247 dbg <<
"\t" << c <<
"\n";
257#ifndef KDAB_NO_UNIT_TESTS
259#include <QStandardItemModel>
261#include "unittest/test.h"
281 assertEqual(invalidIndex, invalidIndex);
322#include "moc_kdganttconstraintmodel.cpp"
QDebug operator<<(QDebug dbg, const KDChart::ThreeDBarAttributes &a)
The ConstraintModel keeps track of the interdependencies between gantt items in a View.
virtual void addConstraint(const Constraint &c)
Adds the constraint c to this ConstraintModel If the Constraint c is already in this ConstraintModel,...
void clear()
Removes all Constraints from this model The signal constraintRemoved(const Constraint&) is emitted fo...
~ConstraintModel() override
Destroys this ConstraintModel.
QList< Constraint > constraintsForIndex(const QModelIndex &) const
QList< Constraint > constraints() const
ConstraintModel(QObject *parent=nullptr)
Constructor.
bool hasConstraint(const Constraint &c) const
Returns true if a Constraint with start s and end e exists, otherwise false.
void constraintRemoved(const KDGantt::Constraint &)
virtual bool removeConstraint(const Constraint &c)
Removes the Constraint c from this ConstraintModel.
void constraintAdded(const KDGantt::Constraint &)
A class used to represent a dependency.
QModelIndex endIndex() const
bool compareIndexes(const Constraint &other) const
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, Constraint, "test")
bool removeRow(int row, const QModelIndex &parent)
const char * constData() const const
void push_back(const T &value)
bool isValid() const const
T qobject_cast(QObject *object)
QSet::iterator insert(const T &value)
QList< T > values() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
QByteArray toLatin1() const const
std::string toStdString() const const