[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/soc-parley/parley/src/vocabulary
From:       Avgoustinos Kadis <avgoustinos.kadis () kdemail ! net>
Date:       2008-07-16 8:31:21
Message-ID: 1216197081.783626.25866.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 833116 by kadis:

Shows combobox only when there is a suggestion and it's not the same as 
the word.



 M  +52 -37    vocabularydelegate.cpp  
 M  +5 -0      vocabularydelegate.h  


--- branches/work/soc-parley/parley/src/vocabulary/vocabularydelegate.cpp \
#833115:833116 @@ -40,6 +40,33 @@
     m_translator = 0;
 }
 
+QSet<QString> VocabularyDelegate::getTranslations(const QModelIndex & index) const
+{
+    QSet<QString> translations; //translations of this column from all the other \
languages +            
+    int language = index.column() / VocabularyModel::EntryColumnsMAX;
+    QString toLanguage = m_doc->identifier(language).locale();
+
+    //iterate through all the Translation columns
+    for (int i = 0; i < index.model()->columnCount(index.parent()); i ++) {
+        if (VocabularyModel::columnType(i) == VocabularyModel::Translation) \
//translation column +        {
+            QString fromLanguage = \
m_doc->identifier(VocabularyModel::translation(i)).locale(); +            QString \
word = index.model()->index(index.row(),i,QModelIndex()).data().toString(); +
+            if (fromLanguage != toLanguage) {
+                kDebug() << fromLanguage << toLanguage << word;
+                //get the word translations and add them to the translations set
+                QSet<QString> * tr = \
m_translator->getTranslation(word,fromLanguage,toLanguage); +                if (tr)
+                    translations.unite(*(tr));
+            }
+        }
+    }
+
+    return translations;
+}
+
 QWidget * VocabularyDelegate::createEditor(QWidget * parent, const \
QStyleOptionViewItem & option, const QModelIndex & index) const  {
     Q_UNUSED(option); /// as long as it's unused
@@ -78,41 +105,23 @@
         if (VocabularyModel::columnType( index.column() ) == \
VocabularyModel::Translation) {  
             //get the translations of this word
-            
-            QSet<QString> translations; //translations of this column from all the \
                other languages
-            
-            int language = index.column() / VocabularyModel::EntryColumnsMAX;
-            QString toLanguage = m_doc->identifier(language).locale();
+            QSet<QString> translations = getTranslations(index);
 
-            //iterate through all the Translation columns
-            for (int i = 0; i < index.model()->columnCount(index.parent()); i ++) {
-                if (VocabularyModel::columnType(i) == VocabularyModel::Translation) \
                //translation column
-                {
-                    QString fromLanguage = \
                m_doc->identifier(VocabularyModel::translation(i)).locale();
-                    QString word = \
index.model()->index(index.row(),i,QModelIndex()).data().toString(); +            \
//create combo box +            //if there is only one word and that is the \
suggestion word (in translations) then don't create the combobox +            if \
(!translations.isEmpty() && !(translations.size() == 1 && (*translations.begin()) == \
index.model()->data(index, Qt::DisplayRole).toString())) {  
-                    if (fromLanguage != toLanguage) {
-                        kDebug() << fromLanguage << toLanguage << word;
-                        //get the word translations and add them to the translations \
                set
-                        QSet<QString> * tr = \
                m_translator->getTranslation(word,fromLanguage,toLanguage);
-                        if (tr)
-                            translations.unite(*(tr));
-                    }
-                }
-            }
+                QComboBox *translationCombo = new QComboBox(parent);
+                translationCombo->setFrame(false);
 
-            //create combo box
-            QComboBox *translationCombo = new QComboBox(parent);
-            translationCombo->setFrame(false);
-    
-            if (!translations.isEmpty())
                 translationCombo->addItems(translations.toList());
 
-            translationCombo->setEditable(true);
-            translationCombo->setFont(index.model()->data(index, \
                Qt::FontRole).value<QFont>());
-            translationCombo->setEditText(index.model()->data(index, \
                Qt::DisplayRole).toString());
-    
-            return translationCombo;
+                translationCombo->setEditable(true);
+                translationCombo->setFont(index.model()->data(index, \
Qt::FontRole).value<QFont>()); +                \
translationCombo->setEditText(index.model()->data(index, \
Qt::DisplayRole).toString()); +
+                return translationCombo;
+            }
         }
     }
 
@@ -162,10 +171,13 @@
     switch (VocabularyModel::columnType(index.column())) {
     case (VocabularyModel::Translation): {
         if (VocabularyModel::columnType( index.column() ) == \
                VocabularyModel::Translation) {
-            QString value = index.model()->data(index, Qt::DisplayRole).toString();
-            QComboBox * translationCombo = qobject_cast<QComboBox*>(editor);
-            translationCombo->setEditText(value);
-            break;
+            QSet<QString> translations = getTranslations(index);
+            if (!translations.isEmpty() && !(translations.size() == 1 && \
(*translations.begin()) == index.model()->data(index, Qt::DisplayRole).toString())) { \
+                QString value = index.model()->data(index, \
Qt::DisplayRole).toString(); +                QComboBox * translationCombo = \
qobject_cast<QComboBox*>(editor); +                \
translationCombo->setEditText(value); +                break;
+            }
         }
     }
     default: {
@@ -215,9 +227,12 @@
     }
     case (VocabularyModel::Translation): {
         if (VocabularyModel::columnType( index.column() ) == \
                VocabularyModel::Translation) {
-            QComboBox * translationCombo = qobject_cast<QComboBox*>(editor);
-            model->setData(index,translationCombo->currentText());
-            break;
+            QSet<QString> translations = getTranslations(index);
+            if (!translations.isEmpty() && !(translations.size() == 1 && \
(*translations.begin()) == index.model()->data(index, Qt::DisplayRole).toString())) { \
+                QComboBox * translationCombo = qobject_cast<QComboBox*>(editor); +   \
model->setData(index,translationCombo->currentText()); +                break;
+            }
         }
     }
     default: {
--- branches/work/soc-parley/parley/src/vocabulary/vocabularydelegate.h \
#833115:833116 @@ -38,6 +38,8 @@
     void setCurrentIndex(const QModelIndex &index);
     void setTranslator(Translator * translator);
 
+    
+
 public slots:
     void setDocument(KEduVocDocument *doc);
 
@@ -48,10 +50,13 @@
     void commitAndCloseEditor();
 
 private:
+    
     QModelIndex m_currentIndex;
     KEduVocDocument *m_doc;
     Translator * m_translator;
 
+    QSet<QString> getTranslations(const QModelIndex & index) const;
+
     // for the word type combo
     class WordTypeBasicModel;
 };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic