~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kdgantt/kdganttconstraintproxy.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
21
 
 **
22
 
 **********************************************************************/
23
 
#include "kdganttconstraintproxy.h"
24
 
#include "kdganttconstraintmodel.h"
25
 
 
26
 
#include <QAbstractProxyModel>
27
 
 
28
 
using namespace KDGantt;
29
 
 
30
 
/*!\class KDGantt::ConstraintProxy
31
 
 * \internal
32
 
 */
33
 
 
34
 
ConstraintProxy::ConstraintProxy( QObject* parent )
35
 
    : QObject( parent )
36
 
{
37
 
}
38
 
 
39
 
ConstraintProxy::~ConstraintProxy()
40
 
{
41
 
}
42
 
 
43
 
void ConstraintProxy::setSourceModel( ConstraintModel* src )
44
 
{
45
 
    if ( m_source ) disconnect( m_source );
46
 
    m_source = src;
47
 
 
48
 
    copyFromSource();
49
 
 
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& ) ) );
54
 
}
55
 
 
56
 
void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
57
 
{
58
 
    if ( m_destination ) disconnect( m_destination );
59
 
    m_destination = dest;
60
 
 
61
 
    copyFromSource();
62
 
 
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& ) ) );
67
 
}
68
 
 
69
 
void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
70
 
{
71
 
    m_proxy = proxy;
72
 
}
73
 
 
74
 
ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
75
 
ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
76
 
QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
77
 
 
78
 
 
79
 
void ConstraintProxy::copyFromSource()
80
 
{
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() ) );
89
 
        }
90
 
    }
91
 
}
92
 
 
93
 
void ConstraintProxy::slotSourceConstraintAdded( const Constraint& c )
94
 
{
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() ) );
99
 
}
100
 
 
101
 
void ConstraintProxy::slotSourceConstraintRemoved( const Constraint& c )
102
 
{
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() ) );
107
 
}
108
 
 
109
 
void ConstraintProxy::slotDestinationConstraintAdded( const Constraint& c )
110
 
{
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() ) );
115
 
}
116
 
 
117
 
void ConstraintProxy::slotDestinationConstraintRemoved( const Constraint& c )
118
 
{
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() ) );
123
 
}
124
 
 
125
 
#include "moc_kdganttconstraintproxy.cpp"