Import fixing.
This commit is contained in:
parent
4017420e4f
commit
4c494f63ae
6 changed files with 22 additions and 7 deletions
|
@ -433,3 +433,7 @@ Qt::ItemFlags FeedsImportExportModel::flags(const QModelIndex &index) const {
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FeedsImportExportModel::isItemChecked(FeedsModelRootItem *item) {
|
||||||
|
return m_checkStates.contains(item) && m_checkStates.value(item, Qt::Unchecked);
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ class FeedsImportExportModel : public QAbstractItemModel {
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
bool isItemChecked(FeedsModelRootItem *item);
|
||||||
|
|
||||||
// Returns feed/category which lies at the specified index or
|
// Returns feed/category which lies at the specified index or
|
||||||
// root item if index is invalid.
|
// root item if index is invalid.
|
||||||
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
|
FeedsModelRootItem *itemForIndex(const QModelIndex &index) const;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "definitions/definitions.h"
|
#include "definitions/definitions.h"
|
||||||
#include "core/feedsmodelcategory.h"
|
#include "core/feedsmodelcategory.h"
|
||||||
#include "core/feedsmodelfeed.h"
|
#include "core/feedsmodelfeed.h"
|
||||||
|
#include "core/feedsimportexportmodel.h"
|
||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
#include "miscellaneous/databasefactory.h"
|
#include "miscellaneous/databasefactory.h"
|
||||||
#include "miscellaneous/iconfactory.h"
|
#include "miscellaneous/iconfactory.h"
|
||||||
|
@ -525,15 +526,15 @@ QModelIndex FeedsModel::indexForItem(FeedsModelRootItem *item) const {
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_message) {
|
bool FeedsModel::mergeModel(FeedsImportExportModel *model, QString &output_message) {
|
||||||
if (root_item == NULL) {
|
if (model == NULL || model->rootItem() == NULL) {
|
||||||
output_message = tr("Invalid tree data.");
|
output_message = tr("Invalid tree data.");
|
||||||
qDebug("Root item for merging two models is null.");
|
qDebug("Root item for merging two models is null.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStack<FeedsModelRootItem*> original_parents; original_parents.push(m_rootItem);
|
QStack<FeedsModelRootItem*> original_parents; original_parents.push(m_rootItem);
|
||||||
QStack<FeedsModelRootItem*> new_parents; new_parents.push(root_item);
|
QStack<FeedsModelRootItem*> new_parents; new_parents.push(model->rootItem());
|
||||||
bool some_feed_category_error = false;
|
bool some_feed_category_error = false;
|
||||||
|
|
||||||
// We are definitely about to add some new items into the model.
|
// We are definitely about to add some new items into the model.
|
||||||
|
@ -545,6 +546,12 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me
|
||||||
FeedsModelRootItem *source_parent = new_parents.pop();
|
FeedsModelRootItem *source_parent = new_parents.pop();
|
||||||
|
|
||||||
foreach (FeedsModelRootItem *source_item, source_parent->childItems()) {
|
foreach (FeedsModelRootItem *source_item, source_parent->childItems()) {
|
||||||
|
if (!model->isItemChecked(source_item)) {
|
||||||
|
// We can skip this item, because it is not checked and should not be imported.
|
||||||
|
// NOTE: All descendants are thus skipped too.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (source_item->kind() == FeedsModelRootItem::Category) {
|
if (source_item->kind() == FeedsModelRootItem::Category) {
|
||||||
FeedsModelCategory *source_category = static_cast<FeedsModelCategory*>(source_item);
|
FeedsModelCategory *source_category = static_cast<FeedsModelCategory*>(source_item);
|
||||||
FeedsModelCategory *new_category = new FeedsModelCategory(*source_category);
|
FeedsModelCategory *new_category = new FeedsModelCategory(*source_category);
|
||||||
|
@ -563,7 +570,6 @@ bool FeedsModel::mergeRootItem(FeedsModelRootItem *root_item, QString &output_me
|
||||||
}
|
}
|
||||||
else if (source_item->kind() == FeedsModelRootItem::Feed) {
|
else if (source_item->kind() == FeedsModelRootItem::Feed) {
|
||||||
FeedsModelFeed *source_feed = static_cast<FeedsModelFeed*>(source_item);
|
FeedsModelFeed *source_feed = static_cast<FeedsModelFeed*>(source_item);
|
||||||
// TODO: dodělat kopirovaci konstruktor pořádně.
|
|
||||||
FeedsModelFeed *new_feed = new FeedsModelFeed(*source_feed);
|
FeedsModelFeed *new_feed = new FeedsModelFeed(*source_feed);
|
||||||
|
|
||||||
// Append this feed and end this iteration.
|
// Append this feed and end this iteration.
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
class FeedsModelCategory;
|
class FeedsModelCategory;
|
||||||
class FeedsModelFeed;
|
class FeedsModelFeed;
|
||||||
|
class FeedsImportExportModel;
|
||||||
|
|
||||||
typedef QList<QPair<int, FeedsModelCategory*> > CategoryAssignment;
|
typedef QList<QPair<int, FeedsModelCategory*> > CategoryAssignment;
|
||||||
typedef QPair<int, FeedsModelCategory*> CategoryAssignmentItem;
|
typedef QPair<int, FeedsModelCategory*> CategoryAssignmentItem;
|
||||||
|
@ -138,7 +139,7 @@ class FeedsModel : public QAbstractItemModel {
|
||||||
|
|
||||||
// Takes structure residing under given root item and adds feeds/categories from
|
// Takes structure residing under given root item and adds feeds/categories from
|
||||||
// it to active structure.
|
// it to active structure.
|
||||||
bool mergeRootItem(FeedsModelRootItem *root_item, QString &output_message);
|
bool mergeModel(FeedsImportExportModel *model, QString &output_message);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Feeds operations.
|
// Feeds operations.
|
||||||
|
|
|
@ -55,13 +55,15 @@ FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item)
|
||||||
}
|
}
|
||||||
|
|
||||||
FeedsModelFeed::FeedsModelFeed(const FeedsModelFeed &other)
|
FeedsModelFeed::FeedsModelFeed(const FeedsModelFeed &other)
|
||||||
: FeedsModelRootItem(NULL), m_totalCount(0), m_unreadCount(0) {
|
: FeedsModelRootItem(NULL) {
|
||||||
m_passwordProtected = other.passwordProtected();
|
m_passwordProtected = other.passwordProtected();
|
||||||
m_username = other.username();
|
m_username = other.username();
|
||||||
m_password = other.password();
|
m_password = other.password();
|
||||||
m_status = other.status();
|
m_status = other.status();
|
||||||
m_networkError = other.networkError();
|
m_networkError = other.networkError();
|
||||||
m_type = other.type();
|
m_type = other.type();
|
||||||
|
m_totalCount = other.countOfAllMessages();
|
||||||
|
m_unreadCount = other.countOfUnreadMessages();
|
||||||
m_autoUpdateType = other.autoUpdateType();
|
m_autoUpdateType = other.autoUpdateType();
|
||||||
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
|
m_autoUpdateInitialInterval = other.autoUpdateInitialInterval();
|
||||||
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
|
m_autoUpdateRemainingInterval = other.autoUpdateRemainingInterval();
|
||||||
|
|
|
@ -236,7 +236,7 @@ void FormImportExport::exportFeeds() {
|
||||||
void FormImportExport::importFeeds() {
|
void FormImportExport::importFeeds() {
|
||||||
QString output_message;
|
QString output_message;
|
||||||
|
|
||||||
if (qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->mergeRootItem(m_model->rootItem(), output_message)) {
|
if (qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel()->mergeModel(m_model, output_message)) {
|
||||||
qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->expandAll();
|
qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->expandAll();
|
||||||
m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, output_message, output_message);
|
m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, output_message, output_message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue