connect all parts of viewsdialog

--inform about data changes and enable
also the Reset button
work/spdx
Michail Vourlakos 4 years ago
parent 58e184d90a
commit 5577a0c328

@ -107,9 +107,14 @@ void Views::init()
}); });
} }
void Views::reset()
{
m_model->resetData();
}
bool Views::hasChangedData() const bool Views::hasChangedData() const
{ {
return true;// m_model->hasChangedData(); return m_model->hasChangedData();
} }
bool Views::hasSelectedView() const bool Views::hasSelectedView() const

@ -73,7 +73,7 @@ public:
void selectRow(const QString &id); void selectRow(const QString &id);
//! actions //! actions
// void reset(); void reset();
// void save(); // void save();
// void removeSelected(); // void removeSelected();

@ -43,12 +43,15 @@ ViewsDialog::ViewsDialog(SettingsDialog *parent, Controller::Layouts *controller
//! we must create handlers after creating/adjusting the ui //! we must create handlers after creating/adjusting the ui
m_handler = new Handler::ViewsHandler(this); m_handler = new Handler::ViewsHandler(this);
//! Button Group
m_applyNowBtn = new QPushButton(QIcon::fromTheme("dialog-yes"), i18n("Apply Now"), m_ui->buttonBox);
m_applyNowBtn->setToolTip(i18n("Apply all dock, panels changes now"));
m_ui->buttonBox->addButton(m_applyNowBtn, QDialogButtonBox::ApplyRole);
//! Signals/Slots
connect(m_handler, &Handler::ViewsHandler::currentLayoutChanged, this, &ViewsDialog::updateApplyButtonsState); connect(m_handler, &Handler::ViewsHandler::currentLayoutChanged, this, &ViewsDialog::updateApplyButtonsState);
connect(m_handler, &Handler::ViewsHandler::dataChanged, this, &ViewsDialog::updateApplyButtonsState); connect(m_handler, &Handler::ViewsHandler::dataChanged, this, &ViewsDialog::updateApplyButtonsState);
connect(m_ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked,
this, &ViewsDialog::onOk);
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
this, &ViewsDialog::onCancel); this, &ViewsDialog::onCancel);
@ -81,13 +84,10 @@ Latte::Corona *ViewsDialog::corona() const
void ViewsDialog::updateApplyButtonsState() void ViewsDialog::updateApplyButtonsState()
{ {
/* if (m_handler->hasChangedData()) { bool changed = m_handler->hasChangedData();
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true); m_applyNowBtn->setEnabled(changed);
} else { m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
}*/
} }
void ViewsDialog::accept() void ViewsDialog::accept()
@ -111,7 +111,7 @@ void ViewsDialog::onCancel()
void ViewsDialog::onReset() void ViewsDialog::onReset()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
// m_handler->reset(); m_handler->reset();
} }
void ViewsDialog::loadConfig() void ViewsDialog::loadConfig()

