1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-27 06:03:51 +03:00

introduce original/edited Named in layout data

This commit is contained in:
Michail Vourlakos 2020-03-13 12:08:54 +02:00
parent 4428d4b083
commit a9bc5aa19f
7 changed files with 86 additions and 28 deletions

View File

@ -34,7 +34,8 @@ Layout::~Layout()
Layout::Layout(const Layout &o)
: id(o.id),
name(o.name),
m_editedName(o.m_editedName),
m_originalName(o.m_originalName),
color(o.color),
background(o.background),
textColor(o.textColor),
@ -50,7 +51,8 @@ Layout::Layout(const Layout &o)
Layout &Layout::operator=(const Layout &rhs)
{
id = rhs.id;
name = rhs.name;
m_editedName = rhs.m_editedName;
m_originalName = rhs.m_originalName;
color = rhs.color;
background = rhs.background;
textColor = rhs.textColor;
@ -67,7 +69,8 @@ Layout &Layout::operator=(const Layout &rhs)
bool Layout::operator==(const Layout &rhs) const
{
return (id == rhs.id)
&& (name == rhs.name)
&& (m_editedName == rhs.m_editedName)
&& (m_originalName == rhs.m_originalName)
&& (color == rhs.color)
&& (background == rhs.background)
&& (textColor == rhs.textColor)
@ -89,6 +92,32 @@ bool Layout::isShared() const
return !shares.isEmpty();
}
bool Layout::nameWasEdited() const
{
return !m_editedName.isEmpty() && (m_editedName != m_originalName);
}
QString Layout::editedName() const
{
return m_editedName.isEmpty() ? m_originalName : m_editedName;
}
void Layout::setEditedName(const QString name)
{
m_editedName = name;
}
QString Layout::originalName() const
{
return m_originalName;
}
void Layout::setOriginalName(const QString name)
{
m_originalName = name;
m_editedName = "";
}
}
}
}

View File

@ -40,7 +40,6 @@ public:
//! Layout data
QString id;
QString name;
QString color;
QString background;
QString textColor;
@ -51,13 +50,25 @@ public:
QStringList activities;
QStringList shares;
QString editedName() const;
void setEditedName(const QString name);
QString originalName() const;
void setOriginalName(const QString name);
//! Functionality
bool isShared() const;
bool nameWasEdited() const;
//! Operators
Layout &operator=(const Layout &rhs);
bool operator==(const Layout &rhs) const;
bool operator!=(const Layout &rhs) const;
protected:
QString m_editedName;
QString m_originalName;
};
}

View File

@ -145,10 +145,21 @@ int LayoutsTable::rowCount() const
return m_layouts.count();
}
QString LayoutsTable::idForName(const QString &name) const
QString LayoutsTable::idForOriginalName(const QString &name) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if (m_layouts[i].name == name) {
if (m_layouts[i].originalName() == name) {
return m_layouts[i].id;
}
}
return QString();
}
QString LayoutsTable::idForEditedName(const QString &name) const
{
for(int i=0; i<m_layouts.count(); ++i) {
if ((m_layouts[i].editedName() == name)) {
return m_layouts[i].id;
}
}

View File

@ -52,7 +52,8 @@ public:
int indexOf(const QString &id) const;
int rowCount() const;
QString idForName(const QString &name) const;
QString idForOriginalName(const QString &name) const;
QString idForEditedName(const QString &name) const;
void clear();
void remove(const int &row);

View File

@ -55,9 +55,14 @@ void Layouts::setInMultipleMode(bool inMultiple)
m_inMultipleMode = inMultiple;
}
QString Layouts::idForName(const QString &name)
QString Layouts::idForOriginalName(const QString &name)
{
return m_layoutsTable.idForName(name);
return m_layoutsTable.idForOriginalName(name);
}
QString Layouts::idForEditedName(const QString &name)
{
return m_layoutsTable.idForEditedName(name);
}
int Layouts::rowCount() const
@ -245,7 +250,7 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
return m_layoutsTable[row].name;
return m_layoutsTable[row].editedName();
}
break;
case MENUCOLUMN:
@ -322,7 +327,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
m_layoutsTable[row].name = value.toString();
m_layoutsTable[row].setEditedName(value.toString());
emit dataChanged(index, index, roles);
return true;
}

View File

@ -67,7 +67,8 @@ public:
bool inMultipleMode() const;
void setInMultipleMode(bool inMultiple);
QString idForName(const QString &name);
QString idForOriginalName(const QString &name);
QString idForEditedName(const QString &name);
int rowCount() const;
int rowCount(const QModelIndex &parent) const override;

View File

