detailsdialog:fix save confirmation dialog behavior

--most importantly Discard acts properly now meaning
that layout is updated and previous settings are discarded
work/spdx
Michail Vourlakos 4 years ago
parent 447c08e95e
commit bc86878b91

@ -109,6 +109,7 @@ void DetailsHandler::init()
connect(this, &DetailsHandler::currentLayoutChanged, this, &DetailsHandler::reload);
reload();
m_lastConfirmedLayoutIndex = m_ui->colorsCmb->currentIndex();
//! connect layout combobox after the selected layout has been loaded
connect(m_ui->layoutsCmb, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DetailsHandler::onCurrentLayoutIndexChanged);
@ -254,17 +255,25 @@ void DetailsHandler::onCurrentColorIndexChanged(int row)
void DetailsHandler::onCurrentLayoutIndexChanged(int row)
{
bool switchtonewlayout{true};
if (hasChangedData()) {
int result = saveChanges();
if (result == QMessageBox::Apply) {
save();
} else if (result == QMessageBox::Discard) {
//do nothing
} else if (result == QMessageBox::Cancel) {
switchtonewlayout = false;
bool switchtonewlayout{false};
if (m_lastConfirmedLayoutIndex != row) {
if (hasChangedData()) { //new layout was chosen but there are changes
int result = saveChangesConfirmation();
if (result == QMessageBox::Apply) {
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
save();
} else if (result == QMessageBox::Discard) {
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
} else if (result == QMessageBox::Cancel) {
//do nothing
}
} else { //new layout was chosen and there are no changes
switchtonewlayout = true;
m_lastConfirmedLayoutIndex = row;
}
}
@ -272,7 +281,6 @@ void DetailsHandler::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
@ -400,7 +408,7 @@ void DetailsHandler::updateWindowTitle()
m_dialog->setWindowTitle(i18nc("<layout name> Details","%0 Details").arg(m_ui->layoutsCmb->currentText()));
}
int DetailsHandler::saveChanges()
int DetailsHandler::saveChangesConfirmation()
{
if (hasChangedData()) {
QString layoutName = c_data.name;

@ -106,7 +106,7 @@ private:
void loadLayout(const Latte::Data::Layout &data);
int saveChanges();
int saveChangesConfirmation();
private:
Dialog::DetailsDialog *m_dialog{nullptr};
@ -114,6 +114,8 @@ private:
QSortFilterProxyModel *m_layoutsProxyModel{nullptr};
int m_lastConfirmedLayoutIndex{-1};
//! current data
Model::Colors *m_colorsModel{nullptr};

Loading…
Cancel
Save