kdganttconstraintproxy.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2011 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
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 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "kdganttconstraintproxy.h"
00024 #include "kdganttconstraintmodel.h"
00025 
00026 #include <QAbstractProxyModel>
00027 
00028 using namespace KDGantt;
00029 
00034 ConstraintProxy::ConstraintProxy( QObject* parent )
00035     : QObject( parent )
00036 {
00037 }
00038 
00039 ConstraintProxy::~ConstraintProxy()
00040 {
00041 }
00042 
00043 void ConstraintProxy::setSourceModel( ConstraintModel* src )
00044 {
00045     if ( m_source ) m_source->disconnect( this );
00046     m_source = src;
00047 
00048     copyFromSource();
00049 
00050     connect( m_source, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
00051              this, SLOT( slotSourceConstraintAdded( const KDGantt::Constraint& ) ) );
00052     connect( m_source, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
00053              this, SLOT( slotSourceConstraintRemoved( const KDGantt::Constraint& ) ) );
00054 }
00055 
00056 void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
00057 {
00058     if ( m_destination ) m_destination->disconnect( this );
00059     m_destination = dest;
00060 
00061     copyFromSource();
00062 
00063     connect( m_destination, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
00064              this, SLOT( slotDestinationConstraintAdded( const KDGantt::Constraint& ) ) );
00065     connect( m_destination, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
00066              this, SLOT( slotDestinationConstraintRemoved( const KDGantt::Constraint& ) ) );
00067 }
00068 
00069 void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
00070 {
00071     if ( m_proxy == proxy ) return;
00072     if ( m_proxy  ) m_proxy->disconnect( this );
00073     m_proxy = proxy;
00074     if ( m_proxy ) {
00075         connect( m_proxy, SIGNAL( layoutChanged() ), this, SLOT( slotLayoutChanged() ) );
00076         connect( m_proxy, SIGNAL( modelReset() ), this, SLOT( slotLayoutChanged() ) );
00077     }
00078 }
00079 
00080 ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
00081 ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
00082 QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
00083 
00084 
00085 void ConstraintProxy::copyFromSource()
00086 {
00087     if ( m_destination ) {
00088         m_destination->clear();
00089         if ( !m_source ) return;
00090         const QList<Constraint> lst = m_source->constraints();
00091         Q_FOREACH( const Constraint& c, lst )
00092         {
00093            Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
00094                             c.type(), c.relationType(), c.dataMap() );
00095            m_destination->addConstraint( temp );
00096         }
00097     }
00098 }
00099 
00100 void ConstraintProxy::slotSourceConstraintAdded( const KDGantt::Constraint& c )
00101 {
00102     if ( m_destination )
00103     {
00104         Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
00105                          c.type(), c.relationType(), c.dataMap() );
00106         m_destination->addConstraint( temp );
00107     }
00108 }
00109 
00110 void ConstraintProxy::slotSourceConstraintRemoved( const KDGantt::Constraint& c )
00111 {
00112     if ( m_destination )
00113     {
00114         Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
00115                          c.type(), c.relationType(), c.dataMap() );
00116         m_destination->removeConstraint( temp );
00117     }
00118 }
00119 
00120 void ConstraintProxy::slotDestinationConstraintAdded( const KDGantt::Constraint& c )
00121 {
00122     if ( m_source )
00123     {
00124         Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
00125                          c.type(), c.relationType(), c.dataMap() );
00126         m_source->addConstraint( temp );
00127     }
00128 }
00129 
00130 void ConstraintProxy::slotDestinationConstraintRemoved( const KDGantt::Constraint& c )
00131 {
00132     if ( m_source )
00133     {
00134         Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
00135                          c.type(), c.relationType(), c.dataMap() );
00136         m_source->removeConstraint( temp );
00137     }
00138 }
00139 
00140 void ConstraintProxy::slotLayoutChanged()
00141 {
00142     copyFromSource();
00143 }
00144 
00145 #include "moc_kdganttconstraintproxy.cpp"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/