9#include "kganttconstraintproxy.h"
10#include "kganttconstraintmodel.h"
12#include <QAbstractProxyModel>
18ConstraintProxy::ConstraintProxy(
QObject* parent )
23ConstraintProxy::~ConstraintProxy()
34 connect( m_source, SIGNAL(constraintAdded(KGantt::Constraint)),
35 this, SLOT(slotSourceConstraintAdded(KGantt::Constraint)) );
36 connect( m_source, SIGNAL(constraintRemoved(KGantt::Constraint)),
37 this, SLOT(slotSourceConstraintRemoved(KGantt::Constraint)) );
42 if ( m_destination ) m_destination->disconnect(
this );
47 connect( m_destination, SIGNAL(constraintAdded(KGantt::Constraint)),
48 this, SLOT(slotDestinationConstraintAdded(KGantt::Constraint)) );
49 connect( m_destination, SIGNAL(constraintRemoved(KGantt::Constraint)),
50 this, SLOT(slotDestinationConstraintRemoved(KGantt::Constraint)) );
53void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
55 if ( m_proxy == proxy )
return;
56 if ( m_proxy ) m_proxy->disconnect(
this );
59 connect( m_proxy, SIGNAL(layoutChanged()),
this, SLOT(slotLayoutChanged()) );
60 connect( m_proxy, SIGNAL(modelReset()),
this, SLOT(slotLayoutChanged()) );
64ConstraintModel* ConstraintProxy::sourceModel()
const {
return m_source; }
65ConstraintModel* ConstraintProxy::destinationModel()
const {
return m_destination; }
66QAbstractProxyModel* ConstraintProxy::proxyModel()
const {
return m_proxy; }
69void ConstraintProxy::copyFromSource()
71 if ( m_destination ) {
72 m_destination->clear();
73 if ( !m_source )
return;
74 const QList<Constraint> lst = m_source->constraints();
75 for(
const Constraint& c : lst )
77 Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
78 c.type(), c.relationType(), c.dataMap() );
79 m_destination->addConstraint( temp );
84void ConstraintProxy::slotSourceConstraintAdded(
const KGantt::Constraint& c )
88 Constraint temp( m_proxy->mapFromSource( c.
startIndex() ), m_proxy->mapFromSource( c.
endIndex() ),
90 m_destination->addConstraint( temp );
94void ConstraintProxy::slotSourceConstraintRemoved(
const KGantt::Constraint& c )
98 Constraint temp( m_proxy->mapFromSource( c.
startIndex() ), m_proxy->mapFromSource( c.
endIndex() ),
100 m_destination->removeConstraint( temp );
104void ConstraintProxy::slotDestinationConstraintAdded(
const KGantt::Constraint& c )
108 Constraint temp( m_proxy->mapToSource( c.
startIndex() ), m_proxy->mapToSource( c.
endIndex() ),
110 m_source->addConstraint( temp );
114void ConstraintProxy::slotDestinationConstraintRemoved(
const KGantt::Constraint& c )
118 Constraint temp( m_proxy->mapToSource( c.
startIndex() ), m_proxy->mapToSource( c.
endIndex() ),
120 m_source->removeConstraint( temp );
124void ConstraintProxy::slotLayoutChanged()
129#include "moc_kganttconstraintproxy.cpp"
QModelIndex endIndex() const
RelationType relationType() const
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)