1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-24 05:33:50 +03:00

reject duplicate layout names in settings

This commit is contained in:
Michail Vourlakos 2020-03-16 12:36:43 +02:00
parent 880ed9638e
commit 37cac2ca81
4 changed files with 55 additions and 10 deletions

View File

@ -39,6 +39,7 @@
#include <QDir>
#include <QFile>
#include <QHeaderView>
#include <QItemSelection>
#include <QMessageBox>
#include <QStringList>
#include <QTemporaryDir>
@ -57,7 +58,7 @@ namespace Controller {
Layouts::Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view)
: QObject(parent),
m_parent(parent),
m_parentDialog(parent),
m_corona(corona),
m_model(new Model::Layouts(this, corona)),
m_proxyModel(new QSortFilterProxyModel(this)),
@ -72,6 +73,7 @@ Layouts::Layouts(QDialog *parent, Latte::Corona *corona, QTableView *view)
connect(m_model, &QAbstractItemModel::dataChanged, this, &Layouts::dataChanged);
connect(m_model, &Model::Layouts::rowsInserted, this, &Layouts::dataChanged);
connect(m_model, &Model::Layouts::nameDuplicated, this, &Layouts::on_nameDuplicatedFrom);
}
Layouts::~Layouts()
@ -447,7 +449,7 @@ void Layouts::loadLayouts()
//! there are broken layouts and the user must be informed!
if (brokenLayouts.count() > 0) {
auto msg = new QMessageBox(m_parent);
auto msg = new QMessageBox(m_parentDialog);
msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Layout Warning"));
msg->setText(i18n("The layout(s) <b>%0</b> have <i>broken configuration</i>!!! Please <b>remove them</b> to improve the system stability...").arg(brokenLayouts.join(",")));
@ -835,6 +837,39 @@ void Layouts::saveColumnWidths()
m_corona->universalSettings()->setLayoutsColumnWidths(columnWidths);
}
void Layouts::on_nameDuplicatedFrom(const QString &provenId, const QString &trialId)
{
//! duplicated layout name
auto msg = new QMessageBox(m_parentDialog);
msg->setIcon(QMessageBox::Warning);
msg->setWindowTitle(i18n("Layout Warning"));
msg->setText(i18n("There are layouts with the same name, that is not permitted!!! Please update these names to re-apply the changes..."));
msg->setStandardButtons(QMessageBox::Ok);
connect(msg, &QMessageBox::finished, this, [ &, provenId, trialId](int result) {
int pRow = rowForId(provenId);
int tRow = rowForId(trialId);
if (pRow >= 0) {
QItemSelectionModel::SelectionFlags flags = QItemSelectionModel::ClearAndSelect;
QItemSelection rowSelection;
QModelIndex pIndexS = m_proxyModel->index(pRow, Model::Layouts::BACKGROUNDCOLUMN);
QModelIndex pIndexE = m_proxyModel->index(pRow, Model::Layouts::SHAREDCOLUMN);
rowSelection.select(pIndexS, pIndexE);
m_view->selectionModel()->select(rowSelection, flags);
}
QModelIndex tIndex = m_proxyModel->index(tRow, Model::Layouts::NAMECOLUMN);
m_view->edit(tIndex);
});
msg->open();
}
}
}
}

View File

@ -86,6 +86,7 @@ signals:
private slots:
void saveColumnWidths();
void on_nameDuplicatedFrom(const QString &provenId, const QString &trialId);
private:
void initView();
@ -98,7 +99,7 @@ private:
QString uniqueLayoutName(QString name);
private:
QDialog *m_parent{nullptr};
QDialog *m_parentDialog{nullptr};
Latte::Corona *m_corona{nullptr};
QTableView *m_view{nullptr};

View File

@ -570,10 +570,18 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
QString provenId = m_layoutsTable.idForCurrentName(value.toString());
if (!provenId.isEmpty() && provenId != m_layoutsTable[row].id /*not the same row*/ ){
//! duplicate name should be rejected
emit nameDuplicated(provenId, m_layoutsTable[row].id);
return false;
} else {
m_layoutsTable[row].setCurrentName(value.toString());
emit dataChanged(index, index, roles);
return true;
}
}
break;
case MENUCOLUMN:
if (role == Qt::DisplayRole || role == Qt::UserRole) {

View File

@ -101,6 +101,7 @@ public:
signals:
void inMultipleModeChanged();
void nameDuplicated(const QString &provenId, const QString &trialId);
void rowsInserted();
private slots: