• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kdgantt2

  • sources
  • kde-4.12
  • kdepim
  • kdgantt2
kdganttconstraint.cpp
Go to the documentation of this file.
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 distributed and/or modified under the terms of the
7  ** GNU General Public License version 2 as published by the Free Software
8  ** Foundation and appearing in the file LICENSE.GPL included in the
9  ** packaging of this file.
10  **
11  ** Licensees holding valid commercial KD Gantt licenses may use this file in
12  ** accordance with the KD Gantt Commercial License Agreement provided with
13  ** the Software.
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  ** See http://www.kdab.net/kdgantt for
19  ** information about KD Gantt Commercial License Agreements.
20  **
21  ** Contact info@kdab.net if any conditions of this
22  ** licensing are not clear to you.
23  **
24  **********************************************************************/
25 #include "kdganttconstraint.h"
26 #include "kdganttconstraint_p.h"
27 
28 #include <QDateTime>
29 
30 using namespace KDGantt;
31 
50 Constraint::Private::Private()
51  : type( TypeSoft )
52 {
53 }
54 
55 Constraint::Private::Private( const Private& other )
56  : QSharedData( other )
57 {
58  start=other.start;
59  end=other.end;
60  type=other.type;
61 }
62 
73 Constraint::Constraint( const QModelIndex& idx1, const QModelIndex& idx2, Type type )
74  : d( new Private )
75 {
76  d->start=idx1;
77  d->end=idx2;
78  d->type=type;
79  Q_ASSERT_X( idx1 != idx2 || !idx1.isValid(), "Constraint::Constraint", "cannot create a constraint with idx1 == idx2" );
80 }
81 
83 Constraint::Constraint( const Constraint& other )
84  : d( other.d )
85 {
86 }
87 
89 Constraint::~Constraint()
90 {
91 }
92 
94 Constraint& Constraint::operator=( const Constraint& other )
95 {
96  d = other.d;
97  return *this;
98 }
99 
101 Constraint::Type Constraint::type() const
102 {
103  return d->type;
104 }
105 
107 QModelIndex Constraint::startIndex() const
108 {
109  return d->start;
110 }
111 
113 QModelIndex Constraint::endIndex() const
114 {
115  return d->end;
116 }
117 
122 QVariant Constraint::data( int role ) const
123 {
124  return d->data.value( role );
125 }
126 
132 void Constraint::setData( int role, const QVariant& value )
133 {
134  d->data.insert( role, value );
135 }
136 
140 bool Constraint::operator==( const Constraint& other ) const
141 {
142  if ( d == other.d ) return true;
143  return ( *d ).equals( *( other.d ) );
144 }
145 
147 uint Constraint::hash() const
148 {
149  return ::qHash( d->start ) ^ ::qHash( d->end ) ^ ::qHash( static_cast<uint>( d->type ) );
150 }
151 
152 #ifndef QT_NO_DEBUG_STREAM
153 
154 QDebug operator<<( QDebug dbg, const Constraint& c )
155 {
156  return c.debug( dbg );
157 }
158 
159 QDebug Constraint::debug( QDebug dbg ) const
160 {
161  dbg << "KDGantt::Constraint[ start="<<d->start<<" end="<<d->end<<"]";
162  return dbg;
163 }
164 
165 #endif /* QT_NO_DEBUG_STREAM */
166 
167 #ifndef KDAB_NO_UNIT_TESTS
168 
169 #include <QStandardItemModel>
170 
171 #include "unittest/test.h"
172 
173 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, Constraint, "test" )
174 {
175  QStandardItemModel dummyModel( 100, 100 );
176  QModelIndex idx1 = dummyModel.index( 7, 17, QModelIndex() );
177  QModelIndex idx2 = dummyModel.index( 42, 17, QModelIndex() );
178 
179  Constraint c1 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
180  Constraint c2 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
181  Constraint c3 = c2;
182  Constraint c4( idx1, idx2 );
183  Constraint c5( idx2, idx1 );
184 
185  assertTrue( c1==c2 );
186  assertEqual( qHash( c1 ), qHash( c2 ) );
187  assertTrue( c1==c3 );
188  assertEqual( qHash( c1 ), qHash( c3 ) );
189  assertTrue( c2==c3 );
190  assertEqual( qHash( c2 ), qHash( c3 ) );
191 
192  assertFalse( c2==c4 );
193  assertNotEqual( qHash( c2 ), qHash( c4 ) );
194 
195  assertFalse( c4==c5 );
196 
197  assertEqual( c3.type(), Constraint::TypeSoft );
198 
199  dummyModel.removeRow( 8 );
200  assertFalse( c4==c5 );
201 }
202 
203 #endif /* KDAB_NO_UNIT_TESTS */
KDGantt::Constraint::endIndex
QModelIndex endIndex() const
Definition: kdganttconstraint.cpp:113
KDGantt::Constraint::Private::start
QPersistentModelIndex start
Definition: kdganttconstraint_p.h:48
KDGantt::Constraint::Private::type
Type type
Definition: kdganttconstraint_p.h:50
KDGantt::Constraint::operator=
Constraint & operator=(const Constraint &other)
Definition: kdganttconstraint.cpp:94
kdganttconstraint.h
KDGantt::Constraint::startIndex
QModelIndex startIndex() const
Definition: kdganttconstraint.cpp:107
KDGantt::Constraint::Private::end
QPersistentModelIndex end
Definition: kdganttconstraint_p.h:49
operator<<
QDebug operator<<(QDebug dbg, const Constraint &c)
Definition: kdganttconstraint.cpp:154
KDGantt::Constraint::Constraint
Constraint(const QModelIndex &idx1, const QModelIndex &idx2, Type type=TypeSoft)
Definition: kdganttconstraint.cpp:73
KDGantt::Constraint::setData
void setData(int role, const QVariant &value)
Definition: kdganttconstraint.cpp:132
d
#define d
Definition: kdganttabstractgrid.cpp:53
KDGantt::Constraint::debug
QDebug debug(QDebug dbg) const
Definition: kdganttconstraint.cpp:159
KDAB_SCOPED_UNITTEST_SIMPLE
KDAB_SCOPED_UNITTEST_SIMPLE(KDGantt, Constraint,"test")
Definition: kdganttconstraint.cpp:173
QSharedData
KDGantt::Constraint
A class used to represent a dependency.
Definition: kdganttconstraint.h:38
KDGantt::Constraint::~Constraint
~Constraint()
Definition: kdganttconstraint.cpp:89
KDGantt::Constraint::Type
Type
Definition: kdganttconstraint.h:41
KDGantt::qHash
uint qHash(const Constraint &c)
Definition: kdganttconstraint.h:81
KDGantt::Constraint::data
QVariant data(int role) const
Definition: kdganttconstraint.cpp:122
KDGantt::Constraint::Private::Private
Private()
Definition: kdganttconstraint.cpp:50
KDGantt::Constraint::Private
Definition: kdganttconstraint_p.h:35
KDGantt::Constraint::operator==
bool operator==(const Constraint &other) const
Definition: kdganttconstraint.cpp:140
kdganttconstraint_p.h
KDGantt::Constraint::hash
uint hash() const
Definition: kdganttconstraint.cpp:147
KDGantt::Constraint::type
Type type() const
Definition: kdganttconstraint.cpp:101
KDGantt::Constraint::TypeSoft
Definition: kdganttconstraint.h:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:05 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdgantt2

Skip menu "kdgantt2"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal