[vlc-commits] qt: keep the device list model alphabetically sorted
Pierre Lamot
git at videolan.org
Thu Oct 31 01:02:27 CET 2019
vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Tue Oct 29 14:51:01 2019 +0100| [273b13b01f16add4f8fbbf7fae53f47a1f21454d] | committer: Jean-Baptiste Kempf
qt: keep the device list model alphabetically sorted
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=273b13b01f16add4f8fbbf7fae53f47a1f21454d
---
.../components/mediacenter/mlnetworkdevicemodel.cpp | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
index 7fa57c7813..8979a19836 100644
--- a/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
+++ b/modules/gui/qt/components/mediacenter/mlnetworkdevicemodel.cpp
@@ -279,14 +279,21 @@ void MLNetworkDeviceModel::refreshDeviceList( MediaSourcePtr mediaSource, input_
item.inputItem = InputItemPtr(children[i]->p_item);
QMetaObject::invokeMethod(this, [this, item]() mutable {
- auto it = std::find_if( begin( m_items ), end( m_items ), [&item](const Item& i) {
- return QString::compare(item.name , i.name, Qt::CaseInsensitive ) == 0 &&
- item.mainMrl.scheme() == i.mainMrl.scheme();
+ auto it = std::upper_bound(begin( m_items ), end( m_items ), item, [](const Item& a, const Item& b) {
+ int comp = QString::compare(a.name , b.name, Qt::CaseInsensitive );
+ if (comp == 0)
+ comp = QString::compare(a.mainMrl.scheme(), b.mainMrl.scheme());
+ return comp <= 0;
});
- if ( it != end( m_items ) )
+
+ if (it != end( m_items )
+ && QString::compare(it->name , item.name, Qt::CaseInsensitive ) == 0
+ && it->mainMrl.scheme() == item.mainMrl.scheme())
return;
- beginInsertRows( {}, m_items.size(), m_items.size() );
- m_items.push_back( std::move( item ) );
+
+ int pos = std::distance(begin(m_items), it);
+ beginInsertRows( {}, pos, pos );
+ m_items.insert( it, std::move( item ) );
endInsertRows();
});
}
More information about the vlc-commits
mailing list