Fix random error when remove word from bookmark. Fix show all bookmark feature.
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Tue, 22 Feb 2011 14:49:55 +0000 (15:49 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Tue, 22 Feb 2011 14:49:55 +0000 (15:49 +0100)
src/include/GUIInterface.h
src/mdictionary/backbone/backbone.h
src/mdictionary/gui/DictManagerModel.cpp
src/mdictionary/gui/MainWindow.cpp
src/mdictionary/gui/WordListModel.cpp
src/mdictionary/gui/WordListModel.h
src/mdictionary/gui/WordListWidget.cpp
src/mdictionary/gui/WordListWidget.h
src/mdictionary/qml/WordListWidget.qml

index 1b86f86..8152937 100644 (file)
@@ -191,6 +191,8 @@ Q_SIGNALS:
     void selectedDictionaries(QList<CommonDictInterface* >);
 
     void addToBookmarks(QList<Translation*>);
+
+    void bookmarkMode();
 };
 
 #endif // GUIINTERFACE_H
index e5c619d..f59bc3d 100644 (file)
@@ -229,6 +229,9 @@ public Q_SLOTS:
         _innerBookmarks = QtConcurrent::run(_bookmarks,
                 &Bookmarks::list);
         _bookmarkSearchWatcher.setFuture(_innerBookmarks);
