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
{
return true;// m_model->hasChangedData();
return m_model->hasChangedData();
}
bool Views::hasSelectedView() const

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

@ -43,12 +43,15 @@ ViewsDialog::ViewsDialog(SettingsDialog *parent, Controller::Layouts *controller
//! we must create handlers after creating/adjusting the ui
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::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,
this, &ViewsDialog::onCancel);
@ -81,13 +84,10 @@ Latte::Corona *ViewsDialog::corona() const
void ViewsDialog::updateApplyButtonsState()
{
/* if (m_handler->hasChangedData()) {
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(true);
} else {
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
}*/
bool changed = m_handler->hasChangedData();
m_applyNowBtn->setEnabled(changed);
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
}
void ViewsDialog::accept()
@ -111,7 +111,7 @@ void ViewsDialog::onCancel()
void ViewsDialog::onReset()
{
qDebug() << Q_FUNC_INFO;
// m_handler->reset();
m_handler->reset();
}
void ViewsDialog::loadConfig()

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

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

@ -81,10 +81,8 @@ void ViewsHandler::init()
//! connect layout combobox after the selected layout has been loaded
connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ViewsHandler::onCurrentLayoutIndexChanged);
//! data were changed
connect(this, &ViewsHandler::dataChanged, this, [&]() {
loadLayout(c_data);
});
//!
connect(m_viewsController, &Settings::Controller::Views::dataChanged, this, &ViewsHandler::dataChanged);
}
void ViewsHandler::reload()
@ -92,14 +90,13 @@ void ViewsHandler::reload()
m_dialog->layoutsController()->initializeSelectedLayoutViews();
o_data = m_dialog->layoutsController()->selectedLayoutCurrentData();
c_data = o_data;
Latte::Data::LayoutIcon icon = m_dialog->layoutsController()->selectedLayoutIcon();
m_ui->layoutsCmb->setCurrentText(o_data.name);
m_ui->layoutsCmb->setLayoutIcon(icon);
loadLayout(c_data);
loadLayout(o_data);
}
Latte::Corona *ViewsHandler::corona() const
@ -119,12 +116,12 @@ void ViewsHandler::loadLayout(const Latte::Data::Layout &data)
Latte::Data::Layout ViewsHandler::currentData() const
{
return c_data;
return o_data;
}
bool ViewsHandler::hasChangedData() const
{
return o_data != c_data;
return m_viewsController->hasChangedData();
}
bool ViewsHandler::inDefaultValues() const
@ -136,8 +133,7 @@ bool ViewsHandler::inDefaultValues() const
void ViewsHandler::reset()
{
c_data = o_data;
emit currentLayoutChanged();
m_viewsController->reset();
}
void ViewsHandler::resetDefaults()
@ -147,7 +143,7 @@ void ViewsHandler::resetDefaults()
void ViewsHandler::save()
{
m_dialog->layoutsController()->setLayoutProperties(currentData());
// m_dialog->layoutsController()->setLayoutProperties(currentData());
}
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();
m_dialog->layoutsController()->selectRow(layoutId);
reload();
emit currentLayoutChanged();
} else {
//! 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()
{
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);
return m_dialog->saveChangesConfirmation(saveChangesText);

@ -97,9 +97,7 @@ private:
QSortFilterProxyModel *m_layoutsProxyModel{nullptr};
//! current 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) {
beginRemoveRows(QModelIndex(), 0, m_viewsTable.rowCount() - 1);
m_viewsTable.clear();
endRemoveRows();
}
return o_viewsTable != m_viewsTable;
}
int Views::rowCount() const
@ -87,6 +83,15 @@ const Latte::Data::ViewsTable &Views::originalViewsData()
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()
{
Latte::Data::GenericBasicTable edges;
@ -120,6 +125,12 @@ void Views::initAlignments()
s_verticalAlignments.setValue<Latte::Data::GenericBasicTable>(verticals);
}
void Views::resetData()
{
clear();
setOriginalData(o_viewsTable);
}
bool Views::isVertical(const Plasma::Types::Location &location) const
{
return (location == Plasma::Types::LeftEdge || location == Plasma::Types::RightEdge);

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

Loading…
Cancel
Save