fix search occasionally skipping messages
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>
Mon, 19 Aug 2013 11:04:48 +0000 (13:04 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 27 Aug 2013 11:41:48 +0000 (13:41 +0200)
the bizarre persistence of m_foundWhere would make us skip a hit in a
directly subsequent message if the match was in a field that is searched
before the field the last hit was in.

Task-number: QTBUG-32196
Change-Id: I5007d435cfc3a96bb2b61875a5fc40ac6a23c548
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
src/linguist/linguist/mainwindow.cpp
src/linguist/linguist/mainwindow.h

index a2aac7e..79abaa4 100644 (file)
@@ -268,7 +268,6 @@ MainWindow::MainWindow()
       m_findMatchCase(Qt::CaseInsensitive),
       m_findIgnoreAccelerators(true),
       m_findWhere(DataModel::NoLocation),
-      m_foundWhere(DataModel::NoLocation),
       m_translationSettingsDialog(0),
       m_settingCurrentMessage(false),
       m_fileActiveModel(-1),
@@ -964,9 +963,9 @@ void MainWindow::print()
     }
 }
 
-bool MainWindow::searchItem(const QString &searchWhat)
+bool MainWindow::searchItem(DataModel::FindLocation where, const QString &searchWhat)
 {
-    if ((m_findWhere & m_foundWhere) == 0)
+    if ((m_findWhere & where) == 0)
         return false;
 
     QString text = searchWhat;
@@ -993,41 +992,31 @@ void MainWindow::findAgain()
         bool hadMessage = false;
         for (int i = 0; i < m_dataModel->modelCount(); ++i) {
             if (MessageItem *m = m_dataModel->messageItem(dataIndex, i)) {
+                bool found = true;
                 // Note: we do not look into plurals on grounds of them not
                 // containing anything much different from the singular.
                 if (hadMessage) {
-                    m_foundWhere = DataModel::Translations;
-                    if (!searchItem(m->translation()))
-                        m_foundWhere = DataModel::NoLocation;
+                    if (!searchItem(DataModel::Translations, m->translation()))
+                        found = false;
                 } else {
-                    switch (m_foundWhere) {
-                    case 0:
-                        m_foundWhere = DataModel::SourceText;
-                        // fall-through to search source text
-                    case DataModel::SourceText:
-                        if (searchItem(m->text()))
+                    do {
+                        if (searchItem(DataModel::SourceText, m->text()))
                             break;
-                        if (searchItem(m->pluralText()))
+                        if (searchItem(DataModel::SourceText, m->pluralText()))
                             break;
-                        m_foundWhere = DataModel::Translations;
-                        // fall-through to search translation
-                    case DataModel::Translations:
-                        if (searchItem(m->translation()))
+                        if (searchItem(DataModel::Translations, m->translation()))
                             break;
-                        m_foundWhere = DataModel::Comments;
-                        // fall-through to search comment
-                    case DataModel::Comments:
-                        if (searchItem(m->comment()))
+                        if (searchItem(DataModel::Comments, m->comment()))
                             break;
-                        if (searchItem(m->extraComment()))
+                        if (searchItem(DataModel::Comments, m->extraComment()))
                             break;
-                        if (searchItem(m->translatorComment()))
+                        if (searchItem(DataModel::Comments, m->translatorComment()))
                             break;
-                        m_foundWhere = DataModel::NoLocation;
+                        found = false;
                         // did not find the search string in this message
-                    }
+                    } while (0);
                 }
-                if (m_foundWhere != DataModel::NoLocation) {
+                if (found) {
                     setCurrentMessage(realIndex, i);
 
                     // determine whether the search wrapped
@@ -1056,7 +1045,6 @@ void MainWindow::findAgain()
     qApp->beep();
     QMessageBox::warning(m_findDialog, tr("Qt Linguist"),
                          tr("Cannot find the string '%1'.").arg(m_findText));
-    m_foundWhere  = DataModel::NoLocation;
 }
 
 void MainWindow::showBatchTranslateDialog()
index 8b94808..0220c05 100644 (file)
@@ -205,7 +205,7 @@ private:
     // FIXME: move to DataModel
     void updateDanger(const MultiDataIndex &index, bool verbose);
 
-    bool searchItem(const QString &searchWhat);
+    bool searchItem(DataModel::FindLocation where, const QString &searchWhat);
 
     QProcess *m_assistantProcess;
     QTreeView *m_contextView;
@@ -235,7 +235,6 @@ private:
     Qt::CaseSensitivity m_findMatchCase;
     bool m_findIgnoreAccelerators;
     DataModel::FindLocation m_findWhere;
-    DataModel::FindLocation m_foundWhere;
 
     TranslateDialog *m_translateDialog;
     QString m_latestFindText;