diff --git a/linphone-app/src/app/proxyModel/ProxyModel.cpp b/linphone-app/src/app/proxyModel/ProxyModel.cpp index 9734c7ff2..d47472a0c 100644 --- a/linphone-app/src/app/proxyModel/ProxyModel.cpp +++ b/linphone-app/src/app/proxyModel/ProxyModel.cpp @@ -35,6 +35,19 @@ ProxyModel::ProxyModel (QAbstractItemModel * model, const int& defaultFilterMode sort(0, Qt::DescendingOrder); } +ProxyModel::~ProxyModel(){ + if(mDeleteSourceModel) + deleteSourceModel(); +} + +void ProxyModel::deleteSourceModel(){ + auto oldSourceModel = sourceModel(); + if(oldSourceModel) { + oldSourceModel->deleteLater(); + setSourceModel(nullptr); + } +} + int ProxyModel::getFilterMode () const { return mFilterMode; } diff --git a/linphone-app/src/app/proxyModel/ProxyModel.hpp b/linphone-app/src/app/proxyModel/ProxyModel.hpp index d85e950b8..a85bb45bb 100644 --- a/linphone-app/src/app/proxyModel/ProxyModel.hpp +++ b/linphone-app/src/app/proxyModel/ProxyModel.hpp @@ -35,6 +35,9 @@ public: ProxyModel (QObject *parent = Q_NULLPTR); ProxyModel (QAbstractItemModel * list, const int& defaultFilterMode, QObject *parent = Q_NULLPTR); + virtual ~ProxyModel(); + + virtual void deleteSourceModel(); int getFilterMode () const; void setFilterMode (int filterMode); @@ -56,6 +59,8 @@ protected: bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override; bool lessThan (const QModelIndex &left, const QModelIndex &right) const override; + bool mDeleteSourceModel = false; + private: int mFilterMode; }; diff --git a/linphone-app/src/app/proxyModel/SortFilterProxyModel.cpp b/linphone-app/src/app/proxyModel/SortFilterProxyModel.cpp index f60c5149f..cc4da2f43 100644 --- a/linphone-app/src/app/proxyModel/SortFilterProxyModel.cpp +++ b/linphone-app/src/app/proxyModel/SortFilterProxyModel.cpp @@ -26,6 +26,19 @@ SortFilterProxyModel::SortFilterProxyModel(QObject * parent) : QSortFilterProxyM connect(this, &SortFilterProxyModel::rowsRemoved, this, &SortFilterProxyModel::countChanged); } +SortFilterProxyModel::~SortFilterProxyModel(){ + if(mDeleteSourceModel) + deleteSourceModel(); +} + +void SortFilterProxyModel::deleteSourceModel(){ + auto oldSourceModel = sourceModel(); + if(oldSourceModel) { + oldSourceModel->deleteLater(); + setSourceModel(nullptr); + } +} + int SortFilterProxyModel::getCount() const{ return rowCount(); } diff --git a/linphone-app/src/app/proxyModel/SortFilterProxyModel.hpp b/linphone-app/src/app/proxyModel/SortFilterProxyModel.hpp index 518593faa..e0df17682 100644 --- a/linphone-app/src/app/proxyModel/SortFilterProxyModel.hpp +++ b/linphone-app/src/app/proxyModel/SortFilterProxyModel.hpp @@ -30,6 +30,8 @@ public: Q_PROPERTY(int filterType READ getFilterType WRITE setFilterType NOTIFY filterTypeChanged) SortFilterProxyModel(QObject * parent = nullptr); + virtual ~SortFilterProxyModel(); + virtual void deleteSourceModel(); virtual int getCount() const; virtual int getFilterType () const; @@ -47,6 +49,7 @@ signals: protected: int mFilterType; + bool mDeleteSourceModel = false; }; #endif diff --git a/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp index 50526b763..fd37071b3 100644 --- a/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomProxyModel.cpp @@ -57,6 +57,7 @@ ChatRoomProxyModel::ChatRoomProxyModel (QObject *parent) : QSortFilterProxyModel } ChatRoomProxyModel::~ChatRoomProxyModel(){ + setSourceModel(nullptr); setChatRoomModel(nullptr); // Do remove process like setting haveCall if is Call. } diff --git a/linphone-app/src/components/conference/ConferenceProxyModel.cpp b/linphone-app/src/components/conference/ConferenceProxyModel.cpp index a2a922a13..bf028b98b 100644 --- a/linphone-app/src/components/conference/ConferenceProxyModel.cpp +++ b/linphone-app/src/components/conference/ConferenceProxyModel.cpp @@ -38,6 +38,7 @@ using namespace std; ConferenceProxyModel::ConferenceProxyModel (QObject *parent) : SortFilterProxyModel(parent) { + mDeleteSourceModel = false; setSourceModel(CoreManager::getInstance()->getCallsListModel()); emit conferenceChanged(); diff --git a/linphone-app/src/components/other/timeZone/TimeZoneProxyModel.cpp b/linphone-app/src/components/other/timeZone/TimeZoneProxyModel.cpp index 0d837c0a9..514a7f031 100644 --- a/linphone-app/src/components/other/timeZone/TimeZoneProxyModel.cpp +++ b/linphone-app/src/components/other/timeZone/TimeZoneProxyModel.cpp @@ -27,6 +27,7 @@ // ----------------------------------------------------------------------------- TimeZoneProxyModel::TimeZoneProxyModel (QObject *parent) : SortFilterProxyModel(parent) { + mDeleteSourceModel = true; setSourceModel(new TimeZoneListModel(parent)); sort(0); } diff --git a/linphone-app/src/components/participant/ParticipantDeviceProxyModel.cpp b/linphone-app/src/components/participant/ParticipantDeviceProxyModel.cpp index 272c25480..b29b4c6bd 100644 --- a/linphone-app/src/components/participant/ParticipantDeviceProxyModel.cpp +++ b/linphone-app/src/components/participant/ParticipantDeviceProxyModel.cpp @@ -31,6 +31,10 @@ // ============================================================================= ParticipantDeviceProxyModel::ParticipantDeviceProxyModel (QObject *parent) : SortFilterProxyModel(parent){ + mDeleteSourceModel = true; +} + +ParticipantDeviceProxyModel::~ParticipantDeviceProxyModel(){ } bool ParticipantDeviceProxyModel::filterAcceptsRow ( @@ -85,18 +89,20 @@ void ParticipantDeviceProxyModel::connectTo(ParticipantDeviceListModel* model){ void ParticipantDeviceProxyModel::setCallModel(CallModel * callModel){ setFilterType(1); mCallModel = callModel; - auto sourceModel = new ParticipantDeviceListModel(mCallModel); - connectTo(sourceModel); - setSourceModel(sourceModel); + deleteSourceModel(); + auto newSourceModel = new ParticipantDeviceListModel(mCallModel); + connectTo(newSourceModel); + setSourceModel(newSourceModel); emit countChanged(); emit meChanged(); } void ParticipantDeviceProxyModel::setParticipant(ParticipantModel * participant){ setFilterType(0); - auto sourceModel = participant->getParticipantDevices().get(); - connectTo(sourceModel); - setSourceModel(sourceModel); + deleteSourceModel(); + auto newSourceModel = participant->getParticipantDevices().get(); + connectTo(newSourceModel); + setSourceModel(newSourceModel); emit countChanged(); emit meChanged(); } diff --git a/linphone-app/src/components/participant/ParticipantDeviceProxyModel.hpp b/linphone-app/src/components/participant/ParticipantDeviceProxyModel.hpp index 9a939ac53..dfa0b885f 100644 --- a/linphone-app/src/components/participant/ParticipantDeviceProxyModel.hpp +++ b/linphone-app/src/components/participant/ParticipantDeviceProxyModel.hpp @@ -45,6 +45,7 @@ public: Q_PROPERTY(ParticipantDeviceModel* activeSpeaker READ getActiveSpeakerModel NOTIFY activeSpeakerChanged) ParticipantDeviceProxyModel (QObject *parent = nullptr); + ~ParticipantDeviceProxyModel(); Q_INVOKABLE ParticipantDeviceModel* getAt(int row); ParticipantDeviceModel* getActiveSpeakerModel(); @@ -76,7 +77,6 @@ protected: virtual bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override; virtual bool lessThan (const QModelIndex &left, const QModelIndex &right) const override; - QSharedPointer mDevices; CallModel * mCallModel; bool mShowMe = true; };