From bbaadb8139399ca7d6088bf8ff69fa487eae57bd Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Sun, 25 Aug 2013 14:31:50 +0300 Subject: [PATCH] populate post capture model when page is current and clear it when we leave --- qml/PostCaptureView.qml | 43 ++++++++++++++++++---------------------- src/postcapturemodel.cpp | 10 ++++++++++ src/postcapturemodel.h | 1 + 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/qml/PostCaptureView.qml b/qml/PostCaptureView.qml index 1e01688..a8a28a5 100644 --- a/qml/PostCaptureView.qml +++ b/qml/PostCaptureView.qml @@ -35,6 +35,21 @@ Item { CameraResources.Player : settings.mode == Camera.VideoMode ? CameraResources.Video : CameraResources.Image + property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving + property bool inCameraMode: mainView.currentIndex == 1 && !mainView.moving + + onIsCurrentChanged: { + if (isCurrent) { + postCaptureModel.reload() + } + } + + onInCameraModeChanged: { + if (inCameraMode) { + postCaptureModel.clear() + } + } + Connections { target: view.currentItem onPlayingChanged: { @@ -76,30 +91,10 @@ Item { } } - property variant postCaptureModel: postCaptureModelLoader.item ? - postCaptureModelLoader.item.model : null - property bool loadModel: mainView.currentIndex == 2 && Qt.application.active - - Loader { - id: postCaptureModelLoader - sourceComponent: loadModel ? postCaptureModelComponent : undefined - } - - // We have to do it that way because Loader does not support non-visual elements. - Component { - id: postCaptureModelComponent - - Item { - property alias model: postCaptureModel - - PostCaptureModel { - id: postCaptureModel - imagePath: platformSettings.imagePath - videoPath: platformSettings.videoPath - - Component.onCompleted: reload() - } - } + PostCaptureModel { + id: postCaptureModel + imagePath: platformSettings.imagePath + videoPath: platformSettings.videoPath } Timer { diff --git a/src/postcapturemodel.cpp b/src/postcapturemodel.cpp index 1f71a58..037d67c 100644 --- a/src/postcapturemodel.cpp +++ b/src/postcapturemodel.cpp @@ -108,6 +108,16 @@ void PostCaptureModel::reload() { sort(0, Qt::DescendingOrder); } +void PostCaptureModel::clear() { + if (m_model->rowCount(QModelIndex()) == 0) { + return; + } + + m_data.clear(); + + m_model->setFiles(QStringList()); +} + bool PostCaptureModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { return info(sourceModel()->data(left, Qt::DisplayRole).toString()).created() < info(sourceModel()->data(right, Qt::DisplayRole).toString()).created(); diff --git a/src/postcapturemodel.h b/src/postcapturemodel.h index 411a9a9..2370214 100644 --- a/src/postcapturemodel.h +++ b/src/postcapturemodel.h @@ -58,6 +58,7 @@ public: public slots: void reload(); + void clear(); void remove(const QUrl& file); signals: -- 2.25.1