From 24367932e04d5f856e498c08230405b0513c3fe7 Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Mon, 14 Nov 2016 07:46:41 +0900 Subject: [PATCH] Update qtlibs --- src/libs/qtlibs/config.cpp | 17 ++++++- src/libs/qtlibs/config.h | 5 +- src/libs/qtlibs/dir.cpp | 17 ++++++- src/libs/qtlibs/dir.h | 5 +- src/libs/qtlibs/file.cpp | 17 ++++++- src/libs/qtlibs/file.h | 5 +- src/libs/qtlibs/json.cpp | 75 ++++++++++++++++++----------- src/libs/qtlibs/json.h | 14 ++++-- src/libs/qtlibs/networkresource.cpp | 31 +++++++++++- src/libs/qtlibs/networkresource.h | 5 +- src/libs/qtlibs/package.cpp | 17 ++++++- src/libs/qtlibs/package.h | 5 +- 12 files changed, 164 insertions(+), 49 deletions(-) diff --git a/src/libs/qtlibs/config.cpp b/src/libs/qtlibs/config.cpp index 2dd6fc9..2400224 100644 --- a/src/libs/qtlibs/config.cpp +++ b/src/libs/qtlibs/config.cpp @@ -17,10 +17,23 @@ namespace qtlibs { -Config::Config(const QString &configDirPath, QObject *parent) : - QObject(parent), configDirPath_(configDirPath) +Config::Config(const QString &configDirPath, QObject *parent) + : QObject(parent), configDirPath_(configDirPath) {} +Config::Config(const Config &other) +{ + this->setParent(other.parent()); + setConfigDirPath(other.configDirPath()); +} + +Config &Config::operator =(const Config &other) +{ + this->setParent(other.parent()); + setConfigDirPath(other.configDirPath()); + return *this; +} + QString Config::configDirPath() const { return configDirPath_; diff --git a/src/libs/qtlibs/config.h b/src/libs/qtlibs/config.h index 567fbfe..5f0df5f 100644 --- a/src/libs/qtlibs/config.h +++ b/src/libs/qtlibs/config.h @@ -21,7 +21,10 @@ class Config : public QObject Q_OBJECT public: - explicit Config(const QString &configDirPath, QObject *parent = 0); + explicit Config(const QString &configDirPath = QString(), QObject *parent = 0); + + Config(const Config &other); + Config &operator =(const Config &other); QString configDirPath() const; void setConfigDirPath(const QString &configDirPath); diff --git a/src/libs/qtlibs/dir.cpp b/src/libs/qtlibs/dir.cpp index e244881..e0b579a 100644 --- a/src/libs/qtlibs/dir.cpp +++ b/src/libs/qtlibs/dir.cpp @@ -18,10 +18,23 @@ namespace qtlibs { -Dir::Dir(const QString &path, QObject *parent) : - QObject(parent), path_(path) +Dir::Dir(const QString &path, QObject *parent) + : QObject(parent), path_(path) {} +Dir::Dir(const Dir &other) +{ + this->setParent(other.parent()); + setPath(other.path()); +} + +Dir &Dir::operator =(const Dir &other) +{ + this->setParent(other.parent()); + setPath(other.path()); + return *this; +} + QString Dir::path() const { return path_; diff --git a/src/libs/qtlibs/dir.h b/src/libs/qtlibs/dir.h index cf0b907..31e63a5 100644 --- a/src/libs/qtlibs/dir.h +++ b/src/libs/qtlibs/dir.h @@ -21,7 +21,10 @@ class Dir : public QObject Q_OBJECT public: - explicit Dir(const QString &path, QObject *parent = 0); + explicit Dir(const QString &path = QString(), QObject *parent = 0); + + Dir(const Dir &other); + Dir &operator =(const Dir &other); QString path() const; void setPath(const QString &path); diff --git a/src/libs/qtlibs/file.cpp b/src/libs/qtlibs/file.cpp index 7bb4ef7..d092cfa 100644 --- a/src/libs/qtlibs/file.cpp +++ b/src/libs/qtlibs/file.cpp @@ -17,10 +17,23 @@ namespace qtlibs { -File::File(const QString &path, QObject *parent) : - QObject(parent), path_(path) +File::File(const QString &path, QObject *parent) + : QObject(parent), path_(path) {} +File::File(const File &other) +{ + this->setParent(other.parent()); + setPath(other.path()); +} + +File &File::operator =(const File &other) +{ + this->setParent(other.parent()); + setPath(other.path()); + return *this; +} + QString File::path() const { return path_; diff --git a/src/libs/qtlibs/file.h b/src/libs/qtlibs/file.h index 2e23cdc..bfc1389 100644 --- a/src/libs/qtlibs/file.h +++ b/src/libs/qtlibs/file.h @@ -20,7 +20,10 @@ class File : public QObject Q_OBJECT public: - explicit File(const QString &path, QObject *parent = 0); + explicit File(const QString &path = QString(), QObject *parent = 0); + + File(const File &other); + File &operator =(const File &other); QString path() const; void setPath(const QString &path); diff --git a/src/libs/qtlibs/json.cpp b/src/libs/qtlibs/json.cpp index 2ea9f1c..1cddfe0 100644 --- a/src/libs/qtlibs/json.cpp +++ b/src/libs/qtlibs/json.cpp @@ -16,28 +16,33 @@ namespace qtlibs { -Json::Json(const QByteArray &json, QObject *parent) : - QObject(parent), json_(json) +Json::Json(const QByteArray &json, QObject *parent) + : QObject(parent), json_(json) {} -Json::Json(const QString &string, QObject *parent) : - QObject(parent) +Json::Json(const QJsonObject &object, QObject *parent) + : QObject(parent) { - setJson(string.toUtf8()); + fromObject(object); } -Json::Json(const QJsonObject &object, QObject *parent) : - QObject(parent) +Json::Json(const QJsonArray &array, QObject *parent) + : QObject(parent) { - QJsonDocument doc(object); - setJson(doc.toJson()); + fromArray(array); } -Json::Json(const QJsonArray &array, QObject *parent) : - QObject(parent) +Json::Json(const Json &other) { - QJsonDocument doc(array); - setJson(doc.toJson()); + this->setParent(other.parent()); + setJson(other.json()); +} + +Json &Json::operator =(const Json &other) +{ + this->setParent(other.parent()); + setJson(other.json()); + return *this; } QByteArray Json::json() const @@ -50,26 +55,16 @@ void Json::setJson(const QByteArray &json) json_ = json; } -bool Json::isValid() +void Json::fromObject(const QJsonObject &object) { - QJsonParseError parseError; - QJsonDocument::fromJson(json(), &parseError); - if (parseError.error == QJsonParseError::NoError) { - return true; - } - return false; -} - -bool Json::isObject() -{ - QJsonDocument doc = QJsonDocument::fromJson(json()); - return doc.isObject(); + QJsonDocument doc(object); + setJson(doc.toJson()); } -bool Json::isArray() +void Json::fromArray(const QJsonArray &array) { - QJsonDocument doc = QJsonDocument::fromJson(json()); - return doc.isArray(); + QJsonDocument doc(array); + setJson(doc.toJson()); } QByteArray Json::toJson() @@ -90,4 +85,26 @@ QJsonArray Json::toArray() return doc.array(); } +bool Json::isValid() +{ + QJsonParseError parseError; + QJsonDocument::fromJson(json(), &parseError); + if (parseError.error == QJsonParseError::NoError) { + return true; + } + return false; +} + +bool Json::isObject() +{ + QJsonDocument doc = QJsonDocument::fromJson(json()); + return doc.isObject(); +} + +bool Json::isArray() +{ + QJsonDocument doc = QJsonDocument::fromJson(json()); + return doc.isArray(); +} + } // namespace qtlibs diff --git a/src/libs/qtlibs/json.h b/src/libs/qtlibs/json.h index ae9bee5..9d6cd4e 100644 --- a/src/libs/qtlibs/json.h +++ b/src/libs/qtlibs/json.h @@ -22,20 +22,24 @@ class Json : public QObject Q_OBJECT public: - explicit Json(const QByteArray &json, QObject *parent = 0); - explicit Json(const QString &string, QObject *parent = 0); + explicit Json(const QByteArray &json = QByteArray(), QObject *parent = 0); explicit Json(const QJsonObject &object, QObject *parent = 0); explicit Json(const QJsonArray &array, QObject *parent = 0); + Json(const Json &other); + Json &operator =(const Json &other); + QByteArray json() const; void setJson(const QByteArray &json); - bool isValid(); - bool isObject(); - bool isArray(); + void fromObject(const QJsonObject &object); + void fromArray(const QJsonArray &array); QByteArray toJson(); QJsonObject toObject(); QJsonArray toArray(); + bool isValid(); + bool isObject(); + bool isArray(); private: QByteArray json_; diff --git a/src/libs/qtlibs/networkresource.cpp b/src/libs/qtlibs/networkresource.cpp index 74b24d3..16238f0 100644 --- a/src/libs/qtlibs/networkresource.cpp +++ b/src/libs/qtlibs/networkresource.cpp @@ -17,8 +17,8 @@ namespace qtlibs { -NetworkResource::NetworkResource(const QString &name, const QUrl &url, const bool &async, QObject *parent) : - QObject(parent), name_(name), url_(url), async_(async) +NetworkResource::NetworkResource(const QString &name, const QUrl &url, const bool &async, QObject *parent) + : QObject(parent), name_(name), url_(url), async_(async) { setManager(new QNetworkAccessManager(this)); } @@ -28,6 +28,33 @@ NetworkResource::~NetworkResource() manager()->deleteLater(); } +NetworkResource::NetworkResource(const NetworkResource &other) +{ + this->setParent(other.parent()); + setName(other.name()); + setUrl(other.url()); + setAsync(other.async()); + setRequest(other.request()); + setManager(other.manager()); + setReply(other.reply()); + setMethod(other.method()); +} + +NetworkResource &NetworkResource::operator =(const NetworkResource &other) +{ + manager()->deleteLater(); + + this->setParent(other.parent()); + setName(other.name()); + setUrl(other.url()); + setAsync(other.async()); + setRequest(other.request()); + setManager(other.manager()); + setReply(other.reply()); + setMethod(other.method()); + return *this; +} + QString NetworkResource::name() const { return name_; diff --git a/src/libs/qtlibs/networkresource.h b/src/libs/qtlibs/networkresource.h index 23e11f3..4186ee6 100644 --- a/src/libs/qtlibs/networkresource.h +++ b/src/libs/qtlibs/networkresource.h @@ -24,9 +24,12 @@ class NetworkResource : public QObject Q_OBJECT public: - explicit NetworkResource(const QString &name, const QUrl &url, const bool &async = true, QObject *parent = 0); + explicit NetworkResource(const QString &name = QString(), const QUrl &url = QUrl(), const bool &async = true, QObject *parent = 0); ~NetworkResource(); + NetworkResource(const NetworkResource &other); + NetworkResource &operator =(const NetworkResource &other); + QString name() const; void setName(const QString &name); QUrl url() const; diff --git a/src/libs/qtlibs/package.cpp b/src/libs/qtlibs/package.cpp index 8869b01..d857f14 100644 --- a/src/libs/qtlibs/package.cpp +++ b/src/libs/qtlibs/package.cpp @@ -23,10 +23,23 @@ namespace qtlibs { -Package::Package(const QString &path, QObject *parent) : - QObject(parent), path_(path) +Package::Package(const QString &path, QObject *parent) + : QObject(parent), path_(path) {} +Package::Package(const Package &other) +{ + this->setParent(other.parent()); + setPath(other.path()); +} + +Package &Package::operator =(const Package &other) +{ + this->setParent(other.parent()); + setPath(other.path()); + return *this; +} + QString Package::path() const { return path_; diff --git a/src/libs/qtlibs/package.h b/src/libs/qtlibs/package.h index 3f22b52..b11e775 100644 --- a/src/libs/qtlibs/package.h +++ b/src/libs/qtlibs/package.h @@ -20,7 +20,10 @@ class Package : public QObject Q_OBJECT public: - explicit Package(const QString &path, QObject *parent = 0); + explicit Package(const QString &path = QString(), QObject *parent = 0); + + Package(const Package &other); + Package &operator =(const Package &other); QString path() const; void setPath(const QString &path); -- GitLab