provide functionality for Enabled layout action

work/spdx
Michail Vourlakos 4 years ago
parent 6550112525
commit 4a89138a6e

@ -347,6 +347,35 @@ void Layouts::removeSelected()
m_model->removeLayout(selected.id);
}
void Layouts::toggleEnabledForSelected()
{
if (!hasSelectedLayout()) {
return;
}
Latte::Data::Layout selected = selectedLayoutCurrentData();
if (!selected.activities.isEmpty()) {
m_proxyModel->setData(m_proxyModel->index(m_view->currentIndex().row(), Model::Layouts::ACTIVITYCOLUMN), QStringList(), Qt::UserRole);
} else {
QStringList activities;
bool layoutsenabledonlyinspecificactivities = m_model->hasEnabledLayout()
&& !m_model->hasEnabledLayoutInAllActitivities()
&& !m_model->hasEnabledLayoutInFreeActivities();
if (m_model->hasEnabledLayoutInCurrentActivity() || layoutsenabledonlyinspecificactivities) {
activities << m_model->currentActivityId();
} else if (m_model->hasEnabledLayoutInFreeActivities()) {
activities << Data::Layout::FREEACTIVITIESID;
} else {
activities << Data::Layout::ALLACTIVITIESID;
}
m_proxyModel->setData(m_proxyModel->index(m_view->currentIndex().row(), Model::Layouts::ACTIVITYCOLUMN), activities, Qt::UserRole);
}
}
void Layouts::toggleLockedForSelected()
{
if (!hasSelectedLayout()) {

@ -83,6 +83,7 @@ public:
void reset();
void save();
void removeSelected();
void toggleEnabledForSelected();
void toggleLockedForSelected();
QString iconsPath() const;

@ -101,6 +101,52 @@ void Layouts::setInMultipleMode(bool inMultiple)
emit inMultipleModeChanged();
}
bool Layouts::hasEnabledLayout() const
{
for (int i=0; i<m_layoutsTable.rowCount(); ++i) {
if (m_layoutsTable[i].activities.count() > 0) {
return true;
}
}
return false;
}
bool Layouts::hasEnabledLayoutInAllActitivities() const
{
for (int i=0; i<m_layoutsTable.rowCount(); ++i) {
if (m_layoutsTable[i].activities.contains(Data::Layout::ALLACTIVITIESID)) {
return true;
}
}
return false;
}
bool Layouts::hasEnabledLayoutInFreeActivities() const
{
for (int i=0; i<m_layoutsTable.rowCount(); ++i) {
if (m_layoutsTable[i].activities.contains(Data::Layout::FREEACTIVITIESID)) {
return true;
}
}
return false;
}
bool Layouts::hasEnabledLayoutInCurrentActivity() const
{
QString curActivityId = currentActivityId();
for (int i=0; i<m_layoutsTable.rowCount(); ++i) {
if (m_layoutsTable[i].activities.contains(curActivityId)) {
return true;
}
}
return false;
}
int Layouts::rowCount() const
{
return m_layoutsTable.rowCount();
@ -120,6 +166,11 @@ int Layouts::columnCount(const QModelIndex &parent) const
return ACTIVITYCOLUMN+1;
}
QString Layouts::currentActivityId() const
{
return m_corona->activitiesConsumer()->currentActivity();
}
void Layouts::clear()
{
if (m_layoutsTable.rowCount() > 0) {
@ -734,7 +785,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
}
break;
case ACTIVITYCOLUMN:
if (role == Qt::UserRole) {
if (role == Qt::UserRole) {
setActivities(row, value.toStringList());
emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles);
return true;

@ -93,10 +93,17 @@ public:
bool inMultipleMode() const;
void setInMultipleMode(bool inMultiple);
bool hasEnabledLayout() const;
bool hasEnabledLayoutInAllActitivities() const;
bool hasEnabledLayoutInFreeActivities() const;
bool hasEnabledLayoutInCurrentActivity() const;
int rowCount() const;
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QString currentActivityId() const;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;

@ -351,7 +351,15 @@ void TabLayouts::toggleActivitiesManager()
void TabLayouts::toggleEnabledLayout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_layoutsController->inMultipleMode()) {
return;
}
m_layoutsController->toggleEnabledForSelected();
updatePerLayoutButtonsState();
}
void TabLayouts::updatePerLayoutButtonsState()

Loading…
Cancel
Save