Work on model.
This commit is contained in:
parent
a104844814
commit
dad3cc8555
@ -231,14 +231,14 @@ bool FeedsModel::removeItem(const QModelIndex &index) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedsModel::assignNodeToNewParent(RootItem *item, RootItem *parent) {
|
void FeedsModel::assignNodeToNewParent(RootItem *item, RootItem *new_parent) {
|
||||||
// Get index of parent item (parent standard category).
|
QModelIndex parent_index = indexForItem(new_parent);
|
||||||
QModelIndex parent_index = indexForItem(parent);
|
int new_index_of_item = new_parent->childCount();
|
||||||
|
|
||||||
// TODO: todle jde sloučit s metodou reassignNodeToNewParent.
|
// TODO: sloučit do funkce reassignNodeToNewParent.
|
||||||
|
|
||||||
beginInsertRows(parent_index, parent->childCount(), parent->childCount());
|
beginInsertRows(parent_index, new_index_of_item, new_index_of_item);
|
||||||
parent->appendChild(item);
|
new_parent->appendChild(item);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,18 +246,18 @@ void FeedsModel::reassignNodeToNewParent(RootItem *original_node, RootItem *new_
|
|||||||
RootItem *original_parent = original_node->parent();
|
RootItem *original_parent = original_node->parent();
|
||||||
|
|
||||||
if (original_parent != new_parent) {
|
if (original_parent != new_parent) {
|
||||||
// User edited category and set it new parent item,
|
// User edited item and set it new parent item,
|
||||||
// se we need to move the item in the model too.
|
// se we need to move the item in the model too.
|
||||||
int original_index_of_feed = original_parent->childItems().indexOf(original_node);
|
int original_index_of_item = original_parent->childItems().indexOf(original_node);
|
||||||
int new_index_of_feed = new_parent->childCount();
|
int new_index_of_item = new_parent->childCount();
|
||||||
|
|
||||||
// Remove the original item from the model...
|
// Remove the original item from the model...
|
||||||
beginRemoveRows(indexForItem(original_parent), original_index_of_feed, original_index_of_feed);
|
beginRemoveRows(indexForItem(original_parent), original_index_of_item, original_index_of_item);
|
||||||
original_parent->removeChild(original_node);
|
original_parent->removeChild(original_node);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
// ... and insert it under the new parent.
|
// ... and insert it under the new parent.
|
||||||
beginInsertRows(indexForItem(new_parent), new_index_of_feed, new_index_of_feed);
|
beginInsertRows(indexForItem(new_parent), new_index_of_item, new_index_of_item);
|
||||||
new_parent->appendChild(original_node);
|
new_parent->appendChild(original_node);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
}
|
}
|
||||||
@ -334,6 +334,10 @@ QList<Message> FeedsModel::messagesForFeeds(const QList<Feed*> &feeds) {
|
|||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Category*> FeedsModel::allCategories() {
|
||||||
|
return categoriesForItem(m_rootItem);
|
||||||
|
}
|
||||||
|
|
||||||
int FeedsModel::columnCount(const QModelIndex &parent) const {
|
int FeedsModel::columnCount(const QModelIndex &parent) const {
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
|
|
||||||
@ -572,3 +576,16 @@ QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
|
|||||||
|
|
||||||
return feeds;
|
return feeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<Category*> FeedsModel::categoriesForItem(RootItem *root) {
|
||||||
|
QList<RootItem*> children = root->getRecursiveChildren();
|
||||||
|
QList<Category*> categories;
|
||||||
|
|
||||||
|
foreach (RootItem *child, children) {
|
||||||
|
if (child->kind() == RootItemKind::Category) {
|
||||||
|
categories.append(child->toCategory());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
#include "core/messagesmodel.h"
|
#include "core/messagesmodel.h"
|
||||||
#include "core/rootitem.h"
|
#include "core/rootitem.h"
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
|
|
||||||
|
|
||||||
class Category;
|
class Category;
|
||||||
class Feed;
|
class Feed;
|
||||||
@ -64,7 +62,7 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
bool removeItem(const QModelIndex &index);
|
bool removeItem(const QModelIndex &index);
|
||||||
|
|
||||||
// Assigns item to the new parent.
|
// Assigns item to the new parent.
|
||||||
void assignNodeToNewParent(RootItem *item, RootItem *parent);
|
void assignNodeToNewParent(RootItem *item, RootItem *new_parent);
|
||||||
|
|
||||||
// Checks if new parent node is different from one used by original node.
|
// Checks if new parent node is different from one used by original node.
|
||||||
// If it is, then it reassigns original_node to new parent.
|
// If it is, then it reassigns original_node to new parent.
|
||||||
@ -82,11 +80,18 @@ class FeedsModel : public QAbstractItemModel {
|
|||||||
// in "newspaper" mode.
|
// in "newspaper" mode.
|
||||||
QList<Message> messagesForFeeds(const QList<Feed*> &feeds);
|
QList<Message> messagesForFeeds(const QList<Feed*> &feeds);
|
||||||
|
|
||||||
|
// Returns list of all categories contained in the model.
|
||||||
|
QList<Category*> allCategories();
|
||||||
|
|
||||||
|
// Get list of categories from tree with particular item
|
||||||
|
// as root.
|
||||||
|
QList<Category*> categoriesForItem(RootItem *root);
|
||||||
|
|
||||||
// Returns list of all feeds contained in the model.
|
// Returns list of all feeds contained in the model.
|
||||||
QList<Feed*> allFeeds();
|
QList<Feed*> allFeeds();
|
||||||
|
|
||||||
// Get list of feeds from tree with particular item
|
// Get list of feeds from tree with particular item
|
||||||
// as root. If root itself is a feed, then it is returned.
|
// as root.
|
||||||
QList<Feed*> feedsForItem(RootItem *root);
|
QList<Feed*> feedsForItem(RootItem *root);
|
||||||
|
|
||||||
// Returns list of ALL CHILD feeds which belong to given parent indexes.
|
// Returns list of ALL CHILD feeds which belong to given parent indexes.
|
||||||
|
@ -112,8 +112,8 @@ void FeedsView::saveExpandedStates() {
|
|||||||
// TODO: doědlat
|
// TODO: doědlat
|
||||||
|
|
||||||
// Iterate all categories and save their expand statuses.
|
// Iterate all categories and save their expand statuses.
|
||||||
|
/*
|
||||||
/*foreach (Category *category, sourceModel()->allCategories().values()) {
|
foreach (Category *category, sourceModel()->allCategories().values()) {
|
||||||
settings->setValue(GROUP(Categories),
|
settings->setValue(GROUP(Categories),
|
||||||
QString::number(category->id()),
|
QString::number(category->id()),
|
||||||
isExpanded(model()->mapFromSource(sourceModel()->indexForItem(category))));
|
isExpanded(model()->mapFromSource(sourceModel()->indexForItem(category))));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user