make SHARETOINEDITROLE proxy model capable

pull/12/head
Michail Vourlakos 5 years ago
parent 50ed071d93
commit 688a45289a

@ -633,9 +633,13 @@ bool Layouts::importLayoutsFromV1ConfigFile(QString file)
return false; return false;
} }
void Layouts::on_sharedToInEditChanged(const int &row, const bool &inEdit) void Layouts::on_sharedToInEditChanged(const QString &id, const bool &inEdit)
{ {
m_model->setData(m_model->index(row, Model::Layouts::SHAREDCOLUMN), inEdit, Model::Layouts::SHAREDTOINEDIT); int row = m_model->rowForId(id);
if (row >= 0) {
m_model->setData(m_model->index(row, Model::Layouts::SHAREDCOLUMN), inEdit, Model::Layouts::SHAREDTOINEDITROLE);
}
} }
void Layouts::reset() void Layouts::reset()

@ -96,7 +96,7 @@ signals:
public slots: public slots:
//! needed for Delegate::Shared //! needed for Delegate::Shared
void on_sharedToInEditChanged(const int &row, const bool &inEdit); void on_sharedToInEditChanged(const QString &row, const bool &inEdit);
private slots: private slots:
void loadConfig(); void loadConfig();

@ -244,7 +244,7 @@ void Activities::paint(QPainter *painter, const QStyleOptionViewItem &option, co
painter->restore(); painter->restore();
} else { } else {
bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDIT).toBool(); bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDITROLE).toBool();
// Disabled // Disabled
bool isSelected{Latte::isSelected(option)}; bool isSelected{Latte::isSelected(option)};

@ -90,7 +90,7 @@ QWidget *Shared::createEditor(QWidget *parent, const QStyleOptionViewItem &optio
updateButtonText(button, index); updateButtonText(button, index);
m_controller->on_sharedToInEditChanged(index.row(), true); m_controller->on_sharedToInEditChanged(layoutId, true);
return button; return button;
} }
@ -114,7 +114,8 @@ void Shared::setModelData(QWidget *editor, QAbstractItemModel *model, const QMod
model->setData(index, assignedLayouts, Qt::UserRole); model->setData(index, assignedLayouts, Qt::UserRole);
m_controller->on_sharedToInEditChanged(index.row(), false); QString layoutId = index.data(Model::Layouts::IDROLE).toString();
m_controller->on_sharedToInEditChanged(layoutId, false);
} }
void Shared::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const void Shared::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
@ -126,7 +127,7 @@ void Shared::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &o
void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{ {
bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDIT).toBool(); bool sharedInEdit = index.data(Model::Layouts::SHAREDTOINEDITROLE).toBool();
Data::LayoutsTable allLayouts = qvariant_cast<Data::LayoutsTable>(index.data(Model::Layouts::ALLLAYOUTSROLE)); Data::LayoutsTable allLayouts = qvariant_cast<Data::LayoutsTable>(index.data(Model::Layouts::ALLLAYOUTSROLE));
QStringList assignedIds = index.data(Qt::UserRole).toStringList(); QStringList assignedIds = index.data(Qt::UserRole).toStringList();
QStringList originalIds = index.data(Model::Layouts::ORIGINALSHARESROLE).toStringList(); QStringList originalIds = index.data(Model::Layouts::ORIGINALSHARESROLE).toStringList();
@ -144,7 +145,7 @@ void Shared::paint(QPainter *painter, const QStyleOptionViewItem &option, const
myOptions.state = (myOptions.state & ~QStyle::State_HasFocus); myOptions.state = (myOptions.state & ~QStyle::State_HasFocus);
painter->save(); painter->save();
if (assignedLayouts.rowCount() > 0) { if (assignedLayouts.rowCount() > 0 && !sharedInEdit) {
//! indicator //! indicator
if (!sharedInEdit) { if (!sharedInEdit) {
paintSharedToIndicator(painter, myOptions, index); paintSharedToIndicator(painter, myOptions, index);

@ -476,7 +476,7 @@ QVariant Layouts::data(const QModelIndex &index, int role) const
QVariant layouts; QVariant layouts;
layouts.setValue(m_layoutsTable); layouts.setValue(m_layoutsTable);
return layouts; return layouts;
} else if (role == SHAREDTOINEDIT) { } else if (role == SHAREDTOINEDITROLE) {
return (m_sharedToInEditRow == row); return (m_sharedToInEditRow == row);
} else if (role == ISNEWLAYOUTROLE) { } else if (role == ISNEWLAYOUTROLE) {
return isNewLayout; return isNewLayout;
@ -884,11 +884,12 @@ bool Layouts::setData(const QModelIndex &index, const QVariant &value, int role)
setShares(row, value.toStringList()); setShares(row, value.toStringList());
emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles);
return true; return true;
} else if (role == SHAREDTOINEDIT) { } else if (role == SHAREDTOINEDITROLE) {
bool inEdit = value.toBool(); bool inEdit = value.toBool();
m_sharedToInEditRow = inEdit ? row : -1; m_sharedToInEditRow = inEdit ? row : -1;
roles << Qt::DisplayRole; roles << Qt::DisplayRole;
roles << Qt::UserRole; roles << Qt::UserRole;
roles << SHAREDTOINEDITROLE;
emit dataChanged(this->index(row, ACTIVITYCOLUMN), this->index(row, SHAREDCOLUMN), roles); emit dataChanged(this->index(row, ACTIVITYCOLUMN), this->index(row, SHAREDCOLUMN), roles);
emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles); emit dataChanged(this->index(row, NAMECOLUMN), this->index(row,NAMECOLUMN), roles);
return true; return true;

@ -67,7 +67,7 @@ public:
ALLACTIVITIESSORTEDROLE, ALLACTIVITIESSORTEDROLE,
ALLACTIVITIESDATAROLE, ALLACTIVITIESDATAROLE,
ALLLAYOUTSROLE, ALLLAYOUTSROLE,
SHAREDTOINEDIT, SHAREDTOINEDITROLE,
SORTINGROLE, SORTINGROLE,
ISNEWLAYOUTROLE, ISNEWLAYOUTROLE,
LAYOUTHASCHANGESROLE, LAYOUTHASCHANGESROLE,
@ -173,7 +173,7 @@ private:
//! break MVC only when a SharedTo editor is created //! break MVC only when a SharedTo editor is created
//! because we want to move the dot indicator in the Activities delegate //! because we want to move the dot indicator in the Activities delegate
//! when that happens //! when that happens
int m_sharedToInEditRow{-1}; int m_sharedToInEditRow;
QString m_iconsPath; QString m_iconsPath;

Loading…
Cancel
Save