@ -441,8 +441,8 @@ void SettingsDialog::on_copyButton_clicked()
Settings::Data::Layout original = m_model->at(row);
Settings::Data::Layout copied = original;
copied.name = uniqueLayoutName(m_model->data(m_model->index(row, NAMECOLUMN), Qt::DisplayRole).toString());
copied.id = uniqueTempDirectory() + "/" + copied.name + ".layout.latte";;
copied.setOriginalName(uniqueLayoutName(m_model->data(m_model->index(row, NAMECOLUMN), Qt::DisplayRole).toString()));
copied.id = uniqueTempDirectory() + "/" + copied.originalName() + ".layout.latte";;
copied.activities = QStringList();
copied.isLocked = false;
@ -942,7 +942,7 @@ void SettingsDialog::addLayoutForFile(QString file, QString layoutName, bool new
CentralLayout *settings = new CentralLayout(this, copied.id);
m_layouts[copied.id] = settings;
copied.name = uniqueLayoutName(layoutName);
copied.setOriginalName(uniqueLayoutName(layoutName));
copied.color = settings->color();
copied.textColor = settings->textColor();
copied.background = settings->background();
@ -987,11 +987,11 @@ void SettingsDialog::loadSettings()
CentralLayout *central = new CentralLayout(this, original.id);
original.name = central->name();
original.setOriginalName(central->name());
original.background = central->background();
original.color = central->color();
original.textColor = central->textColor();
original.isActive = (m_corona->layoutsManager()->synchronizer()->layout(original.name) != nullptr);
original.isActive = (m_corona->layoutsManager()->synchronizer()->layout(original.originalName()) != nullptr);
original.isLocked = !central->isWritable();
original.isShownInMenu = central->showInMenu();
original.hasDisabledBorders = central->disableBordersForMaximizedWindows();
@ -1034,7 +1034,7 @@ void SettingsDialog::loadSettings()
//! update keys
for (QHash<const QString, QStringList>::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) {
QString shareid = layoutsBuffer.idForName(i.key());
QString shareid = layoutsBuffer.idForOriginalName(i.key());
if (!shareid.isEmpty()) {
m_sharesMap[shareid] = i.value();
}
@ -1144,11 +1144,11 @@ void SettingsDialog::appendLayout(Settings::Data::Layout &layout)
//! Add Free Activities record
if (layout.activities.isEmpty()) {
if (m_corona->layoutsManager()->memoryUsage() == Types::SingleLayout) {
if (m_corona->layoutsManager()->currentLayoutName() == layout.name) {
if (m_corona->layoutsManager()->currentLayoutName() == layout.originalName()) {
layout.activities << FREEACTIVITIESID;
}
} else if (m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts) {
if (m_corona->layoutsManager()->synchronizer()->centralLayout(layout.name)) {
if (m_corona->layoutsManager()->synchronizer()->centralLayout(layout.originalName())) {
layout.activities << FREEACTIVITIESID;
}
}
@ -1252,7 +1252,7 @@ void SettingsDialog::itemChanged(QStandardItem *item)
QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString();
QString name = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString();
QString originalName = o_layoutsOriginalData.contains(id) ? o_layoutsOriginalData[id].name : name;
QString originalName = o_layoutsOriginalData.contains(id) ? o_layoutsOriginalData[id].originalName() : name;
QFont font = qvariant_cast<QFont>(m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::FontRole));
if (m_corona->layoutsManager()->synchronizer()->layout(originalName)) {
@ -1342,7 +1342,7 @@ void SettingsDialog::updatePerLayoutButtonsState()
QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString();
QString nameInModel = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString();
QString originalName = o_layoutsOriginalData.contains(id) ? o_layoutsOriginalData[id].name : "";
QString originalName = o_layoutsOriginalData.contains(id) ? o_layoutsOriginalData[id].originalName() : "";
bool lockedInModel = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::UserRole).toBool();
bool sharedInModel = !m_model->data(m_model->index(currentRow, SHAREDCOLUMN), Qt::UserRole).toStringList().isEmpty();
bool editable = !isActive(originalName) && !lockedInModel;
@ -1501,7 +1501,7 @@ void SettingsDialog::showLayoutInformation()
QString id = m_model->data(m_model->index(currentRow, IDCOLUMN), Qt::DisplayRole).toString();
QString name = m_model->data(m_model->index(currentRow, NAMECOLUMN), Qt::DisplayRole).toString();
Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name);
Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].originalName());
Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id];
auto msg = new QMessageBox(this);
@ -1519,7 +1519,7 @@ void SettingsDialog::showScreensInformation()
QString id = m_model->data(m_model->index(i, IDCOLUMN), Qt::DisplayRole).toString();
QString name = m_model->data(m_model->index(i, NAMECOLUMN), Qt::DisplayRole).toString();
Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name);
Layout::GenericLayout *genericActive= m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].originalName());
Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id];
QList<int> vScreens = generic->viewsScreens();
@ -1613,7 +1613,7 @@ bool SettingsDialog::saveAllChanges()
//qDebug() << i << ". " << id << " - " << color << " - " << name << " - " << menu << " - " << lActivities;
//! update the generic parts of the layouts
bool isOriginalLayout = o_layoutsOriginalData.contains(id);
Layout::GenericLayout *genericActive= isOriginalLayout ?m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name) : nullptr;
Layout::GenericLayout *genericActive= isOriginalLayout ?m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].originalName()) : nullptr;
Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id];
//! unlock read-only layout
@ -1639,7 +1639,7 @@ bool SettingsDialog::saveAllChanges()
}
//! update only the Central-specific layout parts
CentralLayout *centralActive = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->centralLayout(o_layoutsOriginalData[id].name) : nullptr;
CentralLayout *centralActive = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->centralLayout(o_layoutsOriginalData[id].originalName()) : nullptr;
CentralLayout *central = centralActive ? centralActive : m_layouts[id];
if (central->showInMenu() != menu) {
@ -1753,7 +1753,7 @@ bool SettingsDialog::saveAllChanges()
bool locked = m_model->data(m_model->index(i, NAMECOLUMN), Qt::UserRole).toBool();
bool isOriginalLayout{o_layoutsOriginalData.contains(id)};
Layout::GenericLayout *generic = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name) : nullptr;
Layout::GenericLayout *generic = isOriginalLayout ? m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].originalName()) : nullptr;
Layout::GenericLayout *layout = generic ? generic : m_layouts[id];
if (layout && locked && layout->isWritable()) {
@ -1962,7 +1962,7 @@ bool SettingsDialog::isActive(int row) const
{
QString id = m_model->data(m_model->index(row, IDCOLUMN), Qt::DisplayRole).toString();
if (o_layoutsOriginalData.contains(id)){
return (m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].name) != nullptr);
return (m_corona->layoutsManager()->synchronizer()->layout(o_layoutsOriginalData[id].originalName()) != nullptr);
}
return false;