in CommonDictionaryInterface in searchWordList added default limit value
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 6 Aug 2010 12:03:25 +0000 (14:03 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Fri, 6 Aug 2010 12:03:25 +0000 (14:03 +0200)
trunk/src/includes/CommonDictInterface.h
trunk/src/includes/settings.h
trunk/src/plugins/xdxf/src/TranslationXdxf.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/src/xdxfplugin.h
trunk/src/plugins/xdxf/tests/test.cpp
trunk/src/plugins/xdxf/tests/test.h
trunk/tests/mDictionaryTests/mDictionaryTests.pro.user

index d03fbc2..83571e4 100644 (file)
@@ -56,8 +56,7 @@ class CommonDictInterface : public QObject {
     virtual QString infoNote() const = 0;
 
     /*! returns DictDialog object that creates dialogs
-        for adding new dictionary and change plugin settings
-      */
+        for adding new dictionary and change plugin settings*/
     virtual DictDialog* dictDialog() = 0;
 
 
@@ -82,13 +81,13 @@ class CommonDictInterface : public QObject {
  public Q_SLOTS:
     /*! performs search in dictionary
         \param  word word to search in dictionary
-        \param limit limit on number of results
+        \param  limit limit on number of results,
+                if limit=0 all matching words are returned
 
         After finishing search it have to emit
         \see CommonDictInterface:finalTranslation  finalTranslation
-
     */
-    virtual QList<Translation*> searchWordList(QString word, int limit) = 0;
+    virtual QList<Translation*> searchWordList(QString word, int limit=0) = 0;
 
     //! stop current operation
     virtual void stop() = 0;
index 9434fb6..4486492 100644 (file)
@@ -34,8 +34,10 @@ class CommonDictInterface;
 class Settings {
   public:
     Settings(){}
-    //! \retrun value fo given key
-    //! \param key
+
+    /*! \retrun value fo given key
+         \param key
+    */
     QString value(const QString key) const {
         if(!settings.contains(key)) {
             return QString();
index a691d9a..81939d1 100644 (file)
@@ -35,14 +35,15 @@ public:
     //! \return word to be translated
     QString key() const;
 
-    //! \returns dictionary information (plugin name, languages, <logo> etc)\
-    //!    to be displayed in translation table header
+    /*! \returns dictionary information (plugin name, languages, <logo> etc)\
+        to be displayed in translation table header*/
     QString dictionaryInfo() const;
 
     //! \return parsed raw format into html
     QString toHtml() const;
 
-    //! sets the word for which we want to find a translation
+    /*! sets the word for which we want to find a translation
+        \param word for which we want to find a translation */
     void setKey(QString);
 
     //! sets information about dictionary
index 91f24fe..e8c7d77 100644 (file)
@@ -32,14 +32,13 @@ XdxfPlugin::XdxfPlugin(QObject *parent) : CommonDictInterface(parent),
                     _type(tr("xdxf")), _infoNote(tr("")) {
     _settings = new Settings();
     _dictDialog = new XdxfDictDialog(this);
-    _settings->setValue("type","xdxf");
+    _settings->setValue("Type","xdxf");
     if(isCached())
         _settings->setValue("Cached","true");
     else
         _settings->setValue("Cached","false");
     setPath("dict.xdxf");
     stopped = false;
-
 }
 
 QString XdxfPlugin::langFrom() const {   
@@ -133,10 +132,11 @@ QString XdxfPlugin::search(QString key) {
         return "";
     }
     QXmlStreamReader dictionaryReader(&dictionaryFile);
-
     QString a;
+
     bool match =false;
-    while (!dictionaryReader.atEnd()) {
+    stopped = false;
+    while (!dictionaryReader.atEnd()&& !stopped) {
         dictionaryReader.readNext();
         if(dictionaryReader.tokenType() == QXmlStreamReader::StartElement) {
             if(dictionaryReader.name()=="k") {
@@ -145,12 +145,13 @@ QString XdxfPlugin::search(QString key) {
                     match = true;
             }
         }
-        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters)  {
+        else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
             if(match) {
                 QString temp(dictionaryReader.text().toString());
                 temp.replace("\n","");
                 if(temp == ""){
-                    while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()){
+                    while(dictionaryReader.name()!="ar"&&
+                                !dictionaryReader.atEnd()){
                         dictionaryReader.readNext();
                         temp+=dictionaryReader.text().toString();
                     }
@@ -160,6 +161,7 @@ QString XdxfPlugin::search(QString key) {
             }
         }
     }
+    stopped=false;
     dictionaryFile.close();
     return resultString;
 }
index 0786330..4feb602 100644 (file)
@@ -102,7 +102,7 @@ private:
     QDialog *_settingsDialog;
     QString path;
     uint _hash;
-    bool stopped;   /*volatile*/
+    volatile bool stopped;
     Settings *_settings;
     XdxfDictDialog* _dictDialog;
 };
index 8ecf8bc..d8fbded 100644 (file)
@@ -45,7 +45,7 @@ void Testowanie::searchWordList() {
     QList<Translation*> te4=xdxfPlugin.searchWordList("ho*SE",10);
         QCOMPARE(te4.at(0)->key(), QString("house"));
 
-    QList<Translation*> te5=xdxfPlugin.searchWordList("*",0);
+    QList<Translation*> te5=xdxfPlugin.searchWordList("*");
         QCOMPARE(te5.size(),8);
 
     QList<Translation*> te6=xdxfPlugin.searchWordList("*",8);
@@ -62,6 +62,17 @@ void Testowanie::getNew() {
 */
 }
 
+void Testowanie::stop() {
+    /*test for English-Polish dictionary */
+    CommonDictInterface *xdxfPlugin = new XdxfPlugin(this);
+
+    QString string("*");
+    QFuture<QList<Translation*> > future = QtConcurrent::run(xdxfPlugin, &CommonDictInterface::searchWordList, string, 10);
+    QList<Translation*> te5 = future.result();
+
+    QCOMPARE(te5.size(),8);
+}
+
 void Testowanie::langFrom() {
      /*test for English-Polish dictionary */
     XdxfPlugin xdxfPlugin(this);
index 484d6ff..6168be9 100644 (file)
@@ -25,8 +25,9 @@
 #include <QtTest/QtTest>
 #include <QList>
 #include <QTime>
-
-
+#include <QTimer>
+#include <QtConcurrentRun>
+#include <QFuture>
 #include "../src/xdxfplugin.h"
 
  class Testowanie: public QObject
@@ -39,6 +40,7 @@
      void searchWordList();
      void langFrom();
      void getNew();
+     void stop();
  };
 
 
index ef5a8f0..4b79132 100644 (file)
     <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
     <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
     <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Debug</value>
+    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Debug</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/jakub/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">6</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
    </valuemap>
     <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
     <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
     <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt w PATH Release</value>
+    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">3</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/jakub/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
+    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">6</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
     <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
    </valuemap>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.2" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Debug</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <valuemap key="ProjectExplorer.Target.BuildConfiguration.3" type="QVariantMap">
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">QMake</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">QtProjectManager.QMakeBuildStep</value>
-     <valuelist key="QtProjectManager.QMakeBuildStep.QMakeArguments" type="QVariantList"/>
-    </valuemap>
-    <valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.1" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">false</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList"/>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.BuildStepsCount" type="int">2</value>
-    <valuemap key="ProjectExplorer.BuildConfiguration.CleanStep.0" type="QVariantMap">
-     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Make</value>
-     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.MakeStep</value>
-     <value key="Qt4ProjectManager.MakeStep.Clean" type="bool">true</value>
-     <valuelist key="Qt4ProjectManager.MakeStep.MakeArguments" type="QVariantList">
-      <value type="QString">clean</value>
-     </valuelist>
-     <value key="Qt4ProjectManager.MakeStep.MakeCommand" type="QString"></value>
-    </valuemap>
-    <value key="ProjectExplorer.BuildConfiguration.CleanStepsCount" type="int">1</value>
-    <value key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment" type="bool">false</value>
-    <valuelist key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges" type="QVariantList"/>
-    <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Qt 4.6.3 OpenSource Release</value>
-    <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">/home/bulislaw/devel/mdictionary/trunk/tests/mDictionaryTests-build-desktop</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">2</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">0</value>
-    <value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
-   </valuemap>
-   <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">4</value>
+   <value key="ProjectExplorer.Target.BuildConfigurationCount" type="int">2</value>
    <valuemap key="ProjectExplorer.Target.RunConfiguration.0" type="QVariantMap">
     <value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">mDictionaryTests</value>
     <value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4RunConfiguration</value>