settings:introduce views controller
parent
4719201b4d
commit
c7a11ba7ea
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue