1 #ifndef QTRESTCLIENT_SIMPLEBASE_H
2 #define QTRESTCLIENT_SIMPLEBASE_H
4 #include "QtRestClient/qtrestclient_global.h"
5 #include "QtRestClient/genericrestreply.h"
6 #include "QtRestClient/restclass.h"
10 #include <QtCore/qpointer.h>
11 #include <QtCore/qsharedpointer.h>
12 #include <QtCore/qscopedpointer.h>
17 template <
typename T,
typename =
void>
22 class Simple<T*, std::enable_if_t<std::is_base_of_v<QObject, T>>> :
public QObject
29 virtual QUrl extensionHref()
const = 0;
31 bool hasExtension()
const;
33 bool isExtended()
const;
38 T *currentExtended()
const;
43 template<
typename ET = QObject*>
57 template<
typename ET = QObject*>
59 std::function<
void(T*,
bool)> extensionHandler,
61 std::function<
QString(ET,
int)> failureTransformer = {});
74 template<
typename ET = QObject*>
77 std::function<
void(T*,
bool)> extensionHandler,
79 std::function<
QString(ET,
int)> failureTransformer = {});
89 class Simple<T, std::enable_if_t<std::is_void_v<typename T::QtGadgetHelper>>>
94 inline virtual ~
Simple() =
default;
97 virtual QUrl extensionHref()
const = 0;
99 bool hasExtension()
const;
101 bool isExtended()
const;
105 T currentExtended()
const;
110 template<
typename ET = QObject*>
124 template<
typename ET = QObject*>
126 std::function<
void(T,
bool)> extensionHandler,
128 std::function<
QString(ET,
int)> failureTransformer = {});
141 template<
typename ET = QObject*>
144 std::function<
void(T,
bool)> extensionHandler,
146 std::function<
QString(ET,
int)> failureTransformer = {});
157 #define QTRESTCLIENT_EXT_HREF_PROP(x) \
158 inline QUrl extensionHref() const override { \
159 return property(#x).toUrl();\
175 return extensionHref().isValid();
191 template<
typename ET>
194 if (hasExtension()) {
196 return client->
rootClass()->
get<T*, ET>(extensionHref())
197 ->onSucceeded([extRef](
int, T *data) {
206 template<
typename ET>
211 std::move(extensionHandler),
213 std::move(failureTransformer));
217 template<
typename ET>
218 void Simple<T*, std::enable_if_t<std::is_base_of_v<QObject, T>>>::extend(
RestClient *client,
QObject *scope, std::function<
void (T *,
bool)> extensionHandler,
const std::function<
void (
QString,
int,
RestReply::Error)> &errorHandler, std::function<
QString (ET,
int)> failureTransformer)
221 extensionHandler(ext(),
false);
222 else if(hasExtension()) {
225 ->onSucceeded(scope, [extRef, xEH = std::move(extensionHandler)](int, T *data){
230 ->onAllErrors(scope, errorHandler, std::move(failureTransformer));
256 return extensionHref().isValid();
269 return *(ext().data());
275 template<
typename ET>
278 if (hasExtension()) {
281 ->onSucceeded([extRef](
int, T data){
283 ext.data()->reset(
new T{data});
290 template<
typename ET>
294 extensionHandler(*(ext().data()),
false);
295 else if (hasExtension()) {
298 ->onSucceeded([extRef, xEH = std::move(extensionHandler)](int, T data){
300 ext.data()->reset(
new T{data});
303 ->onAllErrors(errorHandler, std::move(failureTransformer));
308 template<
typename ET>
312 extensionHandler(*(ext().data()),
false);
313 else if (hasExtension()) {
316 ->onSucceeded(scope, [extRef, xEH = std::move(extensionHandler)](int, T data){
318 ext.data()->reset(
new T{data});
321 ->onAllErrors(scope, errorHandler, std::move(failureTransformer));
339 #endif // QTRESTCLIENT_SIMPLEBASE_H