• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kdgantt

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 used under the terms of the GNU General Public
00007  ** License versions 2.0 or 3.0 as published by the Free Software
00008  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00009  ** included in the packaging of this file.  Alternatively you may (at
00010  ** your option) use any later version of the GNU General Public
00011  ** License if such license has been publicly approved by
00012  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00013  ** 
00014  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00015  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00016  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00017  ** not expressly granted herein.
00018  ** 
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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 ) disconnect( m_source );
00046     m_source = src;
00047 
00048     copyFromSource();
00049 
00050     connect( m_source, SIGNAL( constraintAdded( const Constraint& ) ),
00051              this, SLOT( slotSourceConstraintAdded( const Constraint& ) ) );
00052     connect( m_source, SIGNAL( constraintRemoved( const Constraint& ) ),
00053              this, SLOT( slotSourceConstraintRemoved( const Constraint& ) ) );
00054 }
00055 
00056 void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
00057 {
00058     if ( m_destination ) disconnect( m_destination );
00059     m_destination = dest;
00060 
00061     copyFromSource();
00062 
00063     connect( m_destination, SIGNAL( constraintAdded( const Constraint& ) ),
00064              this, SLOT( slotDestinationConstraintAdded( const Constraint& ) ) );
00065     connect( m_destination, SIGNAL( constraintRemoved( const Constraint& ) ),
00066              this, SLOT( slotDestinationConstraintRemoved( const Constraint& ) ) );
00067 }
00068 
00069 void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
00070 {
00071     m_proxy = proxy;
00072 }
00073 
00074 ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
00075 ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
00076 QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
00077 
00078 
00079 void ConstraintProxy::copyFromSource()
00080 {
00081     if ( m_destination ) {
00082         m_destination->clear();
00083         if ( !m_source ) return;
00084         QList<Constraint> lst = m_source->constraints();
00085         Q_FOREACH( const Constraint& c, lst ) {
00086             m_destination->addConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
00087                                                       m_proxy->mapFromSource( c.endIndex() ),
00088                                                       c.type(), c.relationType() ) );
00089         }
00090     }
00091 }
00092 
00093 void ConstraintProxy::slotSourceConstraintAdded( const Constraint& c )
00094 {
00095     //qDebug() << "ConstraintProxy::slotSourceConstraintAdded("<<c<<")";
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 Constraint& c )
00102 {
00103     //qDebug() << "ConstraintProxy::slotSourceConstraintRemoved("<<c<<")";
00104     if ( m_destination ) m_destination->removeConstraint( Constraint( m_proxy->mapFromSource( c.startIndex() ),
00105                                                                       m_proxy->mapFromSource( c.endIndex() ),
00106                                                                       c.type(), c.relationType() ) );
00107 }
00108 
00109 void ConstraintProxy::slotDestinationConstraintAdded( const Constraint& c )
00110 {
00111     //qDebug() << "ConstraintProxy::slotDestinationConstraintAdded("<<c<<")";
00112     if ( m_source ) m_source->addConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
00113                                                          m_proxy->mapToSource( c.endIndex() ),
00114                                                          c.type(), c.relationType() ) );
00115 }
00116 
00117 void ConstraintProxy::slotDestinationConstraintRemoved( const Constraint& c )
00118 {
00119     //qDebug() << "ConstraintProxy::slotDestinationConstraintRemoved("<<c<<")";
00120     if ( m_source ) m_source->removeConstraint( Constraint( m_proxy->mapToSource( c.startIndex() ),
00121                                                             m_proxy->mapToSource( c.endIndex() ),
00122                                                             c.type(), c.relationType() ) );
00123 }
00124 
00125 #include "moc_kdganttconstraintproxy.cpp"

kdgantt

Skip menu "kdgantt"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal