mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-23 13:33:50 +03:00
sort layouts based on their names
--when layouts are presented to the user it is preferred to be perfectly sorted based on their names
This commit is contained in:
parent
8b836da44e
commit
7a3d68ed61
@ -71,6 +71,13 @@ GenericTable<T> &GenericTable<T>::operator<<(const T &rhs)
|
||||
return (*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
GenericTable<T> &GenericTable<T>::insert(const int &pos, const T &rhs)
|
||||
{
|
||||
m_list.insert(pos, rhs);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool GenericTable<T>::operator==(const GenericTable<T> &rhs) const
|
||||
{
|
||||
@ -189,6 +196,22 @@ int GenericTable<T>::rowCount() const
|
||||
return m_list.count();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int GenericTable<T>::sortedPosForName(const QString &name) const
|
||||
{
|
||||
int pos{0};
|
||||
|
||||
for(int i=0; i<m_list.count(); ++i) {
|
||||
if (QString::compare(m_list[i].name, name, Qt::CaseInsensitive) <= 0) {
|
||||
pos++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
QString GenericTable<T>::idForName(const QString &name) const
|
||||
{
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
GenericTable<T> &operator=(const GenericTable<T> &rhs);
|
||||
GenericTable<T> &operator=(GenericTable<T> &&rhs);
|
||||
GenericTable<T> &operator<<(const T &rhs);
|
||||
GenericTable<T> &insert(const int &pos, const T &rhs);
|
||||
bool operator==(const GenericTable<T> &rhs) const;
|
||||
bool operator!=(const GenericTable<T> &rhs) const;
|
||||
T &operator[](const QString &id);
|
||||
@ -56,6 +57,7 @@ public:
|
||||
|
||||
int indexOf(const QString &id) const;
|
||||
int rowCount() const;
|
||||
int sortedPosForName(const QString &name) const;
|
||||
|
||||
QString idForName(const QString &name) const;
|
||||
|
||||
|
@ -576,6 +576,9 @@ void Synchronizer::loadLayouts()
|
||||
//! Shared Layouts should not be used for Activities->Layouts assignments or published lists
|
||||
clearSharedLayoutsFromCentralLists();
|
||||
|
||||
m_layouts.sort(Qt::CaseInsensitive);
|
||||
m_menuLayouts.sort(Qt::CaseInsensitive);
|
||||
|
||||
emit layoutsChanged();
|
||||
emit menuLayoutsChanged();
|
||||
|
||||
@ -609,6 +612,9 @@ void Synchronizer::onLayoutAdded(const QString &layout)
|
||||
}
|
||||
|
||||
if (m_isLoaded) {
|
||||
m_layouts.sort(Qt::CaseInsensitive);
|
||||
m_menuLayouts.sort(Qt::CaseInsensitive);
|
||||
|
||||
emit layoutsChanged();
|
||||
emit menuLayoutsChanged();
|
||||
}
|
||||
|
@ -128,9 +128,11 @@ void Layouts::clear()
|
||||
}
|
||||
|
||||
void Layouts::appendLayout(const Latte::Data::Layout &layout)
|
||||
{
|
||||
beginInsertRows(QModelIndex(), m_layoutsTable.rowCount(), m_layoutsTable.rowCount());
|
||||
m_layoutsTable << layout;
|
||||
{
|
||||
int newRow = m_layoutsTable.sortedPosForName(layout.name);
|
||||
|
||||
beginInsertRows(QModelIndex(), newRow, newRow);
|
||||
m_layoutsTable.insert(newRow, layout);
|
||||
endInsertRows();
|
||||
|
||||
emit rowsInserted();
|
||||
|
Loading…
Reference in New Issue
Block a user