From 5e75b889e01b48f3920e2a4e8e9f8ad8a289c2b5 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Thu, 12 Mar 2020 11:53:37 +0200 Subject: [PATCH] introduce initial LayoutsModel --- app/CMakeLists.txt | 1 + app/settings/data/CMakeLists.txt | 2 +- .../data/{layout.cpp => layoutdata.cpp} | 2 +- app/settings/data/{layout.h => layoutdata.h} | 0 app/settings/data/layoutstable.cpp | 5 ++ app/settings/data/layoutstable.h | 3 +- app/settings/models/CMakeLists.txt | 5 ++ app/settings/models/layoutsmodel.cpp | 51 +++++++++++++++ app/settings/models/layoutsmodel.h | 62 +++++++++++++++++++ app/settings/settingsdialog.cpp | 10 +-- 10 files changed, 134 insertions(+), 7 deletions(-) rename app/settings/data/{layout.cpp => layoutdata.cpp} (98%) rename app/settings/data/{layout.h => layoutdata.h} (100%) create mode 100644 app/settings/models/CMakeLists.txt create mode 100644 app/settings/models/layoutsmodel.cpp create mode 100644 app/settings/models/layoutsmodel.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 275e04e4d..0c1af4f6d 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -16,6 +16,7 @@ add_subdirectory(plasma/extended) add_subdirectory(settings) add_subdirectory(settings/data) add_subdirectory(settings/delegates) +add_subdirectory(settings/models) add_subdirectory(settings/tools) add_subdirectory(shortcuts) add_subdirectory(view) diff --git a/app/settings/data/CMakeLists.txt b/app/settings/data/CMakeLists.txt index 480c90d73..8e10846ba 100644 --- a/app/settings/data/CMakeLists.txt +++ b/app/settings/data/CMakeLists.txt @@ -1,6 +1,6 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} - ${CMAKE_CURRENT_SOURCE_DIR}/layout.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/layoutdata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/layoutstable.cpp PARENT_SCOPE ) diff --git a/app/settings/data/layout.cpp b/app/settings/data/layoutdata.cpp similarity index 98% rename from app/settings/data/layout.cpp rename to app/settings/data/layoutdata.cpp index a1301a5f4..614433d36 100644 --- a/app/settings/data/layout.cpp +++ b/app/settings/data/layoutdata.cpp @@ -18,7 +18,7 @@ * */ -#include "layout.h" +#include "layoutdata.h" namespace Latte { namespace Settings { diff --git a/app/settings/data/layout.h b/app/settings/data/layoutdata.h similarity index 100% rename from app/settings/data/layout.h rename to app/settings/data/layoutdata.h diff --git a/app/settings/data/layoutstable.cpp b/app/settings/data/layoutstable.cpp index 1cf123d3c..4ce48e37b 100644 --- a/app/settings/data/layoutstable.cpp +++ b/app/settings/data/layoutstable.cpp @@ -124,6 +124,11 @@ bool LayoutsTable::contains(const QString &id) const return false; } +int LayoutsTable::rowCount() const +{ + return m_layouts.count(); +} + } } } diff --git a/app/settings/data/layoutstable.h b/app/settings/data/layoutstable.h index 4770acf40..7ec932763 100644 --- a/app/settings/data/layoutstable.h +++ b/app/settings/data/layoutstable.h @@ -21,7 +21,7 @@ #ifndef SETTINGSDATALAYOUTSTABLE_H #define SETTINGSDATALAYOUTSTABLE_H -#include "layout.h" +#include "layoutdata.h" #include @@ -47,6 +47,7 @@ public: const Layout operator[](const uint &index) const; bool contains(const QString &id) const; + int rowCount() const; protected: //! #id, layout_record diff --git a/app/settings/models/CMakeLists.txt b/app/settings/models/CMakeLists.txt new file mode 100644 index 000000000..bab028042 --- /dev/null +++ b/app/settings/models/CMakeLists.txt @@ -0,0 +1,5 @@ +set(lattedock-app_SRCS + ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/layoutsmodel.cpp + PARENT_SCOPE +) diff --git a/app/settings/models/layoutsmodel.cpp b/app/settings/models/layoutsmodel.cpp new file mode 100644 index 000000000..649109cdc --- /dev/null +++ b/app/settings/models/layoutsmodel.cpp @@ -0,0 +1,51 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "layoutsmodel.h" + +namespace Latte { +namespace Settings { +namespace Model { + +Layouts::Layouts(QObject *parent) + : QAbstractTableModel(parent) +{ +} + +int Layouts::rowCount(const QModelIndex &parent) const +{ + return m_layoutsTable.rowCount(); +} + +int Layouts::columnCount(const QModelIndex &parent) const +{ + return SHAREDCOLUMN; +} + +QVariant Layouts::data(const QModelIndex &index, int role) const +{ + return QVariant(); +} + + +} +} +} + diff --git a/app/settings/models/layoutsmodel.h b/app/settings/models/layoutsmodel.h new file mode 100644 index 000000000..580e3ec4c --- /dev/null +++ b/app/settings/models/layoutsmodel.h @@ -0,0 +1,62 @@ +/* + * Copyright 2020 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef SETTINGSLAYOUTSMODEL_H +#define SETTINGSLAYOUTSMODEL_H + +// local +#include "../data/layoutstable.h" +// Qt +#include +#include + + +namespace Latte { +namespace Settings { +namespace Model { + +class Layouts : public QAbstractTableModel +{ +public: + const int IDCOLUMN = 0; + const int HIDDENTEXTCOLUMN = 1; + const int COLORCOLUMN = 2; + const int NAMECOLUMN = 3; + const int MENUCOLUMN = 4; + const int BORDERSCOLUMN = 5; + const int ACTIVITYCOLUMN = 6; + const int SHAREDCOLUMN = 7; + + explicit Layouts(QObject *parent = nullptr); + + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + + QVariant data(const QModelIndex &index, int role) const override; + +private: + Data::LayoutsTable m_layoutsTable; +}; + +} +} +} + +#endif diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 7b1b428bb..1b2930e8c 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -34,7 +34,7 @@ #include "../layouts/synchronizer.h" #include "../liblatte2/types.h" #include "../plasma/extended/theme.h" -#include "data/layout.h" +#include "data/layoutdata.h" #include "delegates/activitiesdelegate.h" #include "delegates/checkboxdelegate.h" #include "delegates/colorcmbboxdelegate.h" @@ -1714,7 +1714,8 @@ bool SettingsDialog::saveAllChanges() //qDebug() << i << ". " << id << " - " << color << " - " << name << " - " << menu << " - " << lActivities; //! update the generic parts of the layouts - Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name); + bool isOriginalLayout = o_layoutsOriginalData.contains(id); + Layout::GenericLayout *genericActive= isOriginalLayout ?m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name) : nullptr; Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id]; //! unlock read-only layout @@ -1740,7 +1741,7 @@ bool SettingsDialog::saveAllChanges() } //! update only the Central-specific layout parts - CentralLayout *centralActive= m_corona->layoutsManager()->synchronizer()->centralLayout(o_layoutsOriginalData[id].name); + CentralLayout *centralActive = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->centralLayout(o_layoutsOriginalData[id].name) : nullptr; CentralLayout *central = centralActive ? centralActive : m_layouts[id]; if (central->showInMenu() != menu) { @@ -1853,7 +1854,8 @@ bool SettingsDialog::saveAllChanges() QString name = m_model->data(m_model->index(i, NAMECOLUMN), Qt::DisplayRole).toString(); bool locked = m_model->data(m_model->index(i, NAMECOLUMN), Qt::UserRole).toBool(); - Layout::GenericLayout *generic = m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name); + bool isOriginalLayout{o_layoutsOriginalData.contains(id)}; + Layout::GenericLayout *generic = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name) : nullptr; Layout::GenericLayout *layout = generic ? generic : m_layouts[id]; if (layout && locked && layout->isWritable()) {