* Starting to work on this. * Working, saving of common data in feeds could work * Working, saving of common data in feeds could work * work on standard * save work * work on multi feed select, should work now for feeds * kind of works, there are some corner cases and UX things that need to be sorted out, will merge so people can test
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
// For license of this file, see <project-root-folder>/LICENSE.md.
|
|
|
|
#include "services/standard/standardcategory.h"
|
|
|
|
#include "database/databasequeries.h"
|
|
#include "definitions/definitions.h"
|
|
#include "exceptions/applicationexception.h"
|
|
#include "services/abstract/gui/formcategorydetails.h"
|
|
#include "services/standard/standardfeed.h"
|
|
#include "services/standard/standardserviceroot.h"
|
|
|
|
#include <QPointer>
|
|
|
|
StandardCategory::StandardCategory(RootItem* parent_item) : Category(parent_item) {}
|
|
|
|
StandardServiceRoot* StandardCategory::serviceRoot() const {
|
|
return qobject_cast<StandardServiceRoot*>(getParentServiceRoot());
|
|
}
|
|
|
|
Qt::ItemFlags StandardCategory::additionalFlags() const {
|
|
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
|
}
|
|
|
|
bool StandardCategory::performDragDropChange(RootItem* target_item) {
|
|
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
|
|
|
try {
|
|
DatabaseQueries::createOverwriteCategory(database, this, getParentServiceRoot()->accountId(), target_item->id());
|
|
serviceRoot()->requestItemReassignment(this, target_item);
|
|
return true;
|
|
}
|
|
catch (const ApplicationException& ex) {
|
|
qCriticalNN << LOGSEC_DB << "Cannot overwrite category:" << QUOTE_W_SPACE_DOT(ex.message());
|
|
qApp->showGuiMessage(Notification::Event::GeneralEvent,
|
|
{tr("Cannot save category data"),
|
|
tr("Cannot save data for category, detailed information was logged via debug log."),
|
|
QSystemTrayIcon::MessageIcon::Critical});
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool StandardCategory::canBeEdited() const {
|
|
return true;
|
|
}
|
|
|
|
bool StandardCategory::canBeDeleted() const {
|
|
return true;
|
|
}
|
|
|
|
bool StandardCategory::deleteViaGui() {
|
|
if (removeItself()) {
|
|
serviceRoot()->requestItemRemoval(this);
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool StandardCategory::removeItself() {
|
|
bool children_removed = true;
|
|
|
|
// Remove all child items (feeds and categories)
|
|
// from the database.
|
|
auto chi = childItems();
|
|
|
|
for (RootItem* child : qAsConst(chi)) {
|
|
if (child->kind() == RootItem::Kind::Category) {
|
|
children_removed &= qobject_cast<StandardCategory*>(child)->removeItself();
|
|
}
|
|
else if (child->kind() == RootItem::Kind::Feed) {
|
|
children_removed &= qobject_cast<StandardFeed*>(child)->removeItself();
|
|
}
|
|
}
|
|
|
|
if (children_removed) {
|
|
// Children are removed, remove this standard category too.
|
|
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
|
|
|
return DatabaseQueries::deleteCategory(database, this);
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
}
|