Beispiel #1
0
bool KEduVocCsvReader::readDoc( KEduVocDocument *doc )
{
    m_doc = doc;

    QString separator = m_doc->csvDelimiter();

    QTextStream inputStream( m_inputFile );
    inputStream.setCodec( "UTF-8" );
    inputStream.setAutoDetectUnicode( true );
    inputStream.seek( 0 );

    int languageCount = 0;

    KEduVocLesson* lesson = new KEduVocLesson( i18n("Vocabulary"), m_doc->lesson());
    m_doc->lesson()->appendChildContainer(lesson);

    while ( !inputStream.atEnd() ) {
        QString s = inputStream.readLine();

        if ( !s.simplified().isEmpty() ) {
            KEduVocExpression* expression = new KEduVocExpression( s.split(separator) );
            languageCount = qMax( languageCount,
                expression->translationIndices().count() );
            lesson->appendEntry( expression );
        }
    }

    for ( int j = 0; j < languageCount; j++ )
    {
        m_doc->appendIdentifier();
    }

    return true;
}
Beispiel #2
0
 bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const
   {
     return
       !dir
       ? (QString::compare(x.getOriginal().upper(),
                           y.getOriginal().upper() ) < 0)
       : (QString::compare(x.getOriginal().upper(),
                           y.getOriginal().upper() ) > 0);
   }
Beispiel #3
0
 bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const
   {
     return
       !dir
       ? (QString::compare(x.getTranslation(index).upper(),
                           y.getTranslation(index).upper() ) < 0)
       : (QString::compare(x.getTranslation(index).upper(),
                           y.getTranslation(index).upper() ) > 0);
   }
Beispiel #4
0
void FromToEntryPage::setData(const QList<int>& entries)
{
    m_entries = entries;

    // only set Grades as title for now:
    direc_label->setTitle(QString(i18n("Confidence Levels from %1 to %2", m_doc->identifier(m_translationFrom).name(), m_doc->identifier(m_translationTo).name())));

    KEduVocExpression *firstEntry = m_doc->entry(m_entries.value(0));

    queryDateEdit->setDateTime(
        firstEntry->translation(m_translationTo)
        .gradeFrom(m_translationFrom).practiceDate());

    gradebox->setCurrentIndex(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).grade());

    totalCountEdit->setValue(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).practiceCount());

    badCountEdit->setValue(firstEntry->translation(m_translationTo).gradeFrom(m_translationFrom).badCount());

    if (m_entries.count() > 1) {
        // fill enabled fields if equal for all edited entries, otherwise empty.
        foreach(int entry, m_entries) {
            // grade
            KEduVocExpression *currentEntry = m_doc->entry(entry);
            if (firstEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).grade()
                    != currentEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).grade()) {
                gradebox->setCurrentIndex(-1);
            }
            // date
            if (firstEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).practiceDate()
                    != currentEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).practiceDate()) {
                queryDateEdit->setDate(queryDateEdit->minimumDate());
                queryDateEdit->setTime(queryDateEdit->minimumTime());
            }

            // total count
            if (firstEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).practiceCount()
                    != currentEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).practiceCount()) {
                totalCountEdit->clear();
            }

            // wrong count
            if (firstEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).badCount()
                    != currentEntry->translation(m_translationTo)
                    .gradeFrom(m_translationFrom).badCount()) {
                badCountEdit->clear();
            }

        }
Beispiel #5
0
 void operator() (KEduVocExpression& x)
   {
      for (int i = 0; i <= x.numTranslations(); i++) {
        if (lesson == 0 || lesson == x.getLesson() ) {
           x.setGrade(i, KV_NORM_GRADE, false);
           x.setGrade(i, KV_NORM_GRADE, true);
           x.setQueryCount (i, 0, true);
           x.setQueryCount (i, 0, false);
           x.setBadCount (i, 0, true);
           x.setBadCount (i, 0, false);
           x.setQueryDate (i, 0, true);
           x.setQueryDate (i, 0, false);
        }
      }
   }
