From 9faa3cac8647ccb21adcbb7991712a7de8d7d2c9 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 20 Mar 2020 16:01:31 +0200 Subject: [PATCH] meaning sortings for layouts model --- .../controllers/layoutscontroller.cpp | 2 +- app/settings/models/layoutsmodel.cpp | 61 ++++++++++++++++++- app/settings/models/layoutsmodel.h | 3 +- 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 373703c94..2ea86498b 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -106,7 +106,7 @@ void Layouts::initView() m_view->verticalHeader()->setVisible(false); m_view->setSortingEnabled(true); - m_proxyModel->setSortRole(Qt::UserRole); + m_proxyModel->setSortRole(Model::Layouts::SORTINGROLE); m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_view->sortByColumn(Model::Layouts::NAMECOLUMN, Qt::AscendingOrder); diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp index d7d06831e..ee32a4145 100644 --- a/app/settings/models/layoutsmodel.cpp +++ b/app/settings/models/layoutsmodel.cpp @@ -71,7 +71,7 @@ Layouts::Layouts(QObject *parent, Latte::Corona *corona) Layouts::~Layouts() { - qDeleteAll(m_activitiesInfo); + qDeleteAll(m_activitiesInfo); } bool Layouts::containsCurrentName(const QString &name) const @@ -447,16 +447,34 @@ QVariant Layouts::data(const QModelIndex &index, int role) const case HIDDENTEXTCOLUMN: return QVariant{}; case BACKGROUNDCOLUMN: + if (role == SORTINGROLE) { + return m_layoutsTable[row].name; + } + if (role == Qt::UserRole) { return m_layoutsTable[row].background.isEmpty() ? m_layoutsTable[row].color : m_layoutsTable[row].background; } break; case NAMECOLUMN: + if (role == SORTINGROLE) { + return m_layoutsTable[row].name; + } + if ((role == Qt::DisplayRole) || (role == Qt::UserRole)) { return m_layoutsTable[row].name; } break; case MENUCOLUMN: + if (role == SORTINGROLE) { + if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { + return 1; + } else if (m_layoutsTable[row].isShownInMenu) { + return 2; + } + + return 0; + } + if (role == Qt::DisplayRole) { return m_layoutsTable[row].isShownInMenu ? CheckMark : QVariant{}; } else if (role == Qt::UserRole) { @@ -464,6 +482,16 @@ QVariant Layouts::data(const QModelIndex &index, int role) const } break; case BORDERSCOLUMN: + if (role == SORTINGROLE) { + if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { + return 1; + } else if (m_layoutsTable[row].hasDisabledBorders) { + return 2; + } + + return 0; + } + if (role == Qt::DisplayRole) { return m_layoutsTable[row].hasDisabledBorders ? CheckMark : QVariant{}; } else if (role == Qt::UserRole) { @@ -471,11 +499,42 @@ QVariant Layouts::data(const QModelIndex &index, int role) const } break; case ACTIVITYCOLUMN: + if (role == SORTINGROLE) { + if ((m_inMultipleMode && m_layoutsTable[row].isShared())) { + //! normal priority + return 1; + } else if (m_layoutsTable[row].activities.count() > 0) { + if (m_layoutsTable[row].activities.contains(Data::Layout::FREEACTIVITIESID)) { + //! highest priority + return 9999; + } else { + //! high priority + return m_layoutsTable[row].activities.count()+1; + } + } + + return 0; + } + if (role == Qt::UserRole) { return m_layoutsTable[row].activities; } break; case SHAREDCOLUMN: + if (role == SORTINGROLE) { + if (m_layoutsTable[row].shares.count() > 0) { + //! highest priority based on number of shares + return 9999 + m_layoutsTable[row].shares.count(); + } + + if (m_layoutsTable[row].activities.contains(Data::Layout::FREEACTIVITIESID)) { + //! high activity priority + return 9998; + } + + return 0; + } + if (role == Qt::UserRole) { return m_layoutsTable[row].shares; } diff --git a/app/settings/models/layoutsmodel.h b/app/settings/models/layoutsmodel.h index 836c50489..5be455cf0 100644 --- a/app/settings/models/layoutsmodel.h +++ b/app/settings/models/layoutsmodel.h @@ -65,7 +65,8 @@ public: ALLACTIVITIESSORTEDROLE, ALLACTIVITIESDATAROLE, ALLLAYOUTSROLE, - SHAREDTOINEDIT + SHAREDTOINEDIT, + SORTINGROLE }; explicit Layouts(QObject *parent, Latte::Corona *corona);