diff --git a/app/data/generictable.cpp b/app/data/generictable.cpp index e5c049907..61da8e56e 100644 --- a/app/data/generictable.cpp +++ b/app/data/generictable.cpp @@ -71,6 +71,13 @@ GenericTable &GenericTable::operator<<(const T &rhs) return (*this); } +template +GenericTable &GenericTable::insert(const int &pos, const T &rhs) +{ + m_list.insert(pos, rhs); + return (*this); +} + template bool GenericTable::operator==(const GenericTable &rhs) const { @@ -189,6 +196,22 @@ int GenericTable::rowCount() const return m_list.count(); } +template +int GenericTable::sortedPosForName(const QString &name) const +{ + int pos{0}; + + for(int i=0; i QString GenericTable::idForName(const QString &name) const { diff --git a/app/data/generictable.h b/app/data/generictable.h index 77033e0f0..e25aca39d 100644 --- a/app/data/generictable.h +++ b/app/data/generictable.h @@ -43,6 +43,7 @@ public: GenericTable &operator=(const GenericTable &rhs); GenericTable &operator=(GenericTable &&rhs); GenericTable &operator<<(const T &rhs); + GenericTable &insert(const int &pos, const T &rhs); bool operator==(const GenericTable &rhs) const; bool operator!=(const GenericTable &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; diff --git a/app/layouts/synchronizer.cpp b/app/layouts/synchronizer.cpp index 59a056de8..0f5774c43 100644 --- a/app/layouts/synchronizer.cpp +++ b/app/layouts/synchronizer.cpp @@ -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(); } diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp index e9ad5a3e4..cf5f28b2c 100644 --- a/app/settings/models/layoutsmodel.cpp +++ b/app/settings/models/layoutsmodel.cpp @@ -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();