diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 18:46:50 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-11-30 18:46:50 +0100 |
commit | 6ad307dd846d07f1b55a1679a8d2eb47525af57d (patch) | |
tree | 3190a317306cfb71b0d5d9bc4c0f06b260a92ce6 /examples/client/main.cpp | |
parent | 0c744f0f14836ee70ca675135a9ca4cef080baa3 (diff) | |
download | sink-6ad307dd846d07f1b55a1679a8d2eb47525af57d.tar.gz sink-6ad307dd846d07f1b55a1679a8d2eb47525af57d.zip |
example client: slot performance measurements, async commands
Diffstat (limited to 'examples/client/main.cpp')
-rw-r--r-- | examples/client/main.cpp | 47 |
1 files changed, 43 insertions, 4 deletions
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 @@ | |||
20 | #include <QApplication> | 20 | #include <QApplication> |
21 | #include <QCommandLineParser> | 21 | #include <QCommandLineParser> |
22 | #include <QCommandLineOption> | 22 | #include <QCommandLineOption> |
23 | #include <QElapsedTimer> | ||
23 | 24 | ||
24 | #include "common/clientapi.h" | 25 | #include "common/clientapi.h" |
25 | #include "common/resource.h" | 26 | #include "common/resource.h" |
@@ -36,6 +37,7 @@ | |||
36 | #include <QLabel> | 37 | #include <QLabel> |
37 | #include <QPushButton> | 38 | #include <QPushButton> |
38 | #include <QItemSelectionModel> | 39 | #include <QItemSelectionModel> |
40 | #include <iostream> | ||
39 | 41 | ||
40 | template <typename T> | 42 | template <typename T> |
41 | class View : public QWidget | 43 | class View : public QWidget |
@@ -84,9 +86,29 @@ public: | |||
84 | 86 | ||
85 | }; | 87 | }; |
86 | 88 | ||
89 | |||
90 | class MyApplication : public QApplication | ||
91 | { | ||
92 | QElapsedTimer t; | ||
93 | public: | ||
94 | MyApplication(int& argc, char ** argv) : QApplication(argc, argv) { } | ||
95 | virtual ~MyApplication() { } | ||
96 | |||
97 | virtual bool notify(QObject* receiver, QEvent* event) | ||
98 | { | ||
99 | t.start(); | ||
100 | bool ret = QApplication::notify(receiver, event); | ||
101 | if(t.elapsed() > 3) | ||
102 | qDebug("processing event type %d for object %s took %dms", | ||
103 | (int)event->type(), receiver->objectName().toLocal8Bit().data(), | ||
104 | (int)t.elapsed()); | ||
105 | return ret; | ||
106 | } | ||
107 | }; | ||
108 | |||
87 | int main(int argc, char *argv[]) | 109 | int main(int argc, char *argv[]) |
88 | { | 110 | { |
89 | QApplication app(argc, argv); | 111 | MyApplication app(argc, argv); |
90 | 112 | ||
91 | QCommandLineParser cliOptions; | 113 | QCommandLineParser cliOptions; |
92 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), | 114 | cliOptions.addPositionalArgument(QObject::tr("[resource]"), |
@@ -129,19 +151,36 @@ int main(int argc, char *argv[]) | |||
129 | query.requestedProperties << "name"; | 151 | query.requestedProperties << "name"; |
130 | query.liveQuery = true; | 152 | query.liveQuery = true; |
131 | 153 | ||
154 | QTime time; | ||
155 | time.start(); | ||
132 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 156 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); |
157 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
158 | |||
133 | if (cliOptions.isSet("list")) { | 159 | if (cliOptions.isSet("list")) { |
134 | query.liveQuery = false; | 160 | query.liveQuery = false; |
135 | qDebug() << "Listing"; | 161 | qDebug() << "Listing"; |
136 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | 162 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { |
137 | for (int i = start; i <= end; i++) { | 163 | for (int i = start; i <= end; i++) { |
138 | qDebug() << model->data(model->index(i, 0, index)).toString(); | 164 | std::cout << "\tRow " << model->rowCount() << ": " << model->data(model->index(i, 0, index)).toString().toStdString() << std::endl; |
139 | } | 165 | } |
140 | }); | 166 | }); |
141 | return app.exec(); | 167 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
168 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { | ||
169 | app.quit(); | ||
170 | } | ||
171 | }); | ||
172 | if (!model->data(QModelIndex(), Akonadi2::Store::ChildrenFetchedRole).toBool()) { | ||
173 | return app.exec(); | ||
174 | } | ||
142 | } else if (cliOptions.isSet("count")) { | 175 | } else if (cliOptions.isSet("count")) { |
143 | query.liveQuery = false; | 176 | query.liveQuery = false; |
144 | qDebug() << "Counted results " << model->rowCount(QModelIndex()); | 177 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
178 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { | ||
179 | std::cout << "\tCounted results " << model->rowCount(QModelIndex()); | ||
180 | app.quit(); | ||
181 | } | ||
182 | }); | ||
183 | return app.exec(); | ||
145 | } else { | 184 | } else { |
146 | query.liveQuery = true; | 185 | query.liveQuery = true; |
147 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); | 186 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); |