diff --git a/app/settings/viewsdialog/CMakeLists.txt b/app/settings/viewsdialog/CMakeLists.txt index 36798c575..f8445ecb6 100644 --- a/app/settings/viewsdialog/CMakeLists.txt +++ b/app/settings/viewsdialog/CMakeLists.txt @@ -1,5 +1,6 @@ set(lattedock-app_SRCS - ${lattedock-app_SRCS} + ${lattedock-app_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/viewscontroller.cpp ${CMAKE_CURRENT_SOURCE_DIR}/viewsdialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/viewshandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/viewsmodel.cpp diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp new file mode 100644 index 000000000..e0a0abecc --- /dev/null +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -0,0 +1,119 @@ +/* + * Copyright 2021 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 "viewscontroller.h" + +// local +#include "ui_viewsdialog.h" +#include "viewsdialog.h" +#include "viewshandler.h" +#include "viewsmodel.h" +#include "../generic/generictools.h" + +// Qt +#include +#include + +// KDE +#include + + +namespace Latte { +namespace Settings { +namespace Controller { + + +Views::Views(Settings::Handler::ViewsHandler *parent) + : QObject(parent), + m_handler(parent), + m_model(new Model::Views(this, m_handler->corona())), + m_proxyModel(new QSortFilterProxyModel(this)), + m_view(m_handler->ui()->viewsTable), + m_storage(KConfigGroup(KSharedConfig::openConfig(),"LatteSettingsDialog").group("ViewsDialog")) +{ + // loadConfig(); + m_proxyModel->setSourceModel(m_model); + + connect(m_model, &QAbstractItemModel::dataChanged, this, &Views::dataChanged); + connect(m_model, &Model::Views::rowsInserted, this, &Views::dataChanged); + connect(m_model, &Model::Views::rowsRemoved, this, &Views::dataChanged); + + init(); +} + +Views::~Views() +{ + // saveConfig(); +} + +QAbstractItemModel *Views::proxyModel() const +{ + return m_proxyModel; +} + +QAbstractItemModel *Views::baseModel() const +{ + return m_model; +} + +QTableView *Views::view() const +{ + return m_view; +} + +void Views::init() +{ + m_view->setModel(m_proxyModel); + //m_view->setHorizontalHeader(m_headerView); + m_view->verticalHeader()->setVisible(false); + m_view->setSortingEnabled(true); + + m_proxyModel->setSortRole(Model::Views::SORTINGROLE); + m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); + + m_view->sortByColumn(m_viewSortColumn, m_viewSortOrder); + + //m_view->setItemDelegateForColumn(Model::Layouts::NAMECOLUMN, new Settings::Layout::Delegate::LayoutName(this)); + //m_view->setItemDelegateForColumn(Model::Layouts::BACKGROUNDCOLUMN, new Settings::Layout::Delegate::BackgroundDelegate(this)); + //m_view->setItemDelegateForColumn(Model::Layouts::MENUCOLUMN, new Settings::Layout::Delegate::CheckBox(this)); + //m_view->setItemDelegateForColumn(Model::Layouts::BORDERSCOLUMN, new Settings::Layout::Delegate::CheckBox(this)); + //m_view->setItemDelegateForColumn(Model::Layouts::ACTIVITYCOLUMN, new Settings::Layout::Delegate::Activities(this)); +} + +bool Views::hasChangedData() const +{ + return true;// m_model->hasChangedData(); +} + +bool Views::hasSelectedView() const +{ + int selectedRow = m_view->currentIndex().row(); + + return (selectedRow >= 0); +} + +void Views::selectRow(const QString &id) +{ + // m_view->selectRow(rowForId(id)); +} + +} +} +} diff --git a/app/settings/viewsdialog/viewscontroller.h b/app/settings/viewsdialog/viewscontroller.h new file mode 100644 index 000000000..7185fed00 --- /dev/null +++ b/app/settings/viewsdialog/viewscontroller.h @@ -0,0 +1,113 @@ +/* + * Copyright 2021 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 VIEWSCONTROLLER_H +#define VIEWSCONTROLLER_H + +// local +#include +#include "viewsmodel.h" +#include "../../lattecorona.h" +#include "../../data/viewdata.h" +#include "../../data/viewstable.h" + +// Qt +#include +#include +#include +#include + + +namespace Latte { +class Corona; +class ViewsDialog; + +namespace Settings { +namespace Handler { +class ViewsHandler; +} +} +} + +namespace Latte { +namespace Settings { +namespace Controller { + +class Views : public QObject +{ + Q_OBJECT + +public: + explicit Views(Settings::Handler::ViewsHandler *parent); + ~Views(); + + QAbstractItemModel *proxyModel() const; + QAbstractItemModel *baseModel() const; + QTableView *view() const; + + bool hasChangedData() const; + + void sortByColumn(int column, Qt::SortOrder order); + + bool hasSelectedView() const; + // const Latte::Data::Layout selectedViewCurrentData() const; + // const Latte::Data::Layout selectedViewOriginalData() const; + + void selectRow(const QString &id); + + //! actions + // void reset(); + // void save(); + // void removeSelected(); + +signals: + void dataChanged(); + +private: + void init(); +private slots: + +// void loadConfig(); +// void saveConfig(); +// void storeColumnWidths(); +// void applyColumnWidths(); + +private: + Settings::Handler::ViewsHandler *m_handler{nullptr}; + + QTableView *m_view{nullptr}; + + //! layoutsView ui settings + int m_viewSortColumn; + Qt::SortOrder m_viewSortOrder; + QStringList m_viewColumnWidths; + + KConfigGroup m_storage; + + //! current data + Model::Views *m_model{nullptr}; + QSortFilterProxyModel *m_proxyModel{nullptr}; +}; + +} +} +} + +#endif diff --git a/app/settings/viewsdialog/viewshandler.cpp b/app/settings/viewsdialog/viewshandler.cpp index 7738cc7af..7089a0c17 100644 --- a/app/settings/viewsdialog/viewshandler.cpp +++ b/app/settings/viewsdialog/viewshandler.cpp @@ -22,11 +22,13 @@ // local #include "ui_viewsdialog.h" +#include "viewscontroller.h" #include "viewsdialog.h" #include "../settingsdialog/layoutscontroller.h" #include "../settingsdialog/layoutsmodel.h" #include "../settingsdialog/delegates/layoutcmbitemdelegate.h" #include "../../data/layoutstable.h" +#include "../../lattecorona.h" #include "../../layout/abstractlayout.h" #include "../../layout/centrallayout.h" #include "../../layouts/manager.h" @@ -44,7 +46,9 @@ ViewsHandler::ViewsHandler(Dialog::ViewsDialog *dialog) m_dialog(dialog), m_ui(m_dialog->ui()) { - init(); + m_viewsController = new Settings::Controller::Views(this); + + init(); } ViewsHandler::~ViewsHandler() @@ -92,6 +96,16 @@ void ViewsHandler::reload() loadLayout(c_data); } +Latte::Corona *ViewsHandler::corona() const +{ + return m_dialog->corona(); +} + +Ui::ViewsDialog *ViewsHandler::ui() const +{ + return m_ui; +} + void ViewsHandler::loadLayout(const Latte::Data::Layout &data) { updateWindowTitle(); diff --git a/app/settings/viewsdialog/viewshandler.h b/app/settings/viewsdialog/viewshandler.h index 5df9c2044..7c4c859a9 100644 --- a/app/settings/viewsdialog/viewshandler.h +++ b/app/settings/viewsdialog/viewshandler.h @@ -35,7 +35,11 @@ class ViewsDialog; } namespace Latte{ +class Corona; namespace Settings{ +namespace Controller{ +class Views; +} namespace Dialog{ class ViewsDialog; } @@ -63,6 +67,9 @@ public: Latte::Data::Layout currentData() const; + Ui::ViewsDialog *ui() const; + Latte::Corona *corona() const; + public slots: void reset() override; void resetDefaults() override; @@ -86,6 +93,7 @@ private: private: Dialog::ViewsDialog *m_dialog{nullptr}; Ui::ViewsDialog *m_ui{nullptr}; + Settings::Controller::Views *m_viewsController{nullptr}; QSortFilterProxyModel *m_layoutsProxyModel{nullptr}; diff --git a/app/settings/viewsdialog/viewsmodel.cpp b/app/settings/viewsdialog/viewsmodel.cpp index c62139a68..d55ac1b57 100644 --- a/app/settings/viewsdialog/viewsmodel.cpp +++ b/app/settings/viewsdialog/viewsmodel.cpp @@ -84,6 +84,19 @@ void Views::setOriginalData(Latte::Data::ViewsTable &data) emit rowsInserted(); } +QVariant Views::data(const QModelIndex &index, int role) const +{ + const int row = index.row(); + int column = index.column(); + //bool isNewLayout = !o_layoutsTable.containsId(m_layoutsTable[row].id); + + if (!m_viewsTable.rowExists(row)) { + return QVariant{}; + } + + return QVariant{}; +} + } } } diff --git a/app/settings/viewsdialog/viewsmodel.h b/app/settings/viewsdialog/viewsmodel.h index 08d3f86ba..a117be1ab 100644 --- a/app/settings/viewsdialog/viewsmodel.h +++ b/app/settings/viewsdialog/viewsmodel.h @@ -39,7 +39,6 @@ class Views : public QAbstractTableModel Q_OBJECT public: - enum Columns { SCREENCOLUMN = 0, @@ -73,6 +72,8 @@ public: int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + const Latte::Data::ViewsTable ¤tViewsData(); const Latte::Data::ViewsTable &originalViewsData(); @@ -80,6 +81,7 @@ public: signals: void rowsInserted(); + void rowsRemoved(); private slots: void clear(); @@ -95,6 +97,4 @@ private: } } - - #endif