00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kdganttconstraintproxy.h"
00026 #include "kdganttconstraintmodel.h"
00027
00028 #include <QAbstractProxyModel>
00029
00030 using namespace KDGantt;
00031
00036 ConstraintProxy::ConstraintProxy( QObject* parent )
00037 : QObject( parent )
00038 {
00039 }
00040
00041 ConstraintProxy::~ConstraintProxy()
00042 {
00043 }
00044
00045 void ConstraintProxy::setSourceModel( ConstraintModel* src )
00046 {
00047 if ( m_source ) disconnect( m_source );
00048 m_source = src;
00049
00050 copyFromSource();
00051
00052 connect( m_source, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
00053 this, SLOT( slotSourceConstraintAdded( const KDGantt::Constraint& ) ) );
00054 connect( m_source, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
00055 this, SLOT( slotSourceConstraintRemoved( const KDGantt::Constraint& ) ) );
00056 }
00057
00058 void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
00059 {
00060 if ( m_destination ) disconnect( m_destination );
00061 m_destination = dest;
00062
00063 copyFromSource();
00064
00065 connect( m_destination, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
00066 this, SLOT( slotDestinationConstraintAdded( const KDGantt::Constraint& ) ) );
00067 connect( m_destination, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
00068 this, SLOT( slotDestinationConstraintRemoved( const KDGantt::Constraint& ) ) );
00069 }
00070
00071 void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
00072 {
00073 m_proxy = proxy;
00074 }
00075
00076 ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
00077 ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
00078 QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
00079
00080
00081 void ConstraintProxy::copyFromSource()
00082 {
00083 if ( m_destination ) {
00084 m_destination->clear();
00085 if ( !m_source ) return;
00086 QList<Constraint> lst = m_source->constraints();
00087 Q_FOREACH( const Constraint& c, lst ) {
00088 m_destination->addConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
00089 m_proxy->mapFromSource( c.endIndex() ) ) );
00090 }
00091 }
00092 }
00093
00094 void ConstraintProxy::slotSourceConstraintAdded( const KDGantt::Constraint& c )
00095 {
00096 if ( m_destination ) m_destination->addConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
00097 m_proxy->mapFromSource( c.endIndex() ),
00098 c.type(), c.relationType() ) );
00099 }
00100
00101 void ConstraintProxy::slotSourceConstraintRemoved( const KDGantt::Constraint& c )
00102 {
00103 if ( m_destination ) m_destination->removeConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
00104 m_proxy->mapFromSource( c.endIndex() ),
00105 c.type(), c.relationType() ) );
00106 }
00107
00108 void ConstraintProxy::slotDestinationConstraintAdded( const KDGantt::Constraint& c )
00109 {
00110 if ( m_source ) m_source->addConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
00111 m_proxy->mapToSource( c.endIndex() ),
00112 c.type(), c.relationType() ) );
00113 }
00114
00115 void ConstraintProxy::slotDestinationConstraintRemoved( const KDGantt::Constraint& c )
00116 {
00117 if ( m_source ) m_source->removeConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
00118 m_proxy->mapToSource( c.endIndex() ),
00119 c.type(), c.relationType() ) );
00120 }
00121
00122 #include "moc_kdganttconstraintproxy.cpp"