"convert list<Translation*> to set<Translation*> in XdxfPlugin"
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 5 Aug 2010 11:43:02 +0000 (13:43 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Thu, 5 Aug 2010 11:43:02 +0000 (13:43 +0200)
trunk/src/plugins/xdxf/src/XdxfPlugin/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp

index 466b7a6..15c509e 100644 (file)
@@ -34,16 +34,20 @@ QString XdxfPlugin::infoNote() const {
 
 QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     stopped = false;
+    if(word.indexOf("*")==-1)
+        word+="*";
     QRegExp regWord(word);
     regWord.setCaseSensitivity(Qt::CaseInsensitive);
     regWord.setPatternSyntax(QRegExp::Wildcard);
 
-    QList<Translation*> translations;
+    QSet<Translation*> translations;
     QFile dictionaryFile(path);
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
-        return translations;
+        return translations.toList();
     }
+
+    /*read information about dictionary*/
     QXmlStreamReader dictionaryReader(&dictionaryFile);
     dictionaryReader.readNextStartElement();
     if(dictionaryReader.name()=="xdxf") {
@@ -58,6 +62,8 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     dictionaryReader.readNextStartElement();
     if(dictionaryReader.name()=="description")
         _infoNote=dictionaryReader.readElementText();
+
+    /*search word list*/
     QString a;
     int i=0;
     while(!dictionaryReader.atEnd() && !stopped){
@@ -67,7 +73,7 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
                 dictionaryReader.readNextStartElement();
            a = dictionaryReader.readElementText();
            if(regWord.exactMatch(a) && i<limit) {
-                translations.append(new TranslationXdxf(a,_infoNote,this));
+                translations<<(new TranslationXdxf(a,_infoNote,this));
                 i++;
                 if(i>=limit)
                     break;
@@ -76,11 +82,12 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     }
     stopped=false;
     dictionaryFile.close();
-    return translations;
+    return translations.toList();
 }
 
 QString XdxfPlugin::search(QString key) {
     QFile dictionaryFile(path);
+    QString resultString("");
     if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
         qDebug()<<"Error: could not open file";
         return "";
@@ -100,13 +107,21 @@ QString XdxfPlugin::search(QString key) {
         }
         else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
             if(match) {
-              QString temp(dictionaryReader.text().toString().replace("\n",""));
-              dictionaryFile.close();
-              return temp;
+                QString temp(dictionaryReader.text().toString().replace("\n",""));
+                qDebug()<<temp;
+                if(temp == ""){
+                    while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()){
+                        dictionaryReader.readNext();
+                        temp+=dictionaryReader.text().toString();
+                    }
+                }
+                dictionaryFile.close();
+                resultString+=temp.replace("\n","")+"\n";
+                match=false;
             }
         }
     }
-    return "";
+    return resultString;
 }
 
 void XdxfPlugin::stop() {
index 4bba1f5..7ce6f4e 100644 (file)
@@ -5,8 +5,8 @@ void Testowanie::search()
 {
     XdxfPlugin xdxfPlugin(this);
     xdxfPlugin.loadDialog();
-    xdxfPlugin.searchWordList("Cain",10);
-    xdxfPlugin.search("Cain");
+    xdxfPlugin.searchWordList("wino",10);
+    xdxfPlugin.search("wino");
     QCOMPARE(xdxfPlugin.search("Apacz"), QString("Apachee"));
  //   QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
  //   QCOMPARE(xdxfPlugin.search("boss"), QString(""));