libkdeedu/keduvocdocument
keduvoclesson.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 manage lessons 00003 ----------------------------------------------------------------------- 00004 00005 begin : August 11, 2007 00006 00007 copyright : (C) 2007 Jeremy Whiting <jeremywhiting@scitools.com> 00008 00009 ----------------------------------------------------------------------- 00010 ***************************************************************************/ 00011 00012 /*************************************************************************** 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 00018 * * 00019 ***************************************************************************/ 00020 00021 #include "keduvoclesson.h" 00022 00023 #include <QSet> 00024 00026 class KEduVocLesson::Private 00027 { 00028 public: 00029 QSet<int> m_entries; 00030 QString m_name; 00031 bool m_inPractice; 00032 }; 00033 00034 KEduVocLesson::KEduVocLesson() 00035 : d( new Private ) 00036 {} 00037 00038 KEduVocLesson::KEduVocLesson( const KEduVocLesson &other ) 00039 : d( new Private ) 00040 { 00041 d->m_entries = other.d->m_entries; 00042 d->m_name = other.d->m_name; 00043 d->m_inPractice = other.d->m_inPractice; 00044 } 00045 00046 KEduVocLesson::~KEduVocLesson() 00047 { 00048 delete d; 00049 } 00050 00051 KEduVocLesson& KEduVocLesson::operator= ( const KEduVocLesson &other ) 00052 { 00053 d->m_entries = other.d->m_entries; 00054 d->m_name = other.d->m_name; 00055 d->m_inPractice = other.d->m_inPractice; 00056 return *this; 00057 } 00058 00059 bool KEduVocLesson::operator==(const KEduVocLesson &other) 00060 { 00061 return d->m_entries == other.d->m_entries && 00062 d->m_name == other.d->m_name && 00063 d->m_inPractice == other.d->m_inPractice;; 00064 } 00065 00066 void KEduVocLesson::setName( const QString &name ) 00067 { 00068 d->m_name = name; 00069 } 00070 00071 QString KEduVocLesson::name() 00072 { 00073 return d->m_name; 00074 } 00075 00076 QList<int> KEduVocLesson::entries() 00077 { 00078 return d->m_entries.toList(); 00079 } 00080 00081 int KEduVocLesson::entryCount() 00082 { 00083 return d->m_entries.count(); 00084 } 00085 00086 void KEduVocLesson::addEntry( int entryid ) 00087 { 00088 d->m_entries.insert( entryid ); 00089 } 00090 00091 void KEduVocLesson::removeEntry( int entryid ) 00092 { 00093 d->m_entries.remove( entryid ); 00094 } 00095 00096 void KEduVocLesson::incrementEntriesAbove( int entryid ) 00097 { 00098 QList<int> entries = d->m_entries.toList(); 00099 00100 // increment all entry id's above entryid 00101 for (int i = 0; i < entries.size(); ++i) { 00102 if (entries[i] >= entryid) { 00103 entries[i] = entries[i] + 1; 00104 } 00105 } 00106 00107 // then put the new list into the set 00108 d->m_entries = entries.toSet(); 00109 } 00110 00111 void KEduVocLesson::decrementEntriesAbove( int entryid ) 00112 { 00113 QList<int> entries = d->m_entries.toList(); 00114 00115 // increment all entry id's above entryid 00116 int i = 0; 00117 while (i < entries.size()) { 00118 if (entries[i] == entryid) { 00119 entries.removeAt(i); 00120 } 00121 else if (entries[i] > entryid) { 00122 entries[i] = entries[i] - 1; 00123 ++i; 00124 } 00125 else { 00126 ++i; 00127 } 00128 } 00129 00130 // then put the new list into the set 00131 d->m_entries = entries.toSet(); 00132 } 00133 00134 bool KEduVocLesson::inPractice() 00135 { 00136 return d->m_inPractice; 00137 } 00138 00139 void KEduVocLesson::setInPractice(bool inPractice) 00140 { 00141 d->m_inPractice = inPractice; 00142 }
KDE 4.0 API Reference