diff options
-rw-r--r-- | common/modelresult.cpp | 11 | ||||
-rw-r--r-- | common/modelresult.h | 1 | ||||
-rw-r--r-- | examples/client/main.cpp | 72 |
3 files changed, 58 insertions, 26 deletions
diff --git a/common/modelresult.cpp b/common/modelresult.cpp index 4fd8d97..d2a7e88 100644 --- a/common/modelresult.cpp +++ b/common/modelresult.cpp | |||
@@ -65,6 +65,17 @@ int ModelResult<T, Ptr>::columnCount(const QModelIndex &parent) const | |||
65 | } | 65 | } |
66 | 66 | ||
67 | template<class T, class Ptr> | 67 | template<class T, class Ptr> |
68 | QVariant ModelResult<T, Ptr>::headerData(int section, Qt::Orientation orientation, int role) const | ||
69 | { | ||
70 | if (role == Qt::DisplayRole) { | ||
71 | if (section < mPropertyColumns.size()) { | ||
72 | return mPropertyColumns.at(section); | ||
73 | } | ||
74 | } | ||
75 | return QVariant(); | ||
76 | } | ||
77 | |||
78 | template<class T, class Ptr> | ||
68 | QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const | 79 | QVariant ModelResult<T, Ptr>::data(const QModelIndex &index, int role) const |
69 | { | 80 | { |
70 | if (role == DomainObjectRole) { | 81 | if (role == DomainObjectRole) { |
diff --git a/common/modelresult.h b/common/modelresult.h index 298e157..ec62a67 100644 --- a/common/modelresult.h +++ b/common/modelresult.h | |||
@@ -45,6 +45,7 @@ public: | |||
45 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | 45 | int rowCount(const QModelIndex &parent = QModelIndex()) const; |
46 | int columnCount(const QModelIndex &parent = QModelIndex()) const; | 46 | int columnCount(const QModelIndex &parent = QModelIndex()) const; |
47 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | 47 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
48 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | ||
48 | QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; | 49 | QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; |
49 | QModelIndex parent(const QModelIndex &index) const; | 50 | QModelIndex parent(const QModelIndex &index) const; |
50 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const; | 51 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const; |
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index ac40fcb..31947e8 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -40,18 +40,6 @@ | |||
40 | #include <iostream> | 40 | #include <iostream> |
41 | 41 | ||
42 | template <typename T> | 42 | template <typename T> |
43 | QString format(const T &object) | ||
44 | { | ||
45 | QString output; | ||
46 | output.append(object->identifier()); | ||
47 | output.append(QStringLiteral("\t")); | ||
48 | output.append(object->getProperty("name").toString()); | ||
49 | output.append(QStringLiteral("\t")); | ||
50 | output.append(object->getProperty("parent").toString()); | ||
51 | return output; | ||
52 | } | ||
53 | |||
54 | template <typename T> | ||
55 | class View : public QWidget | 43 | class View : public QWidget |
56 | { | 44 | { |
57 | public: | 45 | public: |
@@ -98,7 +86,6 @@ public: | |||
98 | 86 | ||
99 | }; | 87 | }; |
100 | 88 | ||
101 | |||
102 | class MyApplication : public QApplication | 89 | class MyApplication : public QApplication |
103 | { | 90 | { |
104 | QElapsedTimer t; | 91 | QElapsedTimer t; |
@@ -118,6 +105,27 @@ public: | |||
118 | } | 105 | } |
119 | }; | 106 | }; |
120 | 107 | ||
108 | static QSharedPointer<QAbstractItemModel> loadModel(const QString &type, Akonadi2::Query query) | ||
109 | { | ||
110 | QTime time; | ||
111 | time.start(); | ||
112 | |||
113 | QSharedPointer<QAbstractItemModel> model; | ||
114 | if (type == "folder") { | ||
115 | query.requestedProperties << "name" << "parent"; | ||
116 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | ||
117 | } else if (type == "mail") { | ||
118 | query.requestedProperties << "subject" << "folder"; | ||
119 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Mail>(query); | ||
120 | } else if (type == "event") { | ||
121 | query.requestedProperties << "summary"; | ||
122 | model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Event>(query); | ||
123 | } | ||
124 | qDebug() << "Folder type " << type; | ||
125 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
126 | return model; | ||
127 | } | ||
128 | |||
121 | int main(int argc, char *argv[]) | 129 | int main(int argc, char *argv[]) |
122 | { | 130 | { |
123 | MyApplication app(argc, argv); | 131 | MyApplication app(argc, argv); |
@@ -127,6 +135,7 @@ int main(int argc, char *argv[]) | |||
127 | QObject::tr("A resource to connect to")); | 135 | QObject::tr("A resource to connect to")); |
128 | cliOptions.addOption(QCommandLineOption("clear")); | 136 | cliOptions.addOption(QCommandLineOption("clear")); |
129 | cliOptions.addOption(QCommandLineOption("debuglevel")); | 137 | cliOptions.addOption(QCommandLineOption("debuglevel")); |
138 | cliOptions.addOption(QCommandLineOption("type", "type to list", "type")); | ||
130 | cliOptions.addOption(QCommandLineOption("list")); | 139 | cliOptions.addOption(QCommandLineOption("list")); |
131 | cliOptions.addOption(QCommandLineOption("count")); | 140 | cliOptions.addOption(QCommandLineOption("count")); |
132 | cliOptions.addOption(QCommandLineOption("synchronize")); | 141 | cliOptions.addOption(QCommandLineOption("synchronize")); |
@@ -161,21 +170,26 @@ int main(int argc, char *argv[]) | |||
161 | } | 170 | } |
162 | query.syncOnDemand = false; | 171 | query.syncOnDemand = false; |
163 | query.processAll = false; | 172 | query.processAll = false; |
164 | query.requestedProperties << "name"; | ||
165 | query.liveQuery = true; | 173 | query.liveQuery = true; |
166 | 174 | ||
167 | QTime time; | 175 | const auto type = cliOptions.value("type"); |
168 | time.start(); | 176 | qDebug() << "Type: " << type; |
169 | 177 | ||
170 | if (cliOptions.isSet("list")) { | 178 | if (cliOptions.isSet("list")) { |
171 | query.liveQuery = false; | 179 | query.liveQuery = false; |
172 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 180 | auto model = loadModel(type, query); |
173 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
174 | qDebug() << "Listing"; | 181 | qDebug() << "Listing"; |
182 | std::cout << "\tColumn\t "; | ||
183 | for (int i = 0; i < model->columnCount(QModelIndex()); i++) { | ||
184 | std::cout << "\t" << model->headerData(i, Qt::Horizontal).toString().toStdString() << std::endl; | ||
185 | } | ||
175 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | 186 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { |
176 | for (int i = start; i <= end; i++) { | 187 | for (int i = start; i <= end; i++) { |
177 | QString output = format<Akonadi2::ApplicationDomain::Folder::Ptr>(model->data(model->index(i, 0, index), Akonadi2::Store::DomainObjectRole).value<Akonadi2::ApplicationDomain::Folder::Ptr>()); | 188 | std::cout << "\tRow " << model->rowCount() << ":\t "; |
178 | std::cout << "\tRow " << model->rowCount() << ": " << output.toStdString() << std::endl; | 189 | for (int col = 0; col < model->columnCount(QModelIndex()); col++) { |
190 | std::cout << "\t" << model->data(model->index(i, col, index)).toString().toStdString(); | ||
191 | } | ||
192 | std::cout << std::endl; | ||
179 | } | 193 | } |
180 | }); | 194 | }); |
181 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { | 195 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
@@ -188,8 +202,7 @@ int main(int argc, char *argv[]) | |||
188 | } | 202 | } |
189 | } else if (cliOptions.isSet("count")) { | 203 | } else if (cliOptions.isSet("count")) { |
190 | query.liveQuery = false; | 204 | query.liveQuery = false; |
191 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 205 | auto model = loadModel(type, query); |
192 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
193 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { | 206 | QObject::connect(model.data(), &QAbstractItemModel::dataChanged, [model, &app](const QModelIndex &, const QModelIndex &, const QVector<int> &roles) { |
194 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { | 207 | if (roles.contains(Akonadi2::Store::ChildrenFetchedRole)) { |
195 | std::cout << "\tCounted results " << model->rowCount(QModelIndex()); | 208 | std::cout << "\tCounted results " << model->rowCount(QModelIndex()); |
@@ -207,15 +220,22 @@ int main(int argc, char *argv[]) | |||
207 | } else { | 220 | } else { |
208 | query.parentProperty = "parent"; | 221 | query.parentProperty = "parent"; |
209 | query.liveQuery = true; | 222 | query.liveQuery = true; |
210 | auto model = Akonadi2::Store::loadModel<Akonadi2::ApplicationDomain::Folder>(query); | 223 | auto model = loadModel(type, query); |
211 | qDebug() << "Loaded model in " << time.elapsed() << " ms"; | ||
212 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { | 224 | QObject::connect(model.data(), &QAbstractItemModel::rowsInserted, [model](const QModelIndex &index, int start, int end) { |
213 | for (int i = start; i <= end; i++) { | 225 | for (int i = start; i <= end; i++) { |
214 | model->fetchMore(model->index(i, 0, index)); | 226 | model->fetchMore(model->index(i, 0, index)); |
215 | } | 227 | } |
216 | }); | 228 | }); |
217 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); | 229 | if (type == "folder") { |
218 | return app.exec(); | 230 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Folder> >::create(model.data()); |
231 | app.exec(); | ||
232 | } else if (type == "mail") { | ||
233 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Mail> >::create(model.data()); | ||
234 | app.exec(); | ||
235 | } else if (type == "event") { | ||
236 | auto view = QSharedPointer<View<Akonadi2::ApplicationDomain::Event> >::create(model.data()); | ||
237 | app.exec(); | ||
238 | } | ||
219 | } | 239 | } |
220 | return 0; | 240 | return 0; |
221 | } | 241 | } |