support setData function for layouts model

--initial support for this
pull/11/head
Michail Vourlakos 5 years ago
parent 4874b254dd
commit 4428d4b083

@ -139,7 +139,7 @@ bool CheckBoxDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, con
}
const QChar CheckMark{0x2714};
return model->setData(index, value == CheckMark ? QString("") : CheckMark, Qt::DisplayRole);
return model->setData(index, value == CheckMark ? false : true, Qt::DisplayRole);
}
}

@ -275,6 +275,91 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
return QVariant{};
}
bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
{
const int row = index.row();
const int column = index.column();
if (!m_layoutsTable.rowExists(row) || column<0 || column >= SHAREDCOLUMN) {
return false;
}
QVector<int> roles;
roles << role;
//! common roles for all row cells
if (role == LAYOUTISLOCKEDROLE) {
m_layoutsTable[row].isLocked = value.toBool();
emit dataChanged(this->index(row,0), this->index(row,SHAREDCOLUMN), roles);
return true;
}
//! specific roles to each independent cell
switch (column) {
case IDCOLUMN:
if (role == Qt::DisplayRole) {
m_layoutsTable[row].id = value.toString();
emit dataChanged(index, index, roles);
return true;
}
break;
case HIDDENTEXTCOLUMN:
return true;
break;
case BACKGROUNDCOLUMN:
if (role == Qt::BackgroundRole) {
QString back = value.toString();
if (back.startsWith("/")) {
m_layoutsTable[row].background = back;
} else {
m_layoutsTable[row].background = QString();
m_layoutsTable[row].color = back;
}
emit dataChanged(index, index, roles);
return true;
}
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
m_layoutsTable[row].name = value.toString();
emit dataChanged(index, index, roles);
return true;
}
break;
case MENUCOLUMN:
if (role == Qt::DisplayRole) {
m_layoutsTable[row].isShownInMenu = value.toBool();
emit dataChanged(index, index, roles);
return true;
}
break;
case BORDERSCOLUMN:
if (role == Qt::DisplayRole) {
m_layoutsTable[row].hasDisabledBorders = value.toBool();
emit dataChanged(index, index, roles);
return true;
}
break;
case ACTIVITYCOLUMN:
if (role == Qt::UserRole) {
m_layoutsTable[row].activities = value.toStringList();
emit dataChanged(index, index, roles);
return true;
}
break;
case SHAREDCOLUMN:
if (role == Qt::UserRole) {
m_layoutsTable[row].shares = value.toStringList();
emit dataChanged(index, index, roles);
return true;
}
break;
};
return false;
}
const Data::Layout &Layouts::at(const int &row)
{
return m_layoutsTable[row];

@ -78,6 +78,7 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const override;
const Data::Layout &at(const int &row);
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void appendLayout(const Settings::Data::Layout &layout);

@ -527,9 +527,9 @@ void SettingsDialog::on_lockedButton_clicked()
return;
}
bool lockedModel = m_model->data(m_model->index(row, NAMECOLUMN), Qt::UserRole).toBool();
bool lockedModel = m_model->data(m_model->index(row, NAMECOLUMN), Settings::Model::Layouts::LAYOUTISLOCKEDROLE).toBool();
m_model->setData(m_model->index(row, NAMECOLUMN), QVariant(!lockedModel), Qt::UserRole);
m_model->setData(m_model->index(row, NAMECOLUMN), !lockedModel, Settings::Model::Layouts::LAYOUTISLOCKEDROLE);
updatePerLayoutButtonsState();
updateApplyButtonsState();

Loading…
Cancel
Save