1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-11 13:18:13 +03:00

make Shared button proxy model aware

This commit is contained in:
Michail Vourlakos 2020-03-16 13:18:59 +02:00
parent a7ecd549b0
commit 4deaa3bc0b
3 changed files with 35 additions and 18 deletions

View File

@ -283,36 +283,36 @@ void Layouts::toggleLockedForSelected()
}
void Layouts::toggleSharedForSelected()
{
{
if (m_view->currentIndex().row() < 0) {
return;
}
int row = m_view->currentIndex().row();
Data::Layout selected = selectedLayout();
if (selected.isShared()) {
m_proxyModel->setData(m_proxyModel->index(m_view->currentIndex().row(), Model::Layouts::SHAREDCOLUMN), QStringList(), Qt::UserRole);
m_proxyModel->setData(m_proxyModel->index(row, Model::Layouts::SHAREDCOLUMN), QStringList(), Qt::UserRole);
} else {
/* bool assigned{false};
QStringList assignedList;
QStringList assignedIds;
QStringList availableShareIds = m_model->availableShareIdsFor(selected.id);
QStringList availableShares = availableSharesFor(row);
for (const auto &id : availableShareIds) {
int iRow = m_model->rowForId(id);
Data::Layout iLayout = m_model->at(iRow);
for (const auto &id : availableShares) {
QString name = nameForId(id);
if (m_corona->layoutsManager()->synchronizer()->layout(name)) {
assignedList << id;
m_model->setData(m_model->index(row, Model::Layouts::SHAREDCOLUMN), assignedList, Qt::UserRole);
assigned = true;
if (m_corona->layoutsManager()->synchronizer()->layout(iLayout.originalName())) {
assignedIds << id;
m_proxyModel->setData(m_proxyModel->index(row, Model::Layouts::SHAREDCOLUMN), assignedIds, Qt::UserRole);
break;
}
}
if (!assigned && availableShares.count()>0) {
assignedList << availableShares[0];
m_model->setData(m_model->index(row, Model::Layouts::SHAREDCOLUMN), assignedList, Qt::UserRole);
assigned = true;
}*/
if (assignedIds.isEmpty() && availableShareIds.count()>0) {
assignedIds << availableShareIds[0];
m_proxyModel->setData(m_proxyModel->index(row, Model::Layouts::SHAREDCOLUMN), assignedIds, Qt::UserRole);
}
}
}

View File

@ -498,6 +498,21 @@ void Layouts::setId(const int &row, const QString &newId)
}
}
QStringList Layouts::availableShareIdsFor(const QString id) const
{
QStringList shares;
for(int i=0; i<rowCount(); ++i) {
if (m_layoutsTable[i].id == id || m_layoutsTable[i].isShared()) {
continue;
}
shares << m_layoutsTable[i].id;
}
return shares;
}
void Layouts::setShares(const int &row, const QStringList &shares)
{
if (!m_layoutsTable.rowExists(row) || m_layoutsTable[row].shares == shares) {
@ -509,7 +524,7 @@ void Layouts::setShares(const int &row, const QStringList &shares)
roles << Qt::UserRole;
m_layoutsTable[row].shares = shares;
emit dataChanged(index(row,SHAREDCOLUMN), index(row,SHAREDCOLUMN), roles);
emit dataChanged(index(row,IDCOLUMN), index(row,SHAREDCOLUMN), roles);
for(int i=0; i<rowCount(); ++i) {
if (i == row) {
@ -519,7 +534,7 @@ void Layouts::setShares(const int &row, const QStringList &shares)
auto cleaned = cleanStrings(m_layoutsTable[i].shares, shares);
if (cleaned != m_layoutsTable[i].shares) {
m_layoutsTable[i].shares = cleaned;
emit dataChanged(index(i,SHAREDCOLUMN), index(i,SHAREDCOLUMN), roles);
emit dataChanged(index(i,IDCOLUMN), index(i,SHAREDCOLUMN), roles);
}
}
}

View File

@ -97,6 +97,8 @@ public:
QString layoutNameForFreeActivities() const;
void setLayoutNameForFreeActivities(const QString &name);
QStringList availableShareIdsFor(const QString id) const;
const Data::LayoutsTable &currentData();
void setCurrentData(Data::LayoutsTable &data);