Commit a0d70929 authored by Fabian Vogt's avatar Fabian Vogt
Browse files

Handle process parent changes in ProcessDataModel

When the PPID of a process changes, it moves around in the model, changing the
layout. This needs to be announced properly, otherwise users of the model get
confused, leading to weird behaviour and crashes.

The added code is pretty much a direct copy from ProcessModel.

BUG: 446534
parent e502f539
Pipeline #107208 passed with stage
in 1 minute and 19 seconds
......@@ -24,6 +24,8 @@ public:
Private(ProcessDataModel *q);
void beginInsertRow(KSysGuard::Process *parent);
void endInsertRow();
void beginMoveProcess(KSysGuard::Process *process, KSysGuard::Process *new_parent);
void endMoveProcess();
void beginRemoveRow(KSysGuard::Process *process);
void endRemoveRow();
......@@ -65,6 +67,12 @@ ProcessDataModel::Private::Private(ProcessDataModel *_q)
connect(m_processes.get(), &KSysGuard::Processes::endAddProcess, q, [this]() {
endInsertRow();
});
connect(m_processes.get(), &KSysGuard::Processes::beginMoveProcess, q, [this](KSysGuard::Process *process, KSysGuard::Process *new_parent) {
beginMoveProcess(process, new_parent);
});
connect(m_processes.get(), &KSysGuard::Processes::endMoveProcess, q, [this]() {
endMoveProcess();
});
connect(m_processes.get(), &KSysGuard::Processes::beginRemoveProcess, q, [this](KSysGuard::Process *process) {
beginRemoveRow(process);
});
......@@ -335,6 +343,27 @@ void ProcessDataModel::Private::endRemoveRow()
q->endRemoveRows();
}
void ProcessDataModel::Private::beginMoveProcess(KSysGuard::Process *process, KSysGuard::Process *new_parent)
{
if (m_flatList)
return; // We don't need to move processes when in simple mode
int current_row = process->parent()->children().indexOf(process);
Q_ASSERT(current_row != -1);
int new_row = new_parent->children().count();
QModelIndex sourceParent = getQModelIndex(process->parent(), 0);
QModelIndex destinationParent = getQModelIndex(new_parent, 0);
q->beginMoveRows(sourceParent, current_row, current_row, destinationParent, new_row);
}
void ProcessDataModel::Private::endMoveProcess()
{
if (m_flatList)
return; // We don't need to move processes when in simple mode
q->endMoveRows();
}
void ProcessDataModel::Private::update()
{
Processes::UpdateFlags flags;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment