Backport r950340 | aacid | 2009-04-06 23:21:18 +0200 (Mon, 06 Apr 2009) | 4 lines
[kdepim.git] / kdgantt / kdganttconstraintproxy.cpp
blob25cd488932fc5f7c88c0687553abd53f8d7fc6ba
1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Gantt library.
5 **
6 ** This file may be used under the terms of the GNU General Public
7 ** License versions 2.0 or 3.0 as published by the Free Software
8 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
9 ** included in the packaging of this file. Alternatively you may (at
10 ** your option) use any later version of the GNU General Public
11 ** License if such license has been publicly approved by
12 ** Klarälvdalens Datakonsult AB (or its successors, if any).
13 **
14 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
15 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
16 ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
17 ** not expressly granted herein.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **********************************************************************/
23 #include "kdganttconstraintproxy.h"
24 #include "kdganttconstraintmodel.h"
26 #include <QAbstractProxyModel>
28 using namespace KDGantt;
30 /*!\class KDGantt::ConstraintProxy
31 * \internal
34 ConstraintProxy::ConstraintProxy( QObject* parent )
35 : QObject( parent )
39 ConstraintProxy::~ConstraintProxy()
43 void ConstraintProxy::setSourceModel( ConstraintModel* src )
45 if ( m_source ) disconnect( m_source );
46 m_source = src;
48 copyFromSource();
50 connect( m_source, SIGNAL( constraintAdded( const Constraint& ) ),
51 this, SLOT( slotSourceConstraintAdded( const Constraint& ) ) );
52 connect( m_source, SIGNAL( constraintRemoved( const Constraint& ) ),
53 this, SLOT( slotSourceConstraintRemoved( const Constraint& ) ) );
56 void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
58 if ( m_destination ) disconnect( m_destination );
59 m_destination = dest;
61 copyFromSource();
63 connect( m_destination, SIGNAL( constraintAdded( const Constraint& ) ),
64 this, SLOT( slotDestinationConstraintAdded( const Constraint& ) ) );
65 connect( m_destination, SIGNAL( constraintRemoved( const Constraint& ) ),
66 this, SLOT( slotDestinationConstraintRemoved( const Constraint& ) ) );
69 void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
71 m_proxy = proxy;
74 ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
75 ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
76 QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
79 void ConstraintProxy::copyFromSource()
81 if ( m_destination ) {
82 m_destination->clear();
83 if ( !m_source ) return;
84 QList<Constraint> lst = m_source->constraints();
85 Q_FOREACH( const Constraint& c, lst ) {
86 m_destination->addConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
87 m_proxy->mapFromSource( c.endIndex() ),
88 c.type(), c.relationType() ) );
93 void ConstraintProxy::slotSourceConstraintAdded( const Constraint& c )
95 //qDebug() << "ConstraintProxy::slotSourceConstraintAdded("<<c<<")";
96 if ( m_destination ) m_destination->addConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
97 m_proxy->mapFromSource( c.endIndex() ),
98 c.type(), c.relationType() ) );
101 void ConstraintProxy::slotSourceConstraintRemoved( const Constraint& c )
103 //qDebug() << "ConstraintProxy::slotSourceConstraintRemoved("<<c<<")";
104 if ( m_destination ) m_destination->removeConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
105 m_proxy->mapFromSource( c.endIndex() ),
106 c.type(), c.relationType() ) );
109 void ConstraintProxy::slotDestinationConstraintAdded( const Constraint& c )
111 //qDebug() << "ConstraintProxy::slotDestinationConstraintAdded("<<c<<")";
112 if ( m_source ) m_source->addConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
113 m_proxy->mapToSource( c.endIndex() ),
114 c.type(), c.relationType() ) );
117 void ConstraintProxy::slotDestinationConstraintRemoved( const Constraint& c )
119 //qDebug() << "ConstraintProxy::slotDestinationConstraintRemoved("<<c<<")";
120 if ( m_source ) m_source->removeConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
121 m_proxy->mapToSource( c.endIndex() ),
122 c.type(), c.relationType() ) );
125 #include "moc_kdganttconstraintproxy.cpp"