KGantt

kganttconstraintproxy.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KGantt library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "kganttconstraintproxy.h"
10#include "kganttconstraintmodel.h"
11
12#include <QAbstractProxyModel>
13
14using namespace KGantt;
15
16
17
18ConstraintProxy::ConstraintProxy( QObject* parent )
19 : QObject( parent )
20{
21}
22
23ConstraintProxy::~ConstraintProxy()
24{
25}
26
27void ConstraintProxy::setSourceModel( ConstraintModel* src )
28{
29 if ( m_source ) m_source->disconnect( this );
30 m_source = src;
31
32 copyFromSource();
33
34 connect( m_source, SIGNAL(constraintAdded(KGantt::Constraint)),
35 this, SLOT(slotSourceConstraintAdded(KGantt::Constraint)) );
36 connect( m_source, SIGNAL(constraintRemoved(KGantt::Constraint)),
37 this, SLOT(slotSourceConstraintRemoved(KGantt::Constraint)) );
38}
39
40void ConstraintProxy::setDestinationModel( ConstraintModel* dest )
41{
42 if ( m_destination ) m_destination->disconnect( this );
43 m_destination = dest;
44
45 copyFromSource();
46
47 connect( m_destination, SIGNAL(constraintAdded(KGantt::Constraint)),
48 this, SLOT(slotDestinationConstraintAdded(KGantt::Constraint)) );
49 connect( m_destination, SIGNAL(constraintRemoved(KGantt::Constraint)),
50 this, SLOT(slotDestinationConstraintRemoved(KGantt::Constraint)) );
51}
52
53void ConstraintProxy::setProxyModel( QAbstractProxyModel* proxy )
54{
55 if ( m_proxy == proxy ) return;
56 if ( m_proxy ) m_proxy->disconnect( this );
57 m_proxy = proxy;
58 if ( m_proxy ) {
59 connect( m_proxy, SIGNAL(layoutChanged()), this, SLOT(slotLayoutChanged()) );
60 connect( m_proxy, SIGNAL(modelReset()), this, SLOT(slotLayoutChanged()) );
61 }
62}
63
64ConstraintModel* ConstraintProxy::sourceModel() const { return m_source; }
65ConstraintModel* ConstraintProxy::destinationModel() const { return m_destination; }
66QAbstractProxyModel* ConstraintProxy::proxyModel() const { return m_proxy; }
67
68
69void ConstraintProxy::copyFromSource()
70{
71 if ( m_destination ) {
72 m_destination->clear();
73 if ( !m_source ) return;
74 const QList<Constraint> lst = m_source->constraints();
75 for( const Constraint& c : lst )
76 {
77 Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
78 c.type(), c.relationType(), c.dataMap() );
79 m_destination->addConstraint( temp );
80 }
81 }
82}
83
84void ConstraintProxy::slotSourceConstraintAdded( const KGantt::Constraint& c )
85{
86 if ( m_destination )
87 {
88 Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
89 c.type(), c.relationType(), c.dataMap() );
90 m_destination->addConstraint( temp );
91 }
92}
93
94void ConstraintProxy::slotSourceConstraintRemoved( const KGantt::Constraint& c )
95{
96 if ( m_destination )
97 {
98 Constraint temp( m_proxy->mapFromSource( c.startIndex() ), m_proxy->mapFromSource( c.endIndex() ),
99 c.type(), c.relationType(), c.dataMap() );
100 m_destination->removeConstraint( temp );
101 }
102}
103
104void ConstraintProxy::slotDestinationConstraintAdded( const KGantt::Constraint& c )
105{
106 if ( m_source )
107 {
108 Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
109 c.type(), c.relationType(), c.dataMap() );
110 m_source->addConstraint( temp );
111 }
112}
113
114void ConstraintProxy::slotDestinationConstraintRemoved( const KGantt::Constraint& c )
115{
116 if ( m_source )
117 {
118 Constraint temp( m_proxy->mapToSource( c.startIndex() ), m_proxy->mapToSource( c.endIndex() ),
119 c.type(), c.relationType(), c.dataMap() );
120 m_source->removeConstraint( temp );
121 }
122}
123
124void ConstraintProxy::slotLayoutChanged()
125{
126 copyFromSource();
127}
128
129#include "moc_kganttconstraintproxy.cpp"
A class used to represent a dependency.
QModelIndex endIndex() const
RelationType relationType() const
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
Global namespace.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.