summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2019-06-07 14:39:32 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2019-06-11 10:59:24 +0200
commit18712f14d6fd2809d2c73ede2871e3b0855aa6b6 (patch)
tree2cb51300898a924264769e7008630a7377e12d20
parent0b9baa982ae430f72150204ad4ee6d7ea78bba2e (diff)
downloadqtivi-18712f14d6fd2809d2c73ede2871e3b0855aa6b6.tar.gz
Correctly emit change signals when clearing the ServiceObject
When the serviceObject of a feature is set to null, the feature is responsible to reset its state to the default again. This commit will make sure that not just the state is fixed, but also reflected to the outside by emitting the change signals. Task-number: AUTOSUITE-1000 Change-Id: I4bc696f0179975a2d719ad420718b574010f5a5e Reviewed-by: Kavindra Palaraja <kpalaraja@luxoft.com> Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rw-r--r--src/ivicore/qiviabstractfeature.cpp4
-rw-r--r--src/ivicore/qiviabstractfeaturelistmodel.cpp4
-rw-r--r--src/ivicore/qiviabstractzonedfeature.cpp2
-rw-r--r--src/ivicore/qivipagingmodel.cpp9
-rw-r--r--src/ivicore/qivisearchandbrowsemodel.cpp9
-rw-r--r--src/ivimedia/qiviamfmtuner.cpp14
-rw-r--r--src/ivimedia/qivimediaindexercontrol.cpp4
-rw-r--r--src/ivimedia/qivimediaplayer.cpp13
-rw-r--r--src/ivimedia/qiviplayqueue.cpp8
-rw-r--r--src/tools/ivigenerator/templates_frontend/interface.cpp.tpl12
-rw-r--r--src/tools/ivigenerator/templates_test/tst_test.cpp.tpl2
-rw-r--r--tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp15
-rw-r--r--tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp20
13 files changed, 86 insertions, 30 deletions
diff --git a/src/ivicore/qiviabstractfeature.cpp b/src/ivicore/qiviabstractfeature.cpp
index 9d1ab2c..7842ba7 100644
--- a/src/ivicore/qiviabstractfeature.cpp
+++ b/src/ivicore/qiviabstractfeature.cpp
@@ -234,6 +234,10 @@ void QIviAbstractFeaturePrivate::onInitializationDone()
Called when no service object is available. The implementation is expected to set all
properties to safe defaults and forget all links to the previous service object.
+ \note You must emit the corresponding change signals for these properties, so that the feature
+ is informed about the state change. This makes it possible for the implemented class to connect
+ to a new service object afterwards.
+
There is no need to disconnect from the service object. If it still exists, it is guaranteed
that \l disconnectFromServiceObject is called first.
diff --git a/src/ivicore/qiviabstractfeaturelistmodel.cpp b/src/ivicore/qiviabstractfeaturelistmodel.cpp
index 16f45d5..9316286 100644
--- a/src/ivicore/qiviabstractfeaturelistmodel.cpp
+++ b/src/ivicore/qiviabstractfeaturelistmodel.cpp
@@ -161,6 +161,10 @@ QIviFeatureInterface *QIviAbstractFeatureListModelPrivate::backend() const
Called when no service object is available. The implementation is expected to set all
properties to safe defaults and forget all links to the previous service object.
+ \note You must emit the corresponding change signals for these properties, so that the feature
+ is informed about the state change. This makes it possible for the implemented class to connect
+ to a new service object afterwards.
+
There is no need to disconnect from the service object. If it still exists, it is guaranteed
that \l disconnectFromServiceObject is called first.
diff --git a/src/ivicore/qiviabstractzonedfeature.cpp b/src/ivicore/qiviabstractzonedfeature.cpp
index 911893e..c3c2464 100644
--- a/src/ivicore/qiviabstractzonedfeature.cpp
+++ b/src/ivicore/qiviabstractzonedfeature.cpp
@@ -131,6 +131,8 @@ void QIviAbstractZonedFeature::clearServiceObject()
d->m_zoneFeatures.clear();
d->m_zoneFeatureList.clear();
d->m_zoneFeatureMap.clear();
+ emit availableZonesChanged(QStringList());
+ emit zonesChanged();
}
/*!
diff --git a/src/ivicore/qivipagingmodel.cpp b/src/ivicore/qivipagingmodel.cpp
index 224f1a3..5986138 100644
--- a/src/ivicore/qivipagingmodel.cpp
+++ b/src/ivicore/qivipagingmodel.cpp
@@ -62,6 +62,7 @@ QIviPagingModelPrivate::QIviPagingModelPrivate(const QString &interface, QIviPag
, m_fetchedDataCount(0)
, m_loadingType(QIviPagingModel::FetchMore)
{
+ QtIviCoreModule::registerTypes();
qRegisterMetaType<QIviPagingModel::LoadingType>();
qRegisterMetaType<QIviStandardItem>();
qRegisterMetaType<QIviStandardItem>("QIviSearchAndBrowseModelItem");
@@ -244,14 +245,22 @@ void QIviPagingModelPrivate::fetchData(int startIndex)
void QIviPagingModelPrivate::clearToDefaults()
{
+ Q_Q(QIviPagingModel);
+
m_chunkSize = 30;
+ emit q->chunkSizeChanged(m_chunkSize);
m_moreAvailable = false;
m_identifier = QUuid::createUuid();
m_fetchMoreThreshold = 10;
+ emit q->fetchMoreThresholdChanged(m_fetchMoreThreshold);
m_fetchedDataCount = 0;
m_loadingType = QIviPagingModel::FetchMore;
+ emit q->loadingTypeChanged(m_loadingType);
m_capabilities = QtIviCoreModule::NoExtras;
+ emit q->capabilitiesChanged(m_capabilities);
m_itemList.clear();
+
+ resetModel();
}
const QIviStandardItem *QIviPagingModelPrivate::itemAt(int i) const
diff --git a/src/ivicore/qivisearchandbrowsemodel.cpp b/src/ivicore/qivisearchandbrowsemodel.cpp
index b4d83af..53b9a0f 100644
--- a/src/ivicore/qivisearchandbrowsemodel.cpp
+++ b/src/ivicore/qivisearchandbrowsemodel.cpp
@@ -124,13 +124,22 @@ void QIviSearchAndBrowseModelPrivate::clearToDefaults()
{
QIviPagingModelPrivate::clearToDefaults();
+ Q_Q(QIviSearchAndBrowseModel);
delete m_queryTerm;
m_queryTerm = nullptr;
+ m_query.clear();
+ emit q->queryChanged(m_query);
m_contentType = QString();
+ emit q->contentTypeChanged(m_contentType);
m_contentTypeRequested = QString();
m_canGoBack = false;
+ emit q->canGoBackChanged(m_canGoBack);
m_availableContentTypes.clear();
+ emit q->availableContentTypesChanged(m_availableContentTypes);
m_canGoForward.clear();
+
+ //Explicitly call the PagingModel resetModel to also reset the fetched data
+ QIviPagingModelPrivate::resetModel();
}
void QIviSearchAndBrowseModelPrivate::onCanGoForwardChanged(const QUuid &identifier, const QVector<bool> &indexes, int start)
diff --git a/src/ivimedia/qiviamfmtuner.cpp b/src/ivimedia/qiviamfmtuner.cpp
index 9590dfd..a73a2c8 100644
--- a/src/ivimedia/qiviamfmtuner.cpp
+++ b/src/ivimedia/qiviamfmtuner.cpp
@@ -63,13 +63,13 @@ QIviAmFmTunerPrivate::QIviAmFmTunerPrivate(const QString &interface, QIviAmFmTun
void QIviAmFmTunerPrivate::clearToDefaults()
{
- m_frequency = -1;
- m_minimumFrequency = -1;
- m_maximumFrequency = -1;
- m_stepSize = -1;
- m_band = QIviAmFmTuner::FMBand;
- m_station = QIviAmFmTunerStation();
- m_scanRunning = false;
+ onFrequencyChanged(-1);
+ onMinimumFrequencyChanged(-1);
+ onMaximumFrequencyChanged(-1);
+ onStepSizeChanged(-1);
+ onBandChanged(QIviAmFmTuner::FMBand);
+ onStationChanged(QIviAmFmTunerStation());
+ onScanStatusChanged(false);
}
void QIviAmFmTunerPrivate::onFrequencyChanged(int frequency)
diff --git a/src/ivimedia/qivimediaindexercontrol.cpp b/src/ivimedia/qivimediaindexercontrol.cpp
index 546088d..36c8384 100644
--- a/src/ivimedia/qivimediaindexercontrol.cpp
+++ b/src/ivimedia/qivimediaindexercontrol.cpp
@@ -60,8 +60,8 @@ QIviMediaIndexerControlPrivate::QIviMediaIndexerControlPrivate(const QString &in
void QIviMediaIndexerControlPrivate::clearToDefaults()
{
- m_progress = 0;
- m_state = QIviMediaIndexerControl::Idle;
+ onProgressChanged(0);
+ onStateChanged(QIviMediaIndexerControl::Idle);
}
void QIviMediaIndexerControlPrivate::onProgressChanged(qreal progress)
diff --git a/src/ivimedia/qivimediaplayer.cpp b/src/ivimedia/qivimediaplayer.cpp
index 591a3c3..879d4cd 100644
--- a/src/ivimedia/qivimediaplayer.cpp
+++ b/src/ivimedia/qivimediaplayer.cpp
@@ -77,13 +77,12 @@ void QIviMediaPlayerPrivate::initialize()
void QIviMediaPlayerPrivate::clearToDefaults()
{
- m_playMode = QIviMediaPlayer::Normal;
- m_currentTrackData = QVariant();
- m_currentTrack = nullptr;
- m_position = -1;
- m_duration = -1;
- m_volume = 0;
- m_muted = false;
+ onPlayModeChanged(QIviMediaPlayer::Normal);
+ onCurrentTrackChanged(QVariant());
+ onPositionChanged(-1);
+ onDurationChanged(-1);
+ onVolumeChanged(0);
+ onMutedChanged(false);
m_playQueue->d_func()->clearToDefaults();
}
diff --git a/src/ivimedia/qiviplayqueue.cpp b/src/ivimedia/qiviplayqueue.cpp
index 378dec9..4d30461 100644
--- a/src/ivimedia/qiviplayqueue.cpp
+++ b/src/ivimedia/qiviplayqueue.cpp
@@ -210,13 +210,19 @@ void QIviPlayQueuePrivate::resetModel()
void QIviPlayQueuePrivate::clearToDefaults()
{
+ Q_Q(QIviPlayQueue);
m_identifier = QUuid::createUuid();
m_currentIndex = -1;
+ emit q->currentIndexChanged(-1);
m_chunkSize = 30;
+ emit q->chunkSizeChanged(30);
m_moreAvailable = false;
m_fetchMoreThreshold = 10;
- m_fetchedDataCount = 0;
+ emit q->fetchMoreThresholdChanged(m_fetchMoreThreshold);
m_loadingType = QIviPlayQueue::FetchMore;
+ emit q->loadingTypeChanged(m_loadingType);
+
+ resetModel();
}
const QIviPlayableItem *QIviPlayQueuePrivate::itemAt(int i) const
diff --git a/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl b/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl
index 7dc0482..1507ecf 100644
--- a/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl
+++ b/src/tools/ivigenerator/templates_frontend/interface.cpp.tpl
@@ -127,13 +127,11 @@ const {{class}}Private *{{class}}Private::get(const {{class}} *v)
void {{class}}Private::clearToDefaults()
{
{% for property in interface.properties %}
-{% if property.type.is_model %}
- if (m_{{property}}) {
- delete m_{{property}}->serviceObject();
- delete m_{{property}};
- }
-{% endif %}
- m_{{property}} = {{property|default_type_value}};
+{% set function_parameters = property|default_type_value %}
+{% if interface.tags.config.zoned %}
+{% set function_parameters = function_parameters + ', QString()' %}
+{% endif%}
+ on{{property|upperfirst}}Changed({{function_parameters}});
{% endfor %}
}
diff --git a/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl
index bcfa34c..fcccdc8 100644
--- a/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl
+++ b/src/tools/ivigenerator/templates_test/tst_test.cpp.tpl
@@ -362,6 +362,7 @@ void {{interface}}Test::testClearServiceObject()
{% for property in interface.properties %}
{% if not property.type.is_model %}
+ QSignalSpy {{property}}Spy(&cc, &{{interface}}::{{property}}Changed);
QCOMPARE(cc.{{property|getter_name}}(), {{property}}TestValue);
{% endif %}
{% endfor %}
@@ -371,6 +372,7 @@ void {{interface}}Test::testClearServiceObject()
{% for property in interface.properties %}
{% if not property.type.is_model %}
QCOMPARE(cc.{{property|getter_name}}(), {{property|default_type_value}});
+ QCOMPARE({{property}}Spy.count(), 1);
{% endif %}
{% endfor %}
diff --git a/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp b/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
index 68239c8..560d2b2 100644
--- a/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
+++ b/tests/auto/core/qivipagingmodel/tst_qivipagingmodel.cpp
@@ -231,24 +231,33 @@ void tst_QIviPagingModel::testClearServiceObject()
QIviPagingModel model;
model.setServiceObject(service);
- //TODO enable when fixed
- //model.setLoadingType(QIviSearchAndBrowseModel::DataChanged);
+ model.setLoadingType(QIviPagingModel::DataChanged);
model.setChunkSize(20);
model.setFetchMoreThreshold(20);
+ QSignalSpy chunkSizeSpy(&model, &QIviPagingModel::chunkSizeChanged);
QVERIFY(model.chunkSize() != defaultModel.chunkSize());
+ QSignalSpy thresholdSpy(&model, &QIviPagingModel::fetchMoreThresholdChanged);
QVERIFY(model.fetchMoreThreshold() != defaultModel.fetchMoreThreshold());
+ QSignalSpy capabilitiesSpy(&model, &QIviPagingModel::capabilitiesChanged);
QVERIFY(model.capabilities() != defaultModel.capabilities());
- //QVERIFY(model.loadingType() != defaultModel.loadingType());
+ QSignalSpy loadingTypeSpy(&model, &QIviPagingModel::loadingTypeChanged);
+ QVERIFY(model.loadingType() != defaultModel.loadingType());
+ QSignalSpy resetSpy(&model, &QAbstractItemModel::modelReset);
QVERIFY(model.rowCount() != defaultModel.rowCount());
QVERIFY(model.setServiceObject(nullptr));
QVERIFY(model.chunkSize() == defaultModel.chunkSize());
+ QCOMPARE(chunkSizeSpy.count(), 1);
QVERIFY(model.fetchMoreThreshold() == defaultModel.fetchMoreThreshold());
+ QCOMPARE(thresholdSpy.count(), 1);
QVERIFY(model.capabilities() == defaultModel.capabilities());
+ QCOMPARE(capabilitiesSpy.count(), 1);
QVERIFY(model.loadingType() == defaultModel.loadingType());
+ QCOMPARE(loadingTypeSpy.count(), 1);
QVERIFY(model.rowCount() == defaultModel.rowCount());
+ QCOMPARE(resetSpy.count(), 1);
}
void tst_QIviPagingModel::testRegisterInstance()
diff --git a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
index 98dcb9d..65882e0 100644
--- a/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
+++ b/tests/auto/core/qivisearchandbrowsemodel/tst_qivisearchandbrowsemodel.cpp
@@ -455,29 +455,43 @@ void tst_QIviSearchAndBrowseModel::testClearServiceObject()
QIviSearchAndBrowseModel model;
model.setServiceObject(service);
- //TODO enable when fixed
- //model.setLoadingType(QIviSearchAndBrowseModel::DataChanged);
+ model.setLoadingType(QIviSearchAndBrowseModel::DataChanged);
model.setChunkSize(20);
model.setContentType("simple");
model.setFetchMoreThreshold(20);
+ QSignalSpy chunkSizeSpy(&model, &QIviSearchAndBrowseModel::chunkSizeChanged);
QVERIFY(model.chunkSize() != defaultModel.chunkSize());
+ QSignalSpy contentTypeSpy(&model, &QIviSearchAndBrowseModel::contentTypeChanged);
QVERIFY(model.contentType() != defaultModel.contentType());
+ QSignalSpy thresholdSpy(&model, &QIviSearchAndBrowseModel::fetchMoreThresholdChanged);
QVERIFY(model.fetchMoreThreshold() != defaultModel.fetchMoreThreshold());
+ QSignalSpy availableContentTypeSpy(&model, &QIviSearchAndBrowseModel::availableContentTypesChanged);
QVERIFY(model.availableContentTypes() != defaultModel.availableContentTypes());
+ QSignalSpy capabilitiesSpy(&model, &QIviSearchAndBrowseModel::capabilitiesChanged);
QVERIFY(model.capabilities() != defaultModel.capabilities());
- //QVERIFY(model.loadingType() != defaultModel.loadingType());
+ QSignalSpy loadingTypeSpy(&model, &QIviSearchAndBrowseModel::loadingTypeChanged);
+ QVERIFY(model.loadingType() != defaultModel.loadingType());
+ QSignalSpy resetSpy(&model, &QAbstractItemModel::modelReset);
QVERIFY(model.rowCount() != defaultModel.rowCount());
QVERIFY(model.setServiceObject(nullptr));
+
QVERIFY(model.chunkSize() == defaultModel.chunkSize());
+ QCOMPARE(chunkSizeSpy.count(), 1);
QVERIFY(model.contentType() == defaultModel.contentType());
+ QCOMPARE(contentTypeSpy.count(), 1);
QVERIFY(model.fetchMoreThreshold() == defaultModel.fetchMoreThreshold());
+ QCOMPARE(thresholdSpy.count(), 1);
QVERIFY(model.availableContentTypes() == defaultModel.availableContentTypes());
+ QCOMPARE(availableContentTypeSpy.count(), 1);
QVERIFY(model.capabilities() == defaultModel.capabilities());
+ QCOMPARE(capabilitiesSpy.count(), 1);
QVERIFY(model.loadingType() == defaultModel.loadingType());
+ QCOMPARE(loadingTypeSpy.count(), 1);
QVERIFY(model.rowCount() == defaultModel.rowCount());
+ QCOMPARE(resetSpy.count(), 1);
}
void tst_QIviSearchAndBrowseModel::testBasic_qml()