From 6ad307dd846d07f1b55a1679a8d2eb47525af57d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 30 Nov 2015 18:46:50 +0100 Subject: example client: slot performance measurements, async commands --- examples/client/main.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 7e69c0a..2aeb328 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "common/clientapi.h" #include "common/resource.h" @@ -36,6 +37,7 @@ #include #include #include +#include template class View : public QWidget @@ -84,9 +86,29 @@ public: }; + +class MyApplication : public QApplication +{ + QElapsedTimer t; +public: + MyApplication(int& argc, char ** argv) : QApplication(argc, argv) { } + virtual ~MyApplication() { } + + virtual bool notify(QObject* receiver, QEvent* event) + { + t.start(); + bool ret = QApplication::notify(receiver, event); + if(t.elapsed() > 3) + qDebug("processing event type %d for object %s took %dms", + (int)event->type(), receiver->objectName().toLocal8Bit().data(), + (int)t.elapsed()); + return ret; + } +}; + int main(int argc, char *argv[]) { - QApplication app(argc, argv); + MyApplication app(argc, argv); QCommandLineParser cliOptions; cliOptions.addPositionalArgument(QObject::tr("[resource]"), @@ -129,19 +151,36 @@ int main(int argc, char *argv[]) query.requestedProperties << "name"; query.liveQuery = true; + QTime time; + time.start(); auto model = Akonadi2::Store::loadModel(query); + qDebug() << "Loaded model in " << time.elapsed() << " ms"; + if (cliOptions.isSet("list")) { query.liveQuery = false; qDebug() << "Listing"; QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { for (int i = start; i <= end; i++) { - qDebug() << model->data(model->index(i, 0, index)).toString(); + std::cout << "\tRow " << model->rowCount() << ": " << model->data(model->index(i, 0, index)).toString().toStdString() << std::endl; } }); - return app.exec(); + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + app.quit(); + } + }); + if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { + return app.exec(); + } } else if (cliOptions.isSet("count")) { query.liveQuery = false; - qDebug() << "Counted results " << model->rowCount(QModelIndex()); + QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector &roles) { + if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { + std::cout << "\tCounted results " << model->rowCount(QModelIndex()); + app.quit(); + } + }); + return app.exec(); } else { query.liveQuery = true; auto view = QSharedPointer >::create(model.data()); -- cgit v1.2.3