1 /****************************************************************************
2 ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB. All rights reserved.
4 ** This file is part of the KD Gantt library.
6 ** This file may be distributed and/or modified under the terms of the
7 ** GNU General Public License version 2 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.GPL included in the
9 ** packaging of this file.
11 ** Licensees holding valid commercial KD Gantt licenses may use this file in
12 ** accordance with the KD Gantt Commercial License Agreement provided with
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 ** See http://www.kdab.net/kdgantt for
19 ** information about KD Gantt Commercial License Agreements.
21 ** Contact info@kdab.net if any conditions of this
22 ** licensing are not clear to you.
24 **********************************************************************/
25 #include "kdganttconstraintproxy.h"
26 #include "kdganttconstraintmodel.h"
28 #include <QAbstractProxyModel>
30 using namespace KDGantt
;
32 /*!\class KDGantt::ConstraintProxy
36 ConstraintProxy::ConstraintProxy( QObject
* parent
)
41 ConstraintProxy::~ConstraintProxy()
45 void ConstraintProxy::setSourceModel( ConstraintModel
* src
)
47 if ( m_source
) disconnect( m_source
);
52 connect( m_source
, SIGNAL(constraintAdded(Constraint
)),
53 this, SLOT(slotSourceConstraintAdded(Constraint
)) );
54 connect( m_source
, SIGNAL(constraintRemoved(Constraint
)),
55 this, SLOT(slotSourceConstraintRemoved(Constraint
)) );
58 void ConstraintProxy::setDestinationModel( ConstraintModel
* dest
)
60 if ( m_destination
) disconnect( m_destination
);
65 connect( m_destination
, SIGNAL(constraintAdded(Constraint
)),
66 this, SLOT(slotDestinationConstraintAdded(Constraint
)) );
67 connect( m_destination
, SIGNAL(constraintRemoved(Constraint
)),
68 this, SLOT(slotDestinationConstraintRemoved(Constraint
)) );
71 void ConstraintProxy::setProxyModel( QAbstractProxyModel
* proxy
)
76 ConstraintModel
* ConstraintProxy::sourceModel() const { return m_source
; }
77 ConstraintModel
* ConstraintProxy::destinationModel() const { return m_destination
; }
78 QAbstractProxyModel
* ConstraintProxy::proxyModel() const { return m_proxy
; }
81 void ConstraintProxy::copyFromSource()
83 if ( m_destination
) {
84 m_destination
->clear();
85 if ( !m_source
) return;
86 QList
<Constraint
> lst
= m_source
->constraints();
87 Q_FOREACH( const Constraint
& c
, lst
) {
88 m_destination
->addConstraint( Constraint( m_proxy
->mapFromSource( c
.startIndex() ),
89 m_proxy
->mapFromSource( c
.endIndex() ) ) );
94 void ConstraintProxy::slotSourceConstraintAdded( const Constraint
& c
)
96 if ( m_destination
) m_destination
->addConstraint( Constraint( m_proxy
->mapFromSource( c
.startIndex() ),
97 m_proxy
->mapFromSource( c
.endIndex() ) ) );
100 void ConstraintProxy::slotSourceConstraintRemoved( const Constraint
& c
)
102 if ( m_destination
) m_destination
->removeConstraint( Constraint( m_proxy
->mapFromSource( c
.startIndex() ),
103 m_proxy
->mapFromSource( c
.endIndex() ) ) );
106 void ConstraintProxy::slotDestinationConstraintAdded( const Constraint
& c
)
108 if ( m_source
) m_source
->addConstraint( Constraint( m_proxy
->mapToSource( c
.startIndex() ),
109 m_proxy
->mapToSource( c
.endIndex() ) ) );
112 void ConstraintProxy::slotDestinationConstraintRemoved( const Constraint
& c
)
114 if ( m_source
) m_source
->removeConstraint( Constraint( m_proxy
->mapToSource( c
.startIndex() ),
115 m_proxy
->mapToSource( c
.endIndex() ) ) );
118 #include "moc_kdganttconstraintproxy.cpp"