+
+        Q_EMIT bookmarkMode();
+        qDebug()<<"1";
    }
 
    /*! Sets settings for backbone: history_size, search_limit,
@@ -273,6 +276,8 @@ Q_SIGNALS:
 
     void bookmarkReady();
 
+    void bookmarkMode();
+
 private Q_SLOTS:
     void bookmarksListReady();
 
index f2aee34..8e53a14 100644 (file)
@@ -116,7 +116,7 @@ bool DictManagerModel::setData(const QModelIndex &index, const QVariant &value,
 
 int DictManagerModel::setDataPriv(int index, const QVariant &value, int role)
 {
-    if (index < 0 || index > _dictList.count())
+    if (index < 0 || index > _dictList.count() - 1)
         return 0;
 
     CommonDictInterface* dictionary = _dictList[index];
index 2b6bafc..f8582dd 100644 (file)
@@ -463,6 +463,9 @@ void MainWindow::connectBackbone() {
     connect(backbone, SIGNAL(closeOk()),
             this, SLOT(close()));
 
+    connect(backbone, SIGNAL(bookmarkMode()),
+            this, SIGNAL(bookmarkMode()));
+
 
     //connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
     //       this, SIGNAL(setBusy()));
@@ -518,6 +521,9 @@ void MainWindow::connectWordList() {
     connect(this, SIGNAL(setIdle()),
             wordListWidget, SLOT(unlockList()));
 
+    connect(this, SIGNAL(bookmarkMode()),
+            wordListWidget, SLOT(bookmarkModeActive()));
+
     connect(wordListWidget, SIGNAL(addBookmark(QList<Translation*>)),
             backbone, SLOT(addBookmark(QList<Translation*>)));
 
index ba9a977..6a167a8 100644 (file)
@@ -8,7 +8,7 @@ WordListModel::WordListModel(QObject *parent) :
     roles[IsBookmarkedRole] = "isBookmarked";
     roles[NumberRole] = "number";
     setRoleNames(roles);
-
+    isBookmarkModeActive = false;
 
 }
 
@@ -39,6 +39,7 @@ void WordListModel::clear()
     if (!empty){
         endResetModel();
     }
+    isBookmarkModeActive = false;
 }
 
 QVariant WordListModel::data(const QModelIndex &index, int role) const
@@ -115,12 +116,7 @@ void WordListModel::setModelProperty(int index, const QVariant value, QString ro
 
 int WordListModel::setDataPriv(int index, const QVariant &value, int role)
 {
-    bool bookmarksOnly = false;
-    if (_wordInBookmarks.values().count(false) == 0){
-        bookmarksOnly = true;
-    }
-
-    if (index < 0 || index > _translations.count())
+    if (index < 0 || index > _translations.count() - 1)
         return 0;
 
     QString word = _wordList[index];
@@ -133,12 +129,11 @@ int WordListModel::setDataPriv(int index, const QVariant &value, int role)
         if (value.type() == QVariant::Bool)
         {
             _wordInBookmarks[word] = value.toBool();
-            Q_EMIT dataChanged(this->index(0), this->index(_translations.count() - 1));
             if (_wordInBookmarks[word] == true){
                 Q_EMIT addToBookmarks(word);
             } else {                
                 Q_EMIT removeFromBookmarks(word);
-                if (bookmarksOnly == true){
+                if (isBookmarkModeActive == true){
                     beginRemoveRows(QModelIndex(), index, index + 1);
                     this->_translations.remove(_wordList[index]);
                     this->_wordInBookmarks.remove(_wordList[index]);
@@ -146,6 +141,7 @@ int WordListModel::setDataPriv(int index, const QVariant &value, int role)
                     endRemoveRows();
                 }
             }
+            Q_EMIT dataChanged(this->index(0), this->index(_translations.count() - 1));
             return 2;
         }
         else
@@ -155,3 +151,8 @@ int WordListModel::setDataPriv(int index, const QVariant &value, int role)
     }
     return 0;
 }
+
+void WordListModel::setBookmarkModeActive(bool mode)
+{
+    isBookmarkModeActive = mode;
+}
index abb128d..11e8439 100644 (file)
@@ -20,6 +20,7 @@ public:
     explicit WordListModel(QObject *parent = 0);
 
     int rowCount(const QModelIndex & parent = QModelIndex()) const;
+    void setBookmarkModeActive(bool mode);
 
     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
     bool setData(const QModelIndex &index, const QVariant &value, int role);
@@ -60,6 +61,8 @@ private:
     QHash<QString, bool > _wordInBookmarks;
     QList<QString> _wordList;
 
+    bool isBookmarkModeActive;
+
 };
 
 #endif // WORDLISTMODEL_H
index 135e4ae..da98e15 100644 (file)
@@ -35,6 +35,8 @@
 WordListWidget::WordListWidget(QWidget *parent):
     QTreeView(parent) {
 
+    isBookmarkModeActive = false;
+
     //creating new model to store words and stars
 #ifdef Q_WS_MAEMO_5
     model = new QStandardItemModel(this);
@@ -187,6 +189,9 @@ void WordListWidget::showSearchResults(
     if (listModel == 0){
         listModel = new WordListModel(this);
     }
+
+    listModel->setBookmarkModeActive(isBookmarkModeActive);
+    isBookmarkModeActive = false;
     listModel->setTranslations(result, wordsInBookmarks);
 
 #endif
@@ -341,3 +346,7 @@ void WordListWidget::clear() {
     }
     searchResult.clear();
 }
+
+void WordListWidget::bookmarkModeActive(){
+    isBookmarkModeActive = true;
+}
index 2a95c37..9b293c9 100644 (file)
@@ -81,6 +81,8 @@ public Q_SLOTS:
     //! clears list
     void clear();
 
+    void bookmarkModeActive();
+
 protected:
 #ifdef Q_WS_MAEMO_5
     //! Reimplemented standard mouseReleaseEvent to check if user clicked on
@@ -126,6 +128,8 @@ private:
     QHash<QString, QList<Translation*> > searchResult;
     WordListProxyStyle* proxyStyle;
 
+    bool isBookmarkModeActive;
+
 #ifndef Q_WS_MAEMO_5
     QVBoxLayout* verticalLayout;
     QDeclarativeView* qmlView;
index 07cf206..9670a14 100644 (file)
@@ -32,11 +32,10 @@ Rectangle {
 
     }
 
-    function setEnabled(Boolean) { wordList.enabled = Boolean }  // slot
+    function setEnabled(Boolean) { wordList.enabled = Boolean }
 
     signal wordSelected(string word);
 
-
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
 
     id: rectangle1