1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-11 13:18:13 +03:00

decouple ExtractTemplateDlg from SettingsWindow

This commit is contained in:
Michail Vourlakos 2021-02-07 18:07:45 +02:00
parent 156b2190a8
commit a4c70b0922
7 changed files with 73 additions and 36 deletions

View File

@ -24,21 +24,34 @@
#include "ui_exporttemplatedialog.h"
#include "../controllers/layoutscontroller.h"
#include "../handlers/exporttemplatehandler.h"
#include "../../view/view.h"
namespace Latte {
namespace Settings {
namespace Dialog {
ExportTemplateDialog::ExportTemplateDialog(SettingsDialog *parent, Controller::Layouts *controller)
ExportTemplateDialog::ExportTemplateDialog(QWidget *parent, const QString &layoutName, const QString &layoutId)
: GenericDialog(parent),
m_parentDlg(parent),
m_ui(new Ui::ExportTemplateDialog),
m_layoutsController(controller)
m_ui(new Ui::ExportTemplateDialog)
{
setAttribute(Qt::WA_DeleteOnClose, true);
//! first we need to setup the ui
m_ui->setupUi(this);
//! we must create handlers after creating/adjusting the ui
m_handler = new Handler::ExportTemplateHandler(this);
m_handler = new Handler::ExportTemplateHandler(this, layoutName, layoutId);
}
ExportTemplateDialog::ExportTemplateDialog(Latte::View *view)
: GenericDialog(nullptr),
m_ui(new Ui::ExportTemplateDialog)
{
setAttribute(Qt::WA_DeleteOnClose, true);
//! first we need to setup the ui
m_ui->setupUi(this);
//! we must create handlers after creating/adjusting the ui
m_handler = new Handler::ExportTemplateHandler(this, view);
}
ExportTemplateDialog::~ExportTemplateDialog()
@ -50,16 +63,6 @@ Ui::ExportTemplateDialog *ExportTemplateDialog::ui() const
return m_ui;
}
Latte::Corona *ExportTemplateDialog::corona() const
{
return m_parentDlg->corona();
}
Controller::Layouts *ExportTemplateDialog::layoutsController() const
{
return m_layoutsController;
}
void ExportTemplateDialog::accept()
{
qDebug() << Q_FUNC_INFO;

View File

@ -28,12 +28,14 @@
// Qt
#include <QDialog>
#include <QObject>
#include <QWindow>
namespace Ui {
class ExportTemplateDialog;
}
namespace Latte {
class View;
namespace Settings {
namespace Controller {
class Layouts;
@ -54,13 +56,11 @@ class ExportTemplateDialog : public GenericDialog
Q_OBJECT
public:
ExportTemplateDialog(SettingsDialog *parent, Controller::Layouts *controller);
ExportTemplateDialog(QWidget *parent, const QString &layoutName, const QString &layoutId);
ExportTemplateDialog(Latte::View *view);
~ExportTemplateDialog();
Latte::Corona *corona() const;
Ui::ExportTemplateDialog *ui() const;
Controller::Layouts *layoutsController() const;
protected:
void accept() override;
@ -69,7 +69,9 @@ private slots:
void onCancel();
private:
SettingsDialog *m_parentDlg{nullptr};
bool m_isExportingLayout{false};
bool m_isExportingView{false};
Ui::ExportTemplateDialog *m_ui;
Controller::Layouts *m_layoutsController{nullptr};

View File

@ -26,11 +26,16 @@
#include "../dialogs/exporttemplatedialog.h"
#include "../models/appletsmodel.h"
#include "../../data/appletdata.h"
#include "../../layout/genericlayout.h"
#include "../../layouts/storage.h"
#include "../../view/view.h"
//! KDE
#include <KLocalizedString>
//! Plasma
#include <Plasma/Containment>
namespace Latte {
namespace Settings {
namespace Handler {
@ -39,7 +44,19 @@ ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *paren
: Generic(parentDialog),
m_parentDialog(parentDialog),
m_ui(m_parentDialog->ui()),
m_appletsModel(new Model::Applets(this, parentDialog->corona()))
m_appletsModel(new Model::Applets(this))
{
init();
}
ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, const QString &layoutName, const QString &layoutId)
: ExportTemplateHandler(parentDialog)
{
loadLayoutApplets(layoutName, layoutId);
}
ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, Latte::View *view)
: ExportTemplateHandler(parentDialog)
{
init();
}
@ -48,6 +65,7 @@ ExportTemplateHandler::~ExportTemplateHandler()
{
}
void ExportTemplateHandler::init()
{
m_ui->appletsTable->horizontalHeader()->setStretchLastSection(true);
@ -62,19 +80,25 @@ void ExportTemplateHandler::init()
m_ui->appletsTable->setModel(m_appletsProxyModel);
loadCurrentLayoutApplets();
}
void ExportTemplateHandler::loadCurrentLayoutApplets()
void ExportTemplateHandler::loadLayoutApplets(const QString &layoutName, const QString &layoutId)
{
Data::Layout o_layout = m_parentDialog->layoutsController()->selectedLayoutOriginalData();
Data::Layout c_layout = m_parentDialog->layoutsController()->selectedLayoutCurrentData();
c_data = Latte::Layouts::Storage::self()->plugins(o_layout.id);
c_data = Latte::Layouts::Storage::self()->plugins(layoutId);
o_data = c_data;
m_appletsModel->setData(c_data);
m_parentDialog->setWindowTitle(i18n("Export Template from %0").arg(c_layout.name));
m_parentDialog->setWindowTitle(i18n("Export Layout Template"));
}
void ExportTemplateHandler::loadViewApplets(Latte::View *view)
{
c_data = Latte::Layouts::Storage::self()->plugins(view->layout(), view->containment()->id());
o_data = c_data;
m_appletsModel->setData(c_data);
m_parentDialog->setWindowTitle(i18n("Export View Template"));
}
bool ExportTemplateHandler::dataAreChanged() const

View File

@ -34,6 +34,7 @@ class ExportTemplateDialog;
}
namespace Latte{
class View;
namespace Settings{
namespace Dialog{
class ExportTemplateDialog;
@ -63,6 +64,8 @@ class ExportTemplateHandler : public Generic
Q_OBJECT
public:
ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog);
ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, const QString &layoutName, const QString &layoutId);
ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog, Latte::View *view);
~ExportTemplateHandler();
bool dataAreChanged() const override;
@ -76,7 +79,8 @@ public:
private:
void init();
void loadCurrentLayoutApplets();
void loadLayoutApplets(const QString &layoutName, const QString &layoutId);
void loadViewApplets(Latte::View *view);
private:
Dialog::ExportTemplateDialog *m_parentDialog{nullptr};

View File

@ -561,7 +561,10 @@ void TabLayouts::exportLayoutAsTemplate()
m_corona->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles();
m_corona->universalSettings()->syncSettings();
Dialog::ExportTemplateDialog *exportDlg = new Dialog::ExportTemplateDialog(m_parentDialog, m_layoutsController);
Data::Layout o_layout = m_layoutsController->selectedLayoutOriginalData();
Data::Layout c_layout = m_layoutsController->selectedLayoutCurrentData();
Dialog::ExportTemplateDialog *exportDlg = new Dialog::ExportTemplateDialog(m_parentDialog, c_layout.name, o_layout.id);
exportDlg->exec();
}

View File

@ -23,6 +23,10 @@
// local
#include "../../layout/abstractlayout.h"
// Qt
#include <QFont>
#include <QIcon>
// KDE
#include <KLocalizedString>
@ -30,9 +34,8 @@ namespace Latte {
namespace Settings {
namespace Model {
Applets::Applets(QObject *parent, Latte::Corona *corona)
: QAbstractTableModel(parent),
m_corona(corona)
Applets::Applets(QObject *parent)
: QAbstractTableModel(parent)
{
}

View File

@ -22,7 +22,6 @@
#define APPLETSMODEL_H
// local
#include "../../lattecorona.h"
#include "../../data/appletdata.h"
// Qt
@ -53,7 +52,7 @@ public:
NAMECOLUMN = 0
};
explicit Applets(QObject *parent, Latte::Corona *corona);
explicit Applets(QObject *parent);
~Applets();
int rowCount() const;
@ -75,7 +74,6 @@ private:
private:
Latte::Data::AppletsTable m_appletsTable;
Latte::Corona *m_corona{nullptr};
};
}