diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp index 0b84f6a7a..294ea970e 100644 --- a/app/settings/models/layoutsmodel.cpp +++ b/app/settings/models/layoutsmodel.cpp @@ -355,6 +355,11 @@ Qt::ItemFlags Layouts::flags(const QModelIndex &index) const return flags; } +int Layouts::sortingPriority(const SortingPriority &priority, const int &row) const +{ + return m_layoutsTable[row].isActive ? 2 * (int)priority : (int)priority; +} + QVariant Layouts::data(const QModelIndex &index, int role) const { const int row = index.row(); @@ -429,12 +434,12 @@ QVariant Layouts::data(const QModelIndex &index, int role) const case MENUCOLUMN: if (role == SORTINGROLE) { if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { - return 1; + return sortingPriority(MEDIUMPRIORITY, row); } else if (m_layoutsTable[row].isShownInMenu) { - return 2; + return sortingPriority(HIGHESTPRIORITY, row); } - return 0; + return sortingPriority(NORMALPRIORITY, row); } if (role == ORIGINALISSHOWNINMENUROLE) { @@ -448,12 +453,12 @@ QVariant Layouts::data(const QModelIndex &index, int role) const case BORDERSCOLUMN: if (role == SORTINGROLE) { if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { - return 1; + return sortingPriority(MEDIUMPRIORITY, row); } else if (m_layoutsTable[row].hasDisabledBorders) { - return 2; + return sortingPriority(HIGHESTPRIORITY, row); } - return 0; + return sortingPriority(NORMALPRIORITY, row); } if (role == ORIGINALHASBORDERSROLE) { @@ -467,19 +472,16 @@ QVariant Layouts::data(const QModelIndex &index, int role) const case ACTIVITYCOLUMN: if (role == SORTINGROLE) { if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { - //! normal priority - return 1; + return sortingPriority(MEDIUMPRIORITY, row) + m_layoutsTable[row].shares.count(); } else if (m_layoutsTable[row].activities.count() > 0) { if (m_layoutsTable[row].activities.contains(Data::Layout::FREEACTIVITIESID)) { - //! highest priority - return 9999; + return sortingPriority(HIGHESTPRIORITY, row); } else { - //! high priority - return m_layoutsTable[row].activities.count()+1; + return sortingPriority(HIGHPRIORITY, row) + m_layoutsTable[row].activities.count(); } } - return 0; + return sortingPriority(NORMALPRIORITY, row) + m_layoutsTable[row].activities.count(); } if (role == ORIGINALASSIGNEDACTIVITIESROLE) { @@ -494,15 +496,15 @@ QVariant Layouts::data(const QModelIndex &index, int role) const if (role == SORTINGROLE) { if (m_layoutsTable[row].shares.count() > 0) { //! highest priority based on number of shares - return 9999 + m_layoutsTable[row].shares.count(); + return HIGHESTPRIORITY + m_layoutsTable[row].shares.count(); } if (m_layoutsTable[row].activities.contains(Data::Layout::FREEACTIVITIESID)) { //! high activity priority - return 9998; + return HIGHPRIORITY; } - return 0; + return NORMALPRIORITY; } if (role == ORIGINALSHARESROLE) { diff --git a/app/settings/models/layoutsmodel.h b/app/settings/models/layoutsmodel.h index 7978fd4ff..0e77fbb55 100644 --- a/app/settings/models/layoutsmodel.h +++ b/app/settings/models/layoutsmodel.h @@ -75,6 +75,14 @@ public: ORIGINALSHARESROLE }; + enum SortingPriority + { + NORMALPRIORITY = 0, + MEDIUMPRIORITY = 1000, + HIGHPRIORITY = 2000, + HIGHESTPRIORITY = 3000 + }; + explicit Layouts(QObject *parent, Latte::Corona *corona); ~Layouts(); @@ -145,6 +153,8 @@ private: void setId(const int &row, const QString &newId); void setShares(const int &row, const QStringList &shares); + int sortingPriority(const SortingPriority &priority, const int &row) const; + QStringList cleanStrings(const QStringList &original, const QStringList &occupied); QStringList assignedActivitiesFromShared(const int &row) const;