Redundant code removed.

This commit is contained in:
Martin Rotter 2013-12-28 11:38:49 +01:00
parent d78ff65044
commit 6e7312e3e7
4 changed files with 0 additions and 141 deletions

View File

@ -433,82 +433,6 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re
}
}
bool MessagesModel::setAllMessagesDeleted(int deleted) {
QSqlDatabase db_handle = database();
if (!db_handle.transaction()) {
qWarning("Starting transaction for all message deletion.");
return false;
}
QSqlQuery query_delete_msg(db_handle);
if (!query_delete_msg.prepare(QString("UPDATE messages SET deleted = :deleted "
"WHERE feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")))) {
qWarning("Query preparation failed for message deletion.");
db_handle.rollback();
return false;
}
query_delete_msg.bindValue(":deleted", deleted);
if (!query_delete_msg.exec()) {
qDebug("Query execution for all message deletion failed.");
db_handle.rollback();
}
// Commit changes.
if (db_handle.commit()) {
// FULLY reload the model if underlying data is changed.
select();
fetchAll();
emit feedCountsChanged();
return true;
}
else {
return db_handle.rollback();
}
}
bool MessagesModel::setAllMessagesRead(int read) {
QSqlDatabase db_handle = database();
if (!db_handle.transaction()) {
qWarning("Starting transaction for all message read change.");
return false;
}
QSqlQuery query_read_msg(db_handle);
if (!query_read_msg.prepare(QString("UPDATE messages SET read = :read "
"WHERE feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")))) {
qWarning("Query preparation failed for message read change.");
db_handle.rollback();
return false;
}
query_read_msg.bindValue(":read", read);
if (!query_read_msg.exec()) {
qDebug("Query execution for all message read change failed.");
db_handle.rollback();
}
// Commit changes.
if (db_handle.commit()) {
// FULLY reload the model if underlying data is changed.
select();
fetchAll();
emit feedCountsChanged();
return true;
}
else {
return db_handle.rollback();
}
}
QVariant MessagesModel::headerData(int section,
Qt::Orientation orientation,
int role) const {

View File

@ -66,14 +66,6 @@ class MessagesModel : public QSqlTableModel {
bool setBatchMessagesDeleted(const QModelIndexList &messages, int deleted);
bool setBatchMessagesRead(const QModelIndexList &messages, int read);
// ALL messages manipulators.
// NOTE: These methods are used for changing of attributes
// of many messages via DIRECT SQL calls.
// List of loaded feed ids is used for WHERE clause.
// Model is reset after one of these methods is applied.
bool setAllMessagesDeleted(int deleted);
bool setAllMessagesRead(int read);
// Fetches ALL available data to the model.
// NOTE: This is almost always needed when sorting
// and makes the model more predictable.

View File

@ -326,54 +326,6 @@ void MessagesView::switchSelectedMessagesImportance() {
reselectIndexes(selected_indexes);
}
void MessagesView::setAllMessagesReadStatus(int read) {
QModelIndex current_index = selectionModel()->currentIndex();
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
QModelIndexList selected_indexes = selectionModel()->selectedRows();
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setAllMessagesRead(read);
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
selected_indexes = m_proxyModel->mapListFromSource(mapped_indexes, true);
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(),
mapped_current_index.column()));
if (read == 0) {
// User selected to mark some messages as unread, if one
// of them will be marked as current, then it will be read again.
m_batchUnreadSwitch = true;
setCurrentIndex(current_index);
m_batchUnreadSwitch = false;
}
else {
setCurrentIndex(current_index);
}
scrollTo(current_index);
reselectIndexes(selected_indexes);
}
void MessagesView::setAllMessagesRead() {
setAllMessagesReadStatus(1);
}
void MessagesView::setAllMessagesUnread() {
setAllMessagesReadStatus(0);
}
void MessagesView::setAllMessagesDeleteStatus(int deleted) {
m_sourceModel->setAllMessagesDeleted(deleted);
// We deleted completely each and every visible message.
// That is why no message can be displayed now.
emit currentMessageRemoved();
}
void MessagesView::setAllMessagesDeleted() {
setAllMessagesDeleteStatus(1);
}
void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
selectionModel()->clearSelection();

View File

@ -46,15 +46,6 @@ class MessagesView : public QTreeView {
void deleteSelectedMessages();
void switchSelectedMessagesImportance();
// Sets ALL (unfiltered) messages read.
void setAllMessagesReadStatus(int read);
void setAllMessagesRead();
void setAllMessagesUnread();
// Sets ALL (unfiltered) messages deleted.
void setAllMessagesDeleteStatus(int deleted);
void setAllMessagesDeleted();
protected slots:
// Marks given indexes as selected.
void reselectIndexes(const QModelIndexList &indexes);