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

kdgantt

kdganttconstraint.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2001-2006 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Gantt library.
00005  **
00006  ** This file may be used under the terms of the GNU General Public
00007  ** License versions 2.0 or 3.0 as published by the Free Software
00008  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00009  ** included in the packaging of this file.  Alternatively you may (at
00010  ** your option) use any later version of the GNU General Public
00011  ** License if such license has been publicly approved by
00012  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00013  ** 
00014  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00015  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00016  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00017  ** not expressly granted herein.
00018  ** 
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  **********************************************************************/
00023 #include "kdganttconstraint.h"
00024 #include "kdganttconstraint_p.h"
00025 
00026 #include <QDateTime>
00027 
00028 using namespace KDGantt;
00029 
00048 Constraint::Private::Private()
00049     : type( TypeSoft ),
00050       relationType( FinishStart )
00051 {
00052 }
00053 
00054 Constraint::Private::Private( const Private& other )
00055     : QSharedData( other )
00056 {
00057     start=other.start;
00058     end=other.end;
00059     type=other.type;
00060     relationType=other.relationType;
00061 }
00062 
00076 Constraint::Constraint( const QModelIndex& idx1,  const QModelIndex& idx2, Constraint::Type type, Constraint::RelationType relationType )
00077     : d( new Private )
00078 {
00079     d->start=idx1;
00080     d->end=idx2;
00081     d->type=type;
00082     d->relationType=relationType;
00083     Q_ASSERT_X( idx1 != idx2 || !idx1.isValid(), "Constraint::Constraint", "cannot create a constraint with idx1 == idx2" );
00084     //qDebug()<<"Constraint::Constraint"<<*this;
00085 }
00086 
00088 Constraint::Constraint( const Constraint& other )
00089     : d( other.d )
00090 {
00091     //qDebug()<<"Constraint::Constraint"<<*this<<other;
00092 }
00093 
00095 Constraint::~Constraint()
00096 {
00097 }
00098 
00100 Constraint& Constraint::operator=( const Constraint& other )
00101 {
00102     d = other.d;
00103     return *this;
00104 }
00105 
00107 Constraint::Type Constraint::type() const
00108 {
00109     return d->type;
00110 }
00111 
00113 Constraint::RelationType Constraint::relationType() const
00114 {
00115     return d->relationType;
00116 }
00117 
00119 QModelIndex Constraint::startIndex() const
00120 {
00121     return d->start;
00122 }
00123 
00125 QModelIndex Constraint::endIndex() const
00126 {
00127     return d->end;
00128 }
00129 
00134 QVariant Constraint::data( int role ) const
00135 {
00136     return d->data.value( role );
00137 }
00138 
00144 void Constraint::setData( int role, const QVariant& value )
00145 {
00146     d->data.insert( role, value );
00147 }
00148 
00152 bool Constraint::operator==( const Constraint& other ) const
00153 {
00154     if ( d == other.d ) return true;
00155     return ( *d ).equals( *( other.d ) );
00156 }
00157 
00159 uint Constraint::hash() const
00160 {
00161     return ::qHash( d->start ) ^ ::qHash( d->end ) ^ ::qHash( static_cast<uint>( d->type ) );
00162 }
00163 
00164 #ifndef QT_NO_DEBUG_STREAM
00165 
00166 QDebug operator<<( QDebug dbg, const Constraint& c )
00167 {
00168     return c.debug( dbg );
00169 }
00170 
00171 QDebug Constraint::debug( QDebug dbg ) const
00172 {
00173     dbg << "KDGantt::Constraint[ start=" << d->start << "end=" << d->end << "relationType=" << d->relationType << "]";
00174     return dbg;
00175 }
00176 
00177 #endif /* QT_NO_DEBUG_STREAM */
00178 
00179 #ifndef KDAB_NO_UNIT_TESTS
00180 
00181 #include <QStandardItemModel>
00182 
00183 #include "unittest/test.h"
00184 
00185 KDAB_SCOPED_UNITTEST_SIMPLE( KDGantt, Constraint, "test" )
00186 {
00187     QStandardItemModel dummyModel( 100, 100 );
00188     QModelIndex idx1 = dummyModel.index( 7, 17, QModelIndex() );
00189     QModelIndex idx2 = dummyModel.index( 42, 17, QModelIndex() );
00190 
00191     Constraint c1 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
00192     Constraint c2 = Constraint( QModelIndex(), QModelIndex(), Constraint::TypeSoft );
00193     Constraint c3 = c2;
00194     Constraint c4( idx1, idx2 );
00195     Constraint c5( idx2, idx1 );
00196 
00197     assertTrue( c1==c2 );
00198     assertEqual( qHash( c1 ), qHash( c2 ) );
00199     assertTrue( c1==c3 );
00200     assertEqual( qHash( c1 ), qHash( c3 ) );
00201     assertTrue( c2==c3 );
00202     assertEqual( qHash( c2 ), qHash( c3 ) );
00203 
00204     assertFalse( c2==c4 );
00205     assertNotEqual( qHash( c2 ), qHash( c4 ) );
00206 
00207     assertFalse( c4==c5 );
00208 
00209     assertEqual( c3.type(), Constraint::TypeSoft );
00210 
00211     dummyModel.removeRow( 8 );
00212     assertFalse( c4==c5 );
00213 }
00214 
00215 #endif /* KDAB_NO_UNIT_TESTS */

kdgantt

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal