X-Git-Url: http://git.maemo.org/git/?p=mdictionary;a=blobdiff_plain;f=src%2Fmdictionary%2Fgui%2FWordListModel.cpp;fp=src%2Fmdictionary%2Fgui%2FWordListModel.cpp;h=6a167a853c47b55b01de15e2a45b578534982fbd;hp=ba9a977c48f919786cfa6d913724e3ab79bccbe2;hb=017dcadabdc237efe9d5062fb3cdd36e8b25106a;hpb=21a14d392f44458d749c76552e971f33625705ea 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; +}