From 017dcadabdc237efe9d5062fb3cdd36e8b25106a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ka=C5=BAmierczak?= Date: Tue, 22 Feb 2011 15:49:55 +0100 Subject: [PATCH] Fix random error when remove word from bookmark. Fix show all bookmark feature. --- src/include/GUIInterface.h | 2 ++ src/mdictionary/backbone/backbone.h | 5 +++++ src/mdictionary/gui/DictManagerModel.cpp | 2 +- src/mdictionary/gui/MainWindow.cpp | 6 ++++++ src/mdictionary/gui/WordListModel.cpp | 19 ++++++++++--------- src/mdictionary/gui/WordListModel.h | 3 +++ src/mdictionary/gui/WordListWidget.cpp | 9 +++++++++ src/mdictionary/gui/WordListWidget.h | 4 ++++ src/mdictionary/qml/WordListWidget.qml | 3 +-- 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/include/GUIInterface.h b/src/include/GUIInterface.h index 1b86f86..8152937 100644 --- a/src/include/GUIInterface.h +++ b/src/include/GUIInterface.h @@ -191,6 +191,8 @@ Q_SIGNALS: void selectedDictionaries(QList); void addToBookmarks(QList); + + void bookmarkMode(); }; #endif // GUIINTERFACE_H diff --git a/src/mdictionary/backbone/backbone.h b/src/mdictionary/backbone/backbone.h index e5c619d..f59bc3d 100644 --- a/src/mdictionary/backbone/backbone.h +++ b/src/mdictionary/backbone/backbone.h @@ -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(); diff --git a/src/mdictionary/gui/DictManagerModel.cpp b/src/mdictionary/gui/DictManagerModel.cpp index f2aee34..8e53a14 100644 --- a/src/mdictionary/gui/DictManagerModel.cpp +++ b/src/mdictionary/gui/DictManagerModel.cpp @@ -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]; diff --git a/src/mdictionary/gui/MainWindow.cpp b/src/mdictionary/gui/MainWindow.cpp index 2b6bafc..f8582dd 100644 --- a/src/mdictionary/gui/MainWindow.cpp +++ b/src/mdictionary/gui/MainWindow.cpp @@ -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)), // 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)), backbone, SLOT(addBookmark(QList))); diff --git a/src/mdictionary/gui/WordListModel.cpp b/src/mdictionary/gui/WordListModel.cpp index ba9a977..6a167a8 100644 --- a/src/mdictionary/gui/WordListModel.cpp +++ b/src/mdictionary/gui/WordListModel.cpp @@ -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; +} diff --git a/src/mdictionary/gui/WordListModel.h b/src/mdictionary/gui/WordListModel.h index abb128d..11e8439 100644 --- a/src/mdictionary/gui/WordListModel.h +++ b/src/mdictionary/gui/WordListModel.h @@ -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 _wordInBookmarks; QList _wordList; + bool isBookmarkModeActive; + }; #endif // WORDLISTMODEL_H diff --git a/src/mdictionary/gui/WordListWidget.cpp b/src/mdictionary/gui/WordListWidget.cpp index 135e4ae..da98e15 100644 --- a/src/mdictionary/gui/WordListWidget.cpp +++ b/src/mdictionary/gui/WordListWidget.cpp @@ -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; +} diff --git a/src/mdictionary/gui/WordListWidget.h b/src/mdictionary/gui/WordListWidget.h index 2a95c37..9b293c9 100644 --- a/src/mdictionary/gui/WordListWidget.h +++ b/src/mdictionary/gui/WordListWidget.h @@ -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 > searchResult; WordListProxyStyle* proxyStyle; + bool isBookmarkModeActive; + #ifndef Q_WS_MAEMO_5 QVBoxLayout* verticalLayout; QDeclarativeView* qmlView; diff --git a/src/mdictionary/qml/WordListWidget.qml b/src/mdictionary/qml/WordListWidget.qml index 07cf206..9670a14 100644 --- a/src/mdictionary/qml/WordListWidget.qml +++ b/src/mdictionary/qml/WordListWidget.qml @@ -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 -- 1.7.9.5