kdganttconstraintproxy.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Gantt library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Gantt licenses may use this file in
00012  ** accordance with the KD Gantt Commercial License Agreement provided with
00013  ** the Software.
00014  **
00015  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017  **
00018  ** See http://www.kdab.net/kdgantt for
00019  **   information about KD Gantt Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
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"

Generated on Thu Mar 4 23:19:13 2010 for KD Chart 2 by  doxygen 1.5.4