@ -28,6 +28,7 @@
// Qt // Qt
#include <QDialog> #include <QDialog>
#include <QObject> #include <QObject>
#include <QPushButton>
namespace Ui { namespace Ui {
class ViewsDialog; class ViewsDialog;
@ -79,6 +80,8 @@ private:
Ui::ViewsDialog *m_ui; Ui::ViewsDialog *m_ui;
Controller::Layouts *m_layoutsController{nullptr}; Controller::Layouts *m_layoutsController{nullptr};
QPushButton *m_applyNowBtn{nullptr};
Handler::ViewsHandler *m_handler; Handler::ViewsHandler *m_handler;
//! properties //! properties

@ -243,7 +243,7 @@
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Reset</set>
</property> </property>
</widget> </widget>
</item> </item>

@ -81,10 +81,8 @@ void ViewsHandler::init()
//! connect layout combobox after the selected layout has been loaded //! connect layout combobox after the selected layout has been loaded
connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ViewsHandler::onCurrentLayoutIndexChanged); connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ViewsHandler::onCurrentLayoutIndexChanged);
//! data were changed //!
connect(this, &ViewsHandler::dataChanged, this, [&]() { connect(m_viewsController, &Settings::Controller::Views::dataChanged, this, &ViewsHandler::dataChanged);
loadLayout(c_data);
});
} }
void ViewsHandler::reload() void ViewsHandler::reload()
@ -92,14 +90,13 @@ void ViewsHandler::reload()
m_dialog->layoutsController()->initializeSelectedLayoutViews(); m_dialog->layoutsController()->initializeSelectedLayoutViews();
o_data = m_dialog->layoutsController()->selectedLayoutCurrentData(); o_data = m_dialog->layoutsController()->selectedLayoutCurrentData();
c_data = o_data;
Latte::Data::LayoutIcon icon = m_dialog->layoutsController()->selectedLayoutIcon(); Latte::Data::LayoutIcon icon = m_dialog->layoutsController()->selectedLayoutIcon();
m_ui->layoutsCmb->setCurrentText(o_data.name); m_ui->layoutsCmb->setCurrentText(o_data.name);
m_ui->layoutsCmb->setLayoutIcon(icon); m_ui->layoutsCmb->setLayoutIcon(icon);
loadLayout(c_data); loadLayout(o_data);
} }
Latte::Corona *ViewsHandler::corona() const Latte::Corona *ViewsHandler::corona() const
@ -119,12 +116,12 @@ void ViewsHandler::loadLayout(const Latte::Data::Layout &data)
Latte::Data::Layout ViewsHandler::currentData() const Latte::Data::Layout ViewsHandler::currentData() const
{ {
return c_data; return o_data;
} }
bool ViewsHandler::hasChangedData() const bool ViewsHandler::hasChangedData() const
{ {
return o_data != c_data; return m_viewsController->hasChangedData();
} }
bool ViewsHandler::inDefaultValues() const bool ViewsHandler::inDefaultValues() const
@ -136,8 +133,7 @@ bool ViewsHandler::inDefaultValues() const
void ViewsHandler::reset() void ViewsHandler::reset()
{ {
c_data = o_data; m_viewsController->reset();
emit currentLayoutChanged();
} }
void ViewsHandler::resetDefaults() void ViewsHandler::resetDefaults()
@ -147,7 +143,7 @@ void ViewsHandler::resetDefaults()
void ViewsHandler::save() void ViewsHandler::save()
{ {
m_dialog->layoutsController()->setLayoutProperties(currentData()); // m_dialog->layoutsController()->setLayoutProperties(currentData());
} }
void ViewsHandler::onCurrentLayoutIndexChanged(int row) void ViewsHandler::onCurrentLayoutIndexChanged(int row)
@ -170,13 +166,10 @@ void ViewsHandler::onCurrentLayoutIndexChanged(int row)
QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString(); QString layoutId = m_layoutsProxyModel->data(m_layoutsProxyModel->index(row, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
m_dialog->layoutsController()->selectRow(layoutId); m_dialog->layoutsController()->selectRow(layoutId);
reload(); reload();
emit currentLayoutChanged(); emit currentLayoutChanged();
} else { } else {
//! reset combobox index //! reset combobox index
m_ui->layoutsCmb->setCurrentText(c_data.name); m_ui->layoutsCmb->setCurrentText(o_data.name);
} }
} }
@ -188,7 +181,7 @@ void ViewsHandler::updateWindowTitle()
int ViewsHandler::saveChanges() int ViewsHandler::saveChanges()
{ {
if (hasChangedData()) { if (hasChangedData()) {
QString layoutName = c_data.name; QString layoutName = o_data.name;
QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed. Do you want to apply the changes or discard them?").arg(layoutName); QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed. Do you want to apply the changes or discard them?").arg(layoutName);
return m_dialog->saveChangesConfirmation(saveChangesText); return m_dialog->saveChangesConfirmation(saveChangesText);

@ -97,9 +97,7 @@ private:
QSortFilterProxyModel *m_layoutsProxyModel{nullptr}; QSortFilterProxyModel *m_layoutsProxyModel{nullptr};
//! current data
Latte::Data::Layout o_data; Latte::Data::Layout o_data;
Latte::Data::Layout c_data;
}; };
} }

@ -46,13 +46,9 @@ Views::~Views()
{ {
} }
void Views::clear() bool Views::hasChangedData() const
{ {
if (m_viewsTable.rowCount() > 0) { return o_viewsTable != m_viewsTable;
beginRemoveRows(QModelIndex(), 0, m_viewsTable.rowCount() - 1);
m_viewsTable.clear();
endRemoveRows();
}
} }
int Views::rowCount() const int Views::rowCount() const
@ -87,6 +83,15 @@ const Latte::Data::ViewsTable &Views::originalViewsData()
return o_viewsTable; return o_viewsTable;
} }
void Views::clear()
{
if (m_viewsTable.rowCount() > 0) {
beginRemoveRows(QModelIndex(), 0, m_viewsTable.rowCount() - 1);
m_viewsTable.clear();
endRemoveRows();
}
}
void Views::initEdges() void Views::initEdges()
{ {
Latte::Data::GenericBasicTable edges; Latte::Data::GenericBasicTable edges;
@ -120,6 +125,12 @@ void Views::initAlignments()
s_verticalAlignments.setValue<Latte::Data::GenericBasicTable>(verticals); s_verticalAlignments.setValue<Latte::Data::GenericBasicTable>(verticals);
} }
void Views::resetData()
{
clear();
setOriginalData(o_viewsTable);
}
bool Views::isVertical(const Plasma::Types::Location &location) const bool Views::isVertical(const Plasma::Types::Location &location) const
{ {
return (location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge); return (location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge);

@ -72,6 +72,11 @@ public:
explicit Views(QObject *parent, Latte::Corona *corona); explicit Views(QObject *parent, Latte::Corona *corona);
~Views(); ~Views();
bool hasChangedData() const;
//! all original data will become also current
void resetData();
int rowCount() const; int rowCount() const;
static int columnCount(); static int columnCount();
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;

Loading…
Cancel
Save