KGantt

kganttconstraint.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 "kganttconstraint.h"
10#include "kganttconstraint_p.h"
11
12#include <QDateTime>
13
14using namespace KGantt;
15
16
17Constraint::Private::Private()
18 : type( TypeSoft ),
19 relationType( FinishStart )
20{
21}
22
23Constraint::Private::Private( const Private& other )
24 : QSharedData( other ),
25 start( other.start ),
26 end( other.end ),
27 type( other.type ),
28 relationType( other.relationType ),
29 data( other.data )
30{
31}
32
34 const QModelIndex& idx2,
35 Constraint::Type type,
36 Constraint::RelationType relationType,
37 const Constraint::DataMap& datamap )
38 : d( new Private )
39{
40 d->start=idx1;
41 d->end=idx2;
42 d->type=type;
43 d->relationType=relationType;
44 d->data=datamap;
45 Q_ASSERT_X( idx1 != idx2 || !idx1.isValid(), "Constraint::Constraint", "cannot create a constraint with idx1 == idx2" );
46}
47
49 : d( new Private )
50{
51}
52
54 : d( other.d )
55{
56}
57
61
63{
64 d = other.d;
65 return *this;
66}
67
68Constraint::Type Constraint::type() const
69{
70 return d->type;
71}
72
73Constraint::RelationType Constraint::relationType() const
74{
75 return d->relationType;
76}
77
79{
80 return d->start;
81}
82
84{
85 return d->end;
86}
87
88QVariant Constraint::data( int role ) const
89{
90 return d->data.value( role );
91}
92
93void Constraint::setData( int role, const QVariant& value )
94{
95 d->data.insert( role, value );
96}
97
99{
100 d->data = datamap;
101}
102
104{
105 return d->data;
106}
107
108bool Constraint::compareIndexes(const Constraint& other) const
109{
110 return (d->start==other.startIndex() || (!d->start.isValid() && !other.startIndex().isValid()))
111 && (d->end==other.endIndex() || (!d->end.isValid() && !other.endIndex().isValid()));
112}
113
114bool Constraint::operator==( const Constraint& other ) const
115{
116 if ( d == other.d ) return true;
117 return ( *d ).equals( *( other.d ) );
118}
119
121{
122 return ::qHash( d->start ) ^ ::qHash( d->end ) ^ ::qHash( static_cast<uint>( d->type ) );
123}
124
125#ifndef QT_NO_DEBUG_STREAM
126
127QDebug operator<<( QDebug dbg, const Constraint& c )
128{
129 return c.debug( dbg );
130}
131
132QDebug Constraint::debug( QDebug dbg ) const
133{
134 dbg << "KGantt::Constraint[ start=" << d->start << "end=" << d->end << "relationType=" << d->relationType << "], data=" << d->data;
135 return dbg;
136}
137
138#endif /* QT_NO_DEBUG_STREAM */
139
140#ifndef KDAB_NO_UNIT_TESTS
141
142#include <QStandardItemModel>
143
144#include "unittest/test.h"
145
146KDAB_SCOPED_UNITTEST_SIMPLE( KGantt, Constraint, "test" )
147{
148 QStandardItemModel dummyModel( 100, 100 );
149 QModelIndex idx1 = dummyModel.index( 7, 17, QModelIndex() );
150 QModelIndex idx2 = dummyModel.index( 42, 17, QModelIndex() );
151
152 Constraint c1 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
153 Constraint c2 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
154 Constraint c3 = c2;
155 Constraint c4( idx1, idx2 );
156 Constraint c5( idx2, idx1 );
157
158 assertTrue( c1==c2 );
159 assertEqual( qHash( c1 ), qHash( c2 ) );
160 assertTrue( c1==c3 );
161 assertEqual( qHash( c1 ), qHash( c3 ) );
162 assertTrue( c2==c3 );
163 assertEqual( qHash( c2 ), qHash( c3 ) );
164
165 assertFalse( c2==c4 );
166 assertNotEqual( qHash( c2 ), qHash( c4 ) );
167
168 assertFalse( c4==c5 );
169
170 assertEqual( c3.type(), Constraint::TypeSoft );
171
172 dummyModel.removeRow( 8 );
173 assertFalse( c4==c5 );
174}
175
176#endif /* KDAB_NO_UNIT_TESTS */
A class used to represent a dependency.
QVariant data(int role) const
void setDataMap(const QMap< int, QVariant > &datamap)
QModelIndex endIndex() const
Constraint & operator=(const Constraint &other)
bool operator==(const Constraint &other) const
RelationType relationType() const
QModelIndex startIndex() const
QMap< int, QVariant > dataMap() const
void setData(int role, const QVariant &value)
Q_SCRIPTABLE Q_NOREPLY void start()
Type type(const QSqlDatabase &db)
Global namespace.
const QList< QKeySequence > & end()
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:21 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.