Term.cpp

Go to the documentation of this file.
00001 #include "Term.h"
00002 
00003 Term::Term( int id = 0, int vocabId = 0 ) : id( id ), vocabId( vocabId ), markedForStudy( FALSE ), imagePath( QString::null ) {
00004 }
00005 
00006 Term::Term( const Term& term ) : id( term.id ), vocabId( term.vocabId ), markedForStudy( term.markedForStudy ), imagePath( term.imagePath ) {
00007     for( TranslationMap::ConstIterator it = term.translations.begin(); it != term.translations.end(); it++ ) {
00008         const Translation& trans = it.data();
00009         addTranslation( trans );
00010     }
00011     for( CommentMap::ConstIterator it = term.comments.begin(); it != term.comments.end(); it++ ) {
00012         const BilingualKey& key = it.key();
00013         const QString& comment = it.data();
00014         addComment( key, comment );
00015     }
00016 }
00017 
00018 Term::~Term() {
00019 }
00020 
00021 const int Term::getId() const {
00022     return( id );
00023 }
00024 
00025 const int Term::getVocabId() const {
00026     return( vocabId );
00027 }
00028 
00029 bool Term::isMarkedForStudy() const {
00030     return( markedForStudy );
00031 }
00032 
00033 void Term::setMarkedForStudy( bool isMarkedForStudy ) {
00034     markedForStudy = isMarkedForStudy;
00035 }
00036 
00037 void Term::addTranslation( const Translation& translation ) {
00038     translations.insert( translation.getLanguage(), translation );
00039 }
00040 
00041 void Term::removeTranslation( const QString& language ) {
00042     translations.remove( language );
00043 }
00044 
00045 bool Term::isTranslationExists( const QString& language ) const {
00046     return( translations.contains( language ) );
00047 }
00048 
00049 Translation& Term::getTranslation( const QString& language )  {
00050     return( translations[ language ] );
00051 }
00052 
00053 Translation Term::getTranslation( const QString& language ) const {
00054     return( translations[ language ] );
00055 }
00056 
00057 Term::TranslationMap::ConstIterator Term::translationsBegin() const {
00058     return( translations.begin() );
00059 }
00060 
00061 Term::TranslationMap::ConstIterator Term::translationsEnd() const {
00062     return( translations.end() );
00063 }
00064 
00065 int Term::getTranslationCount() const {
00066     return( translations.count() );
00067 }
00068 
00069 void Term::addComment( const BilingualKey& key, const QString& comment ) {
00070     comments.insert( key, comment );
00071 }
00072 
00073 void Term::removeComment( const BilingualKey& key ) {
00074     comments.remove( key );
00075 }
00076 
00077 void Term::removeComments( const QString& language ) {
00078     for( CommentMap::ConstIterator it = commentsBegin(); it != commentsEnd(); it++ ) {
00079         const BilingualKey& key = it.key();
00080         if( key.contains( language ) )
00081             removeComment( key );
00082     }
00083 }
00084 
00085 bool Term::isCommentExists( const BilingualKey& key ) const {
00086     return( comments.contains( key ) );
00087 }
00088 
00089 QString& Term::getComment( const BilingualKey& key )  {
00090     return( comments[ key ] );
00091 }
00092 
00093 QString Term::getComment( const BilingualKey& key ) const {
00094     return( comments[ key ] );
00095 }
00096 
00097 Term::CommentMap::ConstIterator Term::commentsBegin() const {
00098     return( comments.begin() );
00099 }
00100 
00101 Term::CommentMap::ConstIterator Term::commentsEnd() const {
00102     return( comments.end() );
00103 }
00104 
00105 const QString Term::getImagePath() const {
00106     return( imagePath );
00107 }
00108 
00109 void Term::setImagePath( const QString& imagePath ) {
00110     this->imagePath = imagePath;
00111 }
00112 
00113 QDataStream& operator<<( QDataStream& out, const Term& term ) {
00114     out << term.id << term.vocabId << term.translations << term.comments << term.imagePath;
00115     return( out );
00116 }
00117 
00118 QDataStream& operator>>( QDataStream& in, Term& term ) {
00119     int tempId;
00120     int tempVocabId;
00121     Term::TranslationMap tempTranslations;
00122     Term::CommentMap tempComments;
00123     QString tempImagePath;
00124 
00125     in >> tempId >> tempVocabId >> tempTranslations >> tempComments;
00126     in >> tempImagePath;
00127 
00128     term = Term( tempId, tempVocabId );
00129     for( Term::TranslationMap::ConstIterator it = tempTranslations.begin(); it != tempTranslations.end(); it++ ) {
00130         const Translation& trans = it.data();
00131         term.addTranslation( trans );
00132     }
00133     for( Term::CommentMap::ConstIterator it = tempComments.begin(); it != tempComments.end(); it++ ) {
00134         const BilingualKey& key = it.key();
00135         const QString& comment = it.data();
00136         term.addComment( key, comment );
00137     }
00138     term.setImagePath( tempImagePath );
00139 
00140     return( in );
00141 }
00142 

Generated on Sun Mar 1 17:30:47 2009 for toMOTko by  doxygen 1.5.6