KD Chart 2  [rev.2.6]
kdganttconstraintproxy.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2019 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
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.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "kdganttconstraintproxy.h"
24 #include "kdganttconstraintmodel.h"
25 
26 #include <QAbstractProxyModel>
27 
28 using namespace KDGantt;
29 
35  : QObject( parent )
36 {
37 }
38 
40 {
41 }
42 
44 {
45  if ( m_source ) m_source->disconnect( this );
46  m_source = src;
47 
48  copyFromSource();
49 
50  connect( m_source, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
51  this, SLOT( slotSourceConstraintAdded( const KDGantt::Constraint& ) ) );
52  connect( m_source, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
53  this, SLOT( slotSourceConstraintRemoved( const KDGantt::Constraint& ) ) );
54 }
55 
57 {
58  if ( m_destination ) m_destination->disconnect( this );
59  m_destination = dest;
60 
61  copyFromSource();
62 
63  connect( m_destination, SIGNAL( constraintAdded( const KDGantt::Constraint& ) ),
64  this, SLOT( slotDestinationConstraintAdded( const KDGantt::Constraint& ) ) );
65  connect( m_destination, SIGNAL( constraintRemoved( const KDGantt::Constraint& ) ),
66  this, SLOT( slotDestinationConstraintRemoved( const KDGantt::Constraint& ) ) );
67 }
68 
70 {
71  if ( m_proxy == proxy ) return;
72  if ( m_proxy ) m_proxy->disconnect( this );
73  m_proxy = proxy;
74  if ( m_proxy ) {
75  connect( m_proxy, SIGNAL( layoutChanged() ), this, SLOT( slotLayoutChanged() ) );
76  connect( m_proxy, SIGNAL( modelReset() ), this, SLOT( slotLayoutChanged() ) );
77  }
78 }
79 
80 ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
81 ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
83 
84 
85 void ConstraintProxy::copyFromSource()
86 {
87  if ( m_destination ) {
88  m_destination->clear();
89  if ( !m_source ) return;
90  const QList<Constraint> lst = m_source->constraints();
91  Q_FOREACH( const Constraint& c, lst )
92  {
93  Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
94  c.type(), c.relationType(), c.dataMap() );
95  m_destination->addConstraint( temp );
96  }
97  }
98 }
99 
100 void ConstraintProxy::slotSourceConstraintAdded( const KDGantt::Constraint& c )
101 {
102  if ( m_destination )
103  {
104  Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
105  c.type(), c.relationType(), c.dataMap() );
106  m_destination->addConstraint( temp );
107  }
108 }
109 
110 void ConstraintProxy::slotSourceConstraintRemoved( const KDGantt::Constraint& c )
111 {
112  if ( m_destination )
113  {
114  Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
115  c.type(), c.relationType(), c.dataMap() );
116  m_destination->removeConstraint( temp );
117  }
118 }
119 
120 void ConstraintProxy::slotDestinationConstraintAdded( const KDGantt::Constraint& c )
121 {
122  if ( m_source )
123  {
124  Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
125  c.type(), c.relationType(), c.dataMap() );
126  m_source->addConstraint( temp );
127  }
128 }
129 
130 void ConstraintProxy::slotDestinationConstraintRemoved( const KDGantt::Constraint& c )
131 {
132  if ( m_source )
133  {
134  Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
135  c.type(), c.relationType(), c.dataMap() );
136  m_source->removeConstraint( temp );
137  }
138 }
139 
140 void ConstraintProxy::slotLayoutChanged()
141 {
142  copyFromSource();
143 }
144 
145 #include "moc_kdganttconstraintproxy.cpp"
A class used to represent a dependency.
ConstraintModel * destinationModel() const
Class only listed here to document inheritance of some KDChart classes.
RelationType relationType() const
QAbstractProxyModel * proxyModel() const
QModelIndex endIndex() const
void setDestinationModel(ConstraintModel *dest)
Class only listed here to document inheritance of some KDChart classes.
QMap< int, QVariant > dataMap() const
void setSourceModel(ConstraintModel *src)
ConstraintModel * sourceModel() const
void setProxyModel(QAbstractProxyModel *proxy)
QModelIndex startIndex() const

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