diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-08-22 16:17:38 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-08-22 16:22:56 +0900 |
commit | fb6df81fa9f224c94118fd79fea91ae15559c7e3 (patch) | |
tree | c5409c28a1baf1d78dd32358e8fa045dfdb69d28 /events | |
parent | c2e38f28987b4fa273765b4234c6a57bdf75e446 (diff) | |
download | libquotient-fb6df81fa9f224c94118fd79fea91ae15559c7e3.tar.gz libquotient-fb6df81fa9f224c94118fd79fea91ae15559c7e3.zip |
Replaced QList<> with QVector<> where appropriate + minor code cleanup
See https://marcmutz.wordpress.com/effective-qt/containers/ for the background and http://lists.qt-project.org/pipermail/development/2015-July/022283.html for the relevant flamewar in Qt dev mailing list.
Diffstat (limited to 'events')
-rw-r--r-- | events/receiptevent.cpp | 24 | ||||
-rw-r--r-- | events/receiptevent.h | 6 |
2 files changed, 12 insertions, 18 deletions
diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp index d2a27079..29d78a20 100644 --- a/events/receiptevent.cpp +++ b/events/receiptevent.cpp @@ -41,17 +41,11 @@ Example of a Receipt Event: using namespace QMatrixClient; -Receipt::Receipt(QString event, QString user, QDateTime time) - : eventId(event) - , userId(user) - , timestamp(time) -{ -} class ReceiptEvent::Private { public: - QHash<QString, QList<Receipt>> eventToReceipts; + QHash<QString, Receipts> eventToReceipts; }; ReceiptEvent::ReceiptEvent() @@ -65,7 +59,7 @@ ReceiptEvent::~ReceiptEvent() delete d; } -QList<Receipt> ReceiptEvent::receiptsForEvent(QString eventId) const +Receipts ReceiptEvent::receiptsForEvent(QString eventId) const { return d->eventToReceipts.value(eventId); } @@ -79,17 +73,17 @@ ReceiptEvent* ReceiptEvent::fromJson(const QJsonObject& obj) { ReceiptEvent* e = new ReceiptEvent(); e->parseJson(obj); - const QJsonObject contents = obj.value("content").toObject(); + const QJsonObject contents = obj["content"].toObject(); + e->d->eventToReceipts.reserve(contents.size()); for( const QString& eventId: contents.keys() ) { - QJsonObject reads = contents.value(eventId).toObject().value("m.read").toObject(); - QList<Receipt> receipts; + const QJsonObject reads = contents[eventId].toObject().value("m.read").toObject(); + Receipts receipts(reads.size()); for( const QString& userId: reads.keys() ) { - QJsonObject user = reads.value(userId).toObject(); - QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user.value("ts").toDouble(), Qt::UTC ); - Receipt receipt(eventId, userId, time); - receipts.append(receipt); + const QJsonObject user = reads[userId].toObject(); + const QDateTime time = QDateTime::fromMSecsSinceEpoch( (quint64) user["ts"].toDouble(), Qt::UTC ); + receipts.push_back({ eventId, userId, time }); } e->d->eventToReceipts.insert(eventId, receipts); } diff --git a/events/receiptevent.h b/events/receiptevent.h index aa72ba90..028bf0f6 100644 --- a/events/receiptevent.h +++ b/events/receiptevent.h @@ -31,9 +31,8 @@ namespace QMatrixClient QString eventId; QString userId; QDateTime timestamp; - - Receipt(QString event, QString user, QDateTime time); }; + using Receipts = QVector<Receipt>; class ReceiptEvent: public Event { @@ -41,7 +40,7 @@ namespace QMatrixClient ReceiptEvent(); virtual ~ReceiptEvent(); - QList<Receipt> receiptsForEvent(QString eventId) const; + Receipts receiptsForEvent(QString eventId) const; QStringList events() const; @@ -52,5 +51,6 @@ namespace QMatrixClient Private* d; }; } +Q_DECLARE_TYPEINFO(QMatrixClient::Receipt, Q_MOVABLE_TYPE); #endif // QMATRIXCLIENT_RECEIPTEVENT_H |