KD Chart API Documentation 3.1
Loading...
Searching...
No Matches
kdganttconstraintproxy.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of the KD Chart library.
4**
5** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6**
7** SPDX-License-Identifier: MIT
8**
9****************************************************************************/
10
13
14#include <QAbstractProxyModel>
15
16using namespace KDGantt;
17
23 : QObject(parent)
24{
25}
26
30
32{
33 if (m_source)
34 m_source->disconnect(this);
35 m_source = src;
36
37 copyFromSource();
38
40 this, &ConstraintProxy::slotSourceConstraintAdded);
42 this, &ConstraintProxy::slotSourceConstraintRemoved);
43}
44
46{
47 if (m_destination)
48 m_destination->disconnect(this);
49 m_destination = dest;
50
51 copyFromSource();
52
54 this, &ConstraintProxy::slotDestinationConstraintAdded);
56 this, &ConstraintProxy::slotDestinationConstraintRemoved);
57}
58
60{
61 if (m_proxy == proxy)
62 return;
63 if (m_proxy)
64 m_proxy->disconnect(this);
65 m_proxy = proxy;
66 if (m_proxy) {
67 connect(m_proxy, &QAbstractProxyModel::layoutChanged, this, &ConstraintProxy::slotLayoutChanged);
68 connect(m_proxy, &QAbstractProxyModel::modelReset, this, &ConstraintProxy::slotLayoutChanged);
69 }
70}
71
73{
74 return m_source;
75}
77{
78 return m_destination;
79}
81{
82 return m_proxy;
83}
84
85void ConstraintProxy::copyFromSource()
86{
87 if (m_destination) {
88 m_destination->clear();
89 if (!m_source)
90 return;
91 const QList<Constraint> lst = m_source->constraints();
92 for (const Constraint &c : lst) {
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
100void ConstraintProxy::slotSourceConstraintAdded(const KDGantt::Constraint &c)
101{
102 if (m_destination) {
103 Constraint temp(m_proxy->mapFromSource(c.startIndex()), m_proxy->mapFromSource(c.endIndex()),
104 c.type(), c.relationType(), c.dataMap());
105 m_destination->addConstraint(temp);
106 }
107}
108
109void ConstraintProxy::slotSourceConstraintRemoved(const KDGantt::Constraint &c)
110{
111 if (m_destination) {
112 Constraint temp(m_proxy->mapFromSource(c.startIndex()), m_proxy->mapFromSource(c.endIndex()),
113 c.type(), c.relationType(), c.dataMap());
114 m_destination->removeConstraint(temp);
115 }
116}
117
118void ConstraintProxy::slotDestinationConstraintAdded(const KDGantt::Constraint &c)
119{
120 if (m_source) {
121 Constraint temp(m_proxy->mapToSource(c.startIndex()), m_proxy->mapToSource(c.endIndex()),
122 c.type(), c.relationType(), c.dataMap());
123 m_source->addConstraint(temp);
124 }
125}
126
127void ConstraintProxy::slotDestinationConstraintRemoved(const KDGantt::Constraint &c)
128{
129 if (m_source) {
130 Constraint temp(m_proxy->mapToSource(c.startIndex()), m_proxy->mapToSource(c.endIndex()),
131 c.type(), c.relationType(), c.dataMap());
132 m_source->removeConstraint(temp);
133 }
134}
135
136void ConstraintProxy::slotLayoutChanged()
137{
138 copyFromSource();
139}
140
141#include "moc_kdganttconstraintproxy.cpp"
The ConstraintModel keeps track of the interdependencies between gantt items in a View.
void constraintRemoved(const KDGantt::Constraint &)
void constraintAdded(const KDGantt::Constraint &)
void setProxyModel(QAbstractProxyModel *proxy)
ConstraintProxy(QObject *parent=nullptr)
QAbstractProxyModel * proxyModel() const
ConstraintModel * sourceModel() const
void setDestinationModel(ConstraintModel *dest)
void setSourceModel(ConstraintModel *src)
ConstraintModel * destinationModel() const
A class used to represent a dependency.
QModelIndex endIndex() const
Type type() const
This is unused for now.
RelationType relationType() const
This is unused for now.
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)

© 2001 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-chart/
Generated on Mon Jul 8 2024 00:00:52 for KD Chart API Documentation by doxygen 1.9.8