Beispiel #6
0
 bool operator() (const KEduVocExpression& x, const KEduVocExpression& y) const
   {
     if (x.getLesson() != y.getLesson() )
       return
         !dir
         ? x.getLesson() < y.getLesson()
         : y.getLesson() < x.getLesson();
     else
       return
         !dir
         ? (QString::compare(x.getOriginal().upper(),
                             y.getOriginal().upper() ) < 0)
         : (QString::compare(x.getOriginal().upper(),
                             y.getOriginal().upper() ) > 0);
   }
void KEduVocDocumentValidatorTest::testWordTypes()
{
    KEduVocDocument doc;
    // create doc - has no word types yet
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 0);

    KEduVocWordType *noun;
    KEduVocWordType *nounMale;
    KEduVocWordType *nounFemale;
    KEduVocWordType *verb;

    noun = new KEduVocWordType("Noun", doc.wordTypeContainer());
    doc.wordTypeContainer()->appendChildContainer(noun);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 1);
    nounMale = new KEduVocWordType("Male", noun);
    noun->appendChildContainer(nounMale);
    nounFemale = new KEduVocWordType("Female", noun);
    noun->appendChildContainer(nounFemale);
    verb = new KEduVocWordType("Verb", doc.wordTypeContainer());
    doc.wordTypeContainer()->appendChildContainer(verb);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 2);
    QCOMPARE(doc.wordTypeContainer()->childContainer(0)->childContainerCount(), 2);

    // create some entries
    for(int i = 0; i < 20; i++) {
        KEduVocExpression *e =
            new KEduVocExpression(QStringList() << QString("lang1 %1").arg(i) << QString("lang2 %1").arg(i));
        doc.lesson()->appendEntry(e);
        e->translation(0)->setWordType(noun);
        e->translation(1)->setWordType(noun);
    }
    QCOMPARE(doc.lesson()->entryCount(), 20);
    QCOMPARE(noun->entryCount(), 20);
    doc.lesson()->entry(0)->translation(0)->setWordType(verb);
    // translation 1 is still noun, so it needs to be in both now
    QCOMPARE(noun->entryCount(), 20);
    QCOMPARE(verb->entryCount(), 1);
    doc.lesson()->entry(0)->translation(1)->setWordType(verb);
    QCOMPARE(noun->entryCount(), 19);
    QCOMPARE(verb->entryCount(), 1);

    // delete word type
    doc.wordTypeContainer()->deleteChildContainer(1);
    // the word type is set to 0 when removed
    QVERIFY(doc.lesson()->entry(0)->translation(0)->wordType() == 0);
    QVERIFY(doc.lesson()->entry(0)->translation(1)->wordType() == 0);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 1);
}
Beispiel #8
0
 void operator() (KEduVocExpression& x)
   {
      if (lesson == 0 || lesson == x.getLesson() ) {
        x.setGrade(index, KV_NORM_GRADE, false);
        x.setGrade(index, KV_NORM_GRADE, true);
        x.setQueryCount (index, 0, true);
        x.setQueryCount (index, 0, false);
        x.setBadCount (index, 0, true);
        x.setBadCount (index, 0, false);
        x.setQueryDate (index, 0, true);
        x.setQueryDate (index, 0, false);
      }
   }
Beispiel #9
0
bool KWQTableModel::removeRows(int row, int count, const QModelIndex & parent)
{
  Q_UNUSED(parent);
  if (count < 1 || row < 0 || row + count > m_doc->lesson()->entryCount(KEduVocLesson::Recursive) || count >= m_doc->lesson()->entryCount(KEduVocLesson::Recursive))
    return false;

  int bottomRow = row + count -1;
  beginRemoveRows(QModelIndex(), row, row + count - 1);

  for (int i = bottomRow; i >= row; i--) {
    KEduVocExpression* entry = m_doc->lesson()->entries(KEduVocLesson::Recursive).value(i);
    entry->lesson()->removeEntry(entry);
    delete entry;
  }

  endRemoveRows();
  m_doc->setModified(true);
  return true;
}
Beispiel #10
0
 void operator() (KEduVocExpression& x) const
   {
     x.removeTranslation(index);
   }