Fix layoutChanged signals : endInsertRows/endRemoveRows doesn't call layoutChanged signals. Call it after any changes to propagate updates.

This commit is contained in:
Julien Wadel 2023-05-23 12:51:41 +02:00
parent 89ad42e1a6
commit 843fb0769d
15 changed files with 42 additions and 36 deletions

View file

@ -62,14 +62,18 @@ public:
// Add functions
virtual void add(T item){
int row = mList.count();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
mList << item;
endInsertRows();
emit layoutChanged();
}
virtual void add(QList<T> items){
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), mList.size(), mList.size() + items.size()-1);
mList << items;
endInsertRows();
emit layoutChanged();
}
virtual void prepend(T item){
@ -93,10 +97,12 @@ public:
int limit = row + count - 1;
if (row < 0 || count < 0 || limit >= mList.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i)
mList.takeAt(row);
endRemoveRows();
emit layoutChanged();
return true;
}

View file

@ -65,10 +65,12 @@ public:
template <class T>
void add(QList<QSharedPointer<T>> items){
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), mList.size(), mList.size() + items.size() - 1);
for(auto i : items)
mList << i.template objectCast<QObject>();
endInsertRows();
emit layoutChanged();
}
template <class T>
@ -78,10 +80,12 @@ public:
template <class T>
void prepend(QList<QSharedPointer<T>> items){
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), 0, items.size()-1);
items << mList;
mList = items;
endInsertRows();
emit layoutChanged();
}
virtual bool remove(QObject *itemToRemove) override{

View file

@ -581,7 +581,6 @@ void CallsListModel::addCall (const shared_ptr<linphone::Call> &call) {
connect(callModel.get(), &CallModel::statusChanged, this, &CallsListModel::handleCallStatusChanged);
add(callModel);
emit layoutChanged();
if (call->getDir() == linphone::Call::Dir::Outgoing) {
QQuickWindow *callsWindow = App::getInstance()->getCallsWindow();
@ -616,7 +615,6 @@ void CallsListModel::addDummyCall () {
connect(callModel.get(), &CallModel::statusChanged, this, &CallsListModel::handleCallStatusChanged);
add(callModel);
emit layoutChanged();
}
void CallsListModel::removeCall (const shared_ptr<linphone::Call> &call) {

View file

@ -238,7 +238,7 @@ bool ChatRoomModel::removeRows (int row, int count, const QModelIndex &parent) {
if (row < 0 || count < 0 || limit >= mList.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) {
@ -253,6 +253,7 @@ bool ChatRoomModel::removeRows (int row, int count, const QModelIndex &parent) {
else if (limit == mList.count())
emit lastEntryRemoved();
emit focused();// Removing rows is like having focus. Don't wait asynchronous events.
emit layoutChanged();
return true;
}
@ -870,9 +871,6 @@ void ChatRoomModel::updateNewMessageNotice(const int& count){
prepend(mUnreadMessageNotice);
qDebug() << "New message notice timestamp to :" << lastUnreadMessage.toString() << " recv at " << lastReceivedMessage.toString();
}
// Seems to be a Qt bug : If layoutChanged() is not send, some delegates after notice will be wrong (their $chatEntry will be updated with undefined while not being really updated on next check)
// Reproduce case with a ChatMessage after a Notice: On Notice deletion, this chatMessage will update its text with an undefined $chatEntry. But when checking the value of its $chatEntry after this event(make a MouseArea with a click event), it will be the correct one (and not the undefined).
emit layoutChanged();
}
}
@ -981,6 +979,7 @@ void ChatRoomModel::initEntries(){
EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mFirstLastEntriesStep, this);
qDebug() << "Internal Entries : Built";
if(entries.size() >0){
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(),0, entries.size()-1);
for(auto e : entries) {
if( e->mType == ChatRoomModel::EntryType::MessageEntry){
@ -991,6 +990,7 @@ void ChatRoomModel::initEntries(){
mList.push_back(e);
}
endInsertRows();
emit layoutChanged();
updateNewMessageNotice(mChatRoom->getUnreadMessagesCount());
}
qDebug() << "Internal Entries : End";
@ -1073,13 +1073,16 @@ int ChatRoomModel::loadMoreEntries(){
EntrySorterHelper::getLimitedSelection(&entries, prepareEntries, mLastEntriesStep, this);
if(entries.size() >0){
if(mPostModelChangedEvents)
if(mPostModelChangedEvents){
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), 0, entries.size()-1);
}
for(auto entry : entries)
mList.prepend(entry);
if(mPostModelChangedEvents)
if(mPostModelChangedEvents){
endInsertRows();
//emit layoutChanged();
emit layoutChanged();
}
updateLastUpdateTime();
}
newEntries = entries.size();
@ -1111,9 +1114,11 @@ void ChatRoomModel::insertCall (const std::shared_ptr<linphone::CallLog> &callLo
QSharedPointer<ChatCallModel> model = ChatCallModel::create(callLog, true);
if(model){
int row = mList.count();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
mList << model;
endInsertRows();
emit layoutChanged();
if (callLog->getStatus() == linphone::Call::Status::Success) {
model = ChatCallModel::create(callLog, false);
if(model)
@ -1141,7 +1146,6 @@ void ChatRoomModel::insertCalls (const QList<std::shared_ptr<linphone::CallLog>
}
if(entries.size() > 0){
prepend(entries);
emit layoutChanged();
}
}
}
@ -1173,7 +1177,6 @@ void ChatRoomModel::insertMessages (const QList<std::shared_ptr<linphone::ChatMe
if(entries.size() > 0){
prepend(entries);
setUnreadMessagesCount(mChatRoom->getUnreadMessagesCount());
emit layoutChanged();
}
}
}
@ -1197,7 +1200,6 @@ void ChatRoomModel::insertNotices (const QList<std::shared_ptr<linphone::EventLo
}
if(entries.size() > 0){
prepend(entries);
emit layoutChanged();
}
}
}

View file

@ -79,7 +79,7 @@ bool ConferenceHelperModel::ConferenceAddModel::addToConference (const shared_pt
return false;
int row = rowCount();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
addToConferencePrivate(linphoneAddress->clone());
endInsertRows();
@ -99,6 +99,7 @@ bool ConferenceHelperModel::ConferenceAddModel::addToConference (const QString &
return false;
int row = rowCount();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
qInfo() << QStringLiteral("Add sip address to conference: `%1`.").arg(sipAddress);
@ -127,7 +128,7 @@ bool ConferenceHelperModel::ConferenceAddModel::removeFromConference (const QStr
return false;
int row = mRefs.indexOf(&(*it));
emit layoutAboutToBeChanged();
beginRemoveRows(QModelIndex(), row, row);
qInfo() << QStringLiteral("Remove sip address from conference: `%1`.").arg(sipAddress);
@ -136,7 +137,7 @@ bool ConferenceHelperModel::ConferenceAddModel::removeFromConference (const QStr
mSipAddresses.remove(sipAddress);
endRemoveRows();
emit layoutChanged();
mConferenceHelperModel->invalidate();
return true;

View file

@ -74,7 +74,7 @@ bool ContactsImporterListModel::removeRows (int row, int count, const QModelInde
if (row < 0 || count < 0 || limit >= mList.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) {
@ -82,7 +82,7 @@ bool ContactsImporterListModel::removeRows (int row, int count, const QModelInde
}
endRemoveRows();
emit layoutChanged();
return true;
}
@ -115,8 +115,6 @@ ContactsImporterModel *ContactsImporterListModel::createContactsImporter(QVarian
contactsImporter->setFields(newData);
addContactsImporter(contactsImporter);
emit layoutChanged();
emit contactsImporterAdded(contactsImporter);
}
}

View file

@ -63,7 +63,7 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
return false;
auto friendsList = CoreManager::getInstance()->getCore()->getFriendsLists();
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) {
@ -79,7 +79,7 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren
}
endRemoveRows();
emit layoutChanged();
return true;
}
@ -140,8 +140,6 @@ ContactModel *ContactsListModel::addContact (VcardModel *vcardModel) {
// Make sure new subscribe is issued.
friendsList->updateSubscriptions();
emit layoutChanged();
emit contactAdded(contact);
return contact.get();

View file

@ -127,7 +127,7 @@ bool HistoryModel::removeRows (int row, int count, const QModelIndex &parent) {
if (row < 0 || count < 0 || limit >= mEntries.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i) {
@ -143,6 +143,7 @@ bool HistoryModel::removeRows (int row, int count, const QModelIndex &parent) {
emit lastEntryRemoved();
emit CoreManager::getInstance()->callLogsCountChanged();
emit focused();// Removing rows is like having focus. Don't wait asynchronous events.
emit layoutChanged();
return true;
}
@ -235,7 +236,7 @@ void HistoryModel::insertCall (const shared_ptr<linphone::CallLog> &callLog) {
});
int row = int(distance(mEntries.begin(), it));
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
it = mEntries.insert(it, entry);
endInsertRows();

View file

@ -72,7 +72,6 @@ void LdapListModel::add(){
connect(ldap.get(), &LdapModel::indexChanged, this, &LdapListModel::indexChanged);
ldap->init();
ProxyListModel::add(ldap);
emit layoutChanged();
}
void LdapListModel::remove (LdapModel *ldap) {

View file

@ -93,7 +93,6 @@ void ColorListModel::add(QSharedPointer<ColorModel> color){
mData.insert(color->getName(), QVariant::fromValue(color.get()));
ProxyListModel::add(color);
emit layoutChanged();
}
QString ColorListModel::buildDescription(QString description){

View file

@ -62,8 +62,6 @@ void ImageListModel::add(QSharedPointer<ImageModel> image){
mData.insert(image->getId(), QVariant::fromValue(image.get()));
ProxyListModel::add(image);
emit layoutChanged();
}
void ImageListModel::useConfig (const std::shared_ptr<linphone::Config> &config) {

View file

@ -153,6 +153,8 @@ void ParticipantListModel::updateParticipants () {
}
if( itDbParticipant == dbParticipants.end()){
int row = itParticipant - mList.begin();
if(!changed)
emit layoutAboutToBeChanged();
beginRemoveRows(QModelIndex(), row, row);
itParticipant = mList.erase(itParticipant);
endRemoveRows();
@ -196,7 +198,6 @@ void ParticipantListModel::add (QSharedPointer<ParticipantModel> participant){
connect(this, &ParticipantListModel::securityLevelChanged, participant.get(), &ParticipantModel::onSecurityLevelChanged);
connect(participant.get(),&ParticipantModel::updateAdminStatus, this, &ParticipantListModel::setAdminStatus);
ProxyListModel::add(participant);
emit layoutChanged();
emit participantsChanged();
}

View file

@ -256,14 +256,14 @@ bool SipAddressesModel::removeRows (int row, int count, const QModelIndex &paren
if (row < 0 || count < 0 || limit >= mRefs.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i)
mPeerAddressToSipAddressEntry.remove(mRefs.takeAt(row)->sipAddress);
endRemoveRows();
emit layoutChanged();
return true;
}
@ -545,7 +545,7 @@ void SipAddressesModel::addOrUpdateSipAddress (const QString &sipAddress, T data
addOrUpdateSipAddress(sipAddressEntry, data);
int row = mRefs.count();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(), row, row);
mPeerAddressToSipAddressEntry[sipAddress] = move(sipAddressEntry);

View file

@ -105,7 +105,7 @@ bool TimelineListModel::removeRows (int row, int count, const QModelIndex &paren
if (row < 0 || count < 0 || limit >= mList.count())
return false;
emit layoutAboutToBeChanged();
beginRemoveRows(parent, row, limit);
for (int i = 0; i < count; ++i){
@ -122,6 +122,7 @@ bool TimelineListModel::removeRows (int row, int count, const QModelIndex &paren
}
emit countChanged();
emit layoutChanged();
return true;
}
@ -314,7 +315,6 @@ void TimelineListModel::add (QSharedPointer<TimelineModel> timeline){
connect(timeline.get(), &TimelineModel::chatRoomDeleted, this, &TimelineListModel::onChatRoomDeleted);
connect(chatRoomModel, &ChatRoomModel::lastUpdateTimeChanged, this, &TimelineListModel::updated);
ProxyListModel::add(timeline);
emit layoutChanged();
emit countChanged();
}

View file

@ -48,7 +48,6 @@ void TunnelConfigListModel::updateTunnelConfigs(std::shared_ptr<linphone::Tunnel
mList << QSharedPointer<TunnelConfigModel>::create(config);
}
endResetModel();
emit layoutChanged();
}
bool TunnelConfigListModel::apply(std::shared_ptr<linphone::Tunnel> tunnel){
@ -62,9 +61,11 @@ bool TunnelConfigListModel::apply(std::shared_ptr<linphone::Tunnel> tunnel){
void TunnelConfigListModel::addTunnelConfig(){
int row = rowCount();
emit layoutAboutToBeChanged();
beginInsertRows(QModelIndex(),row,row);
mList << QSharedPointer<TunnelConfigModel>::create(linphone::Factory::get()->createTunnelConfig());
endInsertRows();
emit layoutChanged();
}
void TunnelConfigListModel::removeTunnelConfig(std::shared_ptr<linphone::Tunnel> tunnel, TunnelConfigModel * model){