validate layouts data to follow userrole

--all layouts table cell user Qt::UserRole as
the first role to user for their data and any
subdata should use an explicitly-set
LAYOUTUSERROLE
pull/12/head
Michail Vourlakos 5 years ago
parent f6aeea9980
commit c62ff66ffd

@ -105,6 +105,10 @@ void Layouts::initView()
m_view->horizontalHeader()->setStretchLastSection(true);
m_view->verticalHeader()->setVisible(false);
m_view->setSortingEnabled(true);
m_proxyModel->setSortRole(Qt::UserRole);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
m_view->sortByColumn(Model::Layouts::NAMECOLUMN, Qt::AscendingOrder);
//!find the available colors
@ -162,7 +166,7 @@ bool Layouts::selectedLayoutIsCurrentActive() const
const Data::Layout Layouts::selectedLayoutCurrentData() const
{
int selectedRow = m_view->currentIndex().row();
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::DisplayRole).toString();
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
return m_model->currentData(selectedId);
}
@ -170,7 +174,7 @@ const Data::Layout Layouts::selectedLayoutCurrentData() const
const Data::Layout Layouts::selectedLayoutOriginalData() const
{
int selectedRow = m_view->currentIndex().row();
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::DisplayRole).toString();
QString selectedId = m_proxyModel->data(m_proxyModel->index(selectedRow, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
return m_model->originalData(selectedId);;
}
@ -201,7 +205,7 @@ void Layouts::setInMultipleMode(bool inMultiple)
int Layouts::rowForId(QString id) const
{
for (int i = 0; i < m_proxyModel->rowCount(); ++i) {
QString rowId = m_proxyModel->data(m_proxyModel->index(i, Model::Layouts::IDCOLUMN), Qt::DisplayRole).toString();
QString rowId = m_proxyModel->data(m_proxyModel->index(i, Model::Layouts::IDCOLUMN), Qt::UserRole).toString();
if (rowId == id) {
return i;
@ -214,7 +218,7 @@ int Layouts::rowForId(QString id) const
int Layouts::rowForName(QString layoutName) const
{
for (int i = 0; i < m_proxyModel->rowCount(); ++i) {
QString rowName = m_proxyModel->data(m_proxyModel->index(i, Model::Layouts::NAMECOLUMN), Qt::DisplayRole).toString();
QString rowName = m_proxyModel->data(m_proxyModel->index(i, Model::Layouts::NAMECOLUMN), Qt::UserRole).toString();
if (rowName == layoutName) {
return i;
@ -747,7 +751,7 @@ void Layouts::save()
Data::Layout jLayout = m_model->at(j);
if (jLayout.id == fromRenamePaths[i]) {
m_model->setData(m_model->index(j, Model::Layouts::IDCOLUMN), newFile, Qt::DisplayRole);
m_model->setData(m_model->index(j, Model::Layouts::IDCOLUMN), newFile, Qt::UserRole);
}
}
}

@ -69,7 +69,7 @@ QWidget *BackgroundCmbBox::createEditor(QWidget *parent, const QStyleOptionViewI
}
}
QString value = index.model()->data(index, Qt::BackgroundRole).toString();
QString value = index.model()->data(index, Qt::UserRole).toString();
//! add the background if exists
if (value.startsWith("/")) {
@ -83,7 +83,7 @@ QWidget *BackgroundCmbBox::createEditor(QWidget *parent, const QStyleOptionViewI
void BackgroundCmbBox::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QComboBox *comboBox = static_cast<QComboBox *>(editor);
QString value = index.model()->data(index, Qt::BackgroundRole).toString();
QString value = index.model()->data(index, Qt::UserRole).toString();
int pos = Colors.indexOf(value);
@ -99,7 +99,7 @@ void BackgroundCmbBox::setModelData(QWidget *editor, QAbstractItemModel *model,
QComboBox *comboBox = static_cast<QComboBox *>(editor);
QString itemData = comboBox->currentData().toString();
model->setData(index, comboBox->currentText(), Qt::BackgroundRole);
model->setData(index, comboBox->currentText(), Qt::UserRole);
}
void BackgroundCmbBox::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
@ -115,7 +115,7 @@ void BackgroundCmbBox::paint(QPainter *painter, const QStyleOptionViewItem &opti
//! Remove the focus dotted lines
myOptions.state = (myOptions.state & ~QStyle::State_HasFocus);
QVariant background = index.data(Qt::BackgroundRole);
QVariant background = index.data(Qt::UserRole);
//! draw underlying background
QStyledItemDelegate::paint(painter, myOptions, index);

@ -57,7 +57,7 @@ void LayoutName::setEditorData(QWidget *editor, const QModelIndex &index) const
QLineEdit *lineEditor = qobject_cast<QLineEdit *>(editor);
if (lineEditor) {
QString name = index.data(Qt::DisplayRole).toString();
QString name = index.data(Qt::UserRole).toString();
lineEditor->setText(name);
}
}
@ -67,7 +67,7 @@ void LayoutName::setModelData(QWidget *editor, QAbstractItemModel *model, const
QLineEdit *lineEditor = qobject_cast<QLineEdit *>(editor);
if (lineEditor) {
model->setData(index, lineEditor->text(), Qt::DisplayRole);
model->setData(index, lineEditor->text(), Qt::UserRole);
}
}
@ -90,7 +90,7 @@ void LayoutName::paint(QPainter *painter, const QStyleOptionViewItem &option, co
if (isLocked || isShared) {
QStandardItemModel *model = (QStandardItemModel *) index.model();
QString nameText = index.data(Qt::DisplayRole).toString();
QString nameText = index.data(Qt::UserRole).toString();
bool active = Latte::isActive(option);
bool enabled = Latte::isEnabled(option);

@ -440,19 +440,19 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
switch (column) {
case IDCOLUMN:
if (role == Qt::DisplayRole) {
if (role == Qt::DisplayRole || role == Qt::UserRole){
return m_layoutsTable[row].id;
}
break;
case HIDDENTEXTCOLUMN:
return QVariant{};
case BACKGROUNDCOLUMN:
if (role == Qt::BackgroundRole) {
if (role == Qt::UserRole) {
return m_layoutsTable[row].background.isEmpty() ? m_layoutsTable[row].color : m_layoutsTable[row].background;
}
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
if ((role == Qt::DisplayRole) || (role == Qt::UserRole)) {
return m_layoutsTable[row].name;
}
break;
@ -471,12 +471,12 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
}
break;
case ACTIVITYCOLUMN:
if (role == Qt::DisplayRole || role == Qt::UserRole) {
if (role == Qt::UserRole) {
return m_layoutsTable[row].activities;
}
break;
case SHAREDCOLUMN:
if (role == Qt::DisplayRole || role == Qt::UserRole) {
if (role == Qt::UserRole) {
return m_layoutsTable[row].shares;
}
break;
@ -688,8 +688,9 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
//! specific roles to each independent cell
switch (column) {
case IDCOLUMN:
if (role == Qt::DisplayRole) {
if (role==Qt::UserRole) {
setId(row, value.toString());
emit dataChanged(index, index, roles);
return true;
}
break;
@ -697,7 +698,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
return true;
break;
case BACKGROUNDCOLUMN:
if (role == Qt::BackgroundRole) {
if (role == Qt::UserRole) {
QString back = value.toString();
if (back.startsWith("/")) {
@ -711,7 +712,7 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
}
break;
case NAMECOLUMN:
if (role == Qt::DisplayRole) {
if (role == Qt::UserRole) {
QString provenId = m_layoutsTable.idForName(value.toString());
if (!provenId.isEmpty() && provenId != m_layoutsTable[row].id /*not the same row*/ ){
@ -726,14 +727,14 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
}
break;
case MENUCOLUMN:
if (role == Qt::DisplayRole || role == Qt::UserRole) {
if (role == Qt::UserRole) {
m_layoutsTable[row].isShownInMenu = value.toBool();
emit dataChanged(index, index, roles);
return true;
}
break;
case BORDERSCOLUMN:
if (role == Qt::DisplayRole || role == Qt::UserRole) {
if (role == Qt::UserRole) {
m_layoutsTable[row].hasDisabledBorders = value.toBool();
emit dataChanged(index, index, roles);
return true;

Loading…
Cancel
Save