roles[IsBookmarkedRole] = "isBookmarked";
roles[NumberRole] = "number";
setRoleNames(roles);
-
+ _isBookmarkModeActive = false;
}
if (!empty){
endResetModel();
}
+ _isBookmarkModeActive = false;
}
QVariant WordListModel::data(const QModelIndex &index, int role) const
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];
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]);
endRemoveRows();
}
}
+ Q_EMIT dataChanged(this->index(0), this->index(_translations.count() - 1));
return 2;
}
else
}
return 0;
}
+
+void WordListModel::setBookmarkModeActive(bool mode)
+{
+ _isBookmarkModeActive = mode;
+}