[partition] Simplify DeviceModel sorting
This commit is contained in:
parent
544131c4bc
commit
cccd4402d8
@ -36,6 +36,15 @@
|
|||||||
// STL
|
// STL
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
static void
|
||||||
|
sortDevices( DeviceModel::DeviceList& l )
|
||||||
|
{
|
||||||
|
std::sort( l.begin(), l.end(), []( const Device* dev1, const Device* dev2 )
|
||||||
|
{
|
||||||
|
return dev1->deviceNode() < dev2->deviceNode();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
DeviceModel::DeviceModel( QObject* parent )
|
DeviceModel::DeviceModel( QObject* parent )
|
||||||
: QAbstractListModel( parent )
|
: QAbstractListModel( parent )
|
||||||
{
|
{
|
||||||
@ -50,10 +59,7 @@ DeviceModel::init( const DeviceList& devices )
|
|||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_devices = devices;
|
m_devices = devices;
|
||||||
std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 )
|
sortDevices( m_devices );
|
||||||
{
|
|
||||||
return dev1->deviceNode() < dev2->deviceNode();
|
|
||||||
} );
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,13 +137,8 @@ void
|
|||||||
DeviceModel::addDevice( Device *device )
|
DeviceModel::addDevice( Device *device )
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
m_devices << device;
|
m_devices << device;
|
||||||
std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 )
|
sortDevices( m_devices );
|
||||||
{
|
|
||||||
return dev1->deviceNode() < dev2->deviceNode();
|
|
||||||
} );
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,12 +146,7 @@ void
|
|||||||
DeviceModel::removeDevice( Device *device )
|
DeviceModel::removeDevice( Device *device )
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
m_devices.removeAll( device );
|
m_devices.removeAll( device );
|
||||||
std::sort( m_devices.begin(), m_devices.end(), []( const Device* dev1, const Device* dev2 )
|
sortDevices( m_devices );
|
||||||
{
|
|
||||||
return dev1->deviceNode() < dev2->deviceNode();
|
|
||||||
} );
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user