Only emit dataChanged() when the data actually changed
This commit is contained in:
parent
73adff15ca
commit
20635dfd6e
1 changed files with 17 additions and 13 deletions
|
@ -201,7 +201,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case IdRole: {
|
case IdRole: {
|
||||||
double id = value.toDouble(&retval);
|
double id = value.toDouble(&retval);
|
||||||
if (retval) {
|
if (retval && id != m_notes[index.row()].id()) {
|
||||||
m_notes[index.row()].setId(id);
|
m_notes[index.row()].setId(id);
|
||||||
emit dataChanged(index, index, QVector<int>{ IdRole });
|
emit dataChanged(index, index, QVector<int>{ IdRole });
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case ModifiedRole: {
|
case ModifiedRole: {
|
||||||
double modified = value.toDouble(&retval);
|
double modified = value.toDouble(&retval);
|
||||||
if (retval) {
|
if (retval && modified != m_notes[index.row()].modified()) {
|
||||||
m_notes[index.row()].setModified(modified);
|
m_notes[index.row()].setModified(modified);
|
||||||
emit dataChanged(index, index, QVector<int>{ ModifiedRole });
|
emit dataChanged(index, index, QVector<int>{ ModifiedRole });
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case TitleRole: {
|
case TitleRole: {
|
||||||
QString title = value.toString();
|
QString title = value.toString();
|
||||||
if (!title.isEmpty()) {
|
if (title != m_notes[index.row()].title()) {
|
||||||
m_notes[index.row()].setTitle(title);
|
m_notes[index.row()].setTitle(title);
|
||||||
emit dataChanged(index, index, QVector<int>{ TitleRole });
|
emit dataChanged(index, index, QVector<int>{ TitleRole });
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -226,7 +226,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case CategoryRole: {
|
case CategoryRole: {
|
||||||
QString category = value.toString();
|
QString category = value.toString();
|
||||||
if (!category.isEmpty()) {
|
if (category != m_notes[index.row()].category()) {
|
||||||
m_notes[index.row()].setCategory(category);
|
m_notes[index.row()].setCategory(category);
|
||||||
emit dataChanged(index, index, QVector<int>{ CategoryRole });
|
emit dataChanged(index, index, QVector<int>{ CategoryRole });
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -235,7 +235,7 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case ContentRole: {
|
case ContentRole: {
|
||||||
QString content = value.toString();
|
QString content = value.toString();
|
||||||
if (!content.isEmpty()) {
|
if (content != m_notes[index.row()].content()) {
|
||||||
m_notes[index.row()].setContent(content);
|
m_notes[index.row()].setContent(content);
|
||||||
emit dataChanged(index, index, QVector<int>{ ContentRole });
|
emit dataChanged(index, index, QVector<int>{ ContentRole });
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -244,14 +244,16 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case FavoriteRole: {
|
case FavoriteRole: {
|
||||||
bool favorite = value.toBool();
|
bool favorite = value.toBool();
|
||||||
m_notes[index.row()].setFavorite(favorite);
|
if (favorite != m_notes[index.row()].favorite()) {
|
||||||
emit dataChanged(index, index, QVector<int>{ FavoriteRole });
|
m_notes[index.row()].setFavorite(favorite);
|
||||||
retval = true;
|
emit dataChanged(index, index, QVector<int>{ FavoriteRole });
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EtagRole: {
|
case EtagRole: {
|
||||||
QString etag = value.toString();
|
QString etag = value.toString();
|
||||||
if (!etag.isEmpty()) {
|
if (etag != m_notes[index.row()].etag()) {
|
||||||
m_notes[index.row()].setEtag(etag);
|
m_notes[index.row()].setEtag(etag);
|
||||||
emit dataChanged(index, index, QVector<int>{ EtagRole });
|
emit dataChanged(index, index, QVector<int>{ EtagRole });
|
||||||
retval = true;
|
retval = true;
|
||||||
|
@ -260,14 +262,16 @@ bool NotesModel::setData(const QModelIndex &index, const QVariant &value, int ro
|
||||||
}
|
}
|
||||||
case ErrorRole: {
|
case ErrorRole: {
|
||||||
bool error = value.toBool();
|
bool error = value.toBool();
|
||||||
m_notes[index.row()].setError(error);
|
if (error != m_notes[index.row()].error()) {
|
||||||
emit dataChanged(index, index, QVector<int>{ ErrorRole });
|
m_notes[index.row()].setError(error);
|
||||||
retval = true;
|
emit dataChanged(index, index, QVector<int>{ ErrorRole });
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ErrorMessageRole: {
|
case ErrorMessageRole: {
|
||||||
QString errorMessage = value.toString();
|
QString errorMessage = value.toString();
|
||||||
if (!errorMessage.isEmpty()) {
|
if (errorMessage != m_notes[index.row()].errorMessage()) {
|
||||||
m_notes[index.row()].setErrorMessage(errorMessage);
|
m_notes[index.row()].setErrorMessage(errorMessage);
|
||||||
emit dataChanged(index, index, QVector<int>{ ErrorMessageRole });
|
emit dataChanged(index, index, QVector<int>{ ErrorMessageRole });
|
||||||
retval = true;
|
retval = true;
|
||||||
|
|
Loading…
Reference in a new issue