summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2019-04-15 14:39:33 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2019-05-08 16:58:02 +0000
commit4a62812faae53c0dbaecdcb3ff66e0608c2da912 (patch)
tree374b3e9d7864de7a5da52c461c954023f04a2257
parent533f5973e63d5c462bdffe273792063b624da56f (diff)
downloadqtivi-4a62812faae53c0dbaecdcb3ff66e0608c2da912.tar.gz
Refactor the QIviSearchAndBrowseModelInterface
The refactoring is needed to better support async backends e.g. QtRO. Change-Id: I10d8e9fd34afb05443d8ebdeb225385178e9b88f Fixes: AUTOSUITE-928 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--src/ivicore/ivicore.pro1
-rw-r--r--src/ivicore/qivipagingmodel.cpp8
-rw-r--r--src/ivicore/qivisearchandbrowsemodel.cpp157
-rw-r--r--src/ivicore/qivisearchandbrowsemodel.h7
-rw-r--r--src/ivicore/qivisearchandbrowsemodel_p.h11
-rw-r--r--src/ivicore/qivisearchandbrowsemodelinterface.cpp167
-rw-r--r--src/ivicore/qivisearchandbrowsemodelinterface.h33
-rw-r--r--src/ivicore/qivisearchandbrowsemodelinterface_p.h73
-rw-r--r--src/ivicore/qtivicoremodule.cpp16
-rw-r--r--src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp82
-rw-r--r--src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h15
-rw-r--r--src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp74
-rw-r--r--src/plugins/ivimedia/media_simulator/usbbrowsebackend.h22
-rw-r--r--src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp65
-rw-r--r--src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h14
-rw-r--r--tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp95
16 files changed, 419 insertions, 421 deletions
diff --git a/src/ivicore/ivicore.pro b/src/ivicore/ivicore.pro
index 67e9964..bc0c722 100644
--- a/src/ivicore/ivicore.pro
+++ b/src/ivicore/ivicore.pro
@@ -44,7 +44,6 @@ HEADERS += \
qivisearchandbrowsemodel.h \
qivisearchandbrowsemodel_p.h \
qivisearchandbrowsemodelinterface.h \
- qivisearchandbrowsemodelinterface_p.h \
qivistandarditem.h \
qivifeatureinterface.h \
qividefaultpropertyoverrider_p.h \
diff --git a/src/ivicore/qivipagingmodel.cpp b/src/ivicore/qivipagingmodel.cpp
index 99d4bad..224f1a3 100644
--- a/src/ivicore/qivipagingmodel.cpp
+++ b/src/ivicore/qivipagingmodel.cpp
@@ -431,11 +431,11 @@ QIviPagingModel::QIviPagingModel(QObject *parent)
The backend can return the final number of items for a specific request. This makes it possible to support the QIviPagingModel::DataChanged loading
type.
\value SupportsFiltering
- The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsSorting
- The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsAndConjunction
The backend supports handling multiple filters at the same time and these filters can be combined by using the AND conjunction.
\value SupportsOrConjunction
diff --git a/src/ivicore/qivisearchandbrowsemodel.cpp b/src/ivicore/qivisearchandbrowsemodel.cpp
index f926608..b4d83af 100644
--- a/src/ivicore/qivisearchandbrowsemodel.cpp
+++ b/src/ivicore/qivisearchandbrowsemodel.cpp
@@ -68,17 +68,9 @@ QIviSearchAndBrowseModelPrivate::~QIviSearchAndBrowseModelPrivate()
void QIviSearchAndBrowseModelPrivate::resetModel()
{
QIviSearchAndBrowseModelInterface* backend = searchBackend();
- if (backend)
- setAvailableContenTypes(backend->availableContentTypes().toList());
-
- checkType();
if (backend)
- backend->setContentType(m_identifier, m_contentType);
-
- parseQuery();
-
- QIviPagingModelPrivate::resetModel();
+ backend->setContentType(m_identifier, m_contentTypeRequested);
}
void QIviSearchAndBrowseModelPrivate::parseQuery()
@@ -99,7 +91,7 @@ void QIviSearchAndBrowseModelPrivate::parseQuery()
QIviQueryParser parser;
parser.setQuery(m_query);
- parser.setAllowedIdentifiers(searchBackend()->supportedIdentifiers(m_contentType));
+ parser.setAllowedIdentifiers(m_queryIdentifiers);
QIviAbstractQueryTerm* queryTerm = parser.parse();
@@ -128,19 +120,6 @@ void QIviSearchAndBrowseModelPrivate::setupFilter(QIviAbstractQueryTerm* queryTe
m_orderTerms = orderTerms;
}
-void QIviSearchAndBrowseModelPrivate::checkType()
-{
- if (!searchBackend() || m_contentType.isEmpty())
- return;
-
- if (!m_availableContentTypes.contains(m_contentType)) {
- QString error = QString(QStringLiteral("Unsupported type: \"%1\" \n Supported types are: \n")).arg(m_contentType);
- for (const QString &type : qAsConst(m_availableContentTypes))
- error.append(type + QLatin1String("\n"));
- qtivi_qmlOrCppWarning(q_ptr, error);
- }
-}
-
void QIviSearchAndBrowseModelPrivate::clearToDefaults()
{
QIviPagingModelPrivate::clearToDefaults();
@@ -148,12 +127,30 @@ void QIviSearchAndBrowseModelPrivate::clearToDefaults()
delete m_queryTerm;
m_queryTerm = nullptr;
m_contentType = QString();
+ m_contentTypeRequested = QString();
m_canGoBack = false;
m_availableContentTypes.clear();
+ m_canGoForward.clear();
}
-void QIviSearchAndBrowseModelPrivate::setCanGoBack(bool canGoBack)
+void QIviSearchAndBrowseModelPrivate::onCanGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start)
{
+ if (m_identifier != identifier)
+ return;
+
+ //Always keep the list size in sync;
+ m_canGoForward.resize(qMax(m_itemList.count(), indexes.count()));
+
+ //Update the list
+ for (int i = 0; i < indexes.count(); i++)
+ m_canGoForward[start + i] = indexes.at(i);
+}
+
+void QIviSearchAndBrowseModelPrivate::onCanGoBackChanged(const QUuid &identifier, bool canGoBack)
+{
+ if (m_identifier != identifier)
+ return;
+
Q_Q(QIviSearchAndBrowseModel);
if (m_canGoBack == canGoBack)
return;
@@ -162,7 +159,24 @@ void QIviSearchAndBrowseModelPrivate::setCanGoBack(bool canGoBack)
emit q->canGoBackChanged(m_canGoBack);
}
-void QIviSearchAndBrowseModelPrivate::setAvailableContenTypes(const QStringList &contentTypes)
+void QIviSearchAndBrowseModelPrivate::onContentTypeChanged(const QUuid &identifier, const QString &contentType)
+{
+ if (m_identifier != identifier)
+ return;
+
+ Q_Q(QIviSearchAndBrowseModel);
+ // Don't return if the content type is already correct. We still need to continue to update the
+ // query and start fetching again
+ if (m_contentType != contentType) {
+ m_contentType = contentType;
+ emit q->contentTypeChanged(m_contentType);
+ }
+ parseQuery();
+
+ QIviPagingModelPrivate::resetModel();
+}
+
+void QIviSearchAndBrowseModelPrivate::onAvailableContentTypesChanged(const QStringList &contentTypes)
{
Q_Q(QIviSearchAndBrowseModel);
if (m_availableContentTypes == contentTypes)
@@ -172,6 +186,14 @@ void QIviSearchAndBrowseModelPrivate::setAvailableContenTypes(const QStringList
emit q->availableContentTypesChanged(contentTypes);
}
+void QIviSearchAndBrowseModelPrivate::onQueryIdentifiersChanged(const QUuid &identifier, const QSet<QString> &queryIdentifiers)
+{
+ if (m_identifier != identifier)
+ return;
+
+ m_queryIdentifiers = queryIdentifiers;
+}
+
QIviSearchAndBrowseModelInterface *QIviSearchAndBrowseModelPrivate::searchBackend() const
{
return QIviAbstractFeatureListModelPrivate::backend<QIviSearchAndBrowseModelInterface*>();
@@ -181,12 +203,11 @@ void QIviSearchAndBrowseModelPrivate::updateContentType(const QString &contentTy
{
Q_Q(QIviSearchAndBrowseModel);
m_query = QString();
+ m_queryIdentifiers.clear();
emit q->queryChanged(m_query);
- m_contentType = contentType;
- emit q->contentTypeChanged(m_contentType);
-
- if (searchBackend())
- setCanGoBack(searchBackend()->canGoBack(m_identifier, m_contentType));
+ m_contentTypeRequested = contentType;
+ m_canGoForward.clear();
+ m_canGoBack = false;
resetModel();
}
@@ -530,7 +551,7 @@ QString QIviSearchAndBrowseModel::contentType() const
void QIviSearchAndBrowseModel::setContentType(const QString &contentType)
{
Q_D(QIviSearchAndBrowseModel);
- if (d->m_contentType == contentType)
+ if (d->m_contentTypeRequested == contentType)
return;
d->updateContentType(contentType);
@@ -616,14 +637,19 @@ void QIviSearchAndBrowseModel::goBack()
return;
}
- if (!backend->canGoBack(d->m_identifier, d->m_contentType)) {
+ if (!d->m_canGoBack) {
qtivi_qmlOrCppWarning(this, "Can't go backward anymore");
return;
}
- QString newContentType = backend->goBack(d->m_identifier, d->m_contentType);
- if (!newContentType.isEmpty())
- d->updateContentType(newContentType);
+ QIviPendingReply<QString> reply = backend->goBack(d->m_identifier);
+ reply.then([this, reply](const QString &value) {
+ Q_D(QIviSearchAndBrowseModel);
+ d->updateContentType(value);
+ },
+ [this]() {
+ qtivi_qmlOrCppWarning(this, "Going backward failed");
+ });
}
/*!
@@ -642,7 +668,7 @@ bool QIviSearchAndBrowseModel::canGoForward(int i) const
Q_D(const QIviSearchAndBrowseModel);
QIviSearchAndBrowseModelInterface *backend = d->searchBackend();
- if (i >= d->m_itemList.count() || i < 0)
+ if (i >= d->m_canGoForward.count() || i < 0)
return false;
if (!backend) {
@@ -650,11 +676,7 @@ bool QIviSearchAndBrowseModel::canGoForward(int i) const
return false;
}
- const QIviStandardItem *item = d->itemAt(i);
- if (!item)
- return false;
-
- return backend->canGoForward(d->m_identifier, d->m_contentType, item->id());
+ return d->m_canGoForward[i];
}
/*!
@@ -699,27 +721,36 @@ QIviSearchAndBrowseModel *QIviSearchAndBrowseModel::goForward(int i, NavigationT
return nullptr;
}
- const QIviStandardItem *item = d->itemAt(i);
- if (!item)
- return nullptr;
-
- if (!backend->canGoForward(d->m_identifier, d->m_contentType, item->id())) {
+ if (!d->m_canGoForward.value(i, false)) {
qtivi_qmlOrCppWarning(this, "Can't go forward anymore");
return nullptr;
}
if (navigationType == OutOfModelNavigation) {
if (d->m_capabilities.testFlag(QtIviCoreModule::SupportsStatelessNavigation)) {
- QString newContentType = backend->goForward(d->m_identifier, d->m_contentType, item->id());
- auto newModel = new QIviSearchAndBrowseModel(serviceObject(), newContentType);
+ QIviPendingReply<QString> reply = backend->goForward(d->m_identifier, i);
+ auto newModel = new QIviSearchAndBrowseModel(serviceObject());
+ reply.then([reply, newModel](const QString &value) {
+ newModel->setContentType(value);
+ },
+ [this]() {
+ qtivi_qmlOrCppWarning(this, "Going forward failed");
+ });
return newModel;
+
} else {
qtivi_qmlOrCppWarning(this, "The backend doesn't support the OutOfModelNavigation");
return nullptr;
}
} else {
- QString newContentType = backend->goForward(d->m_identifier, d->m_contentType, item->id());
- d->updateContentType(newContentType);
+ QIviPendingReply<QString> reply = backend->goForward(d->m_identifier, i);
+ reply.then([this, reply](const QString &value) {
+ Q_D(QIviSearchAndBrowseModel);
+ d->updateContentType(value);
+ },
+ [this]() {
+ qtivi_qmlOrCppWarning(this, "Going forward failed");
+ });
}
return nullptr;
@@ -762,7 +793,7 @@ QIviPendingReply<void> QIviSearchAndBrowseModel::insert(int index, const QVarian
return QIviPendingReply<void>::createFailedReply();
}
- return backend->insert(d->m_identifier, d->m_contentType, index, item);
+ return backend->insert(d->m_identifier, index, variant);
}
/*!
@@ -794,7 +825,7 @@ QIviPendingReply<void> QIviSearchAndBrowseModel::remove(int index)
return QIviPendingReply<void>::createFailedReply();
}
- return backend->remove(d->m_identifier, d->m_contentType, index);
+ return backend->remove(d->m_identifier, index);
}
/*!
@@ -826,7 +857,7 @@ QIviPendingReply<void> QIviSearchAndBrowseModel::move(int cur_index, int new_ind
return QIviPendingReply<void>::createFailedReply();
}
- return backend->move(d->m_identifier, d->m_contentType, cur_index, new_index);
+ return backend->move(d->m_identifier, cur_index, new_index);
}
/*!
@@ -857,7 +888,7 @@ QIviPendingReply<int> QIviSearchAndBrowseModel::indexOf(const QVariant &variant)
return QIviPendingReply<int>::createFailedReply();
}
- return backend->indexOf(d->m_identifier, d->m_contentType, item);
+ return backend->indexOf(d->m_identifier, variant);
}
/*!
@@ -876,11 +907,10 @@ QHash<int, QByteArray> QIviSearchAndBrowseModel::roleNames() const
/*!
\internal
*/
-QIviSearchAndBrowseModel::QIviSearchAndBrowseModel(QIviServiceObject *serviceObject, const QString &contentType, QObject *parent)
+QIviSearchAndBrowseModel::QIviSearchAndBrowseModel(QIviServiceObject *serviceObject, QObject *parent)
: QIviSearchAndBrowseModel(parent)
{
setServiceObject(serviceObject);
- setContentType(contentType);
}
/*!
@@ -902,11 +932,20 @@ void QIviSearchAndBrowseModel::connectToServiceObject(QIviServiceObject *service
if (!backend)
return;
- QIviPagingModel::connectToServiceObject(serviceObject);
+ QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::availableContentTypesChanged,
+ d, &QIviSearchAndBrowseModelPrivate::onAvailableContentTypesChanged);
+ QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::contentTypeChanged,
+ d, &QIviSearchAndBrowseModelPrivate::onContentTypeChanged);
+ QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::queryIdentifiersChanged,
+ d, &QIviSearchAndBrowseModelPrivate::onQueryIdentifiersChanged);
+ QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::canGoBackChanged,
+ d, &QIviSearchAndBrowseModelPrivate::onCanGoBackChanged);
+ QObjectPrivate::connect(backend, &QIviSearchAndBrowseModelInterface::canGoForwardChanged,
+ d, &QIviSearchAndBrowseModelPrivate::onCanGoForwardChanged);
- d->setCanGoBack(backend->canGoBack(d->m_identifier, d->m_contentType));
+ QIviPagingModel::connectToServiceObject(serviceObject);
- d->resetModel();
+ //once the initialization is done QIviPagingModel will reset the model
}
/*!
diff --git a/src/ivicore/qivisearchandbrowsemodel.h b/src/ivicore/qivisearchandbrowsemodel.h
index ee30861..4502604 100644
--- a/src/ivicore/qivisearchandbrowsemodel.h
+++ b/src/ivicore/qivisearchandbrowsemodel.h
@@ -107,13 +107,18 @@ Q_SIGNALS:
void canGoBackChanged(bool canGoBack);
protected:
- QIviSearchAndBrowseModel(QIviServiceObject *serviceObject, const QString &contentType, QObject *parent = nullptr);
+ QIviSearchAndBrowseModel(QIviServiceObject *serviceObject, QObject *parent = nullptr);
QIviSearchAndBrowseModel(QIviSearchAndBrowseModelPrivate &dd, QObject *parent);
void connectToServiceObject(QIviServiceObject *serviceObject) override;
void clearServiceObject() override;
private:
Q_DECLARE_PRIVATE(QIviSearchAndBrowseModel)
+ Q_PRIVATE_SLOT(d_func(), void onCanGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start))
+ Q_PRIVATE_SLOT(d_func(), void onCanGoBackChanged(const QUuid &identifier, bool canGoBack))
+ Q_PRIVATE_SLOT(d_func(), void onQueryIdentifiersChanged(const QUuid &identifier, const QSet<QString> &queryIdentifiers))
+ Q_PRIVATE_SLOT(d_func(), void onContentTypeChanged(const QUuid &identifier, const QString &contentType))
+ Q_PRIVATE_SLOT(d_func(), void onAvailableContentTypesChanged(const QStringList &contentTypes))
};
QT_END_NAMESPACE
diff --git a/src/ivicore/qivisearchandbrowsemodel_p.h b/src/ivicore/qivisearchandbrowsemodel_p.h
index 34fcfcc..b401cbe 100644
--- a/src/ivicore/qivisearchandbrowsemodel_p.h
+++ b/src/ivicore/qivisearchandbrowsemodel_p.h
@@ -76,10 +76,12 @@ public:
void resetModel() override;
void parseQuery();
void setupFilter(QIviAbstractQueryTerm* queryTerm, const QList<QIviOrderTerm> &orderTerms);
- void checkType();
void clearToDefaults() override;
- void setCanGoBack(bool canGoBack);
- void setAvailableContenTypes(const QStringList &contentTypes);
+ void onCanGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start);
+ void onCanGoBackChanged(const QUuid &identifier, bool canGoBack);
+ void onContentTypeChanged(const QUuid &identifier, const QString &contentType);
+ void onAvailableContentTypesChanged(const QStringList &contentTypes);
+ void onQueryIdentifiersChanged(const QUuid &identifier, const QSet<QString> &queryIdentifiers);
QIviSearchAndBrowseModelInterface *searchBackend() const;
void updateContentType(const QString &contentType);
@@ -92,8 +94,11 @@ public:
QIviAbstractQueryTerm *m_queryTerm;
QList<QIviOrderTerm> m_orderTerms;
+ QString m_contentTypeRequested;
QString m_contentType;
QStringList m_availableContentTypes;
+ QSet<QString> m_queryIdentifiers;
+ QVector<bool> m_canGoForward;
bool m_canGoBack;
};
diff --git a/src/ivicore/qivisearchandbrowsemodelinterface.cpp b/src/ivicore/qivisearchandbrowsemodelinterface.cpp
index 7a8081f..cea71cc 100644
--- a/src/ivicore/qivisearchandbrowsemodelinterface.cpp
+++ b/src/ivicore/qivisearchandbrowsemodelinterface.cpp
@@ -41,7 +41,6 @@
****************************************************************************/
#include "qivisearchandbrowsemodelinterface.h"
-#include "qivisearchandbrowsemodelinterface_p.h"
QT_BEGIN_NAMESPACE
@@ -67,71 +66,52 @@ QT_BEGIN_NAMESPACE
<example of a fully featured backend>
*/
-/*!
- \fn QIviSearchAndBrowseModelInterface::QIviSearchAndBrowseModelInterface(QObject *parent = nullptr)
-
- Constructs a backend interface.
-
- The \a parent is sent to the QObject constructor.
-*/
QIviSearchAndBrowseModelInterface::QIviSearchAndBrowseModelInterface(QObject *parent)
- : QIviPagingModelInterface(*new QIviSearchAndBrowseModelInterfacePrivate(), parent)
+ : QIviPagingModelInterface(parent)
{}
/*!
- Returns all the available content types for this backend instance.
+ \fn template <class T> QIviSearchAndBrowseModelInterface::identifiersFromItem()
- It's recommended to use the registerContentType() function instead, which takes care of this function for you.
-*/
-QSet<QString> QIviSearchAndBrowseModelInterface::availableContentTypes() const
-{
- Q_D(const QIviSearchAndBrowseModelInterface);
- return d->m_types;
-}
+ Returns all properties of type T.
-/*!
- Returns the available identifiers for the given \a contentType.
-
- Every identifier can be used in the \l {Qt IVI Query Language} for filtering or sorting.
-
- It's recommended to use the registerContentType() function instead, which takes care of this function for you.
-*/
-QSet<QString> QIviSearchAndBrowseModelInterface::supportedIdentifiers(const QString &contentType) const
-{
- Q_D(const QIviSearchAndBrowseModelInterface);
- return d->m_identifiers.values(contentType).toSet();
-}
-
-
-/*!
- \fn template <class T> QIviSearchAndBrowseModelInterface::registerContentType(const QString &contentType)
-
- Registers the type T with the name \a contentType.
- In addition all properties of type T will be registered as identifiers for the \l {Qt IVI Query Language}
+ These can registered as identifiers for the \l {Qt IVI Query Language} using the
+ queryIdentifiersChanged() signal.
*/
/*!
\internal
*/
-void QIviSearchAndBrowseModelInterface::registerContentType(const QMetaObject &object, const QString &contentType)
+QSet<QString> QIviSearchAndBrowseModelInterface::identifiersFromItem(const QMetaObject &object)
{
- Q_D(QIviSearchAndBrowseModelInterface);
+ QSet<QString> identifiers;
for (int i=0; i < object.propertyCount(); i++) {
QLatin1String propName(object.property(i).name());
if (propName != QLatin1String("objectName"))
- d->m_identifiers.insert(contentType, propName);
+ identifiers.insert(propName);
}
- d->m_types.insert(contentType);
+ return identifiers;
}
/*!
\fn void QIviSearchAndBrowseModelInterface::setContentType(const QUuid &identifier, const QString &contentType)
Sets the \a contentType of the QIviSearchAndBrowseModel instance identified by \a identifier.
- The given contenType can contain additional path information. The encoding is defined by by the
- goForward() method.
+ The given contenType can contain additional path information. The encoding is defined by the
+ goForward() method. In case the \a contentType is not valid the error() signal should be used.
+
+ \note The QIviSearchAndBrowseModel doesn't check the validity of the contentType, this is the backend's
+ responsibility.
+
+ If the QIviSearchAndBrowseModel supports filtering (see QIviPagingModel::capabilitiesChanged),
+ the backend needs to emit the queryIdentifiersChanged signal once the contentType is set.
- Calls to this function are followed by calls to setupFilter() and fetchData()
+ Finally, the contentTypeChanged signal needs to be emitted, when the backend has set the contentType
+ and it's ready for use.
+
+ Calls to this function are followed by calls to setupFilter() and fetchData().
+
+ \sa identifiersFromItem queryIdentifiersChanged contentTypeChanged
*/
/*!
@@ -145,74 +125,117 @@ void QIviSearchAndBrowseModelInterface::registerContentType(const QMetaObject &o
*/
/*!
- \fn bool QIviSearchAndBrowseModelInterface::canGoBack(const QUuid &identifier, const QString &type)
+ \fn QIviPendingReply<QString> QIviSearchAndBrowseModelInterface::goBack(const QUuid &identifier)
+
+ Requests to go back to the previous displayed data set of the QIviSearchAndBrowseModel instance identified by \a identifier.
- Returns true when the QIviSearchAndBrowseModel instance identified by \a identifier can go back and return to the previously shown data set.
- The \a type parameter holds the currently displayed content type.
+ The new content type is returned in the form of a QIviPendingReply. Once ready the new content type
+ must be set using setSuccess(), or using setFailed() if there's an error.
See \l Browsing for more information on how this is used.
- \sa goBack()
+ \sa canGoBackChanged()
*/
/*!
- \fn QString QIviSearchAndBrowseModelInterface::goBack(const QUuid &identifier, const QString &type)
+ \fn QIviPendingReply<QString> QIviSearchAndBrowseModelInterface::goForward(const QUuid &identifier, int index)
- Requests to go back to the previous displayed data set of the QIviSearchAndBrowseModel instance identified by \a identifier.
- The current content type is passed as \a type and the new content type should be returned.
+ Requests to go to the next data set of the QIviSearchAndBrowseModel instance identified by \a identifier at \a index.
+
+ The new content type is returned in the form of a QIviPendingReply. Once ready the new content type
+ must be set using setSuccess(), or using setFailed() if there's an error.
See \l Browsing for more information on how this is used.
- \sa canGoBack()
+ \sa canGoForwardChanged()
*/
/*!
- \fn bool QIviSearchAndBrowseModelInterface::canGoForward(const QUuid &identifier, const QString &type, const QString &itemId)
+ \fn QIviSearchAndBrowseModelInterface::insert(const QUuid &identifier, int index, const QVariant &item)
- Returns true when the QIviSearchAndBrowseModel instance identified by \a identifier and the current content type \a type has an
- item identified by \a itemId and this item can be used to show a new set of data.
+ Adds the browsable \a item to the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier at \a index.
- See \l Browsing for more information on how this is used.
- \sa goForward
+ The provided item could be owned by another model or QML, because of that it's expected that the backend stores its internal representation.
+
+ \sa dataChanged()
*/
/*!
- \fn QString QIviSearchAndBrowseModelInterface::goForward(const QUuid &identifier, const QString &type, const QString &itemId)
+ \fn QIviSearchAndBrowseModelInterface::remove(const QUuid &identifier, int index)
- Requests to go to the next data set of the QIviSearchAndBrowseModel instance identified by \a identifier and the current content type \a type.
- The item which is used for the new set of data is passed as \a itemId and the new content type should be returned.
+ Removes the browsable item at position \a index from the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier.
- See \l Browsing for more information on how this is used.
- \sa canGoForward()
+ \sa dataChanged()
*/
/*!
- \fn QIviSearchAndBrowseModelInterface::insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item)
+ \fn QIviSearchAndBrowseModelInterface::move(const QUuid &identifier, int currentIndex, int newIndex)
- Adds the browsable \a item into the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier and the current content type \a type at \a index.
- The provided item could be owned by another model or QML, because of that it's expected that the backend stores its internal representation.
+ Moves the browsable item at position \a currentIndex of the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier to the new position \a newIndex.
\sa dataChanged()
*/
/*!
- \fn QIviSearchAndBrowseModelInterface::remove(const QUuid &identifier, const QString &type, int index)
+ \fn QIviSearchAndBrowseModelInterface::indexOf(const QUuid &identifier, const QVariant &item)
- Removes the browsable item at position \a index from the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier and the current content type \a type.
+ Determines the index of \a item in the model identified by \a identifier.
+*/
- \sa dataChanged()
+/*!
+ \fn QIviSearchAndBrowseModelInterface::canGoBackChanged(const QUuid &identifier, bool canGoBack)
+
+ Emitted to inform the QIviSearchAndBrowseModel instance, identified by \a identifier, whether it \a canGoBack to the data set previously
+ shown. If the instance can display the previous data set, \a canGoBack is set to \c true.
+
+ See \l Browsing for more information on how this is used.
+ \sa goBack
*/
+
/*!
- \fn QIviSearchAndBrowseModelInterface::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex)
+ \fn QIviSearchAndBrowseModelInterface::canGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start)
- Moves the browsable item at position \a currentIndex of the current dataset of the QIviSearchAndBrowseModel instance identified by \a identifier and the current content type \a type to the new position \a newIndex.
+ Emitted to inform the QIviSearchAndBrowseModel instance identified by \a identifier that the following
+ \a indexes can be used to show a new set of data.
- \sa dataChanged()
+ The \a start parameter can be used to inform only about a limited set of indexes. This signal
+ can be emitted during a QIviPagingModelInterface::fetchData() call to inform about the state
+ of the just fetched data.
+
+ See \l Browsing for more information on how this is used.
+ \sa goForward
+*/
+
+/*!
+ \fn QIviSearchAndBrowseModelInterface::contentTypeChanged(const QUuid &identifier, const QString &contentType)
+
+ Emitted as a result of a call to setContentType, to inform the QIviSearchAndBrowseModel instance identified by \a identifier
+ about it's new \a contentType.
+
+ \sa setContentType
+*/
+
+/*!
+ \fn QIviSearchAndBrowseModelInterface:availableContentTypesChanged(const QStringList &availableContentTypes)
+
+ Emitted during the initialization phase, to inform about all available content types(\a availableContentTypes).
+
+ The value is provided to the user as indication of which content types can be used.
+
+ \note The QIviSearchAndBrowseModel doesn't check the validity of the contentType, this is the responsibility
+ of the backend.
+
+ \sa setContentType
*/
/*!
- \fn QIviSearchAndBrowseModelInterface::indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item)
+ \fn QIviSearchAndBrowseModelInterface:queryIdentifiersChanged(const QUuid &identifier, const QSet<QString> &queryIdentifiers)
+
+ Emitted as a result of a call to setContentType, to inform the QIviSearchAndBrowseModel instance identified by \a identifier
+ about the currently supported \a queryIdentifiers.
- Determines the index of \a item in the model identified by \a identifier and \a type.
+ The \a queryIdentifiers are used to setup the \l {Qt IVI Query Language} to be able to show
+ meaningful errors for invalid queries. Not emitting this signal, will cause the \l {Qt IVI Query Language} to not limit the
+ possible identifiers.
*/
QT_END_NAMESPACE
diff --git a/src/ivicore/qivisearchandbrowsemodelinterface.h b/src/ivicore/qivisearchandbrowsemodelinterface.h
index f6fc52c..6d8fa98 100644
--- a/src/ivicore/qivisearchandbrowsemodelinterface.h
+++ b/src/ivicore/qivisearchandbrowsemodelinterface.h
@@ -53,6 +53,7 @@
#include <QtIviCore/QIviPagingModelInterface>
#include <QtIviCore/QIviSearchAndBrowseModel>
#include <QtIviCore/QIviStandardItem>
+#include <QtIviCore/qiviqmlconversion_helper.h>
QT_BEGIN_NAMESPACE
@@ -65,29 +66,31 @@ class Q_QTIVICORE_EXPORT QIviSearchAndBrowseModelInterface : public QIviPagingMo
public:
explicit QIviSearchAndBrowseModelInterface(QObject *parent = nullptr);
- virtual QSet<QString> availableContentTypes() const;
- virtual QSet<QString> supportedIdentifiers(const QString &contentType) const;
-
virtual void setContentType(const QUuid &identifier, const QString &contentType) = 0;
virtual void setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms) = 0;
- virtual bool canGoBack(const QUuid &identifier, const QString &type) = 0;
- virtual QString goBack(const QUuid &identifier, const QString &type) = 0; // Only used when in-model navigation
- //TODO pass also an pointer here instead of the id ?
- virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) = 0; //Every Item has a id property which is filled by the backend implementation.
- virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) = 0; //Returns the new type identifier used for the next level. The identifier will stay the same for the following calls but the type might differ.
+ virtual QIviPendingReply<QString> goBack(const QUuid &identifier) = 0;
+ virtual QIviPendingReply<QString> goForward(const QUuid &identifier, int index) = 0;
+
+ virtual QIviPendingReply<void> insert(const QUuid &identifier, int index, const QVariant &item) = 0;
+ virtual QIviPendingReply<void> remove(const QUuid &identifier, int index) = 0;
+ virtual QIviPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) = 0;
+ virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QVariant &item) = 0;
- virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item) = 0;
- virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) = 0;
- virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) = 0;
- virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item) = 0;
+Q_SIGNALS:
+ void canGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start);
+ void canGoBackChanged(const QUuid &identifier, bool canGoBack);
+ //does this really make sense ?
+ void contentTypeChanged(const QUuid &identifier, const QString &contentType);
+ void availableContentTypesChanged(const QStringList &availableContentTypes);
+ void queryIdentifiersChanged(const QUuid &identifier, const QSet<QString> &queryIdentifiers);
protected:
template <typename T>
- void registerContentType(const QString &contentType) {
- registerContentType(T::staticMetaObject, contentType);
+ QSet<QString> identifiersFromItem() {
+ return identifiersFromItem(T::staticMetaObject);
}
- void registerContentType(const QMetaObject &object, const QString &contentType);
+ QSet<QString> identifiersFromItem(const QMetaObject &object);
private:
Q_DECLARE_PRIVATE(QIviSearchAndBrowseModelInterface)
diff --git a/src/ivicore/qivisearchandbrowsemodelinterface_p.h b/src/ivicore/qivisearchandbrowsemodelinterface_p.h
deleted file mode 100644
index 3f85f60..0000000
--- a/src/ivicore/qivisearchandbrowsemodelinterface_p.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 Luxoft Sweden AB
-** Copyright (C) 2018 Pelagicore AG
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtIvi module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL-QTAS$
-** Commercial License Usage
-** Licensees holding valid commercial Qt Automotive Suite licenses may use
-** this file in accordance with the commercial license agreement provided
-** with the Software or, alternatively, in accordance with the terms
-** contained in a written agreement between you and The Qt Company. For
-** licensing terms and conditions see https://www.qt.io/terms-conditions.
-** For further information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-** SPDX-License-Identifier: LGPL-3.0
-**
-****************************************************************************/
-
-#ifndef QIVISEARCHMODELINTERFACE_P_H
-#define QIVISEARCHMODELINTERFACE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qobject_p.h>
-#include <private/qtiviglobal_p.h>
-
-#include "qivisearchandbrowsemodelinterface.h"
-
-QT_BEGIN_NAMESPACE
-
-class Q_QTIVICORE_EXPORT QIviSearchAndBrowseModelInterfacePrivate : public QObjectPrivate
-{
-public:
- QMultiHash<QString, QString> m_identifiers;
- QSet<QString> m_types;
-};
-
-QT_END_NAMESPACE
-
-#endif // QIVISEARCHMODELINTERFACE_P_H
diff --git a/src/ivicore/qtivicoremodule.cpp b/src/ivicore/qtivicoremodule.cpp
index 90e7e2d..2f3c941 100644
--- a/src/ivicore/qtivicoremodule.cpp
+++ b/src/ivicore/qtivicoremodule.cpp
@@ -74,11 +74,11 @@ QObject* qtivicoremodule_singletontype_provider(QQmlEngine*, QJSEngine*)
The backend can return the final number of items for a specific request. This makes it possible to support the QIviSearchAndBrowseModel::DataChanged loading
type.
\value SupportsFiltering
- The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsSorting
- The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsAndConjunction
The backend supports handling multiple filters at the same time and these filters can be combined by using the AND conjunction.
\value SupportsOrConjunction
@@ -108,11 +108,11 @@ QtIviCoreModule::QtIviCoreModule(QObject *parent)
The backend can return the final number of items for a specific request. This makes it possible to support the QIviSearchAndBrowseModel::DataChanged loading
type.
\value SupportsFiltering
- The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports filtering of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsSorting
- The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypes() and QIviSearchAndBrowseModelInterface::supportedIdentifiers() will be used as input for the
- \l {Qt IVI Query Language}. \sa QIviSearchAndBrowseModelInterface::registerContentType
+ The backend supports sorting of the content. QIviSearchAndBrowseModelInterface::availableContentTypesChanged() and QIviSearchAndBrowseModelInterface::queryIdentifiersChanged() will be used as input for the
+ \l {Qt IVI Query Language}.
\value SupportsAndConjunction
The backend supports handling multiple filters at the same time and these filters can be combined by using the AND conjunction.
\value SupportsOrConjunction
diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
index 4e95b5a..66fd4cd 100644
--- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
+++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.cpp
@@ -61,9 +61,6 @@ SearchAndBrowseBackend::SearchAndBrowseBackend(const QSqlDatabase &database, QOb
m_threadPool->setMaxThreadCount(1);
qRegisterMetaType<SearchAndBrowseItem>();
- registerContentType<SearchAndBrowseItem>(artistLiteral);
- registerContentType<SearchAndBrowseItem>(albumLiteral);
- registerContentType<QIviAudioTrackItem>(trackLiteral);
m_db = database;
m_db.open();
@@ -71,6 +68,11 @@ SearchAndBrowseBackend::SearchAndBrowseBackend(const QSqlDatabase &database, QOb
void SearchAndBrowseBackend::initialize()
{
+ QStringList contentTypes;
+ contentTypes << artistLiteral;
+ contentTypes << albumLiteral;
+ contentTypes << trackLiteral;
+ emit availableContentTypesChanged(contentTypes);
emit initializationDone();
}
@@ -88,6 +90,19 @@ void SearchAndBrowseBackend::setContentType(const QUuid &identifier, const QStri
{
auto &state = m_state[identifier];
state.contentType = contentType;
+
+ QStringList types = state.contentType.split('/');
+ QString current_type = types.last();
+ bool canGoBack = types.count() >= 2;
+
+ QSet<QString> identifiers;
+ if (current_type == artistLiteral || current_type == albumLiteral)
+ identifiers = identifiersFromItem<SearchAndBrowseItem>();
+ else
+ identifiers = identifiersFromItem<QIviAudioTrackItem>();
+ emit queryIdentifiersChanged(identifier, identifiers);
+ emit canGoBackChanged(identifier, canGoBack);
+ emit contentTypeChanged(identifier, contentType);
}
void SearchAndBrowseBackend::setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms)
@@ -244,6 +259,17 @@ void SearchAndBrowseBackend::search(const QUuid &identifier, const QString &quer
}
emit dataFetched(identifier, list, start, list.count() >= count);
+
+ auto &state = m_state[identifier];
+ for (int i=0; i < list.count(); i++) {
+ if (start + i >= state.items.count())
+ state.items.append(list.at(i));
+ else
+ state.items.replace(start + i, list.at(i));
+ }
+
+ if (type == artistLiteral || type == albumLiteral)
+ emit canGoForwardChanged(identifier, QVector<bool>(list.count(), true), start);
}
QString SearchAndBrowseBackend::createSortOrder(const QString &type, const QList<QIviOrderTerm> &orderTerms)
@@ -339,81 +365,73 @@ QString SearchAndBrowseBackend::createWhereClause(const QString &type, QIviAbstr
return QString();
}
-bool SearchAndBrowseBackend::canGoBack(const QUuid &identifier, const QString &type)
-{
- Q_UNUSED(identifier)
- return type.split('/').count() >= 2;
-}
-
-QString SearchAndBrowseBackend::goBack(const QUuid &identifier, const QString &type)
+QIviPendingReply<QString> SearchAndBrowseBackend::goBack(const QUuid &identifier)
{
- Q_UNUSED(identifier)
- QStringList types = type.split('/');
+ auto &state = m_state[identifier];
+ QStringList types = state.contentType.split('/');
if (types.count() < 2)
- return QString();
+ return QIviPendingReply<QString>::createFailedReply();
types.removeLast();
types.replace(types.count() - 1, types.at(types.count() - 1).split('?').at(0));
- return types.join('/');
+ return QIviPendingReply<QString>(types.join('/'));
}
-bool SearchAndBrowseBackend::canGoForward(const QUuid &identifier, const QString &type, const QString &itemId)
+QIviPendingReply<QString> SearchAndBrowseBackend::goForward(const QUuid &identifier, int index)
{
- return !goForward(identifier, type, itemId).isEmpty();
-}
+ auto &state = m_state[identifier];
+
+ const QIviStandardItem *i = qtivi_gadgetFromVariant<QIviStandardItem>(this, state.items.value(index, QVariant()));
+ if (!i)
+ return QIviPendingReply<QString>::createFailedReply();
+
+ QString itemId = i->id();
+ QStringList types = state.contentType.split('/');
-QString SearchAndBrowseBackend::goForward(const QUuid &identifier, const QString &type, const QString &itemId)
-{
- Q_UNUSED(identifier)
- QStringList types = type.split('/');
QString current_type = types.last();
- QString new_type = type + QStringLiteral("?%1").arg(QLatin1String(itemId.toUtf8().toBase64(QByteArray::Base64UrlEncoding)));
+ QString new_type = state.contentType + QStringLiteral("?%1").arg(QLatin1String(itemId.toUtf8().toBase64(QByteArray::Base64UrlEncoding)));
if (current_type == artistLiteral)
new_type += QLatin1String("/album");
else if (current_type == albumLiteral)
new_type += QLatin1String("/track");
else
- return QString();
+ return QIviPendingReply<QString>::createFailedReply();
- return new_type;
+ return QIviPendingReply<QString>(new_type);
}
-QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item)
+QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, int index, const QVariant &item)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(index)
Q_UNUSED(item)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index)
+QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, int index)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(index)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex)
+QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, int currentIndex, int newIndex)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(currentIndex)
Q_UNUSED(newIndex)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item)
+QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QVariant &item)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(item)
return QIviPendingReply<int>::createFailedReply();
diff --git a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
index 74fa57e..a6ecc32 100644
--- a/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
+++ b/src/plugins/ivimedia/media_simulator/searchandbrowsebackend.h
@@ -81,15 +81,13 @@ public:
void setContentType(const QUuid &identifier, const QString &contentType) override;
void setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms) override;
void fetchData(const QUuid &identifier, int start, int count) override;
- bool canGoBack(const QUuid &identifier, const QString &type) override;
- QString goBack(const QUuid &identifier, const QString &type) override;
- bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
- QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
+ QIviPendingReply<QString> goBack(const QUuid &identifier) override;
+ QIviPendingReply<QString> goForward(const QUuid &identifier, int index) override;
- QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item) override;
- QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override;
- QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override;
- QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item) override;
+ QIviPendingReply<void> insert(const QUuid &identifier, int index, const QVariant &item) override;
+ QIviPendingReply<void> remove(const QUuid &identifier, int index) override;
+ QIviPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) override;
+ QIviPendingReply<int> indexOf(const QUuid &identifier, const QVariant &item) override;
private slots:
void search(const QUuid &identifier, const QString &queryString, const QString &type, int start, int count);
@@ -104,6 +102,7 @@ private:
QString contentType;
QIviAbstractQueryTerm *queryTerm = nullptr;
QList<QIviOrderTerm> orderTerms;
+ QVariantList items;
};
QMap<QUuid, State> m_state;
};
diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp
index 07c6aa9..3561c20 100644
--- a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp
+++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.cpp
@@ -52,27 +52,32 @@ UsbBrowseBackend::UsbBrowseBackend(const QString &path, QObject *parent)
, m_rootFolder(path)
{
qRegisterMetaType<SearchAndBrowseItem>();
- registerContentType<SearchAndBrowseItem>(fileLiteral);
}
void UsbBrowseBackend::initialize()
{
+ emit availableContentTypesChanged(QStringList(fileLiteral));
emit initializationDone();
}
void UsbBrowseBackend::registerInstance(const QUuid &identifier)
{
- m_contentType.insert(identifier, QString());
+ m_state.insert(identifier, {});
}
void UsbBrowseBackend::unregisterInstance(const QUuid &identifier)
{
- m_contentType.remove(identifier);
+ m_state.remove(identifier);
}
void UsbBrowseBackend::setContentType(const QUuid &identifier, const QString &contentType)
{
- m_contentType[identifier] = contentType;
+ auto &state = m_state[identifier];
+ state.contentType = contentType;
+
+ emit queryIdentifiersChanged(identifier, identifiersFromItem<SearchAndBrowseItem>());
+ emit canGoBackChanged(identifier, contentType != fileLiteral);
+ emit contentTypeChanged(identifier, contentType);
}
void UsbBrowseBackend::setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms)
@@ -90,10 +95,11 @@ void UsbBrowseBackend::fetchData(const QUuid &identifier, int start, int count)
QtIviCoreModule::SupportsGetSize
));
+ auto &state = m_state[identifier];
QVariantList list;
QString folder = m_rootFolder;
- if (m_contentType[identifier] != fileLiteral)
- folder += m_contentType[identifier];
+ if (state.contentType != fileLiteral)
+ folder += QDir::separator() + state.contentType;
QDir dir(folder);
QFileInfoList infoList = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks);
@@ -107,79 +113,73 @@ void UsbBrowseBackend::fetchData(const QUuid &identifier, int start, int count)
}
emit dataFetched(identifier, list, start, list.count() >= count);
-}
-bool UsbBrowseBackend::canGoBack(const QUuid &identifier, const QString &type)
-{
- Q_UNUSED(identifier)
- return type != fileLiteral;
+ for (int i=0; i < list.count(); i++) {
+ if (start + i >= state.items.count())
+ state.items.append(list.at(i));
+ else
+ state.items.replace(start + i, list.at(i));
+ }
+ emit canGoForwardChanged(identifier, QVector<bool>(infoList.count(), true), 0);
}
-QString UsbBrowseBackend::goBack(const QUuid &identifier, const QString &type)
+QIviPendingReply<QString> UsbBrowseBackend::goBack(const QUuid &identifier)
{
- Q_UNUSED(identifier)
- QStringList types = type.split('/');
+ auto &state = m_state[identifier];
+ QStringList types = state.contentType.split('/');
- if (types.count() < 2 && type != fileLiteral)
+ if (types.count() < 2 && state.contentType != fileLiteral)
return fileLiteral;
types.removeLast();
types.replace(types.count() - 1, types.at(types.count() - 1).split('?').at(0));
- return types.join('/');
+ return QIviPendingReply<QString>(types.join('/'));
}
-bool UsbBrowseBackend::canGoForward(const QUuid &identifier, const QString &type, const QString &itemId)
+QIviPendingReply<QString> UsbBrowseBackend::goForward(const QUuid &identifier, int index)
{
- Q_UNUSED(identifier);
- if (type != fileLiteral)
- return QDir(m_rootFolder + "/" + type + "/" + itemId).count();
- else
- return QDir(m_rootFolder + "/" + itemId).count();
-}
+ auto &state = m_state[identifier];
-QString UsbBrowseBackend::goForward(const QUuid &identifier, const QString &type, const QString &itemId)
-{
- Q_UNUSED(identifier)
- if (type != fileLiteral)
- return type + "/" + itemId;
+ const QIviStandardItem *i = qtivi_gadgetFromVariant<QIviStandardItem>(this, state.items.value(index, QVariant()));
+ if (!i)
+ return QIviPendingReply<QString>::createFailedReply();
+
+ if (state.contentType != fileLiteral)
+ return QIviPendingReply<QString>(state.contentType + "/" + i->id());
else
- return itemId;
+ return QIviPendingReply<QString>(i->id());
}
-QIviPendingReply<void> UsbBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item)
+QIviPendingReply<void> UsbBrowseBackend::insert(const QUuid &identifier, int index, const QVariant &item)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(index)
Q_UNUSED(item)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<void> UsbBrowseBackend::remove(const QUuid &identifier, const QString &type, int index)
+QIviPendingReply<void> UsbBrowseBackend::remove(const QUuid &identifier, int index)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(index)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<void> UsbBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex)
+QIviPendingReply<void> UsbBrowseBackend::move(const QUuid &identifier, int currentIndex, int newIndex)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(currentIndex)
Q_UNUSED(newIndex)
return QIviPendingReply<void>::createFailedReply();
}
-QIviPendingReply<int> UsbBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item)
+QIviPendingReply<int> UsbBrowseBackend::indexOf(const QUuid &identifier, const QVariant &item)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
Q_UNUSED(item)
return QIviPendingReply<int>::createFailedReply();
diff --git a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h
index 8c6b900..3adfd56 100644
--- a/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h
+++ b/src/plugins/ivimedia/media_simulator/usbbrowsebackend.h
@@ -58,19 +58,23 @@ public:
void setContentType(const QUuid &identifier, const QString &contentType) override;
void setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms) override;
void fetchData(const QUuid &identifier, int start, int count) override;
- bool canGoBack(const QUuid &identifier, const QString &type) override;
- QString goBack(const QUuid &identifier, const QString &type) override;
- bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
- QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
+// bool canGoBack(const QUuid &identifier, const QString &type) override;
+ QIviPendingReply<QString> goBack(const QUuid &identifier) override;
+// bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
+ QIviPendingReply<QString> goForward(const QUuid &identifier, int index) override;
- QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item) override;
- QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override;
- QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override;
- QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item) override;
+ QIviPendingReply<void> insert(const QUuid &identifier, int index, const QVariant &item) override;
+ QIviPendingReply<void> remove(const QUuid &identifier, int index) override;
+ QIviPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) override;
+ QIviPendingReply<int> indexOf(const QUuid &identifier, const QVariant &item) override;
private:
QString m_rootFolder;
- QHash<QUuid, QString> m_contentType;
+ struct State {
+ QString contentType;
+ QVariantList items;
+ };
+ QMap<QUuid, State> m_state;
};
#endif // USBBROWSEBACKEND_H
diff --git a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp
index fa0ce9b..f9e3e6c 100644
--- a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp
+++ b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.cpp
@@ -50,12 +50,14 @@ SearchAndBrowseBackend::SearchAndBrowseBackend(AmFmTunerBackend *tunerBackend, Q
, m_tunerBackend(tunerBackend)
{
qRegisterMetaType<QIviAmFmTunerStation>();
- registerContentType<QIviAmFmTunerStation>(QStringLiteral("station"));
- registerContentType<QIviAmFmTunerStation>(QStringLiteral("presets"));
}
void SearchAndBrowseBackend::initialize()
{
+ QStringList contentTypes;
+ contentTypes << QStringLiteral("stations");
+ contentTypes << QStringLiteral("presets");
+ emit availableContentTypesChanged(contentTypes);
emit initializationDone();
}
@@ -72,6 +74,8 @@ void SearchAndBrowseBackend::unregisterInstance(const QUuid &identifier)
void SearchAndBrowseBackend::setContentType(const QUuid &identifier, const QString &contentType)
{
m_contentType[identifier] = contentType;
+ emit queryIdentifiersChanged(identifier, identifiersFromItem<QIviAmFmTunerStation>());
+ emit contentTypeChanged(identifier, contentType);
}
void SearchAndBrowseBackend::setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms)
@@ -110,44 +114,31 @@ void SearchAndBrowseBackend::fetchData(const QUuid &identifier, int start, int c
emit dataFetched(identifier, requestedStations, start, start + count < stations.length());
}
-bool SearchAndBrowseBackend::canGoBack(const QUuid &identifier, const QString &type)
+QIviPendingReply<QString> SearchAndBrowseBackend::goBack(const QUuid &identifier)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
- return false;
+ return QIviPendingReply<QString>::createFailedReply();
}
-QString SearchAndBrowseBackend::goBack(const QUuid &identifier, const QString &type)
+QIviPendingReply<QString> SearchAndBrowseBackend::goForward(const QUuid &identifier, int index)
{
Q_UNUSED(identifier)
- Q_UNUSED(type)
- return QString();
+ Q_UNUSED(index)
+ return QIviPendingReply<QString>::createFailedReply();
}
-bool SearchAndBrowseBackend::canGoForward(const QUuid &identifier, const QString &type, const QString &itemId)
+QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, int index, const QVariant &item)
{
- Q_UNUSED(identifier)
- Q_UNUSED(type)
- Q_UNUSED(itemId)
- return false;
-}
-
-QString SearchAndBrowseBackend::goForward(const QUuid &identifier, const QString &type, const QString &itemId)
-{
- Q_UNUSED(identifier)
- Q_UNUSED(type)
- Q_UNUSED(itemId)
- return QString();
-}
+ const QIviAmFmTunerStation *station = qtivi_gadgetFromVariant<QIviAmFmTunerStation>(this, item);
+ if (!station)
+ return QIviPendingReply<void>::createFailedReply();
-QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item)
-{
- if (type != QLatin1String("presets") || item->type() != QLatin1String("amfmtunerstation"))
+ const QString type = m_contentType.value(identifier);
+ if (type != QLatin1String("presets"))
return QIviPendingReply<void>::createFailedReply();
- const QIviAmFmTunerStation &station = *static_cast<const QIviAmFmTunerStation*>(item);
- m_presets.insert(index, station);
- QVariantList stations = { QVariant::fromValue(station) };
+ m_presets.insert(index, *station);
+ QVariantList stations = { QVariant::fromValue(*station) };
emit dataChanged(identifier, stations, index, 0);
QIviPendingReply<void> reply;
@@ -155,8 +146,9 @@ QIviPendingReply<void> SearchAndBrowseBackend::insert(const QUuid &identifier, c
return reply;
}
-QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, const QString &type, int index)
+QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, int index)
{
+ const QString type = m_contentType.value(identifier);
if (type != QLatin1String("presets"))
return QIviPendingReply<void>::createFailedReply();
@@ -168,8 +160,9 @@ QIviPendingReply<void> SearchAndBrowseBackend::remove(const QUuid &identifier, c
return reply;
}
-QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex)
+QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, int currentIndex, int newIndex)
{
+ const QString type = m_contentType.value(identifier);
if (type != QLatin1String("presets"))
return QIviPendingReply<void>::createFailedReply();
@@ -188,14 +181,14 @@ QIviPendingReply<void> SearchAndBrowseBackend::move(const QUuid &identifier, con
return reply;
}
-QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item)
+QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, const QVariant &item)
{
- Q_UNUSED(identifier)
-
- if (item->type() != QLatin1String("amfmtunerstation"))
+ const QIviAmFmTunerStation *station = qtivi_gadgetFromVariant<QIviAmFmTunerStation>(this, item);
+ if (!station)
return QIviPendingReply<int>::createFailedReply();
QVector<QIviAmFmTunerStation> stations;
+ const QString type = m_contentType.value(identifier);
if (type == QLatin1String("station"))
stations = m_tunerBackend->m_bandHash[QIviAmFmTuner::AMBand].m_stations + m_tunerBackend->m_bandHash[QIviAmFmTuner::FMBand].m_stations;
@@ -204,9 +197,7 @@ QIviPendingReply<int> SearchAndBrowseBackend::indexOf(const QUuid &identifier, c
else
return QIviPendingReply<int>::createFailedReply();
- QIviAmFmTunerStation station = *static_cast<const QIviAmFmTunerStation*>(item);
-
QIviPendingReply<int> reply;
- reply.setSuccess(stations.indexOf(station));
+ reply.setSuccess(stations.indexOf(*station));
return reply;
}
diff --git a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h
index 49cefad..4ba061c 100644
--- a/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h
+++ b/src/plugins/ivimedia/tuner_simulator/searchandbrowsebackend.h
@@ -61,15 +61,13 @@ public:
void setContentType(const QUuid &identifier, const QString &contentType) override;
void setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms) override;
void fetchData(const QUuid &identifier, int start, int count) override;
- bool canGoBack(const QUuid &identifier, const QString &type) override;
- QString goBack(const QUuid &identifier, const QString &type) override;
- bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
- QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override;
+ QIviPendingReply<QString> goBack(const QUuid &identifier) override;
+ QIviPendingReply<QString> goForward(const QUuid &identifier, int index) override;
- QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item) override;
- QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override;
- QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override;
- QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item) override;
+ QIviPendingReply<void> insert(const QUuid &identifier, int index, const QVariant &item) override;
+ QIviPendingReply<void> remove(const QUuid &identifier, int index) override;
+ QIviPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) override;
+ QIviPendingReply<int> indexOf(const QUuid &identifier, const QVariant &item) override;
private:
AmFmTunerBackend *m_tunerBackend;
diff --git a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
index ff28d58..98dcb9d 100644
--- a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
+++ b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
@@ -44,12 +44,6 @@ class TestBackend : public QIviSearchAndBrowseModelInterface
public:
- //Registers the type under the passed names. Can be called more often to fill the availableTypes
- void registerType(const QString &name)
- {
- registerContentType<QIviStandardItem>(name);
- }
-
//Sets the capabilities this instance should report
void setCapabilities(QtIviCoreModule::ModelCapabilities capabilities)
{
@@ -59,7 +53,6 @@ public:
//Adds very simple Data which can be used for most of the unit tests
void initializeSimpleData()
{
- registerType("simple");
m_lists.insert("simple", createItemList("simple"));
}
@@ -67,17 +60,14 @@ public:
void initializeNavigationData()
{
static const QStringList types = { "levelOne", "levelTwo", "levelThree" };
- for (const QString &type : types) {
- registerType(type);
+ for (const QString &type : types)
m_lists.insert(type, createItemList(type));
- }
}
//Adds a data set which can be filtered and sorted
void initializeFilterData()
{
QString type("filter");
- registerType(type);
QList<QIviStandardItem> list;
for (int i=0; i<100; i++) {
@@ -109,6 +99,7 @@ public:
void initialize() override
{
+ emit availableContentTypesChanged(m_lists.keys());
emit initializationDone();
}
@@ -126,6 +117,10 @@ public:
{
Q_UNUSED(identifier)
m_contentType = contentType;
+ if (contentType == "levelTwo" || contentType == "levelThree")
+ emit canGoBackChanged(identifier, true);
+ emit queryIdentifiersChanged(identifier, identifiersFromItem<QIviStandardItem>());
+ emit contentTypeChanged(identifier, contentType);
}
void setupFilter(const QUuid &identifier, QIviAbstractQueryTerm *term, const QList<QIviOrderTerm> &orderTerms) override
@@ -228,56 +223,49 @@ public:
requestedItems.append(QVariant::fromValue(list.at(i)));
emit dataFetched(identifier, requestedItems, start, start + count < list.count());
- }
- virtual bool canGoBack(const QUuid &identifier, const QString &type) override
- {
- Q_UNUSED(identifier)
- return (type == "levelTwo" || type == "levelThree");
+ //All but the first item can go forward
+ if (m_contentType == "levelOne" || m_contentType == "levelTwo")
+ emit canGoForwardChanged(identifier, QVector<bool>(requestedItems.count() - 1, true), start + 1);
}
- virtual QString goBack(const QUuid &identifier, const QString &type) override
+ virtual QIviPendingReply<QString> goBack(const QUuid &identifier) override
{
Q_UNUSED(identifier)
- if (type == "levelThree")
- return "levelTwo";
- else if (type == "levelTwo")
- return "levelOne";
-
- return "levelOne";
- }
-
- virtual bool canGoForward(const QUuid &identifier, const QString &type, const QString &itemId) override
- {
- Q_UNUSED(identifier)
- if (itemId.endsWith("0"))
- return false;
+ if (m_contentType == "levelThree")
+ return QIviPendingReply<QString>("levelTwo");
+ else if (m_contentType == "levelTwo")
+ return QIviPendingReply<QString>("levelOne");
- return (type == "levelOne" || type == "levelTwo");
+ return QIviPendingReply<QString>::createFailedReply();
}
- virtual QString goForward(const QUuid &identifier, const QString &type, const QString &itemId) override
+ virtual QIviPendingReply<QString> goForward(const QUuid &identifier, int index) override
{
Q_UNUSED(identifier)
- Q_UNUSED(itemId)
+ Q_UNUSED(index)
- if (type == "levelOne")
- return "levelTwo";
- else if (type == "levelTwo")
- return "levelThree";
+ if (m_contentType == "levelOne")
+ return QIviPendingReply<QString>("levelTwo");
+ else if (m_contentType == "levelTwo")
+ return QIviPendingReply<QString>("levelThree");
- return "levelOne";
+ return QIviPendingReply<QString>::createFailedReply();
}
- virtual QIviPendingReply<void> insert(const QUuid &identifier, const QString &type, int index, const QIviStandardItem *item) override
+ virtual QIviPendingReply<void> insert(const QUuid &identifier, int index, const QVariant &var) override
{
- QList<QIviStandardItem> list = m_lists.value(type);
+ const QIviStandardItem *item = qtivi_gadgetFromVariant<QIviStandardItem>(this, var);
+ if (!item)
+ return QIviPendingReply<void>::createFailedReply();
+
+ QList<QIviStandardItem> list = m_lists.value(m_contentType);
list.insert(index, *item);
QVariantList variantList = { QVariant::fromValue(*item) };
- m_lists.insert(type, list);
+ m_lists.insert(m_contentType, list);
emit dataChanged(identifier, variantList, index, 0);
@@ -286,12 +274,12 @@ public:
return reply;
}
- virtual QIviPendingReply<void> remove(const QUuid &identifier, const QString &type, int index) override
+ virtual QIviPendingReply<void> remove(const QUuid &identifier, int index) override
{
- QList<QIviStandardItem> list = m_lists.value(type);
+ QList<QIviStandardItem> list = m_lists.value(m_contentType);
list.removeAt(index);
- m_lists.insert(type, list);
+ m_lists.insert(m_contentType, list);
emit dataChanged(identifier, QVariantList(), index, 1);
@@ -300,9 +288,9 @@ public:
return reply;
}
- virtual QIviPendingReply<void> move(const QUuid &identifier, const QString &type, int currentIndex, int newIndex) override
+ virtual QIviPendingReply<void> move(const QUuid &identifier, int currentIndex, int newIndex) override
{
- QList<QIviStandardItem> list = m_lists.value(type);
+ QList<QIviStandardItem> list = m_lists.value(m_contentType);
int min = qMin(currentIndex, newIndex);
int max = qMax(currentIndex, newIndex);
@@ -312,7 +300,7 @@ public:
for (int i = min; i <= max; i++)
variantLIst.append(QVariant::fromValue(list.at(i)));
- m_lists.insert(type, list);
+ m_lists.insert(m_contentType, list);
emit dataChanged(identifier, variantLIst, min, max - min + 1);
@@ -321,10 +309,14 @@ public:
return reply;
}
- virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QString &type, const QIviStandardItem *item) override
+ virtual QIviPendingReply<int> indexOf(const QUuid &identifier, const QVariant &var) override
{
Q_UNUSED(identifier)
- QList<QIviStandardItem> list = m_lists.value(type);
+ const QIviStandardItem *item = qtivi_gadgetFromVariant<QIviStandardItem>(this, var);
+ if (!item)
+ return QIviPendingReply<int>::createFailedReply();
+
+ QList<QIviStandardItem> list = m_lists.value(m_contentType);
QIviPendingReply<int> reply;
reply.setSuccess(list.indexOf(*item));
@@ -949,11 +941,6 @@ void tst_QIviSearchAndBrowseModel::testInputErrors()
model.fetchMore(model.index(0,0));
QVERIFY(!countChanged.count());
- // Invalid content Type
- QTest::ignoreMessage(QtWarningMsg, "Unsupported type: \"levelOne\" \n Supported types are: \nsimple\n");
- model.setContentType("levelOne");
- model.setContentType("simple");
-
// Invalid query
QTest::ignoreMessage(QtWarningMsg, "Got end of file but expected on of the following types:\n integer\n float\nid>\n ^");
model.setQuery(QString("id>"));