From 2149af25b1371c49c551c9c7966b0ae8f94f5a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 11 Apr 2016 19:25:33 +0200 Subject: [PATCH] Added copy constructors and operator= to folder and comicdb, LibraryItem has to be a QObject, and QObject disables copy. --- common/comic_db.cpp | 18 +++++++++++++++++- common/comic_db.h | 9 ++++++--- common/folder.cpp | 19 +++++++++++++++++++ common/folder.h | 22 ++++++++++++---------- common/library_item.cpp | 12 ++++++++++++ common/library_item.h | 6 ++++-- 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/common/comic_db.cpp b/common/comic_db.cpp index 6e92b85a..cd63abca 100644 --- a/common/comic_db.cpp +++ b/common/comic_db.cpp @@ -11,6 +11,11 @@ ComicDB::ComicDB() } +ComicDB::ComicDB(const ComicDB &comicDB) +{ + operator=(comicDB); +} + bool ComicDB::isDir() { return false; @@ -105,7 +110,18 @@ QString ComicDB::toTXT() if(!info.notes.isNull()) txt.append(QString("notes:%1\r\n").arg(info.notes.toString())); - return txt; + return txt; +} + +ComicDB &ComicDB::operator=(const ComicDB &other) +{ + LibraryItem::operator =(other); + + this->_hasCover = other._hasCover; + + this->info = other.info; + + return *this; } QString ComicDB::getFileName() const diff --git a/common/comic_db.h b/common/comic_db.h index b56f2685..8b9cdb15 100644 --- a/common/comic_db.h +++ b/common/comic_db.h @@ -122,14 +122,16 @@ private: class ComicDB : public LibraryItem { + Q_OBJECT public: ComicDB(); + ComicDB(const ComicDB & comicDB); bool isDir(); bool _hasCover; - bool hasCover() {return _hasCover;}; + bool hasCover() {return _hasCover;} //return comic file name QString getFileName() const; @@ -147,12 +149,13 @@ public: ComicInfo info; - bool operator==(const ComicDB & other){return id == other.id;}; + ComicDB & operator=(const ComicDB & other); + bool operator==(const ComicDB & other){return id == other.id;} friend QDataStream &operator<<(QDataStream &, const ComicDB &); friend QDataStream &operator>>(QDataStream &, ComicDB &); }; -Q_DECLARE_METATYPE(ComicDB); +Q_DECLARE_METATYPE(ComicDB) #endif diff --git a/common/folder.cpp b/common/folder.cpp index e69de29b..4f08207e 100644 --- a/common/folder.cpp +++ b/common/folder.cpp @@ -0,0 +1,19 @@ + +#include "folder.h" + +Folder::Folder(const Folder &folder) +{ + operator=(folder); +} + +Folder &Folder::operator =(const Folder &other) +{ + LibraryItem::operator =(other); + + this->knownParent = other.knownParent; + this->knownId = other.knownId; + this->finished = other.finished; + this->completed = other.completed; + + return *this; +} diff --git a/common/folder.h b/common/folder.h index 862c05de..2dc7002a 100644 --- a/common/folder.h +++ b/common/folder.h @@ -11,16 +11,18 @@ public: bool knownParent; bool knownId; - Folder():knownParent(false), knownId(false){}; - Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;}; - Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;}; - void setId(qulonglong sid){id = sid;knownId = true;}; - void setFather(qulonglong pid){parentId = pid;knownParent = true;}; - bool isDir() {return true;}; - bool isFinished() const {return finished;}; - bool isCompleted() const {return completed;}; - void setFinished(bool b) {finished = b;}; - void setCompleted(bool b) {completed = b;}; + Folder():knownParent(false), knownId(false){} + Folder(qulonglong sid, qulonglong pid,QString fn, QString fp):knownParent(true), knownId(true){id = sid; parentId = pid;name = fn; path = fp;} + Folder(QString fn, QString fp):knownParent(false), knownId(false){name = fn; path = fp;} + Folder(const Folder &folder); + Folder &operator =(const Folder & other); + void setId(qulonglong sid){id = sid;knownId = true;} + void setFather(qulonglong pid){parentId = pid;knownParent = true;} + bool isDir() {return true;} + bool isFinished() const {return finished;} + bool isCompleted() const {return completed;} + void setFinished(bool b) {finished = b;} + void setCompleted(bool b) {completed = b;} private: bool finished; diff --git a/common/library_item.cpp b/common/library_item.cpp index e69de29b..3d92a6ee 100644 --- a/common/library_item.cpp +++ b/common/library_item.cpp @@ -0,0 +1,12 @@ + +#include "library_item.h" + +LibraryItem &LibraryItem::operator=(const LibraryItem &other) +{ + this->name = other.name; + this->path = other.path; + this->parentId = other.parentId; + this->id = other.id; + + return *this; +} diff --git a/common/library_item.h b/common/library_item.h index 2f6b8d9f..5ca1958e 100644 --- a/common/library_item.h +++ b/common/library_item.h @@ -3,14 +3,16 @@ #include -class LibraryItem +class LibraryItem : public QObject { + Q_OBJECT public: virtual bool isDir() = 0; + LibraryItem & operator=(const LibraryItem & other); QString name; QString path; qulonglong parentId; qulonglong id; }; -#endif \ No newline at end of file +#endif