Some feed deleting.
This commit is contained in:
parent
40dec8c043
commit
01a41de45b
@ -159,17 +159,14 @@ bool FeedsModel::removeItems(const QModelIndexList &indexes) {
|
||||
FeedsModelRootItem *parent_item = itemForIndex(parent_index);
|
||||
|
||||
beginRemoveRows(parent_index, index.row(), index.row());
|
||||
if (parent_item->removeChild(index.row())) {
|
||||
if (item->removeItself() || parent_item->removeChild(index.row())) {
|
||||
items_for_deletion << item;
|
||||
}
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
|
||||
// Free deleted items from the memory.
|
||||
while (!items_for_deletion.isEmpty()) {
|
||||
delete items_for_deletion.takeFirst();
|
||||
}
|
||||
qDeleteAll(items_for_deletion);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -24,16 +24,6 @@ class FeedsModelCategory : public FeedsModelRootItem {
|
||||
explicit FeedsModelCategory(const FeedsModelCategory &other);
|
||||
virtual ~FeedsModelCategory();
|
||||
|
||||
inline bool removeItself() {
|
||||
bool result = true;
|
||||
|
||||
foreach (FeedsModelRootItem *child, m_childItems) {
|
||||
result &= child->removeItself();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// All types of categories offer these getters/setters.
|
||||
inline Type type() const {
|
||||
return m_type;
|
||||
|
@ -62,6 +62,7 @@ class FeedsModelRootItem {
|
||||
// This typically removes item and its
|
||||
// "children" (for example messages or child feeds)
|
||||
// from the database.
|
||||
// Returns true if "I" was removed.
|
||||
virtual bool removeItself() {
|
||||
return false;
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include "core/feedsmodelstandardcategory.h"
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/databasefactory.h"
|
||||
#include "core/textfactory.h"
|
||||
#include "gui/iconthemefactory.h"
|
||||
#include "gui/iconfactory.h"
|
||||
|
||||
#include <QVariant>
|
||||
#include <QSqlQuery>
|
||||
|
||||
|
||||
FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item)
|
||||
@ -89,6 +91,31 @@ QVariant FeedsModelStandardCategory::data(int column, int role) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool FeedsModelStandardCategory::removeItself() {
|
||||
bool result = true;
|
||||
|
||||
// Remove all child items (feeds, categories.)
|
||||
foreach (FeedsModelRootItem *child, m_childItems) {
|
||||
result &= child->removeItself();
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Children are removed, remove this standard category too.
|
||||
QSqlDatabase database = DatabaseFactory::instance()->connection();
|
||||
QSqlQuery query_remove(database);
|
||||
|
||||
query_remove.setForwardOnly(true);
|
||||
|
||||
// Remove all messages from this standard feed.
|
||||
query_remove.prepare("DELETE FROM Categories WHERE id = :category;");
|
||||
query_remove.bindValue(":category", id());
|
||||
|
||||
return query_remove.exec();
|
||||
}
|
||||
|
||||
FeedsModelStandardCategory *FeedsModelStandardCategory::loadFromRecord(const QSqlRecord &record) {
|
||||
FeedsModelStandardCategory *category = new FeedsModelStandardCategory(NULL);
|
||||
|
||||
|
@ -21,6 +21,10 @@ class FeedsModelStandardCategory : public FeedsModelCategory {
|
||||
// Returns the actual data representation of standard category.
|
||||
QVariant data(int column, int role) const;
|
||||
|
||||
// Removes category and all its children from persistent
|
||||
// database.
|
||||
bool removeItself();
|
||||
|
||||
// Loads particular "standard category" from given sql record.
|
||||
static FeedsModelStandardCategory *loadFromRecord(const QSqlRecord &record);
|
||||
};
|
||||
|
@ -163,9 +163,24 @@ void FeedsModelStandardFeed::update() {
|
||||
}
|
||||
|
||||
bool FeedsModelStandardFeed::removeItself() {
|
||||
// TODO: pokracovat, vymazat tento standardni
|
||||
// kanal z database a smazat jeho zpravy atp.
|
||||
return false;
|
||||
QSqlDatabase database = DatabaseFactory::instance()->connection();
|
||||
QSqlQuery query_remove(database);
|
||||
|
||||
query_remove.setForwardOnly(true);
|
||||
|
||||
// Remove all messages from this standard feed.
|
||||
query_remove.prepare("DELETE FROM Messages WHERE feed = :feed;");
|
||||
query_remove.bindValue(":feed", id());
|
||||
|
||||
if (!query_remove.exec()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove feed itself.
|
||||
query_remove.prepare("DELETE FROM Feeds WHERE id = :feed;");
|
||||
query_remove.bindValue(":feed", id());
|
||||
|
||||
return query_remove.exec();
|
||||
}
|
||||
|
||||
void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
||||
|
@ -107,10 +107,11 @@ void FeedsView::deleteSelectedItems() {
|
||||
QModelIndexList selection = selectionModel()->selectedRows();
|
||||
QModelIndexList mapped_selection = m_proxyModel->mapListToSource(selection);
|
||||
|
||||
FeedsModelRootItem *parent = m_sourceModel->itemForIndex(mapped_selection.at(0).parent());
|
||||
//FeedsModelRootItem *parent = m_sourceModel->itemForIndex(mapped_selection.at(0).parent());
|
||||
|
||||
m_sourceModel->removeItems(mapped_selection);
|
||||
|
||||
/*
|
||||
QModelIndex id = m_sourceModel->indexForItem(parent);
|
||||
|
||||
if (id.isValid()) {
|
||||
@ -118,7 +119,7 @@ void FeedsView::deleteSelectedItems() {
|
||||
selectionModel()->select(m_proxyModel->mapFromSource(id),
|
||||
QItemSelectionModel::Rows |
|
||||
QItemSelectionModel::Select);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void FeedsView::markSelectedFeedsReadStatus(int read) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user