void QuizFrame::editCurrentTerm() { if( controller->isQuizInProgress() ) { Folder* vocabTree = controller->getVocabTree(); Term* term = controller->getCurrentTerm(); if( !term ) { QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) ); return; } Vocabulary* vocab = vocabTree->getVocabulary( term->getVocabId() ); if( vocab == NULL || !vocab->isTermExists( term->getId() ) ) { QMessageBox::warning( this, QObject::tr( "Information" ), tr( "DissociatedWord" ) ); return; } TermDialog dialog( *vocab, controller, this, *term ); int result = dialog.exec(); if( result ) { QString firstLang( controller->getQuizFirstLanguage() ); QString testLang( controller->getQuizTestLanguage() ); Term newTerm = dialog.getTerm(); Translation firstLangTrans = newTerm.getTranslation( firstLang ); Translation testLangTrans = newTerm.getTranslation( testLang ); term->addTranslation( firstLangTrans ); term->addTranslation( testLangTrans ); BilingualKey commentKey( firstLang, testLang ); term->addComment( commentKey, newTerm.getComment( commentKey ) ); term->setImagePath( newTerm.getImagePath() ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); setTerm( newTerm ); } } }
void SearchDialog::goResultVocab() { ResultListItem* currItem = (ResultListItem*)resultsListView->currentItem(); if( currItem ) { Term* term = currItem->getTerm(); if( term ) { emit showTermRequested( TermKey( term->getId(), term->getVocabId() ) ); close(); } } }
//replaces all the constants in the clause by a new variable. Also, returns an //array of terms persent in the original clause (first the variable ids and //then the constant ids) Array<int> * Clause::updateToVarClause() { Array<int> * termIds = new Array<int>(); //dummy values at position 0 - varIds start from 1 termIds->append(0); const Predicate *pred; //first populate the variable ids to get a count for (int i = 0; i < predicates_->size(); i++) { pred = (*predicates_)[i]; for (int j = 0; j < pred->getNumTerms(); j++) { const Term* t = pred->getTerm(j); if (t->getType() == Term::VARIABLE) { int id = t->getId(); assert(id < 0); termIds->growToSize(-id+1); (*termIds)[-id] = id; } } } //now, convert all constants to variables while storing //their ids (constant values) for (int i = 0; i < predicates_->size(); i++) { pred = (*predicates_)[i]; for (int j = 0; j < pred->getNumTerms(); j++) { Term* t = (Term *) pred->getTerm(j); //if its a variable - do not need to do anything if (t->getType() == Term::VARIABLE) continue; int constantId = t->getId(); assert(constantId >= 0); termIds->append(constantId); //now convert this term to a new variable int varId = termIds->size()-1; t->setId(-varId); } } return termIds; }
void Domain::changePredTermsToNewIds(Predicate* const & p, hash_map<int,int>& oldToNewConstIds) { // p could be NULL if (p) { for (int j = 0; j < p->getNumTerms(); j++) { Term* t = (Term*) p->getTerm(j); if (t->getType() == Term::CONSTANT) { int oldId = t->getId(); assert(oldToNewConstIds.find(oldId) != oldToNewConstIds.end()); t->setId(oldToNewConstIds[oldId]); } } } }
void SearchDialog::doRemoveTerms( bool allowSelectTrans /* = true */, bool confirmBeforeRemove /* = true */ ) { int selectedItemCount = 0; // Find all the translation languages of the selected terms. QStringList translationLanguages; for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { selectedItemCount++; Term* term = termItem->getTerm(); for( Term::TranslationMap::ConstIterator it = term->translationsBegin(); it != term->translationsEnd(); it++ ) { const Translation& trans = *it; if( !translationLanguages.contains( trans.getLanguage() ) ) translationLanguages.append( trans.getLanguage() ); } } } if( selectedItemCount == 0 ) return; if( translationLanguages.count() <= 2 ) { int response; if( confirmBeforeRemove ) { QMessageBox msgBox( QObject::tr( "Warning" ), tr( "ConfirmRemoveSelectedTerms" ), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this ); msgBox.setButtonText( QMessageBox::Yes, tr( "Yes" ) ); msgBox.setButtonText( QMessageBox::No, tr( "No" ) ); response = msgBox.exec(); } else response = QMessageBox::Yes; if( response == QMessageBox::Yes ) { for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { Term* term = termItem->getTerm(); Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() ); if( !term->getImagePath().isNull() ) { QDir imagePath( term->getImagePath() ); if( imagePath.isRelative() ) { const QString& imagePath = controller->getApplicationDirName() + "/" + vocab->getParent()->getPath() + "/v-" + QString::number( vocab->getId() ) + "/" + term->getImagePath(); QFile imageFile( imagePath ); if( imageFile.exists() ) { if( !imageFile.remove() ) cerr << "Could not remove image " << qPrintable( imagePath ) << endl; } } } vocab->removeTerm( term->getId() ); delete( termItem ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); } } resultsListView->clearSelection(); updateUi(); emit termsRemoved(); } } else { int response; QStringList selectedLanguages; if( allowSelectTrans ) { TranslationSelectionDialog msgBox( tr( "MultipleTranslationsDetectedForRemoveTermsCaption" ), tr( "MultipleTranslationsDetectedForRemoveTerms" ), translationLanguages, TranslationSelectionDialog::selectionModeTargetLanguage, controller, this ); msgBox.setMaximumHeight( size().height() - 40 ); msgBox.setMaximumWidth( size().width() - 40 ); response = msgBox.exec(); if( response ) selectedLanguages = msgBox.getSelectedLanguages(); } else { selectedLanguages = QStringList(); selectedLanguages.append( controller->getPreferences().getFirstLanguage() ); selectedLanguages.append( controller->getPreferences().getTestLanguage() ); } if( selectedLanguages.count() == 0 ) return; for( int i = 0; i < resultsListView->topLevelItemCount(); i++ ) { ResultListItem* termItem = (ResultListItem*)resultsListView->topLevelItem( i ); if( termItem->isSelected() ) { Term* term = termItem->getTerm(); Vocabulary* vocab = controller->getVocabTree()->getVocabulary( term->getVocabId() ); for( QStringList::ConstIterator it = selectedLanguages.begin(); it != selectedLanguages.end(); it++ ) { QString lang = *it; term->removeTranslation( lang ); } if( term->getTranslationCount() == 0 ) { if( !term->getImagePath().isNull() ) { QDir imagePath( term->getImagePath() ); if( imagePath.isRelative() ) { const QString& imagePath = controller->getApplicationDirName() + "/" + vocab->getParent()->getPath() + "/v-" + QString::number( vocab->getId() ) + "/" + term->getImagePath(); QFile imageFile( imagePath ); if( imageFile.exists() ) { if( !imageFile.remove() ) cerr << "Could not remove image " << qPrintable( imagePath ) << endl; } } } vocab->removeTerm( term->getId() ); delete( termItem ); vocab->setModificationDate( QDateTime::currentDateTime() ); vocab->setDirty( true ); } } } resultsListView->clearSelection(); updateUi(); } }
void Vocabulary::addTerm( const Term& term ) { terms.insert( term.getId(), term ); }