mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-23 13:33:50 +03:00
settings:introduce views controller
This commit is contained in:
parent
4719201b4d
commit
c7a11ba7ea
@ -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
|
||||
|
119
app/settings/viewsdialog/viewscontroller.cpp
Normal file
119
app/settings/viewsdialog/viewscontroller.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "viewscontroller.h"
|
||||
|
||||
// local
|
||||
#include "ui_viewsdialog.h"
|
||||
#include "viewsdialog.h"
|
||||
#include "viewshandler.h"
|
||||
#include "viewsmodel.h"
|
||||
#include "../generic/generictools.h"
|
||||
|
||||
// Qt
|
||||
#include <QHeaderView>
|
||||
#include <QItemSelection>
|
||||
|
||||
// KDE
|
||||
#include <KMessageWidget>
|
||||
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
113
app/settings/viewsdialog/viewscontroller.h
Normal file
113
app/settings/viewsdialog/viewscontroller.h
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef VIEWSCONTROLLER_H
|
||||
#define VIEWSCONTROLLER_H
|
||||
|
||||
// local
|
||||
#include <coretypes.h>
|
||||
#include "viewsmodel.h"
|
||||
#include "../../lattecorona.h"
|
||||
#include "../../data/viewdata.h"
|
||||
#include "../../data/viewstable.h"
|
||||
|
||||
// Qt
|
||||
#include <QAbstractItemModel>
|
||||
#include <QHash>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QTableView>
|
||||
|
||||
|
||||
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
|
@ -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();
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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{};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user